Browse Source

修改防错统计和导出等信息

baihe 3 years ago
parent
commit
9079160628
19 changed files with 225 additions and 123 deletions
  1. 2 2
      application-facade/src/main/java/com/factory/controller/wx/StatisticsController.java
  2. 9 0
      application-facade/src/main/java/com/factory/web/entity/pm/req/SearchCheckRecordReq.java
  3. 11 0
      application-facade/src/main/java/com/factory/web/entity/pm/req/SearchPmPlanReq.java
  4. 4 0
      application-facade/src/main/java/com/factory/web/entity/pm/res/PmCheckRecordItemListRes.java
  5. 8 4
      application-facade/src/main/java/com/factory/web/entity/pm/res/PmCheckRecordRes.java
  6. 1 1
      application-facade/src/main/java/com/factory/web/mapper/fa/FirstArticleTaskHisBlobMapper.java
  7. 1 1
      application-facade/src/main/java/com/factory/web/mapper/pm/OnsiteTaskHisBlobMapper.java
  8. 16 3
      application-facade/src/main/java/com/factory/web/service/impl/FileServiceImpl.java
  9. 31 16
      application-facade/src/main/java/com/factory/web/service/impl/pm/PreventMistakeServiceImpl.java
  10. 1 19
      application-facade/src/main/java/com/factory/web/service/impl/statistics/StatisticsServiceImpl.java
  11. 4 1
      application-facade/src/main/java/com/factory/wx/entity/req/AbnormalDetailReq.java
  12. 9 0
      application-facade/src/main/java/com/factory/wx/entity/req/AbnormalPlanReq.java
  13. 5 0
      application-facade/src/main/java/com/factory/wx/entity/res/AbnormalPlanRes.java
  14. 4 4
      application-facade/src/main/java/com/factory/wx/mapper/AbnormalStatisticsMapper.java
  15. 31 23
      application-facade/src/main/java/com/factory/wx/service/impl/AbnormalStatisticsServiceImpl.java
  16. 28 21
      application-facade/src/main/resources/mapper/AbnormalStatisticsMapper.xml
  17. 23 14
      application-facade/src/main/resources/mapper/PreventMistakeMapper.xml
  18. 3 3
      application-facade/src/main/resources/mapper/ReminderMapper.xml
  19. 34 11
      common-base/src/main/java/com/factory/base/util/time/TimeUtils.java

+ 2 - 2
application-facade/src/main/java/com/factory/controller/wx/StatisticsController.java

@@ -55,14 +55,14 @@ public class StatisticsController {
         return ResponseBeanBuilder.ok(map);
     }
 
-    @ApiOperation(value = "异常计划详情")
+    @ApiOperation(value = "异常计划详情(按照计划显示列表)")
     @PostMapping("/detail")
     public ResponseBean<AbnormalDetailRes> abnormalDetail(@RequestBody AbnormalDetailReq abnormalDetailReq) {
         AbnormalDetailRes abnormalDetailRes = abnormalStatisticsService.getAbnormalDetail(abnormalDetailReq);
         return ResponseBeanBuilder.ok(abnormalDetailRes);
     }
 
