“zhuo”
2023-08-11 e72b3ab95aace19535fe596897822f0e334de5d6
cnas-server/src/main/java/com/yuanchu/limslaboratory/service/impl/CnasAnnualPlanServiceImpl.java
@@ -2,6 +2,7 @@
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -11,6 +12,7 @@
import com.yuanchu.limslaboratory.service.CnasAnnualPlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.Date;
@@ -31,19 +33,60 @@
    /**
     * 查询审核计划
     *
     * @return
     */
    @Override
    public IPage<CnasAnnualPlanVo> selectAllList(Page<Object> objectPage, Date beginTime, Date endTime) {
        IPage<CnasAnnualPlanVo> page = cnasAnnualPlanMapper.selectAllList(objectPage, beginTime, endTime);
    public IPage<CnasAnnualPlanVo> selectAllList(Page<Object> objectPage, Date planTime) {
        //判断是否有日期
        Integer yearTime = null;
        Integer monthTime = null;
        if (planTime != null) {
            yearTime = DateUtil.year(planTime);
            monthTime = DateUtil.month(planTime) + 2;
        }
        IPage<CnasAnnualPlanVo> page = cnasAnnualPlanMapper.selectAllList(objectPage, yearTime, monthTime);
        page.getRecords().forEach(cnasAnnualPlanVo -> {
            //获取计划时间
            Date time = cnasAnnualPlanVo.getPlanTime();
            //添加年
            //添加年月
            cnasAnnualPlanVo.setYear(DateUtil.year(time));
            //添加月
            cnasAnnualPlanVo.setMonth(DateUtil.month(time) + 1);
            //判断审核状态
            //获取当前时间
            Date nowDate = new Date();
            //获取当前的年月
            int year = DateUtil.year(nowDate);
            int month = DateUtil.month(nowDate) + 1;
            if (cnasAnnualPlanVo.getAuditTime() == null && month > cnasAnnualPlanVo.getMonth() || year > cnasAnnualPlanVo.getYear()) {
                cnasAnnualPlanVo.setAuditState(2);
            } else if (cnasAnnualPlanVo.getAuditTime() != null) {
                cnasAnnualPlanVo.setAuditState(1);
            } else {
                cnasAnnualPlanVo.setAuditState(0);
            }
        });
        return page;
    }
    /**
     * 上传附件
     */
    @Override
    public void addAccessory(String name, Date auditTime, MultipartFile file) {
        //todo: 上传附件未完成
    }
    /**
     * 删除年度计划
     *
     * @return
     */
    @Override
    public Integer deleteCnasAnnualPlan(Integer planId) {
        LambdaUpdateWrapper<CnasAnnualPlan> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(CnasAnnualPlan::getId, planId);
        updateWrapper.set(CnasAnnualPlan::getState, 0);
        return cnasAnnualPlanMapper.update(new CnasAnnualPlan(), updateWrapper);
    }
}