| | |
| | | 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.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.system.domain.SysUserLevelInsurance; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelInsuranceDto; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelInsuranceQueryCriteria; |
| | | import me.zhengjie.utils.*; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import me.zhengjie.modules.treatment.service.dto.UserInsuranceQueryCriteria; |
| | | import me.zhengjie.modules.treatment.service.mapstruct.UserInsuranceGenMapper; |
| | | import me.zhengjie.modules.treatment.service.mapstruct.UserInsuranceMapper; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | } |
| | | |
| | | @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 |
| | | @Transactional |
| | | public UserInsuranceDto findById(Long id) { |
| | | UserInsurance userInsurance = userInsuranceRepository.findById(id).orElseGet(UserInsurance::new); |