-    @ApiOperation(value = "异常防错计划详情")
+    @ApiOperation(value = "异常重检计划详情:暂无使用空")
     @PostMapping("/detail/pm")
     public ResponseBean<AbnormalDetailRes> abnormalDetailPM(@RequestBody AbnormalDetailReq abnormalDetailReq) {
         return ResponseBeanBuilder.ok();

+ 9 - 0
application-facade/src/main/java/com/factory/web/entity/pm/req/SearchCheckRecordReq.java

@@ -1,5 +1,7 @@
 package com.factory.web.entity.pm.req;
 
+import java.time.LocalDateTime;
+
 import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -30,5 +32,12 @@ public class SearchCheckRecordReq {
 
     @ApiModelProperty(value = "巡检项目id")
     private Long onsiteItemId;
+    
+    
+    @ApiModelProperty(value = "开始时间",hidden = true)
+    private LocalDateTime sdate;
+    @ApiModelProperty(value = "结束时间",hidden = true)
+    private LocalDateTime edate;
+
 
 }

+ 11 - 0
application-facade/src/main/java/com/factory/web/entity/pm/req/SearchPmPlanReq.java

@@ -1,6 +1,9 @@
 package com.factory.web.entity.pm.req;
 
+import java.time.LocalDateTime;
+
 import com.fasterxml.jackson.annotation.JsonInclude;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -24,5 +27,13 @@ public class SearchPmPlanReq {
 
     @ApiModelProperty(value = "计划Id")
     private Long bentelerPlanId;
+    
+    @ApiModelProperty(value = "计划时间范围内任务yyyy-MM")
+    private String yearMonth;
+    
+    @ApiModelProperty(value = "开始时间",hidden = true)
+    private LocalDateTime sdate;
+    @ApiModelProperty(value = "结束时间",hidden = true)
+    private LocalDateTime edate;
 
 }

+ 4 - 0
application-facade/src/main/java/com/factory/web/entity/pm/res/PmCheckRecordItemListRes.java

@@ -30,6 +30,10 @@ public class PmCheckRecordItemListRes implements Serializable {
 
     @ApiModelProperty(value = "巡检项目内容")
     private String itemContent;
+    
+    @ApiModelProperty(value = "0日巡检  1周巡检  2月巡检")
+    private Integer typeFlag;
+
 
     @ApiModelProperty(value = "一个月内的点检记录")
     private List<PmCheckRecordRes> checkRecordList;

+ 8 - 4
application-facade/src/main/java/com/factory/web/entity/pm/res/PmCheckRecordRes.java

@@ -1,6 +1,10 @@
 package com.factory.web.entity.pm.res;
 
+import java.io.Serializable;
+import java.time.LocalDate;
+
 import com.fasterxml.jackson.annotation.JsonInclude;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -8,9 +12,6 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
-import java.io.Serializable;
-import java.time.LocalDate;
-
 /**
  * 检查记录
  *
@@ -29,6 +30,9 @@ public class PmCheckRecordRes implements Serializable {
     private LocalDate taskTime;
 
     @ApiModelProperty(value = "巡检结果 0通过  1巡检不通过 2没有巡检")
-    private String result;
+    private int result;
+    
+    @ApiModelProperty(value = "重检旧值")
+    private int resultBak;
 
 }

+ 1 - 1
application-facade/src/main/java/com/factory/web/mapper/fa/FirstArticleTaskHisBlobMapper.java

@@ -22,7 +22,7 @@ public interface FirstArticleTaskHisBlobMapper extends BaseMapper<FirstArticleTa
 	@Select({
 		"select t.task_time createdTime",
 		" from first_article_task_his_blob h",
-		" join first_article_task t on t.id = h.first_article_task_id and t.`status` not in (0,2)",
+		" join first_article_task t on t.id = h.first_article_task_id and t.`status` = 4 ",
 		" where t.task_time between #{sday} and #{eday} group by t.id"
 	})
 	List<FirstArticleTaskHisBlob> getFinishRecheckTask(@Param("sday")LocalDateTime sday,@Param("eday")LocalDateTime wday);

+ 1 - 1
application-facade/src/main/java/com/factory/web/mapper/pm/OnsiteTaskHisBlobMapper.java

@@ -22,7 +22,7 @@ public interface OnsiteTaskHisBlobMapper extends BaseMapper<OnsiteTaskHisBlob> {
 	@Select({
 		"select t.task_time createdTime",
 		" from onsite_task_his_blob h",
-		" join onsite_task t on t.id = h.onsite_task_id and t.`status` not in (0,2)",
+		" join onsite_task t on t.id = h.onsite_task_id and t.`status` = 4 ",
 		" where t.task_time between #{sday} and #{eday} group by t.id"
 	})
 	List<OnsiteTaskHisBlob> getFinishRecheckTask(@Param("sday")LocalDateTime sday,@Param("eday")LocalDateTime wday);

+ 16 - 3
application-facade/src/main/java/com/factory/web/service/impl/FileServiceImpl.java

@@ -15,6 +15,7 @@ import java.util.stream.Collectors;
 import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Drawing;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
@@ -139,8 +140,13 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
             Optional<OnsiteCalendar> cal = plan.getOnsiteCalendarList().stream().filter(s -> s.getTypeFlag().equals(param.getTypeFlag())).findFirst();
             String userNm = getUserName(!cal.isPresent() ? null : cal.get().getUserId());
             String[] datas = null;
+            StringBuilder sb = new StringBuilder();
             for (PmCheckRecordListRes res : check) {
-                for (PmCheckRecordItemListRes item : res.getItemList()) {
+            	List<PmCheckRecordItemListRes> tlist = res.getItemList().stream().filter(p->p.getTypeFlag().equals(param.getTypeFlag())).collect(Collectors.toList());
+            	if(tlist.isEmpty()) {
+            		continue;
+            	}	
+                for (PmCheckRecordItemListRes item : tlist) {
                     datas = inidata();
                     datas[0] = param.getTypeFlag() == 0 ? "日" : param.getTypeFlag() == 1 ? "周" : "月";
                     datas[1] = res.getWsName();
@@ -148,12 +154,19 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
                     for (PmCheckRecordRes r : item.getCheckRecordList()) {
                         int day = r.getTaskTime().getDayOfMonth();
                         nmMap.put(day, userNm);
-                        if (r.getResult().equals("0")) {
+                        if(r.getResultBak()==1) {
+                        	datas[2 + day] = "×";
+                        	sb.append(r.getResult()==0?"√,":"x,");
+                        }else if (r.getResult()==0) {
                             datas[2 + day] = "√";
                         }else {
                             datas[2 + day] = "×";
                         }
                     }
+                    if(sb.length()>0) {
+                    	datas[34] = sb.toString().substring(0,sb.length()-1);
+                    	sb.delete(0, sb.length());
+                    }
                     rs.add(datas);
                 }
 
@@ -163,7 +176,7 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
     }
 
     private String[] inidata() {
-        String[] datas = new String[34];
+        String[] datas = new String[35];
         for (int i = 0; i < datas.length; i++) {
             datas[i] = "";
         }

+ 31 - 16
application-facade/src/main/java/com/factory/web/service/impl/pm/PreventMistakeServiceImpl.java

@@ -4,7 +4,12 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.util.*;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 import java.util.function.Function;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -24,6 +28,7 @@ import com.factory.base.entity.enumPo.PlanStatus;
 import com.factory.base.entity.enumPo.PlanType;
 import com.factory.base.entity.po.benteler.BentelerPlan;
 import com.factory.base.util.res.ResponseBeanBuilder;
+import com.factory.base.util.time.TimeUtils;
 import com.factory.web.entity.fa.FirstArticleWorkshop;
 import com.factory.web.entity.pm.ApprovalRule;
 import com.factory.web.entity.pm.OnsiteApprovalPlan;
@@ -692,33 +697,34 @@ public class PreventMistakeServiceImpl extends ServiceImpl<PreventMistakeMapper,
     public ResponseBean<List<PmCheckRecordListRes>> getPmCheckRecordList(SearchPmCheckRecordListReq req) {
         List<OnsiteWorkshop> onsiteWorkshopList = onsiteWorkshopService.list(Wrappers.<OnsiteWorkshop>lambdaQuery()
                 .eq(OnsiteWorkshop::getBentelerPlanId, req.getBentelerPlanId()));
-
+		LocalDateTime[] se = TimeUtils.getMonthStartAndEnd(req.getYearMonth());
         List<PmCheckRecordListRes> workshopList = new ArrayList<PmCheckRecordListRes>();
         PmCheckRecordListRes workshop = null;
+        SearchCheckRecordReq itemResultReq = new SearchCheckRecordReq();
+        itemResultReq.setSdate(se[0]);
+        itemResultReq.setEdate(se[1]);
         for (OnsiteWorkshop onsiteWorkshop : onsiteWorkshopList) {
             workshop = new PmCheckRecordListRes();
             workshop.setWorkshopId(onsiteWorkshop.getId());
             workshop.setWsName(onsiteWorkshop.getWsName());
 
             List<OnsiteItem> onsiteItemList = onsiteItemService.list(Wrappers.<OnsiteItem>lambdaQuery()
-                    .eq(OnsiteItem::getWorkshopId, workshop.getWorkshopId()));
+                    .eq(OnsiteItem::getWorkshopId, workshop.getWorkshopId())
+                    .eq(req.getTypeFlag()!=null, OnsiteItem::getTypeFlag, req.getTypeFlag())
+                    );
 
             List<PmCheckRecordItemListRes> itemList = new ArrayList<PmCheckRecordItemListRes>();
             PmCheckRecordItemListRes item = null;
             for (OnsiteItem onsiteItem : onsiteItemList) {
                 item = new PmCheckRecordItemListRes();
-
+                item.setTypeFlag(onsiteItem.getTypeFlag());
                 item.setOnsiteItemId(onsiteItem.getId());
                 item.setItemContent(onsiteItem.getItemContent());
-
-                SearchCheckRecordReq itemResultReq = new SearchCheckRecordReq();
+                
                 itemResultReq.setOnsiteItemId(item.getOnsiteItemId());
-                itemResultReq.setYearMonth(req.getYearMonth());
                 itemResultReq.setTypeFlag(req.getTypeFlag());
                 List<PmCheckRecordRes> itemResultList = preventMistakeMapper.getPmItemResultList(itemResultReq);
-
                 item.setCheckRecordList(itemResultList);
-
                 itemList.add(item);
             }
 
@@ -884,13 +890,12 @@ public class PreventMistakeServiceImpl extends ServiceImpl<PreventMistakeMapper,
 		List<OnsiteItemResult> onsiteItemResultList = onsiteItemResultService.list(Wrappers.<OnsiteItemResult>lambdaQuery()
                 .eq(OnsiteItemResult::getOnsiteTaskId, req.getOnsiteTaskId()));
 
-        /* task提交时,备份result到resultBak */
+        /* task提交时,备份result异常信息到resultBak */
         for (OnsiteItemResult onsiteItemResult : onsiteItemResultList) {
-            OnsiteItemResult oir = OnsiteItemResult.builder()
-                    .id(onsiteItemResult.getId())
-                    .resultBak(onsiteItemResult.getResult())
-                    .build();
-            onsiteItemResultService.updateById(oir);
+        	if(onsiteItemResult.getResult()==1) {
+        		onsiteItemResultService.lambdaUpdate().eq(OnsiteItemResult::getId, onsiteItemResult.getId())
+        		.set(OnsiteItemResult::getResultBak, 1).update();
+        	}
         }
 
         boolean flag = true; // true表示巡检项目都通过,false表示巡检项目有不通过的
@@ -993,6 +998,16 @@ public class PreventMistakeServiceImpl extends ServiceImpl<PreventMistakeMapper,
 	 */
 	@Override
 	public ResponseBean<List<PmCheckListRes>> getPmCheckList(SearchPmPlanReq req) {
+		BentelerPlan plan = this.getById(req.getBentelerPlanId());
+		LocalDateTime[] se = null;
+		if(plan.getStatus()==5) {
+			se = TimeUtils.getStartAndEndDayTime(plan.getEffectiveDate().atStartOfDay(), 3, 0);
+		}else {
+			se = TimeUtils.getMonthStartAndEnd(req.getYearMonth());
+		}
+		req.setSdate(se[0]);
+		req.setEdate(se[1]);
+		//这里应该传递时间,否则历史版本会没有显示
 		List<PmCheckListRes> pmCheckList = preventMistakeMapper.getPmCheckList(req);
 		List<Integer> types = Arrays.asList(0, 1, 2);
 		types.forEach(type -> {

+ 1 - 19
application-facade/src/main/java/com/factory/web/service/impl/statistics/StatisticsServiceImpl.java

@@ -1,6 +1,5 @@
 package com.factory.web.service.impl.statistics;
 
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -51,11 +50,10 @@ public class StatisticsServiceImpl implements StatisticsService {
     @Override
     public ResponseBean<ExceptionCountRes> getExceptionsByMonth(StatisticsDateReq statisticsDateReq) {
 
-        LocalDateTime month = getMonth(statisticsDateReq);
         
         List<String> releasedDates = new ArrayList<>();
         List<String> recheckedDates = new ArrayList<>();
-        LocalDateTime[] se = TimeUtils.getStartAndEndDayTime(month, 3, 1);
+        LocalDateTime[] se = TimeUtils.getMonthStartAndEnd(statisticsDateReq.getMonth());
         //取首件放行状态数量
         List<FirstArticleTask> firstArticleTaskList = firstArticleTaskMapper.selectList(Wrappers.<FirstArticleTask>lambdaQuery()
                 .eq(FirstArticleTask::getStatus, 2)
@@ -93,20 +91,4 @@ public class StatisticsServiceImpl implements StatisticsService {
                 .build());
     }
 
-    /**
-     * 验证日期格式
-     *
-     * @param statisticsDateReq 默认2021-06
-     * @return
-     */
-    private LocalDateTime getMonth(StatisticsDateReq statisticsDateReq) {
-    	LocalDateTime month = LocalDateTime.now();
-        try {
-            month = TimeUtils.paserMonthString(statisticsDateReq.getMonth());
-        } catch (Exception e) {
-            log.error("年月格式错误",e);
-            ResponseBeanBuilder.fail("年月格式错误");
-        }
-        return month;
-    }
 }

+ 4 - 1
application-facade/src/main/java/com/factory/wx/entity/req/AbnormalDetailReq.java

@@ -25,6 +25,9 @@ public class AbnormalDetailReq {
     @ApiModelProperty(value = "计划类型 1首件 2防错")
     private Long checkType;
 
-    @ApiModelProperty(value = "异常类型")
+    @ApiModelProperty(value = "异常类型:1重检2放行")
     private Integer abnormalType;
+    
+    @ApiModelProperty(value = "任务ID:暂无")
+    private Long taskId;
 }

+ 9 - 0
application-facade/src/main/java/com/factory/wx/entity/req/AbnormalPlanReq.java

@@ -1,5 +1,7 @@
 package com.factory.wx.entity.req;
 
+import java.time.LocalDateTime;
+
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -30,4 +32,11 @@ public class AbnormalPlanReq {
 
     @ApiModelProperty(value = "计划列表每页数量")
     private int size;
+    
+    @ApiModelProperty(value = "开始时间",hidden = true)
+    private LocalDateTime sdate;
+    @ApiModelProperty(value = "结束时间",hidden = true)
+    private LocalDateTime edate;
 }
+
+

+ 5 - 0
application-facade/src/main/java/com/factory/wx/entity/res/AbnormalPlanRes.java

@@ -1,5 +1,7 @@
 package com.factory.wx.entity.res;
 
+import java.time.LocalDate;
+
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -31,5 +33,8 @@ public class AbnormalPlanRes {
     
     @ApiModelProperty(value = "任务ID")
     private Long taskId;
+    
+    @ApiModelProperty(value = "任务时间")
+    private LocalDate taskTime;
 
 }

+ 4 - 4
application-facade/src/main/java/com/factory/wx/mapper/AbnormalStatisticsMapper.java

@@ -38,7 +38,7 @@ public interface AbnormalStatisticsMapper {
      * @param planId
      * @return
      */
-    List<AbnormalTaskInfoRes> getFaReleaseListByPlanId(Long planId);
+    List<AbnormalTaskInfoRes> getFaReleaseListByPlanId(@Param("planId") Long planId,@Param("taskId") Long taskId);
 
     /**
      * 根据计划id获取防错放行
@@ -46,7 +46,7 @@ public interface AbnormalStatisticsMapper {
      * @param planId
      * @return
      */
-    List<AbnormalTaskInfoRes> getPmReleaseListByPlanId(Long planId);
+    List<AbnormalTaskInfoRes> getPmReleaseListByPlanId(@Param("planId") Long planId,@Param("taskId") Long taskId);
 
     /**
      * 根据计划id获取首件重检
@@ -54,7 +54,7 @@ public interface AbnormalStatisticsMapper {
      * @param planId
      * @return
      */
-    List<AbnormalTaskInfoRes> getFaRecheckedListByPlanId(Long planId);
+    List<AbnormalTaskInfoRes> getFaRecheckedListByPlanId(@Param("planId") Long planId,@Param("taskId") Long taskId);
 
     /**
      * 根据计划id获取防错重检
@@ -62,7 +62,7 @@ public interface AbnormalStatisticsMapper {
      * @param planId
      * @return
      */
-    List<AbnormalTaskInfoRes> getPmRecheckedListByPlanId(Long planId);
+    List<AbnormalTaskInfoRes> getPmRecheckedListByPlanId(@Param("planId") Long planId,@Param("taskId") Long taskId);
 
     List<AbnormalItemRes> getPmAbnormalItemResultList(@Param("req") SearchAbnormalReq searchReq);
 

+ 31 - 23
application-facade/src/main/java/com/factory/wx/service/impl/AbnormalStatisticsServiceImpl.java

@@ -1,8 +1,17 @@
 package com.factory.wx.service.impl;
 
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.factory.base.entity.po.benteler.BentelerPlan;
 import com.factory.base.util.res.ResponseBeanBuilder;
+import com.factory.base.util.time.TimeUtils;
 import com.factory.web.entity.fa.FirstArticleApprovalTask;
 import com.factory.web.entity.fa.FirstArticleTitle;
 import com.factory.web.entity.fa.FirstArticleWorkshop;
@@ -10,7 +19,12 @@ import com.factory.web.entity.pm.OnsiteApprovalTask;
 import com.factory.web.entity.pm.OnsiteTitle;
 import com.factory.web.entity.pm.OnsiteWorkshop;
 import com.factory.web.entity.pm.req.SearchAbnormalReq;
-import com.factory.web.entity.pm.res.*;
+import com.factory.web.entity.pm.res.AbnormalApprovalTaskRes;
+import com.factory.web.entity.pm.res.AbnormalItemRes;
+import com.factory.web.entity.pm.res.AbnormalItemResultRes;
+import com.factory.web.entity.pm.res.AbnormalTaskInfoRes;
+import com.factory.web.entity.pm.res.AbnormalWorkshopRes;
+import com.factory.web.entity.statistics.StatisticsDateReq;
 import com.factory.web.mapper.BentelerPlanMapper;
 import com.factory.web.mapper.FileMapper;
 import com.factory.web.mapper.pm.PreventMistakeMapper;
@@ -28,21 +42,15 @@ import com.factory.wx.entity.res.AbnormalPlanRes;
 import com.factory.wx.mapper.AbnormalStatisticsMapper;
 import com.factory.wx.service.AbnormalStatisticsService;
 import com.factory.wx.service.WxPlanService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * @author sMArT
  * @version 1.0
  * @date 2021-07-23 1:33 上午
  */
+@Slf4j
 @Service("abnormalStatisticsService")
 public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService {
     @Autowired
@@ -76,9 +84,11 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
      */
     @Override
     public List<AbnormalPlanRes> getExceptionPlansByMonth(AbnormalPlanReq abnormalPlanReq) {
-        String month = getMonth(abnormalPlanReq);
-        abnormalPlanReq.setMonth(month);
-
+    	LocalDateTime month = getMonth(abnormalPlanReq);
+        
+        LocalDateTime[] se = TimeUtils.getStartAndEndDayTime(month, 3, 0);
+        abnormalPlanReq.setSdate(se[0]);
+        abnormalPlanReq.setEdate(se[1]);
         List<AbnormalPlanRes> releasedAbnormalPlans = new ArrayList<>();
         //已重检
         if (abnormalPlanReq.getAbnormalType() == 1) {
@@ -142,11 +152,11 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
         List<AbnormalTaskInfoRes> faList = new ArrayList<>();
         if (abnormalDetailReq.getAbnormalType() == 1) {
             //重检内容
-            faList = abnormalStatisticsMapper.getFaRecheckedListByPlanId(abnormalDetailReq.getPlanId());
+            faList = abnormalStatisticsMapper.getFaRecheckedListByPlanId(abnormalDetailReq.getPlanId(),abnormalDetailReq.getTaskId());
         }
         if (abnormalDetailReq.getAbnormalType() == 2) {
             //放行内容
-            faList = abnormalStatisticsMapper.getFaReleaseListByPlanId(abnormalDetailReq.getPlanId());
+            faList = abnormalStatisticsMapper.getFaReleaseListByPlanId(abnormalDetailReq.getPlanId(),abnormalDetailReq.getTaskId());
         }
 
         for (AbnormalTaskInfoRes faInfo : faList) {
@@ -230,11 +240,11 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
         List<AbnormalTaskInfoRes> pmList = new ArrayList<>();
         if (abnormalDetailReq.getAbnormalType() == 1) {
             //重检内容
-            pmList = abnormalStatisticsMapper.getPmRecheckedListByPlanId(abnormalDetailReq.getPlanId());
+            pmList = abnormalStatisticsMapper.getPmRecheckedListByPlanId(abnormalDetailReq.getPlanId(),abnormalDetailReq.getTaskId());
         }
         if (abnormalDetailReq.getAbnormalType() == 2) {
             //放行内容
-            pmList = abnormalStatisticsMapper.getPmReleaseListByPlanId(abnormalDetailReq.getPlanId());
+            pmList = abnormalStatisticsMapper.getPmReleaseListByPlanId(abnormalDetailReq.getPlanId(),abnormalDetailReq.getTaskId());
         }
         for (AbnormalTaskInfoRes pmInfo : pmList) {
             List<OnsiteWorkshop> onsiteWorkshopList = onsiteWorkshopService.list(Wrappers.<OnsiteWorkshop>lambdaQuery()
@@ -309,14 +319,12 @@ public class AbnormalStatisticsServiceImpl implements AbnormalStatisticsService
      * @param abnormalPlanReq 默认2021-06
      * @return
      */
-    private String getMonth(AbnormalPlanReq abnormalPlanReq) {
-        String month = "2021-06";
+    private LocalDateTime getMonth(AbnormalPlanReq statisticsDateReq) {
+    	LocalDateTime month = LocalDateTime.now();
         try {
-            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
-            Date date = simpleDateFormat.parse(abnormalPlanReq.getMonth());
-            month = simpleDateFormat.format(date);
-        } catch (ParseException e) {
-            e.printStackTrace();
+            month = TimeUtils.paserMonthString(statisticsDateReq.getMonth());
+        } catch (Exception e) {
+            log.error("年月格式错误",e);
             ResponseBeanBuilder.fail("年月格式错误");
         }
         return month;

+ 28 - 21
application-facade/src/main/resources/mapper/AbnormalStatisticsMapper.xml

@@ -10,6 +10,7 @@
         bp.`name` AS plan_name,
         bp.plan_type,
         ot.id as taskId,
+        ot.task_time ,
         2 AS abnormal_type
         FROM
         onsite_task ot,
@@ -25,13 +26,14 @@
         <if test="name != ''">
             AND bp.`name` LIKE CONCAT('%',#{name},'%')
         </if>
-        AND ot.task_time LIKE CONCAT(#{month},'%')
+        AND ot.task_time between #{sdate} and #{edate}
         UNION
         SELECT DISTINCT
         bp.id AS plan_id,
         bp.`name` AS plan_name,
         bp.plan_type,
         ot.id as taskId,
+        ot.task_time ,
         2 AS abnormal_type
         FROM
         first_article_task ot,
@@ -47,7 +49,7 @@
         <if test="name != ''">
             AND bp.`name` LIKE CONCAT('%',#{name},'%')
         </if>
-        AND ot.task_time LIKE CONCAT(#{month},'%');
+        AND ot.task_time between #{sdate} and #{edate}
     </select>
     <!-- 获取重检异常计划列表 -->
     <select id="getRecheckedAbnormalPlans" parameterType="com.factory.wx.entity.req.AbnormalPlanReq"
@@ -57,6 +59,7 @@
         bp.`name` AS plan_name,
         bp.plan_type,
         ot.id as taskId,
+        ot.task_time ,
         1 AS abnormal_type
         FROM
         onsite_task ot,
@@ -66,17 +69,18 @@
         WHERE
         othb.onsite_task_id = ot.id
         AND ot.onsite_calendar_id = oc.id
-        AND oc.benteler_plan_id = bp.id and ot.`status` not in (0,2)
+        AND oc.benteler_plan_id = bp.id and ot.`status` = 4 
         <if test="name != ''">
             AND bp.`name` LIKE CONCAT('%',#{name},'%')
         </if>
-        AND ot.task_time LIKE CONCAT(#{month},'%')
-        UNION
+        AND ot.task_time between #{sdate} and #{edate}
+        UNION ALL
         SELECT DISTINCT
         fac.benteler_plan_id AS plan_id,
         bp.`name` AS plan_name,
         bp.plan_type,
         fat.id  as taskId,
+        fat.task_time ,
         1 AS abnormal_type
         FROM
         first_article_task fat,
@@ -86,11 +90,11 @@
         WHERE
         fathb.first_article_task_id = fat.id
         AND fat.first_article_calendar_id = fac.id
-        AND fac.benteler_plan_id = bp.id and fat.`status` not in (0,2)
+        AND fac.benteler_plan_id = bp.id and fat.`status` = 4 
         <if test="name != ''">
             AND bp.`name` LIKE CONCAT('%',#{name},'%')
         </if>
-        AND fat.task_time LIKE CONCAT(#{month},'%');
+        AND fat.task_time between #{sdate} and #{edate}
     </select>
 
     <!-- 取得防错放行 -->
@@ -118,6 +122,9 @@
           AND oat.`status` = 1
           AND ot.`status` = 2
           AND bp.id = #{planId}
+          <if test="taskId!=null">
+          	ot.id=#{taskId}
+          </if>
     </select>
     <!-- 取得首件放行 -->
     <select id="getFaReleaseListByPlanId" resultType="com.factory.web.entity.pm.res.AbnormalTaskInfoRes">
@@ -144,6 +151,9 @@
           AND faat.`status` = 1
           AND fat.`status` = 2
           AND bp.id = #{planId}
+          <if test="taskId!=null">
+          AND fat.id = #{taskId}
+          </if>
     </select>
     <!-- 防错重检信息 -->
     <select id="getPmRecheckedListByPlanId" resultType="com.factory.web.entity.pm.res.AbnormalTaskInfoRes">
@@ -159,17 +169,15 @@
              onsite_calendar oc,
              benteler_plan bp,
              us_user uu,
-             (
-                 SELECT DISTINCT othb.onsite_task_id
-                 FROM onsite_task_his_blob othb,
-                      onsite_task ot
-                 WHERE othb.onsite_task_id = ot.id
-             ) r
-        WHERE ot.id = r.onsite_task_id
+           onsite_task_his_blob othb
+        WHERE othb.onsite_task_id = ot.id and ot.`status`=4
           AND ot.onsite_calendar_id = oc.id
           AND oc.benteler_plan_id = bp.id
           AND oc.user_id = uu.id
           AND bp.id = #{planId}
+          <if test="taskId!=null">
+          	ot.id=#{taskId}
+          </if>
     </select>
     <!-- 首件重检信息 -->
     <select id="getFaRecheckedListByPlanId" resultType="com.factory.web.entity.pm.res.AbnormalTaskInfoRes">
@@ -185,17 +193,16 @@
              first_article_calendar fac,
              benteler_plan bp,
              us_user uu,
-             (
-                 SELECT DISTINCT fathb.first_article_task_id
-                 FROM first_article_task_his_blob fathb,
-                      first_article_task fat
-                 WHERE fathb.first_article_task_id = fat.id
-             ) r
-        WHERE fat.id = r.first_article_task_id
+            first_article_task_his_blob fathb
+        WHERE fathb.first_article_task_id = fat.id and fat.`status`=4
           AND fat.first_article_calendar_id = fac.id
           AND fac.benteler_plan_id = bp.id
           AND (fac.principal_one_id = uu.id or fac.principal_two_id = uu.id)
           AND bp.id = #{planId}
+          <if test="taskId!=null">
+          AND fat.id = #{taskId}
+          </if>
+          group by fat.id
     </select>
 
     <!-- 取得防错工作站下的巡检项目和检查结果 -->

+ 23 - 14
application-facade/src/main/resources/mapper/PreventMistakeMapper.xml

@@ -183,14 +183,16 @@
     </select>
     <!-- 取得一个月里巡检项目每天的检查结果 --><!-- 暂时取onsite_task的时间,如果取onsite_item_result的时间,会不会有第二天才处理头一天的任务的 -->
     <select id="getPmItemResultList" resultType="com.factory.web.entity.pm.res.PmCheckRecordRes">
-        SELECT ot.task_time,
-        oir.result
-        FROM onsite_item_result oir,
-        onsite_task ot,
-        onsite_item oi
-        WHERE oir.onsite_task_id = ot.id
-        AND oir.onsite_item_id = oi.id
-        AND oi.type_flag = #{req.typeFlag}
+        SELECT 
+        oir.created_time as taskTime,
+        oir.result,
+        oir.result_bak resultBak
+        FROM 
+        onsite_task ot 
+        join onsite_item_result oir on oir.onsite_task_id = ot.id 
+        join onsite_item oi on oir.onsite_item_id = oi.id
+        
+        WHERE oi.type_flag = #{req.typeFlag}
         <if test="req.yearMonth != null and req.yearMonth != ''">
             AND DATE_FORMAT(ot.task_time, '%Y-%m') = #{req.yearMonth}
         </if>
@@ -254,11 +256,18 @@
                MIN(oir.created_time) AS check_time
         FROM benteler_plan bp
                  JOIN onsite_calendar oc ON (bp.id = oc.benteler_plan_id)
-                 JOIN us_user uu ON (oc.user_id = uu.id)
-                 LEFT JOIN onsite_task ot ON (oc.id = ot.onsite_calendar_id)
+                 JOIN us_user uu ON oc.user_id = uu.id
+                 LEFT JOIN onsite_task ot ON (oc.id = ot.onsite_calendar_id) 
+                 <choose>
+                 <when test="req.sdate != null ">
+	            	AND  ot.task_time between #{req.sdate} and #{req.edate}
+	        	 </when>
+	        	 <otherwise>
+	        		AND TO_DAYS(ot.task_time) &gt;= TO_DAYS(NOW())
+	        	 </otherwise>
+                 </choose>
                  LEFT JOIN onsite_item_result oir ON (ot.id = oir.onsite_task_id)
-        WHERE TO_DAYS(ot.task_time) = TO_DAYS(NOW())
-          AND bp.id = #{req.bentelerPlanId}
+        WHERE  bp.id = #{req.bentelerPlanId}
         GROUP BY ot.onsite_calendar_id
     </select>
 
@@ -439,7 +448,7 @@
              onsite_task_his_blob othb,
              us_user uu
         WHERE othb.onsite_task_id = ot.id
-          AND ot.onsite_calendar_id = oc.id  and ot.`status` not in (0,2)
+          AND ot.onsite_calendar_id = oc.id  and ot.`status` = 4
           AND oc.benteler_plan_id = bp.id
           AND oc.user_id = uu.id
           AND ot.task_time = #{req.checkDate}
@@ -506,7 +515,7 @@
              first_article_task_his_blob fathb,
              us_user uu
         WHERE fathb.first_article_task_id = fat.id
-          AND fat.first_article_calendar_id = fac.id and fat.`status` not in (0,2)
+          AND fat.first_article_calendar_id = fac.id and fat.`status` = 4
           AND fac.benteler_plan_id = bp.id 
           AND (fac.principal_one_id = uu.id or fac.principal_two_id = uu.id)
           AND fat.task_time = #{req.checkDate}

+ 3 - 3
application-facade/src/main/resources/mapper/ReminderMapper.xml

@@ -20,7 +20,7 @@
         rat.task_id = ot.id
         AND ot.onsite_calendar_id = oc.id
         AND oc.benteler_plan_id = bp.id
-        AND rat.task_type = 2
+        AND rat.task_type = 2 and bp.`status` = 4
         AND rat.approval_role_id = 
         <foreach collection="req.roleIds" open="(" close=")" separator="," item="roleId">
         	#{roleId}
@@ -28,7 +28,7 @@
         <if test="req.name!=null and req.name != ''">
             AND bp.`name` LIKE CONCAT('%',#{req.name},'%')
         </if>
-        UNION
+        UNION ALL
         SELECT DISTINCT
         bp.id AS plan_id,
         bp.`name` AS name,
@@ -44,7 +44,7 @@
         rat.task_id = ot.id
         AND ot.first_article_calendar_id = oc.id
         AND oc.benteler_plan_id = bp.id
-        AND rat.task_type = 1
+        AND rat.task_type = 1 and bp.`status` = 4
         AND rat.approval_role_id = 
         <foreach collection="req.roleIds" open="(" close=")" separator="," item="roleId">
         	#{roleId}

+ 34 - 11
common-base/src/main/java/com/factory/base/util/time/TimeUtils.java

@@ -50,6 +50,13 @@ public class TimeUtils {
     public static String getWeekInfo(int week) {
         return weekInfo.get(week);
     }
+    /**
+     * 0为当前的时间
+     * @param now
+     * @param type
+     * @param num
+     * @return
+     */
     public static LocalDate[] getStartAndEndDay(LocalDate now, int type, int num) {
         LocalDate[] se = new LocalDate[2];
         if (type == 1) {//周一到周日
@@ -62,22 +69,38 @@ public class TimeUtils {
         }
         return se;
     }
+    /**
+     * 0为当前的时间
+     * @param now
+     * @param type
+     * @param num
+     * @return
+     */
     public static LocalDateTime[] getStartAndEndDayTime(LocalDateTime now, int type, int num) {
         LocalDateTime[] se = new LocalDateTime[2];
         if (type == 1) {//日
-            se[0] = now.truncatedTo(ChronoUnit.DAYS);
-            se[1] = se[0].plusDays(num);
+            se[0] = LocalDateTime.of(now.toLocalDate(),LocalTime.MIN);
+            se[1] =  LocalDateTime.of(now.toLocalDate(),LocalTime.MAX);
         } else if (type == 2) {//周
-            DayOfWeek week = now.getDayOfWeek();
-            se[0] = now.truncatedTo(ChronoUnit.DAYS).minusDays(week.getValue() - 1);
-            se[1] = se[0].plusWeeks(num);
+        	int week = now.getDayOfWeek().getValue();
+            se[0] = LocalDateTime.of(now.minusDays(week - 1).toLocalDate(),LocalTime.MIN);
+            se[1] = LocalDateTime.of(now.plusDays(7-week+num*7).toLocalDate(),LocalTime.MAX);
         } else if (type == 3) {//月
-            int d = now.getDayOfMonth();
-            se[0] = now.truncatedTo(ChronoUnit.DAYS).minusDays(d - 1);
-            se[1] = se[0].plusMonths(num);
+            se[0] = LocalDateTime.of(now.with(TemporalAdjusters.firstDayOfMonth()).toLocalDate(),LocalTime.MIN);
+            se[1] = LocalDateTime.of(now.with(TemporalAdjusters.lastDayOfMonth()).plusMonths(num).toLocalDate(),LocalTime.MAX);
         }
         return se;
     }
+    
+    public static LocalDateTime[] getMonthStartAndEnd(String monthStr) {
+    	LocalDateTime n = null;
+    	try {
+    		n = paserMonthString(monthStr);
+    	}catch (Exception e) {
+			n = LocalDateTime.now();
+		}
+        return getStartAndEndDayTime(n, 3, 0);
+  }
 
     public static String formatLocalTime(LocalTime time) {
         if (time == null) {
@@ -135,9 +158,9 @@ public class TimeUtils {
         LocalDate now2 = LocalDate.now();
         System.out.println(Arrays.toString(getStartAndEndDay(now2, 1, 0)));
         System.out.println(Arrays.toString(getStartAndEndDay(now2, 2, 0)));
-        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 1, 2)));
-        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 2, 2)));
-        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 3, 2)));
+        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 1, 0)));
+        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 2, 0)));
+        System.out.println(Arrays.toString(getStartAndEndDayTime(now, 3, 0)));
         System.out.println(now.getDayOfMonth());
         System.out.println(now.getDayOfWeek().getValue());
         System.out.println(getMonthString(now));