From a4c58a143cf5e89a29228aa0110f43b892c47aab Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Fri, 15 Dec 2023 09:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A8=E9=87=8F=E7=9C=8B=E6=9D=BF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/QcInterfaceController.java | 42 ++- .../com/op/quality/domain/QcInterface.java | 77 +++++- .../op/quality/mapper/QcInterfaceMapper.java | 19 +- .../quality/service/IQcInterfaceService.java | 17 +- .../service/impl/QcInterfaceServiceImpl.java | 225 +++++++++++++++- .../mapper/quality/QcInterfaceMapper.xml | 248 ++++++++++++------ 6 files changed, 529 insertions(+), 99 deletions(-) diff --git a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcInterfaceController.java b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcInterfaceController.java index d99bdd43..b7629199 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcInterfaceController.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcInterfaceController.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Map; /** * 质量看板接口 @@ -82,8 +83,47 @@ public class QcInterfaceController { * @return */ @PostMapping("/getProduceStaticInfo") - public List getProduceStaticInfo(@RequestBody QcInterface qcInterface) { + public Map getProduceStaticInfo(@RequestBody QcInterface qcInterface) { return qcInterfaceService.getProduceStaticInfo(qcInterface); } + /** + * 过程检验--质量异常信息 + * @param qcInterface + * @return + */ + @PostMapping("/getProduceNoOkList") + public List getProduceNoOkList(@RequestBody QcInterface qcInterface) { + return qcInterfaceService.getProduceNoOkList(qcInterface); + } + + /** + * 过程检验-检验统计 + * @param qcInterface + * @return + */ + @PostMapping("/getProMonthNoOk") + public Map> getProMonthNoOk(@RequestBody QcInterface qcInterface) { + return qcInterfaceService.getProMonthNoOk(qcInterface); + } + + /** + * 过程检验-产品异常趋势 + * @param qcInterface + * @return + */ + @PostMapping("/getLineDayNoOk") + public QcInterface getLineDayNoOk(@RequestBody QcInterface qcInterface) { + return qcInterfaceService.getLineDayNoOk(qcInterface); + } + + /** + * 过程检验-产品不合格率同期对比 + * @param qcInterface + * @return + */ + @PostMapping("/getMonthOfYearContrast") + public List getMonthOfYearContrast(@RequestBody QcInterface qcInterface) { + return qcInterfaceService.getMonthOfYearContrast(qcInterface); + } } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcInterface.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcInterface.java index 01bb9d8f..41a65f3f 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcInterface.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcInterface.java @@ -6,6 +6,8 @@ import com.op.common.core.web.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import java.util.List; + /** * 看板 * @@ -14,7 +16,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; */ public class QcInterface extends BaseEntity { private static final long serialVersionUID = 1L; - private String ymdType; + private String ymdType; private String ymdTypeName; private String dictType; private String factoryCode; @@ -33,6 +35,79 @@ public class QcInterface extends BaseEntity { private String checkResult; private String checkManName; private String checkName; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private String checkTime; + private String sampleQuality; + private String noOkQuality; + private List dayStr; + private List series; + private String machineCode; + private String machineName; + private List data; + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMachineCode() { + return machineCode; + } + + public void setMachineCode(String machineCode) { + this.machineCode = machineCode; + } + + public String getMachineName() { + return machineName; + } + + public void setMachineName(String machineName) { + this.machineName = machineName; + } + + public List getSeries() { + return series; + } + + public void setSeries(List series) { + this.series = series; + } + + public List getDayStr() { + return dayStr; + } + + public void setDayStr(List dayStr) { + this.dayStr = dayStr; + } + + public String getSampleQuality() { + return sampleQuality; + } + + public void setSampleQuality(String sampleQuality) { + this.sampleQuality = sampleQuality; + } + + public String getNoOkQuality() { + return noOkQuality; + } + + public void setNoOkQuality(String noOkQuality) { + this.noOkQuality = noOkQuality; + } + + public String getCheckTime() { + return checkTime; + } + + public void setCheckTime(String checkTime) { + this.checkTime = checkTime; + } public String getCheckNo() { return checkNo; diff --git a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcInterfaceMapper.java b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcInterfaceMapper.java index 67fa536e..ae2fad65 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcInterfaceMapper.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcInterfaceMapper.java @@ -3,9 +3,12 @@ package com.op.quality.mapper; import com.op.quality.domain.QcCheckProject; import com.op.quality.domain.QcCheckType; import com.op.quality.domain.QcInterface; +import com.op.quality.domain.QcProCheck; +import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import java.util.List; +import java.util.Map; /** * 质量看板Mapper接口 @@ -16,9 +19,9 @@ import java.util.List; @Mapper public interface QcInterfaceMapper { - List getDictData(QcInterface qcInterface); + List getDictData(QcInterface qcInterface); - List getOverallInfo(QcInterface qcInterface); + List getOverallInfo(QcInterface qcInterface); List getCheckProjectsPie(QcInterface qcInterface); @@ -27,4 +30,16 @@ public interface QcInterfaceMapper { List getSupplierTaskList(QcInterface qcInterface); List getSupplierNoOkList(QcInterface qcInterface); + + List getProduceNoOkList(QcInterface qcInterface); + + QcInterface getProduceHz(QcInterface qcInterface); + @MapKey("ymd") + Map getYearNoOkHz(QcInterface qcInterface); + + List getLineNames(); + @MapKey("ymd") + Map getDayNoOkHz(QcInterface qcInterface); + @MapKey("ymd") + Map getMothNoOkNum(QcInterface qcInterface); } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/IQcInterfaceService.java b/op-modules/op-quality/src/main/java/com/op/quality/service/IQcInterfaceService.java index c22eb5a8..6676f007 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/IQcInterfaceService.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/IQcInterfaceService.java @@ -5,6 +5,7 @@ import com.op.quality.domain.QcCheckType; import com.op.quality.domain.QcInterface; import java.util.List; +import java.util.Map; /** * @@ -13,11 +14,11 @@ import java.util.List; */ public interface IQcInterfaceService { - List getDictData(QcInterface qcInterface); + List getDictData(QcInterface qcInterface); - List getOverallInfo(QcInterface qcInterface); + List getOverallInfo(QcInterface qcInterface); - List getCheckProjectsPie(QcInterface qcInterface); + List getCheckProjectsPie(QcInterface qcInterface); List getSupplierBadTOP5(QcInterface qcInterface); @@ -25,5 +26,13 @@ public interface IQcInterfaceService { List getSupplierNoOkList(QcInterface qcInterface); - List getProduceStaticInfo(QcInterface qcInterface); + Map getProduceStaticInfo(QcInterface qcInterface); + + List getProduceNoOkList(QcInterface qcInterface); + + Map> getProMonthNoOk(QcInterface qcInterface); + + QcInterface getLineDayNoOk(QcInterface qcInterface); + + List getMonthOfYearContrast(QcInterface qcInterface); } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcInterfaceServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcInterfaceServiceImpl.java index 8d6f0ec7..7ca943b3 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcInterfaceServiceImpl.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcInterfaceServiceImpl.java @@ -2,20 +2,22 @@ package com.op.quality.service.impl; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.op.common.core.utils.DateUtils; -import com.op.quality.domain.QcCheckType; import com.op.quality.domain.QcInterface; +import com.op.quality.domain.QcProCheck; import com.op.quality.mapper.QcInterfaceMapper; import com.op.quality.service.IQcInterfaceService; -import com.op.system.api.domain.SysDictData; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.time.LocalDate; -import java.util.Calendar; -import java.util.List; +import java.util.*; /** * 检验项目维护Service业务层处理 @@ -90,7 +92,7 @@ public class QcInterfaceServiceImpl implements IQcInterfaceService { Integer.parseInt(ymdArray[1]), Integer.parseInt(ymdArray[2])); LocalDate date2 = LocalDate.now(); - if(date1.compareTo(date2)<0){ + if(date1.compareTo(date2)<0){ dto.setCheckStatus("逾期未检"); }else { dto.setCheckStatus("0".equals(dto.getCheckStatus()) ? "待检测" : "检测完成"); @@ -114,14 +116,223 @@ public class QcInterfaceServiceImpl implements IQcInterfaceService { } @Override - public List getProduceStaticInfo(QcInterface qcInterface) { + public Map getProduceStaticInfo(QcInterface qcInterface) { DynamicDataSourceContextHolder.push(qcInterface.getFactoryCode()); String nowYMD = DateUtils.getDate(); qcInterface.setYmd(nowYMD); - List dtos = qcInterfaceMapper.getSupplierNoOkList(qcInterface); + Map dtoMap = new HashMap<>(); + qcInterface.setYmdType("dd"); + QcInterface hz = qcInterfaceMapper.getProduceHz(qcInterface); + if(hz != null){ + dtoMap.put("todayPro",hz.getQuality()); + dtoMap.put("todaySample",hz.getSampleQuality()); + dtoMap.put("todayNoOk",hz.getNoOkQuality()); + BigDecimal tOkRate = (new BigDecimal(hz.getSampleQuality()) + .subtract(new BigDecimal(hz.getNoOkQuality())) + ) + .multiply(new BigDecimal(100)) + .divide(new BigDecimal(hz.getQuality()),2, RoundingMode.HALF_UP); + dtoMap.put("todayOkRate",tOkRate+"%"); + } + + qcInterface.setYmdType("mm"); + QcInterface hz2 = qcInterfaceMapper.getProduceHz(qcInterface); + if(hz2 != null){ + dtoMap.put("monthPro",hz2.getQuality()); + dtoMap.put("monthNoOk",hz2.getNoOkQuality()); + BigDecimal tOkRate2 = (new BigDecimal(hz2.getSampleQuality()) + .subtract(new BigDecimal(hz2.getNoOkQuality())) + ) + .multiply(new BigDecimal(100)) + .divide(new BigDecimal(hz2.getQuality()),2, RoundingMode.HALF_UP); + dtoMap.put("monthOkRate",tOkRate2+"%"); + } + return dtoMap; + } + + @Override + public List getProduceNoOkList(QcInterface qcInterface) { + DynamicDataSourceContextHolder.push(qcInterface.getFactoryCode()); + String nowYMD = DateUtils.getDate(); + qcInterface.setYmd(nowYMD); + List dtos = qcInterfaceMapper.getProduceNoOkList(qcInterface); return dtos; } + @Override + public Map> getProMonthNoOk(QcInterface qcInterface) { + DynamicDataSourceContextHolder.push(qcInterface.getFactoryCode()); + Map> dtoMap = new HashMap<>(); + + String nowYMD = DateUtils.getDate(); + String[] nowYMDs = nowYMD.split("-"); + int nowMonth = Integer.parseInt(nowYMDs[1]); + List monthNames = new ArrayList<>(); + + qcInterface.setYmd(nowYMD); + qcInterface.setYmdType("yyyy"); + Map noOkHzs = qcInterfaceMapper.getYearNoOkHz(qcInterface); + List monthData = new ArrayList<>(); + + for(int mh = 1;mh<=nowMonth;mh++){ + String yyyymm = nowYMDs[1]+"-"+String.format("%02d",mh); + monthNames.add(yyyymm); + if(noOkHzs != null) { + monthData.add(noOkHzs.get(yyyymm).getNoOkQuality()); + }else{ + monthData.add("0"); + } + } + + dtoMap.put("month",monthNames); + dtoMap.put("monthData",monthData); + + return dtoMap; + } + + @Override + public QcInterface getLineDayNoOk(QcInterface qcInterface) { + DynamicDataSourceContextHolder.push(qcInterface.getFactoryCode()); + QcInterface dto = new QcInterface(); + + Calendar calendar = Calendar.getInstance(); + Date now = calendar.getTime(); + calendar.set(Calendar.DAY_OF_MONTH, 1); + Date firstDayOfMonth = calendar.getTime(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String startTime = dateFormat.format(firstDayOfMonth); + String endTime = dateFormat.format(now); + + //日期名称数组 + List xAxisDatas = getDays(startTime,endTime); + dto.setDayStr(xAxisDatas);// + //通过报工获取到真实参与生产的线体 + List lines = qcInterfaceMapper.getLineNames(); + if(CollectionUtils.isEmpty(lines)){ + return null; + } + String nowYMD = DateUtils.getDate(); + qcInterface.setYmd(nowYMD); + qcInterface.setYmdType("yyyy"); + Map noOkHzs = qcInterfaceMapper.getDayNoOkHz(qcInterface); + if(noOkHzs==null){ + return null; + } + List series = new ArrayList<>(); + QcInterface serie = null; + for(QcProCheck line:lines){ + serie = new QcInterface(); + List data = new ArrayList<>(); + serie.setMachineName(line.getMachineName()); + for(String dayStr:xAxisDatas){ + QcInterface dayInfo = noOkHzs.get(line.getMachineCode()+dayStr); + if(dayInfo!=null){ + data.add(dayInfo.getNoOkQuality()); + }else{ + data.add("0"); + } + } + serie.setData(data); + series.add(serie); + } + dto.setSeries(series);// + return dto; + } + + @Override + public List getMonthOfYearContrast(QcInterface qcInterface) { + DynamicDataSourceContextHolder.push(qcInterface.getFactoryCode()); + List dtos = new ArrayList<>(); + + QcInterface nowYM = new QcInterface(); + QcInterface lastYM = new QcInterface(); + String nowYMD = DateUtils.getDate(); + String[] nowYMDs = nowYMD.split("-"); + int nowYear = Integer.parseInt(nowYMDs[0]); + int lastYear = nowYear-1; + List daystr1 = new ArrayList<>(); + List daystr0 = new ArrayList<>(); + for(int m=1;m<=12;m++){ + daystr0.add(lastYear+"-"+String.format("%02d",m)); + daystr1.add(nowYear+"-"+String.format("%02d",m)); + } + lastYM.setDayStr(daystr0); + nowYM.setDayStr(daystr1); + + qcInterface.setYmd("'"+nowYear+"','"+lastYear+"'"); + + Map noOkNum = qcInterfaceMapper.getMothNoOkNum(qcInterface); + if(noOkNum==null){ + return null; + } + + List data0 = new ArrayList<>();//不合规数量 + List dataStr0 = new ArrayList<>();//不合格率 + for(String day0:daystr0){ + QcInterface last = noOkNum.get(day0); + if(last != null){ + data0.add(last.getNoOkQuality()); + BigDecimal norate0 = new BigDecimal(last.getNoOkQuality()).multiply(new BigDecimal(100)) + .divide(new BigDecimal(last.getQuality()),2,RoundingMode.HALF_UP); + dataStr0.add(norate0.toString()); + }else{ + data0.add("0"); + dataStr0.add("0.00"); + } + } + + List data1 = new ArrayList<>();//不合规数量 + List dataStr1 = new ArrayList<>();//不合格率 + for(String day1:daystr1){ + QcInterface now = noOkNum.get(day1); + if(now != null){ + data1.add(now.getNoOkQuality()); + BigDecimal norate0 = new BigDecimal(now.getNoOkQuality()).multiply(new BigDecimal(100)) + .divide(new BigDecimal(now.getQuality()),2,RoundingMode.HALF_UP); + dataStr1.add(norate0.toString()); + }else{ + data1.add("0"); + dataStr1.add("0.00"); + } + } + + lastYM.setData(data0); + lastYM.setDayStr(dataStr0); + + nowYM.setData(data1); + nowYM.setDayStr(dataStr1); + + dtos.add(lastYM); + dtos.add(nowYM); + return dtos; + } + + /**两个日期之间的所有日期**/ + public static List getDays(String startTime,String endTime) { + + // 返回的日期集合 + List days = new ArrayList(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date start = dateFormat.parse(startTime); + Date end = dateFormat.parse(endTime); + + Calendar tempStart = Calendar.getInstance(); + tempStart.setTime(start); + + Calendar tempEnd = Calendar.getInstance(); + tempEnd.setTime(end); + tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束) + while (tempStart.before(tempEnd)) { + days.add(dateFormat.format(tempStart.getTime())); + tempStart.add(Calendar.DAY_OF_YEAR, 1); + } + } catch (ParseException e) { + e.printStackTrace(); + } + return days; + } + } diff --git a/op-modules/op-quality/src/main/resources/mapper/quality/QcInterfaceMapper.xml b/op-modules/op-quality/src/main/resources/mapper/quality/QcInterfaceMapper.xml index 6de815bf..71100b03 100644 --- a/op-modules/op-quality/src/main/resources/mapper/quality/QcInterfaceMapper.xml +++ b/op-modules/op-quality/src/main/resources/mapper/quality/QcInterfaceMapper.xml @@ -1,7 +1,7 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> @@ -15,34 +15,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(0) quality,'all' ymdTypeName from wms_raw_order_in where active_flag = '1' - - and CONVERT(varchar(4),receipt_time, 120) = SUBSTRING(#{ymd},0,5) - - - and CONVERT(varchar(7),receipt_time, 120) =SUBSTRING(#{ymd},0,8) - - - and CONVERT(varchar(10),receipt_time, 120) = SUBSTRING(#{ymd},0,11) - + + and CONVERT(varchar(4),receipt_time, 120) = SUBSTRING(#{ymd},0,5) + + + and CONVERT(varchar(7),receipt_time, 120) =SUBSTRING(#{ymd},0,8) + + + and CONVERT(varchar(10),receipt_time, 120) = SUBSTRING(#{ymd},0,11) + union ALL select count(0),'unOk' from qc_check_unqualified qcu left join qc_check_type qct on qcu.type = qct.order_code where qct.type_code = #{typeCode} and qcu.del_flag = '0' - - and CONVERT(varchar(4),qcu.create_time, 120) = SUBSTRING(#{ymd},0,5) - - - and CONVERT(varchar(7),qcu.create_time, 120) = SUBSTRING(#{ymd},0,8) - - - and CONVERT(varchar(10),qcu.create_time, 120) = SUBSTRING(#{ymd},0,11) - + + and CONVERT(varchar(4),qcu.create_time, 120) = SUBSTRING(#{ymd},0,5) + + + and CONVERT(varchar(7),qcu.create_time, 120) = SUBSTRING(#{ymd},0,8) + + + and CONVERT(varchar(10),qcu.create_time, 120) = SUBSTRING(#{ymd},0,11) + - select top 5 * from( - select - concat(t1.supplier_name,'-',t1.material_name) supplierName, - ROUND(t2.noOkNum*100.00/t1.allNum, 2) quality - from ( - select count(0) allNum, - qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name - from qc_check_task qct - where qct.type_code = #{typeCode} - - and CONVERT(varchar(4),qct.income_time, 120) = SUBSTRING(#{ymd},0,5) - - - and CONVERT(varchar(7),qct.income_time, 120) = SUBSTRING(#{ymd},0,8) - - - and CONVERT(varchar(10),qct.income_time, 120) = SUBSTRING(#{ymd},0,11) - - group by - qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name - ) t1 - left join ( - select - count(0) noOkNum,qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name - from qc_check_task qct - where qct.type_code = #{typeCode} and qct.check_result = 'N' - - and CONVERT(varchar(4),qct.income_time, 120) = SUBSTRING(#{ymd},0,5) - - - and CONVERT(varchar(7),qct.income_time, 120) = SUBSTRING(#{ymd},0,8) - - - and CONVERT(varchar(10),qct.income_time, 120) = SUBSTRING(#{ymd},0,11) - - group by - qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name - ) t2 on t1.supplier_code = t2.supplier_code and t1.material_code = t2.material_code + select + concat(t1.supplier_name,'-',t1.material_name) supplierName, + ROUND(t2.noOkNum*100.00/t1.allNum, 2) quality + from ( + select count(0) allNum, + qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name + from qc_check_task qct + where qct.type_code = #{typeCode} + + and CONVERT(varchar(4),qct.income_time, 120) = SUBSTRING(#{ymd},0,5) + + + and CONVERT(varchar(7),qct.income_time, 120) = SUBSTRING(#{ymd},0,8) + + + and CONVERT(varchar(10),qct.income_time, 120) = SUBSTRING(#{ymd},0,11) + + group by + qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name + ) t1 + left join ( + select + count(0) noOkNum,qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name + from qc_check_task qct + where qct.type_code = #{typeCode} and qct.check_result = 'N' + + and CONVERT(varchar(4),qct.income_time, 120) = SUBSTRING(#{ymd},0,5) + + + and CONVERT(varchar(7),qct.income_time, 120) = SUBSTRING(#{ymd},0,8) + + + and CONVERT(varchar(10),qct.income_time, 120) = SUBSTRING(#{ymd},0,11) + + group by + qct.supplier_code,qct.supplier_name,qct.material_code,qct.material_name + ) t2 on t1.supplier_code = t2.supplier_code and t1.material_code = t2.material_code ) t order by t.quality desc + + + + + + +