| | |
| | | package com.ycl.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.common.base.Result; |
| | | import com.ycl.common.utils.DateUtils; |
| | | import com.ycl.domain.entity.Plan; |
| | | import com.ycl.domain.entity.ProjectPlanInfo; |
| | | import com.ycl.domain.entity.ProjectPlanRecord; |
| | | import com.ycl.domain.form.ProjectPlanRecordAddRequestForm; |
| | | import com.ycl.domain.form.ProjectPlanRecordForm; |
| | | import com.ycl.domain.query.ProjectPlanRecordQuery; |
| | | import com.ycl.domain.vo.ProjectPlanRecordResponseVO; |
| | | import com.ycl.domain.vo.ProjectPlanRecordVO; |
| | | import com.ycl.framework.utils.PageUtil; |
| | | import com.ycl.mapper.PlanMapper; |
| | | import com.ycl.mapper.ProjectPlanInfoMapper; |
| | | import com.ycl.mapper.ProjectPlanRecordMapper; |
| | | import com.ycl.service.ProjectPlanRecordService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.domain.form.ProjectPlanRecordForm; |
| | | import com.ycl.domain.vo.ProjectPlanRecordVO; |
| | | import com.ycl.domain.query.ProjectPlanRecordQuery; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @RequiredArgsConstructor |
| | | public class ProjectPlanRecordServiceImpl extends ServiceImpl<ProjectPlanRecordMapper, ProjectPlanRecord> implements ProjectPlanRecordService { |
| | | |
| | | private static final Integer MONTH_FLAG = 0; |
| | | private static final Integer SEASON_FLAG = 1; |
| | | private static final Integer YEAR_FLAG = 2; |
| | | |
| | | private final ProjectPlanRecordMapper projectPlanRecordMapper; |
| | | private final PlanMapper planMapper; |
| | | private final ProjectPlanInfoMapper projectPlanInfoMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result add(ProjectPlanRecordForm form) { |
| | | ProjectPlanRecord entity = ProjectPlanRecordForm.getEntityByForm(form, null); |
| | | baseMapper.insert(entity); |
| | | public Result add(ProjectPlanRecordAddRequestForm form) { |
| | | ProjectPlanRecord item = new ProjectPlanRecord(); |
| | | // 查询项目计划id |
| | | item.setPlanId(new LambdaQueryChainWrapper<>(planMapper).eq(Plan::getProjectInfoId, form.getProjectInfoId()).one().getId()); |
| | | // 判断标志位是否为0,如果为0,则为月度计划,1为季度计划,2为年度计划 |
| | | if (form.getPlanTimeFlag() == MONTH_FLAG) { |
| | | // 判断id是否为0 |
| | | if (form.getId() == 0) { |
| | | // 新增月度计划 |
| | | item.setProjectInfoId(form.getProjectInfoId()); |
| | | item.setPlanTime(LocalDate.now().getMonthValue()); |
| | | item.setPlanTimeFlag(MONTH_FLAG); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | } else { |
| | | // 新增月度计划 |
| | | item = baseMapper.selectById(form.getId()); |
| | | item.setId(null); |
| | | Integer planTime = item.getPlanTime(); |
| | | item.setPlanTime(planTime == 12 ? 1 : planTime + 1); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | item.setActualInvest(null); |
| | | } |
| | | } else if (form.getPlanTimeFlag() == SEASON_FLAG) { |
| | | // 判断id是否为0 |
| | | if (form.getId() == 0) { |
| | | // 新增季度计划 |
| | | item.setProjectInfoId(form.getProjectInfoId()); |
| | | item.setPlanTime(1); |
| | | item.setPlanTimeFlag(SEASON_FLAG); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | } else { |
| | | // 新增季度计划 |
| | | item = baseMapper.selectById(form.getId()); |
| | | item.setId(null); |
| | | item.setPlanTime(item.getPlanTime() + 1); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | item.setActualInvest(null); |
| | | } |
| | | }else { |
| | | // 判断id是否为0 |
| | | if (form.getId() == 0) { |
| | | // 新增年度计划 |
| | | item.setProjectInfoId(form.getProjectInfoId()); |
| | | item.setPlanTime(LocalDate.now().getYear()); |
| | | item.setPlanTimeFlag(YEAR_FLAG); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | } else { |
| | | // 新增年计划 |
| | | item = baseMapper.selectById(form.getId()); |
| | | item.setId(null); |
| | | item.setPlanTime(item.getPlanTime() + 1); |
| | | item.setCreateTime(DateUtils.getNowDate()); |
| | | item.setReportStatus(1); |
| | | item.setActualInvest(null); |
| | | } |
| | | } |
| | | baseMapper.insertItem(item); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | public Result removeById(Long id) { |
| | | // 删除计划记录 |
| | | baseMapper.deleteById(id); |
| | | // 删除计划项 |
| | | new LambdaUpdateChainWrapper<>(projectPlanInfoMapper) |
| | | .eq(ProjectPlanInfo::getProjectPlanRecordId, id) |
| | | .remove(); |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result detail(Integer id) { |
| | | ProjectPlanRecordVO vo = baseMapper.getById(id); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | public Result detail(Long id) { |
| | | ProjectPlanRecordResponseVO vo = new ProjectPlanRecordResponseVO(); |
| | | // 获取月度计划 |
| | | vo.setMonthRecords(baseMapper.selectPlanList(id, MONTH_FLAG)); |
| | | // 获取季度计划 |
| | | vo.setSeasonRecords(baseMapper.selectPlanList(id, SEASON_FLAG)); |
| | | // 获取年度计划 |
| | | vo.setYearRecords(baseMapper.selectPlanList(id, YEAR_FLAG)); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |