| | |
| | | package com.ycl.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ycl.common.base.Result; |
| | | import com.ycl.common.enums.business.ProjectCategoryEnum; |
| | | import com.ycl.common.enums.business.ProjectStatusEnum; |
| | | import com.ycl.common.enums.business.ProjectTypeEnum; |
| | | import com.ycl.common.utils.DateUtils; |
| | | import com.ycl.domain.entity.Plan; |
| | | import com.ycl.domain.vo.ProjectPlanResponseVO; |
| | | import com.ycl.domain.vo.ProjetPlanRecordItem; |
| | | import com.ycl.framework.utils.PageUtil; |
| | | import com.ycl.mapper.PlanMapper; |
| | | import com.ycl.mapper.ProjectPlanRecordMapper; |
| | | import com.ycl.service.PlanService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.domain.form.PlanForm; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements PlanService { |
| | | |
| | | private final PlanMapper planMapper; |
| | | private final ProjectPlanRecordServiceImpl projectPlanRecordServiceImpl; |
| | | private final ProjectPlanRecordMapper projectPlanRecordMapper; |
| | | |
| | | private static final Integer MONTH_FLAG = 0; |
| | | private static final Integer SEASON_FLAG = 1; |
| | | private static final Integer YEAR_FLAG = 2; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | @Override |
| | | public Result page(PlanQuery query) { |
| | | IPage<ProjectPlanResponseVO> page = PageUtil.getPage(query, ProjectPlanResponseVO.class); |
| | | baseMapper.getPage(page, query); |
| | | baseMapper.getPage(query, page); |
| | | // 对分页后的属性进行处理 |
| | | List<ProjectPlanResponseVO> records = page.getRecords(); |
| | | for (ProjectPlanResponseVO record : records) { |
| | |
| | | record.setProjectStatus(ProjectStatusEnum.getDescByType(record.getProjectStatus())); |
| | | record.setProjectColorCode("green"); |
| | | } |
| | | |
| | | updateException(records); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | // 对查询后的结果进行异常问题更新 |
| | | public void updateException(List<ProjectPlanResponseVO> records) { |
| | | records.forEach(record -> { |
| | | if (null != record.getProjectPhase() && record.getProjectPhase().equals(ProjectCategoryEnum.IMPLEMENT.getDesc())){ // 实施阶段 |
| | | List<ProjetPlanRecordItem> month = projectPlanRecordMapper.selectPlanList(record.getId(), MONTH_FLAG); |
| | | List<ProjetPlanRecordItem> season = projectPlanRecordMapper.selectPlanList(record.getId(), SEASON_FLAG); |
| | | List<ProjetPlanRecordItem> year = projectPlanRecordMapper.selectPlanList(record.getId(), YEAR_FLAG); |
| | | |
| | | Date now = DateUtils.getNowDate(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 月度判断 |
| | | if (month.size() > 0) { |
| | | Integer planMonth = month.get(month.size() - 1).getPlanTime(); |
| | | calendar.setTime(now); |
| | | calendar.add(Calendar.DAY_OF_MONTH, 3); |
| | | int monthAfterThreeDays = calendar.get(Calendar.MONTH) + 1; |
| | | |
| | | if ((planMonth < 12 && planMonth < monthAfterThreeDays)) { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | }else if((planMonth == 12 && monthAfterThreeDays == 1)){ |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, null) |
| | | .update(); |
| | | } |
| | | }else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | |
| | | if (season.size() > 0) { |
| | | // 季度判断 |
| | | int seasonNum =season.get(season.size() - 1).getPlanTime(); |
| | | Date createTime = season.get(0).getCreateTime(); |
| | | calendar.setTime(createTime); |
| | | calendar.add(Calendar.MONTH, seasonNum * 3); |
| | | Date createTimeAfterMonths = calendar.getTime(); |
| | | // 计算两个日期之间的差值,单位为毫秒 |
| | | long diffInMillies = createTimeAfterMonths.getTime() - now.getTime(); |
| | | // 将差值转换为天数 |
| | | long diffInDays = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS); |
| | | if (diffInDays < 3) { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | }else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, null) |
| | | .update(); |
| | | } |
| | | }else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | |
| | | if (year.size() > 0) { |
| | | // 年度判断 |
| | | Integer planYear = year.get(year.size() - 1).getPlanTime(); |
| | | calendar.setTime(now); |
| | | calendar.add(Calendar.DAY_OF_YEAR, 3); // 添加3天 |
| | | int planYearAfter3Days = calendar.get(Calendar.YEAR); |
| | | if (planYearAfter3Days > planYear) { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | }else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, null) |
| | | .update(); |
| | | } |
| | | }else { |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | |
| | | month.forEach(item -> { |
| | | if (item.getReportStatus() == 1) { // 未上报 |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | }); |
| | | season.forEach(item -> { |
| | | if (item.getReportStatus() == 1) { // 未上报 |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | }); |
| | | year.forEach(item -> { |
| | | if (item.getReportStatus() == 1) { // 未上报 |
| | | new LambdaUpdateChainWrapper<>(planMapper) |
| | | .eq(Plan::getProjectInfoId, record.getId()) |
| | | .set(Plan::getException, 0) |
| | | .update(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result detail(Integer id) { |
| | | public Result detail(Long id) { |
| | | PlanVO vo = baseMapper.getById(id); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | return Result.ok().data(vo); |