XiaoRuby
2023-08-19 d0a6fc23f31f924cb1744397478dc4c7c57c04e1
inspection-server/src/main/java/com/yuanchu/limslaboratory/service/impl/PlanServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,61 @@
package com.yuanchu.limslaboratory.service.impl;
import com.yuanchu.limslaboratory.mapper.PlanMapper;
import com.yuanchu.limslaboratory.pojo.vo.PlanVo;
import com.yuanchu.limslaboratory.service.PlanService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
 * <p>
 * æœåŠ¡å®žçŽ°ç±»
 * </p>
 *
 * @author æ±Ÿè‹éµ·é›ç½‘络科技有限公司
 * @since 2023-08-09
 */
@Service
public class PlanServiceImpl implements PlanService {
    @Resource
    private PlanMapper planMapper;
    /**
     * æŸ¥è¯¢æ£€éªŒè®¡åˆ’
     *
     * @return
     */
    @Override
    public List<PlanVo> selectAllPlan(String device, Date beginTime, Date endTime, String user) {
        //获取数据库数据
        List<PlanVo> planVos = planMapper.selectAllPlan(device, beginTime, endTime, user);
        //添加计划工期和检验进度
        planVos.forEach(planVo -> {
            //添加检验进度
            //判断是否是已完成
            if (planVo.getState() != null) {
                planVo.setProgress(100);
            }
            //判断是否是未分配
            if (planVo.getCheckproject() == null) {
                planVo.setProgress(0);
            }
            //判断是否是进行中
            if (planVo.getState() == null && planVo.getCheckproject() != null) {
                planVo.setProgress(50);
            }
            //添加计划工期
            if (planVo.getFinishtime() != null && planVo.getStarttime() != null) {
                long startTimeInMillis = planVo.getStarttime().getTime();
                long endTimeInMillis = planVo.getFinishtime().getTime();
                long durationInMillis = endTimeInMillis - startTimeInMillis;
                long duration = durationInMillis / (1000 * 60 * 60);
                planVo.setDuration(Integer.valueOf((int) duration));
            }
        });
        return planVos;
    }
}