package com.example.erp.service.pp; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.example.erp.entity.pp.FlowCard; import com.example.erp.entity.sd.OrderGlassDetail; import com.example.erp.entity.sd.OrderProcessDetail; import com.example.erp.mapper.pp.FlowCardMapper; import com.example.erp.mapper.sd.OrderGlassDetailMapper; import com.example.erp.mapper.sd.OrderProcessDetailMapper; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import com.fasterxml.jackson.core.type.TypeReference; import java.io.IOException; import java.sql.Date; import java.util.*; import static com.example.erp.service.sd.OrderService.getOrderProcessDetails; @Service @DS("pp") public class FlowCardService { final FlowCardMapper flowCardMapper; final OrderGlassDetailMapper orderGlassDetailMapper; final OrderProcessDetailMapper orderProcessDetailMapper; public FlowCardService(FlowCardMapper flowCardMapper, OrderGlassDetailMapper orderGlassDetailMapper, OrderProcessDetailMapper orderProcessDetailMapper) { this.flowCardMapper = flowCardMapper; this.orderGlassDetailMapper = orderGlassDetailMapper; this.orderProcessDetailMapper = orderProcessDetailMapper; } //流程卡管理查询 public Map selectProcessCard(Integer pageNum, Integer pageSize, Date selectTime1, Date selectTime2, FlowCard flowCard) { Integer offset = (pageNum - 1) * pageSize; Map map = new HashMap<>(); map.put("data", flowCardMapper.selectFlowCard(offset, pageSize, selectTime1, selectTime2, flowCard)); map.put("total", flowCardMapper.getPageTotal(offset, pageSize, selectTime1, selectTime2, flowCard)); return map; } //分架查询 public Map selectAddProcess(Date selectTime1, Date selectTime2, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.selectFlowCardMp(selectTime1, selectTime2, flowCard)); return map; } //分架明细查询 public Map detailsSelectSv(String orderId, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.detailsSelectMp(orderId, flowCard)); return map; } //删除流程卡 public Boolean deleteFlowCardSv(String orderId, String processId) { if (!orderId.isEmpty() && !processId.isEmpty()) { //判断该流程卡是否报工 Integer count = flowCardMapper.reportingWorkCount(processId); if (count == 0) { //修改分架状态 flowCardMapper.updateDeleteState(orderId, processId); //删除报工流程明细表数据 flowCardMapper.deleteReportingWork(processId); //删除分架明细 flowCardMapper.deleteFlowCardMp(orderId, processId); //判断该订单流程卡是否全部删除 Integer flowNumber = flowCardMapper.selectFlowCardCount(orderId); if (flowNumber == 0) { //修改订单表分架状态为0,全部删除 flowCardMapper.updateProcessingCard(orderId, 0); } else { //修改订单表分架状态为1,删除部分 flowCardMapper.updateProcessingCard(orderId, 1); } return true; } else { return false; } } else { return false; } } //分架新增明细查询 public Map selectNoCardSv(String orderId, String productionId, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.selectNoCardMp(orderId, productionId, flowCard)); map.put("orderOtherMoney", flowCardMapper.selectorderOtherMoney()); return map; } //修改排版状态 public Boolean updateLayoutStatusSv(String processId, Integer state) { if (!processId.isEmpty()) { // Integer Status = flowCardMapper.selectLayoutStatus(processId); flowCardMapper.updateLayoutStatusMp(processId, state); return true; } else { return false; } } //保存流程卡数据 public Boolean addFlowCardSv(Map object) { String userName = ""; if (object.get("userName") != null) { userName = object.get("userName").toString(); } String productionId = ""; if (object.get("productionId") != null) { productionId = object.get("productionId").toString(); } List FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class); if (!FlowCardList.isEmpty()) { for (FlowCard flowCard : FlowCardList) { //查询每个序号的层数 Integer layer = flowCardMapper.selectLayer(productionId, flowCard.getOrderNumber()); //添加流程卡数据 flowCardMapper.addFlowCardMp(flowCard.getProcessId(), flowCard.getOrderNumber(), flowCard.getLandingSequence(), flowCard.getQuantity(), productionId, userName, layer); //修改分架状态,将状态改为1 flowCardMapper.updateFlowState(productionId, flowCard.getOrderNumber()); //查询该订单未分架数量 Integer FlowCount = flowCardMapper.selectFlowCount(productionId); if (FlowCount == 0) { //修改订单表分架状态为2 flowCardMapper.updateProcessingCard(productionId, 2); } else { //修改订单表分架状态为1,未全部分架完成 flowCardMapper.updateProcessingCard(productionId, 1); } //查询订单小片表获取工艺传入小片工艺表 List orderGlassDetailList = orderGlassDetailMapper.selectList( new QueryWrapper() .eq("order_id", flowCard.getProcessId().substring(0, 10)) .eq("order_number", flowCard.getOrderNumber()) ); List orderProcessDetailList = getOrderProcessDetails(orderGlassDetailList); orderProcessDetailList.forEach( orderGlassDetail -> orderGlassDetail.setProcessId(flowCard.getProcessId())); //赋值订单工艺表 orderProcessDetailMapper.insertOrderProcessDetail(orderProcessDetailList); } return true; } else { return false; } } public Map selectSchedulingSv(String selectTime1, String selectTime2, String orderId, String processes, Integer state, FlowCard flowCard) { Map map = new HashMap<>(); if (state == 2) {//已排产 map.put("data", flowCardMapper.selectOkSchedulingMp(selectTime1, selectTime2, orderId, processes, flowCard)); } else if (state == 1) {//未排产 map.put("data", flowCardMapper.selectNoSchedulingMp(selectTime1, selectTime2, orderId, processes, flowCard)); } return map; } //首次查询排版数据 public Map selectLastScheduling(String selectTime1, String selectTime2, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.selectLastSchedulingMp(selectTime1, selectTime2, flowCard)); return map; } public Object flowCardDetailSv(String processId, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.flowCardDetailMp(processId, flowCard)); return map; } public Object selectPrintFlowCardSv(Date selectTime1, Date selectTime2, String orderId, String project, FlowCard flowCard) { if ("null".equals(orderId)) { orderId = ""; } if ("null".equals(project)) { project = ""; } Map map = new HashMap<>(); map.put("data", flowCardMapper.selectPrintFlowCardMp(selectTime1, selectTime2, orderId, project, flowCard)); return map; } public Object selectPrintFlowCard(Date selectTime1, Date selectTime2) { Map map = new HashMap<>(); map.put("data", flowCardMapper.selectPrintFlowCard(selectTime1, selectTime2)); return map; } public Object selectPrintSv(Map object) { Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { Map itemmap = new HashMap<>(); itemmap.put("detail", flowCardMapper.selectPrintMp(flowCard.getOrderId())); list.add(itemmap); } } map.put("data", list); map.put("type", flowCardMapper.selectType()); return map; } private static Map parseJson(String json) { ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.readValue(json, new TypeReference>() {}); } catch (IOException e) { e.printStackTrace(); return null; } } public Map getSelectPrintingSv(Map object, String printMerge, String printLike) { if (printMerge == null){ printMerge= ""; } if (printLike == null){ printLike= ""; } Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { Map itemmap = new HashMap<>(); //流程卡表头表尾数据 //是否传入合并层数 if (printMerge.equals("")||printMerge.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()),flowCard.getGlassChild(),flowCard.getProcess())); //是否包含切割 boolean containsCutting = flowCard.getProcess().contains("切割"); if(String.valueOf(flowCard.getTechnologyNumber()).length()>1 && containsCutting){ List> detailList = flowCardMapper.getDetailListLike(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber())); itemmap.put("detailList", detailList); } else { List> detailList = flowCardMapper.getDetailList(flowCard.getProcessId(), flowCard.getTechnologyNumber()); itemmap.put("detailList", detailList); } } else { //流程卡明细数据 if (printLike.equals("")||printLike.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryListMerge(flowCard.getProcessId(), printMerge)); List> detailList = flowCardMapper.getDetailList(flowCard.getProcessId(), flowCard.getTechnologyNumber()); itemmap.put("detailList", detailList); } else { itemmap.put("detail", flowCardMapper.getPrimaryList(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()), flowCard.getGlassChild(), flowCard.getProcess())); List> detailList = flowCardMapper.getDetailListLike(flowCard.getProcessId(), printMerge); itemmap.put("detailList", detailList); } } //工艺流程 List> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber()); itemmap.put("processList", processList); // itemmap.put("numberList", numberList); list.add(itemmap); } } map.put("data", list); //初始化值 printLike=null; return map; } public Boolean updateComposingSv(Map object) { List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("composing")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { flowCardMapper.updateComposing(flowCard.getProcessId()); } return true; } else { return false; } } public Map getSelectPrintLabelSv(String projectNo) { Map map = new HashMap<>(); map.put("data", flowCardMapper.getPrintLabel(projectNo)); return map; } public Map getSelectPrintLabelSv1(Map object) { Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { // Integer count=flowCardMapper.getPrintLabelCount(flowCard.getProcessId(), flowCard.getTechnologyNumber()); Map itemmap = new HashMap<>(); // for (int i = 0; i < count; i++) { itemmap.put("data", flowCardMapper.getPrintLabel1(flowCard.getProcessId(), flowCard.getTechnologyNumber())); list.add(itemmap); //} } } map.put("data", list); return map; } public Map printFlowCardDetailsSv(String processId, String technologyNumber, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.printFlowCardDetailsMp(processId, technologyNumber, flowCard)); return map; } public Boolean printSortSv(Map object) { List FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class); if (!FlowCardList.isEmpty()) { for (FlowCard flowCard : FlowCardList) { flowCardMapper.printSortMp(flowCard.getProcessId(),flowCard.getOrderNumber(),flowCard.getTechnologyNumber(),flowCard.getSort()); } } return true; } public Map getSelectPrintCustomLabelSv(String type, Integer lableType, Map object) { Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { Set processedProcessIds = new HashSet<>(); // 用来存放已处理过的 processId if (lableType != 2){ for (FlowCard flowCard : flowCardList) { String processId = flowCard.getProcessId(); // 检查是否已经处理过该 processId,如果处理过则跳过 if (processedProcessIds.contains(processId)) { continue; } Map itemmap = new HashMap<>(); itemmap.put("data", flowCardMapper.getPrintCustomData(flowCard.getProcessId(),flowCard.getTechnologyNumber())); list.add(itemmap); // 将该 processId 加入已处理集合 processedProcessIds.add(processId); } } else{ for (FlowCard flowCard : flowCardList) { Map itemmap = new HashMap<>(); itemmap.put("data", flowCardMapper.getPrintCustomDataSemi(flowCard.getProcessId(),flowCard.getTechnologyNumber())); list.add(itemmap); } } } map.put("data", list); map.put("title", flowCardMapper.getPrintTitle(type)); return map; } public Object getCustomLabelDetailSv(String name, String form, String id, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.getCustomLabelDetailMp(name, form,id, flowCard)); return map; } public Boolean updatePrintStateSv(Integer printState, Map object) { List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { // 更新打印状态 flowCardMapper.updatePrintStateMp(printState,flowCard.getProcessId(),flowCard.getTechnologyNumber()); } return true; } else { return false; } } public Map printFlowCardOrderSortSv(String orderId, FlowCard flowCard) { Map map = new HashMap<>(); map.put("data", flowCardMapper.printFlowCardOrderSortMp(orderId, flowCard)); return map; } public Boolean printOrderSort(Map object) { List FlowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("flowCard")), FlowCard.class); if (!FlowCardList.isEmpty()) { for (FlowCard flowCard : FlowCardList) { flowCardMapper.printOrderSortMp(flowCard.getProcessId(),flowCard.getOrderNumber(),flowCard.getTechnologyNumber(),flowCard.getSort()); } } return true; } public Map getSelectPrintingRefundSv(Map object, String printMerge, String printLike) { if (printMerge == null){ printMerge= ""; } if (printLike == null){ printLike= ""; } Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { Map itemmap = new HashMap<>(); //流程卡表头表尾数据 //是否传入合并层数 if (printMerge.equals("")||printMerge.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryListRefund(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()),flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListRefund(flowCard.getProcessId(), flowCard.getTechnologyNumber(),flowCard.getOrderNumber(),flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } else { //流程卡明细数据 if (printLike.equals("")||printLike.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryListMergeRefund(flowCard.getProcessId(), printMerge,flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListRefund(flowCard.getProcessId(), flowCard.getTechnologyNumber(),flowCard.getOrderNumber(), flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } else { itemmap.put("detail", flowCardMapper.getPrimaryListRefund(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()),flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListLikeRefund(flowCard.getProcessId(), printMerge,flowCard.getOrderNumber(),flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } } //工艺流程 List> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber()); itemmap.put("processList", processList); // itemmap.put("numberList", numberList); list.add(itemmap); } } map.put("data", list); //初始化值 printLike=null; return map; } public Map getSelectPrinReworkSv(Map object, String printMerge, String printLike) { if (printMerge == null){ printMerge= ""; } if (printLike == null){ printLike= ""; } Map map = new HashMap<>(); List> list = new ArrayList>();//最终结果 List flowCardList = JSONArray.parseArray(JSONObject.toJSONString(object.get("printList")), FlowCard.class); if (!flowCardList.isEmpty()) { for (FlowCard flowCard : flowCardList) { Map itemmap = new HashMap<>(); //流程卡表头表尾数据 //是否传入合并层数 if (printMerge.equals("")||printMerge.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryListRework(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()),flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListRework(flowCard.getProcessId(), flowCard.getTechnologyNumber(),flowCard.getOrderNumber(),flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } else { //流程卡明细数据 if (printLike.equals("")||printLike.equals("null") ){ itemmap.put("detail", flowCardMapper.getPrimaryListMergeRework(flowCard.getProcessId(), printMerge,flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListRework(flowCard.getProcessId(), flowCard.getTechnologyNumber(),flowCard.getOrderNumber(), flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } else { itemmap.put("detail", flowCardMapper.getPrimaryListRework(flowCard.getProcessId(), String.valueOf(flowCard.getTechnologyNumber()),flowCard.getOrderNumber())); List> detailList = flowCardMapper.getDetailListLikeRework(flowCard.getProcessId(), printMerge,flowCard.getOrderNumber(),flowCard.getReportingWorkId()); itemmap.put("detailList", detailList); } } //工艺流程 List> processList = flowCardMapper.getProcessList(flowCard.getProcessId(), flowCard.getTechnologyNumber()); itemmap.put("processList", processList); // itemmap.put("numberList", numberList); list.add(itemmap); } } map.put("data", list); //初始化值 printLike=null; return map; } }