business/src/main/java/com/ycl/service/impl/ProjectPlanInfoServiceImpl.java
@@ -9,8 +9,8 @@
import com.ycl.domain.entity.ProjectPlanInfo;
import com.ycl.domain.entity.ProjectPlanRecord;
import com.ycl.domain.form.ProjectPlanInfoForm;
import com.ycl.domain.form.ProjectPlanInfoRequestForm;
import com.ycl.domain.query.ProjectPlanInfoQuery;
import com.ycl.domain.vo.ProjectPlanInfoRequest;
import com.ycl.domain.vo.ProjectPlanInfoResponseVO;
import com.ycl.domain.vo.ProjectPlanInfoVO;
import com.ycl.framework.utils.PageUtil;
@@ -20,11 +20,9 @@
import com.ycl.service.ProjectPlanInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
@@ -113,7 +111,7 @@
     * @return
     */
    @Override
    public Result detail(Integer id) {
    public Result detail(Long id) {
        ProjectPlanInfoResponseVO vo = new ProjectPlanInfoResponseVO();
        vo.setList(new LambdaQueryChainWrapper<>(baseMapper).eq(ProjectPlanInfo::getProjectPlanRecordId, id).list());
        vo.setActualInvest(new LambdaQueryChainWrapper<>(projectPlanRecordMapper).eq(ProjectPlanRecord::getId, id).one().getActualInvest());
@@ -135,19 +133,16 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result addPlanInfo(ProjectPlanInfoRequest request) {
        if (CollectionUtils.isEmpty(request.getAddList())) {{
            return Result.error("请选择要添加的计划项");
        }}
    public Result addPlanInfo(ProjectPlanInfoRequestForm form) {
        // 删除原有记录
        new LambdaUpdateChainWrapper<>(baseMapper)
                .eq(ProjectPlanInfo::getProjectPlanRecordId, request.getProjectPlanRecordId())
                .eq(ProjectPlanInfo::getProjectPlanRecordId, form.getProjectPlanRecordId())
                .remove();
        // 批量插入新记录
        List<ProjectPlanInfo> list = new ArrayList<>();
        request.getAddList().forEach(item -> {
        form.getAddList().forEach(item -> {
            ProjectPlanInfo projectPlanInfo = new ProjectPlanInfo();
            projectPlanInfo.setProjectPlanRecordId(request.getProjectPlanRecordId().longValue());
            projectPlanInfo.setProjectPlanRecordId(form.getProjectPlanRecordId());
            projectPlanInfo.setTitle(item.getTitle()); // 计划项标题
            projectPlanInfo.setPlanStatus(0); // 计划项状态为未开始
            projectPlanInfo.setProgressStatus(0); // 计划项进度为未开始
@@ -158,36 +153,37 @@
        this.saveBatch(list);
        // 更新计划记录的投资,以及上报状态
        new LambdaUpdateChainWrapper<>(projectPlanRecordMapper)
                .eq(ProjectPlanRecord::getId, request.getProjectPlanRecordId())
                .set(ProjectPlanRecord::getActualInvest, request.getActualInvest())
                .eq(ProjectPlanRecord::getId, form.getProjectPlanRecordId())
                .set(ProjectPlanRecord::getActualInvest, form.getActualInvest())
                .set(ProjectPlanRecord::getReportStatus, 0)
                .update();
        // 新增一条审核记录
        ProjectPlanExamineRecord item = new ProjectPlanExamineRecord();
        item.setProjectPlanRecordId(request.getProjectPlanRecordId());
        item.setEventType(0); // 计划上报
        list.stream().forEach(i -> {
        for (ProjectPlanInfo i : list){
            ProjectPlanExamineRecord item = new ProjectPlanExamineRecord();
            item.setProjectPlanRecordId(form.getProjectPlanRecordId());
            item.setEventType(0); // 计划上报
            item.setProjectPlanInfoId(i.getId());
            projectPlanExamineRecordMapper.insert(item);
        });
        }
        return Result.ok("添加成功");
    }
    @Override
    public Result savePlanInfo(ProjectPlanInfo item, Integer planRecordId) {
        item.setProjectPlanRecordId(planRecordId.longValue()); // 项目计划记录id
        item.setProgressStatus(0); // 未开始
        item.setDeleted(0); // 未删除
        item.setPlanStatus(0); // 未审核
    public Result savePlanInfo(ProjectPlanInfoForm form, Long planRecordId) {
        ProjectPlanInfo entity = new ProjectPlanInfo();
        BeanUtils.copyProperties(form, entity);
        entity.setProjectPlanRecordId(planRecordId); // 项目计划记录id
        entity.setProgressStatus(0); // 未开始
        entity.setPlanStatus(0); // 未审核
        // 判断id是否存在,存在则更新,不存在则新增
        if (item.getId() == null) {
            baseMapper.insert(item);
        if (entity.getId() == null) {
            baseMapper.insert(entity);
        } else {
            new LambdaUpdateChainWrapper<>(baseMapper).eq(ProjectPlanInfo::getId, item.getId())
                    .set(ProjectPlanInfo::getTitle, item.getTitle())
                    .set(ProjectPlanInfo::getStartTime, item.getStartTime())
                    .set(ProjectPlanInfo::getEndTime, item.getEndTime())
            new LambdaUpdateChainWrapper<>(baseMapper).eq(ProjectPlanInfo::getId, entity.getId())
                    .set(ProjectPlanInfo::getTitle, entity.getTitle())
                    .set(ProjectPlanInfo::getStartTime, entity.getStartTime())
                    .set(ProjectPlanInfo::getEndTime, entity.getEndTime())
                    .update();
        }
        return Result.ok("保存成功");
@@ -202,20 +198,25 @@
                .set(ProjectPlanInfo::getStartTime, request.getStartTime())
                .set(ProjectPlanInfo::getEndTime, request.getEndTime())
                .update();
        // 新增一条审核记录
        ProjectPlanExamineRecord item = new ProjectPlanExamineRecord();
        item.setProjectPlanRecordId(request.getProjectPlanRecordId().longValue());
        item.setProjectPlanInfoId(request.getId().longValue());
        // 查询出原来的审核记录
        ProjectPlanExamineRecord item = new LambdaQueryChainWrapper<>(projectPlanExamineRecordMapper)
                .eq(ProjectPlanExamineRecord::getProjectPlanInfoId, request.getId())
                .eq(ProjectPlanExamineRecord::getProjectPlanRecordId, request.getProjectPlanRecordId())
                .ne(ProjectPlanExamineRecord::getEventType, 2)
                .eq(ProjectPlanExamineRecord::getDeleted, 0) // 未删除
                .orderByDesc(ProjectPlanExamineRecord::getGmtCreate)
                .last("LIMIT 1")
                .one();
        // 更新原来的审核记录
        item.setEventType(1);
        item.setDelayStartTime(request.getStartTime());
        item.setDelayEndTime(request.getEndTime());
        item.setGmtCreate(new Date());
        item.setDeleted(0);
        projectPlanExamineRecordMapper.insertOne(item);
        projectPlanExamineRecordMapper.updateById(item);
        return Result.ok("延期成功");
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result resubmitPlanInfo(ProjectPlanInfoForm form) {
        // 更新重新上报后的内容
        new LambdaUpdateChainWrapper<>(baseMapper)
@@ -228,14 +229,11 @@
        // 新增一条计划上报的审核记录
        ProjectPlanExamineRecord item = new ProjectPlanExamineRecord();
        item.setProjectPlanRecordId(form.getProjectPlanRecordId().longValue());
        item.setProjectPlanInfoId(form.getId().longValue());
        item.setProjectPlanRecordId(form.getProjectPlanRecordId());
        item.setProjectPlanInfoId(form.getId());
        item.setEventType(0); // 计划上报
        item.setDelayStartTime(form.getStartTime());
        item.setDelayEndTime(form.getEndTime());
        item.setGmtCreate(new Date());
        item.setDeleted(0); // 未删除
        projectPlanExamineRecordMapper.insertOne(item);
        projectPlanExamineRecordMapper.insert(item);
        return Result.ok("重新上报成功");
    }
}