| | |
| | | */ |
| | | package me.zhengjie.modules.treatment.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DeptRepository; |
| | |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | @Override |
| | | public List<UserInsuranceDto> queryAll(UserInsuranceQueryCriteria criteria){ |
| | | return userInsuranceMapper.toDto(userInsuranceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); |
| | | } |
| | | |
| | | @Override |
| | | public UserInsuranceDto queryTargetYearMonth(UserInsuranceQueryCriteria criteria) throws ParseException { |
| | | |
| | | // 获取前台传递的时间 |
| | | String yearMonth = criteria.getTargetYearMonth().substring(0,7); |
| | | // 查询用户 |
| | | User user = userRepository.findById(criteria.getUserId()).orElseGet(User::new); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 获取员工的添加时间 |
| | | calendar.setTime(user.getCreateTime()); |
| | | int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); |
| | | int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | if (dayOfMonth <= daysInMonth / 2) { |
| | | calendar.add(Calendar.MONTH, user.getInternshipTime() == null ? 3 : user.getInternshipTime()); |
| | | } else { |
| | | calendar.add(Calendar.MONTH, user.getInternshipTime() == null ? 4 : user.getInternshipTime() + 1); |
| | | } |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | // 获取转正时间 |
| | | String confirmationTime = new Timestamp(calendar.getTimeInMillis()).toString().substring(0, 7); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | | Date date1 = format.parse(yearMonth); |
| | | Date date2 = format.parse(confirmationTime); |
| | | UserInsurance userInsuranceOpt = null; |
| | | // 如果传递的时间在转正时间之前 |
| | | if(date1.before(date2)) { |
| | | // 查询没转正的日期数据 |
| | | userInsuranceOpt = userInsuranceRepository.findbyUserIdAndNotEqualTo(criteria.getUserId(), confirmationTime); |
| | | } else { |
| | | // 查询第二条转正后的数据 |
| | | userInsuranceOpt = userInsuranceRepository.findbyUserIdAndDate(criteria.getUserId(), confirmationTime); |
| | | } |
| | | // 判断查询结果 |
| | | if (userInsuranceOpt != null) { |
| | | // 返回 |
| | | return userInsuranceMapper.toDto(userInsuranceOpt); |
| | | } else { |
| | | throw new RuntimeException("没有获取到当前员工的级别信息!"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional |
| | | public void generate(UserInsuranceGenerateParam param) { |
| | | List<User> userList = null; |
| | | List<Long> deptIds = param.getNodes().stream().filter(node -> node.getLeaf() == false).map(node -> node.getId()).collect(Collectors.toList()); |
| | | List<Long> deptIdAlls = deptService.getDeptChildren(deptRepository.findByIdIn(deptIds)); |
| | | userList = userRepository.findByDeptIdInAndEnabled(deptIdAlls, true); |
| | | // if (param.getUserIds() != null && param.getUserIds().size() > 0) { |
| | | // userList = userRepository.findByIdIn(param.getUserIds()); |
| | | // } else { |
| | | // userList = userRepository.findAllByEnabled(true); |
| | | // } |
| | | List<Long> userIds = param.getNodes().stream().filter(node -> node.getLeaf() == true).map(node -> node.getId()).collect(Collectors.toList()); |
| | | userList.addAll(userRepository.findByIdIn(userIds)); |
| | | List<User> userList = userRepository.findByIdIn(param.getNodes()); |
| | | userList.stream().forEach(user -> { |
| | | Optional<CmnInsurance> cmnInsuranceOpt = cmnInsuranceRepository.findByCompany(user.getCompany()); |
| | | if (cmnInsuranceOpt.isPresent()) { |