From 895046da7d654c8f3b0837a84e077f08c14c38e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=98=89=E4=BC=9F?= <1724121454@qq.com> Date: Fri, 30 Jul 2021 15:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=98=E5=B7=A5=E8=B5=84=E6=BA=90=E5=AF=BC?= =?UTF-8?q?=E5=85=A5+=E4=BA=A7=E5=93=81=E6=8A=A5=E5=BA=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AbnormalBillController.java | 14 +- .../anomaly/mapper/AbnormalBillMapper.java | 4 +- .../anomaly/service/ProductionScrap.java | 14 - .../service/impl/AbnormalBillServiceImpl.java | 32 +- .../service/impl/ProductionScrapImpl.java | 27 -- .../mapper/AbnormalBillDisposeMapper.xml | 2 +- .../resources/mapper/AbnormalBillMapper.xml | 2 +- .../mesnac/common}/dto/ScrapDto.java | 3 +- .../mesnac/common/enums/HandleEnum.java | 6 +- .../mesnac/common/service/AnomalyService.java | 16 + dataimport/pom.xml | 4 + .../handler/UserResourceHandler.java | 185 ++++++++ .../service/MasterObjectDefine.java | 9 + .../controller/SfcScrapController.java | 153 ++++++ .../production/mapper/SfcScrapMapper.java | 18 + .../mesnac/production/model/SfcScrap.java | 232 ++++++++++ .../production/service/SfcScrapService.java | 32 ++ .../service/impl/SfcScrapServiceImpl.java | 148 ++++++ .../main/resources/mapper/SfcScrapMapper.xml | 434 ++++++++++++++++++ 19 files changed, 1273 insertions(+), 62 deletions(-) rename {anomaly/src/main/java/com/foreverwin/mesnac/anomaly => common/src/main/java/com/foreverwin/mesnac/common}/dto/ScrapDto.java (97%) create mode 100644 dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java create mode 100644 production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java create mode 100644 production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java create mode 100644 production/src/main/java/com/foreverwin/mesnac/production/model/SfcScrap.java create mode 100644 production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java create mode 100644 production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcScrapServiceImpl.java create mode 100644 production/src/main/resources/mapper/SfcScrapMapper.xml diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/controller/AbnormalBillController.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/controller/AbnormalBillController.java index 954f26c6..443e0b62 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/controller/AbnormalBillController.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/controller/AbnormalBillController.java @@ -7,7 +7,6 @@ import com.foreverwin.mesnac.anomaly.model.AbnormalBill; import com.foreverwin.mesnac.anomaly.model.AbnormalBillDispose; import com.foreverwin.mesnac.anomaly.service.AbnormalBillService; import com.foreverwin.mesnac.anomaly.service.FileUploadedService; -import com.foreverwin.mesnac.anomaly.service.ProductionScrap; import com.foreverwin.mesnac.common.dto.SfcDispatchDto; import com.foreverwin.mesnac.common.service.SfcDispatchCommonService; import com.foreverwin.mesnac.meapi.service.NcCodeService; @@ -39,8 +38,7 @@ public class AbnormalBillController { @Autowired private FileUploadedService fileUploadedService; - @Autowired - private ProductionScrap productionScrap; + @Autowired private NcCodeService ncCodeService; @@ -342,16 +340,6 @@ public class AbnormalBillController { return R.ok(abnormalBillService.anomalyReveseRepair(abnormalBill,abnormalBillDispose)); } - /** - * 生产报废检索功能 - * @param site - * @param sfc - * @return - */ - @GetMapping("/getScrapDtoBysfc") - public R getScrapDtoBysfc(String site,String sfc){ - return R.ok(productionScrap.getScrapDtoBysfc(site,sfc)); - } @GetMapping("/findNcCodeDescriptionByNcCode") diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/mapper/AbnormalBillMapper.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/mapper/AbnormalBillMapper.java index 8a4f1c9e..3919dda4 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/mapper/AbnormalBillMapper.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/mapper/AbnormalBillMapper.java @@ -2,8 +2,8 @@ package com.foreverwin.mesnac.anomaly.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.foreverwin.mesnac.anomaly.dto.AbnormalBillDto; -import com.foreverwin.mesnac.anomaly.dto.ScrapDto; import com.foreverwin.mesnac.anomaly.model.AbnormalBill; +import com.foreverwin.mesnac.common.dto.ScrapDto; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -34,5 +34,5 @@ public interface AbnormalBillMapper extends BaseMapper { Integer findAbnormalMethodBySFC(@Param("site")String site,@Param("sfc")String sfc); - List findScrapDtoBySfc(@Param("site")String site,@Param("sfc")String sfc); + List findScrapDtoBySfc(@Param("site")String site, @Param("sfc")String sfc); } \ No newline at end of file diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/ProductionScrap.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/ProductionScrap.java index 3bb48060..aa7e49e7 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/ProductionScrap.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/ProductionScrap.java @@ -1,24 +1,10 @@ package com.foreverwin.mesnac.anomaly.service; -import com.foreverwin.mesnac.anomaly.dto.ScrapDto; - -import java.util.List; - /** * @Description TODO * @Author zhaojiawei * @Since 2021-07-28 */ public interface ProductionScrap { - /** - * 判断产品条码在质量异常中是否为报废 - * @param sfc - * @return - */ - boolean jgProductionIsScrap(String site,String sfc); - /** - * 检索 - */ - List getScrapDtoBysfc(String site,String sfc); } diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java index 56d6b14f..871daf86 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/AbnormalBillServiceImpl.java @@ -13,6 +13,7 @@ import com.foreverwin.mesnac.anomaly.model.*; import com.foreverwin.mesnac.anomaly.service.*; import com.foreverwin.mesnac.anomaly.util.ActiveMQUtil; import com.foreverwin.mesnac.common.constant.Constants; +import com.foreverwin.mesnac.common.dto.ScrapDto; import com.foreverwin.mesnac.common.enums.HandleEnum; import com.foreverwin.mesnac.common.helper.NextNumberHelper; import com.foreverwin.mesnac.common.service.AnomalyService; @@ -22,6 +23,7 @@ import com.foreverwin.mesnac.meapi.mapper.*; import com.foreverwin.mesnac.meapi.model.*; import com.foreverwin.mesnac.meapi.service.*; import com.foreverwin.mesnac.meapi.util.StringUtils; +import com.foreverwin.mesnac.production.mapper.SfcScrapMapper; import com.foreverwin.mesnac.quality.service.SelfReportService; import com.foreverwin.modular.core.exception.BaseException; import com.foreverwin.modular.core.exception.BusinessException; @@ -135,6 +137,9 @@ public class AbnormalBillServiceImpl extends ServiceImpl selectPage(FrontPage frontPage, AbnormalBill abnormalBill) { @@ -290,7 +295,7 @@ public class AbnormalBillServiceImpl extends ServiceImpl nwaUsers = nwaUserService.selectList(nwaUser); - if(nwaUsers != null){ + if(nwaUsers != null && nwaUsers.size() > 0){ hashMap.put("currentUser",nwaUsers.get(0).getFullName()); } //初始化异常单号 @@ -1011,4 +1016,29 @@ public class AbnormalBillServiceImpl extends ServiceImpl getScrapDtoBysfc(String site, String sfc) { + //判断该产品条码是否已经报废 + if(sfcScrapMapper.selectById(HandleEnum.SFC_SCRAP.getHandle(site,sfc)) != null){ + throw new BaseException("该产品条码已经报废"); + } + if(this.jgProductionIsScrap(site,sfc)){ + throw new BaseException("该产品条码的异常方案不是报废"); + } + return abnormalBillMapper.findScrapDtoBySfc(site, sfc); + } + + + + } \ No newline at end of file diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/ProductionScrapImpl.java b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/ProductionScrapImpl.java index 0eb750c5..3c258484 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/ProductionScrapImpl.java +++ b/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/service/impl/ProductionScrapImpl.java @@ -1,16 +1,9 @@ package com.foreverwin.mesnac.anomaly.service.impl; -import com.foreverwin.mesnac.anomaly.dto.ScrapDto; -import com.foreverwin.mesnac.anomaly.mapper.AbnormalBillMapper; -import com.foreverwin.mesnac.anomaly.service.AbnormalBillService; import com.foreverwin.mesnac.anomaly.service.ProductionScrap; -import com.foreverwin.modular.core.exception.BaseException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * @Description TODO * @Author zhaojiawei @@ -20,24 +13,4 @@ import java.util.List; @Transactional(rollbackFor = Exception.class) public class ProductionScrapImpl implements ProductionScrap { - @Autowired - private AbnormalBillService abnormalBillService; - - @Autowired - private AbnormalBillMapper abnormalBillMapper; - - @Override - public boolean jgProductionIsScrap(String site,String sfc) { - //查询该sfc在质量异常异常方案是否是报废,如果是,则大于1 - Integer num = abnormalBillMapper.findAbnormalMethodBySFC(site, sfc); - return num <= 0; - } - - @Override - public List getScrapDtoBysfc(String site,String sfc) { - if(this.jgProductionIsScrap(site,sfc)){ - throw new BaseException("该产品条码的异常方案不是报废"); - } - return abnormalBillMapper.findScrapDtoBySfc(site, sfc); - } } diff --git a/anomaly/src/main/resources/mapper/AbnormalBillDisposeMapper.xml b/anomaly/src/main/resources/mapper/AbnormalBillDisposeMapper.xml index 46f6bd5c..eee42d28 100644 --- a/anomaly/src/main/resources/mapper/AbnormalBillDisposeMapper.xml +++ b/anomaly/src/main/resources/mapper/AbnormalBillDisposeMapper.xml @@ -641,7 +641,7 @@ LEFT JOIN CUSTOM_FIELDS "MAP" ON "MAP".HANDLE = SO.HANDLE AND "MAP"."ATTRIBUTE" = 'MAP' LEFT JOIN Z_ABNORMAL_NC_CODE ZANC ON ZAB.HANDLE = ZANC.ABNORMAL_BILL_BO LEFT JOIN NC_CODE_T NCT ON ('NCCodeBO:' || ZAB.SITE || ',' || ZANC.NC_CODE) = NCT.NC_CODE_BO AND NCT.LOCALE = #{language} - INNER JOIN Z_NWA_USER NWA ON NWA.USER_NAME = ZAB.PB_USER AND NWA.SITE = ZAB.SITE + LEFT JOIN Z_NWA_USER NWA ON NWA.USER_NAME = ZAB.PB_USER AND NWA.SITE = ZAB.SITE LEFT JOIN NC_GROUP NG ON NG.NC_GROUP = ZANC.NC_CODE_GROUP AND NG.SITE = ZAB.SITE LEFT JOIN ROUTER R ON SUBSTR(R.HANDLE,1,INSTR(R.HANDLE,',',-1)-1) = SUBSTR(ZABD.ROUTER_BO,1,INSTR(ZABD.ROUTER_BO,',',-1)-1) AND R.CURRENT_REVISION = 'true' diff --git a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml index 79e6ec35..76aaae97 100644 --- a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml +++ b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml @@ -58,7 +58,7 @@ - + diff --git a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/dto/ScrapDto.java b/common/src/main/java/com/foreverwin/mesnac/common/dto/ScrapDto.java similarity index 97% rename from anomaly/src/main/java/com/foreverwin/mesnac/anomaly/dto/ScrapDto.java rename to common/src/main/java/com/foreverwin/mesnac/common/dto/ScrapDto.java index e346569f..701ce0a9 100644 --- a/anomaly/src/main/java/com/foreverwin/mesnac/anomaly/dto/ScrapDto.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/dto/ScrapDto.java @@ -1,4 +1,4 @@ -package com.foreverwin.mesnac.anomaly.dto; +package com.foreverwin.mesnac.common.dto; /** * @Description TODO @@ -6,7 +6,6 @@ package com.foreverwin.mesnac.anomaly.dto; * @Since 2021-07-28 */ public class ScrapDto { - private String sfc; private String status; diff --git a/common/src/main/java/com/foreverwin/mesnac/common/enums/HandleEnum.java b/common/src/main/java/com/foreverwin/mesnac/common/enums/HandleEnum.java index f22b7682..43d119fc 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/enums/HandleEnum.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/enums/HandleEnum.java @@ -136,7 +136,11 @@ public enum HandleEnum { /**用户**/ USR("UserBO","UserBO:{0},{1}"), - TOOL("ToolBO","ToolBO:{0},{1}"); + TOOL("ToolBO","ToolBO:{0},{1}"), + + USER_RESOURCE("UserResourceBo","UserResourceBo:{0},{1},{2}"), + + SFC_SCRAP("SfcScrapBo","SfcScrapBo:{0},{1}"); private String prefix; private String pattern; diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/AnomalyService.java b/common/src/main/java/com/foreverwin/mesnac/common/service/AnomalyService.java index 75839c3a..8952f968 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/AnomalyService.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/AnomalyService.java @@ -1,5 +1,9 @@ package com.foreverwin.mesnac.common.service; +import com.foreverwin.mesnac.common.dto.ScrapDto; + +import java.util.List; + /** * @Description TODO * @Author zhaojiawei @@ -20,4 +24,16 @@ public interface AnomalyService { void createAnomalyTask(String category, String resource, String shopOrder, String sfc, String ncCodes,String position,String ncQty, String ncDescription,String userGroup); + + /** + * 判断产品条码在质量异常中是否为报废 + * @param sfc + * @return + */ + boolean jgProductionIsScrap(String site,String sfc); + + /** + * 检索 + */ + List getScrapDtoBysfc(String site, String sfc); } diff --git a/dataimport/pom.xml b/dataimport/pom.xml index b317b82c..5d9ee2a1 100644 --- a/dataimport/pom.xml +++ b/dataimport/pom.xml @@ -67,5 +67,9 @@ com.foreverwin.mesnac meapi + + com.foreverwin.mesnac + dispatch + \ No newline at end of file diff --git a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java new file mode 100644 index 00000000..e39c28d6 --- /dev/null +++ b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/handler/UserResourceHandler.java @@ -0,0 +1,185 @@ +package com.foreverwin.mesnac.dataimport.handler; + +import com.alibaba.fastjson.JSONObject; +import com.foreverwin.mesnac.common.enums.HandleEnum; +import com.foreverwin.mesnac.common.util.StringUtil; +import com.foreverwin.mesnac.dataimport.handler.base.BaseHandler; +import com.foreverwin.mesnac.dataimport.reader.FileReader; +import com.foreverwin.mesnac.dataimport.reader.FileReaderBuilder; +import com.foreverwin.mesnac.dataimport.reader.RowVisitor; +import com.foreverwin.mesnac.dataimport.service.MasterObjectDefine; +import com.foreverwin.mesnac.dataimport.util.AppUtil; +import com.foreverwin.mesnac.dispatch.mapper.UserResourceMapper; +import com.foreverwin.mesnac.dispatch.model.UserResource; +import com.foreverwin.mesnac.dispatch.service.UserResourceService; +import com.foreverwin.modular.core.exception.BusinessException; +import com.foreverwin.modular.core.util.CommonMethods; +import com.foreverwin.modular.core.util.I18nUtil; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.InputStream; +import java.time.LocalDateTime; +import java.util.Map; + + +/** + * @Description TODO + * @Author zhaojiawei + * @Since 2021-07-29 + */ +public class UserResourceHandler extends BaseHandler { + + @Autowired + private UserResourceMapper userResourceMapper; + + @Autowired + private UserResourceService userResourceService; + + @Override + public String importFile(String site, InputStream inputStream, String fileType, String mode) throws Exception { + int row = 0; + StringBuffer buffer = new StringBuffer(); + Integer[] failedNumber = new Integer[]{0}; + + try { + FileReader fileReader = new FileReaderBuilder().build(fileType); + RowVisitor visitor = getRowVisitor(site, mode, buffer, failedNumber); + row = fileReader.visitor(visitor).read(inputStream, getHeaders()); + } catch (Exception e) { + buffer.append(e.getMessage() + "\n"); + } + + if (buffer.length() > 0) { + buffer.insert(0, I18nUtil.getI18nText("MaterData.import.Summary", new Object[]{row + failedNumber[0], row, failedNumber[0]}) + "\n"); + throw BusinessException.build(buffer.toString()); + } + buffer.insert(0, I18nUtil.getI18nText("MaterData.import.Summary", new Object[]{row + failedNumber[0], row, failedNumber[0]}) + "\n"); + + return buffer.toString(); + } + + @Override + public Map getHeaders() { + return MasterObjectDefine.getHeadsMapping("USER_RESOURCE"); + } + + public RowVisitor getRowVisitor(String site, String mode, StringBuffer buffer, Integer[] failedNumber) { + + return new RowVisitor() { + + @Override + public int visit(long index, JSONObject jsonObject) { + + LocalDateTime now = LocalDateTime.now(); + String user = CommonMethods.getUser(); + String resrce = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrce"))); + String resrceDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("resrceDescription"))); + String userId = StringUtil.toString(jsonObject.getString(jsonObject.getString("userId"))); + String userDescription = StringUtil.toString(jsonObject.getString(jsonObject.getString("userDescription"))); + String temporaryUser = StringUtil.toString(jsonObject.getString(jsonObject.getString("temporaryUser"))); + String status = StringUtil.toString(jsonObject.getString(jsonObject.getString("status"))); + UserResource userResource = new UserResource(); + userResource.setHandle(HandleEnum.USER_RESOURCE.getHandle(site, resrce, userId)); + userResource.setSite(site); + userResource.setResourceBo(HandleEnum.RESOURCE.getHandle(site,resrce)); + userResource.setResrce(resrce); + userResource.setResrceDescription(resrceDescription); + userResource.setUserId(userId); + userResource.setUserDescription(userDescription); + if("Y".equals(temporaryUser)){ + userResource.setTemporaryUser("true"); + }else { + userResource.setTemporaryUser("false"); + } + + if("Y".equals(status)){ + userResource.setStatus("true"); + }else { + userResource.setStatus("false"); + } + + UserResource result = userResourceMapper.selectById(userResource.getHandle()); + if(result == null){ + userResource.setCreatedUser(user); + userResource.setCreatedDateTime(now); + } + userResource.setModifiedUser(user); + userResource.setModifiedDateTime(now); + + + + Object[] params = new Object[10]; + //错误信息提示 + params[0] = index; + params[1] = resrce; + boolean insert = false; + try { + + //如果资源为空或者员工编号为空,则直接跳过 + if (StringUtil.notEmpty(resrce) && StringUtil.notEmpty(userId)) { + //站点 + jsonObject.put("site", site); + //错误提示信息 + boolean resultMessage = false; + // WorkCenterFullConfiguration result = WorkCenterWSClient.find(jsonObject); + if (result != null) { + if (AppUtil.canUpdate(mode)) { + resultMessage = this.update(userResource); + if (resultMessage) { + return 1; + } + }else{ + throw BusinessException.build("第"+index+"行的数据不存在,不能更新,应该选更新插入"); + } + } else { + if (AppUtil.canInsert(mode)) { + insert = true; + // resultMessage = WorkCenterWSClient.insert(userResource); +// if (resultMessage == null) { +// return 1; +// } + } else if (AppUtil.canUpdate(mode)) { + //resultMessage = "第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.upDateObjectNotExist") + "\n"; + } + } + +// if (resultMessage != null) { +// params[2] = resultMessage; +// failedNumber[0]++; +// if (insert) { +// buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", params) + "\n"); +// } else { +// buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", params) + "\n"); +// } +// } + } + return 0; + + } catch (Exception e) { + params[2] = e.getMessage(); + failedNumber[0]++; + if (insert) { + buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.insertfail.workcenter", new Object[]{e.getMessage()}) + "\n"); + } else { + buffer.append("第" +index+ "行:" + I18nUtil.getI18nText("MaterData.import.updatefail.workcenter", new Object[]{e.getMessage()}) + "\n"); + } + } + return 0; + } + + @Override + public String[] getHeader() { + return null; + } + + boolean update(UserResource userResource){ + + + return false; + } + }; + + + } + +} diff --git a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/service/MasterObjectDefine.java b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/service/MasterObjectDefine.java index b13734a2..853136d5 100644 --- a/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/service/MasterObjectDefine.java +++ b/dataimport/src/main/java/com/foreverwin/mesnac/dataimport/service/MasterObjectDefine.java @@ -176,6 +176,15 @@ public class MasterObjectDefine { cvsHeadsMapping.put("remark","备注"); break; + case "USER_RESOURCE": + cvsHeadsMapping.put("resrce","资源编码"); + cvsHeadsMapping.put("resrceDescription","资源描述"); + cvsHeadsMapping.put("userId","员工编号"); + cvsHeadsMapping.put("userDescription","员工姓名"); + cvsHeadsMapping.put("temporaryUser","是否临时员工"); + cvsHeadsMapping.put("status","是否有效"); + break; + default: break; } diff --git a/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java b/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java new file mode 100644 index 00000000..3c129a57 --- /dev/null +++ b/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java @@ -0,0 +1,153 @@ +package com.foreverwin.mesnac.production.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.foreverwin.mesnac.common.service.AnomalyService; +import com.foreverwin.mesnac.production.model.SfcScrap; +import com.foreverwin.mesnac.production.service.SfcScrapService; +import com.foreverwin.modular.core.util.FrontPage; +import com.foreverwin.modular.core.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; + +/** + * + * @author zjw + * @since 2021-07-30 + */ +@RestController +@RequestMapping("/Z-SFC-SCRAP") +public class SfcScrapController { + + @Autowired + public SfcScrapService sfcScrapService; + + @Autowired + private AnomalyService anomalyService; + + /** + * 根据id查询 + * + * @param id 主键 + * @return + */ + @ResponseBody + @GetMapping("/{id:.+}") + public R getSfcScrapById(@PathVariable String id) { + return R.ok( sfcScrapService.getById(id)); + } + + /** + * 查询所有数据 + * + * @return + */ + @ResponseBody + @GetMapping("") + public R getSfcScrapList(SfcScrap sfcScrap){ + List result; + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(sfcScrap); + result = sfcScrapService.list(queryWrapper); + return R.ok(result); + } + + /** + * 分页查询数据 + * + * @param frontPage 分页信息 + * @return + */ + @ResponseBody + @GetMapping("/page") + public R page(FrontPage frontPage, SfcScrap sfcScrap){ + IPage result; + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(sfcScrap); + if (frontPage.getGlobalQuery() != null && !"".equals(frontPage.getGlobalQuery().trim())) { + //TODO modify global query + queryWrapper.lambda().and(wrapper -> wrapper + .like(SfcScrap::getHandle, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getSite, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getSfc, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getOperation, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getStepId, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getType, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getReason, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getCreatedUser, frontPage.getGlobalQuery()) + .or().like(SfcScrap::getModifiedUser, frontPage.getGlobalQuery()) + ); + } + result = sfcScrapService.page(frontPage.getPagePlus(), queryWrapper); + return R.ok(result); + } + + /** + * 新增 + * @param sfcScrap 传递的实体 + * @return null 失败 实体成功 + */ + @PostMapping + public R save(@RequestBody SfcScrap sfcScrap) { + return R.ok(sfcScrapService.save(sfcScrap)); + } + + /** + * 修改 + * @param sfcScrap 传递的实体 + * @return null 失败 实体成功 + */ + @PutMapping + public R updateById(@RequestBody SfcScrap sfcScrap) { + return R.ok(sfcScrapService.updateById(sfcScrap)); + } + + /** + * 根据id删除对象 + * @param id 实体ID + * @return 0 失败 1 成功 + */ + @ResponseBody + @RequestMapping(method = RequestMethod.DELETE, value = "/{id:.+}") + public R removeById(@PathVariable("id") String id){ + return R.ok(sfcScrapService.removeById(id)); + } + + /** + * 批量删除对象 + * @param ids 实体集合ID + * @return 0 失败 1 成功 + */ + @ResponseBody + @RequestMapping(method = RequestMethod.POST, value = "/delete-batch") + public R removeByIds(List ids){ + return R.ok(sfcScrapService.removeByIds(ids)); + } + + /** + * 生产报废检索功能 + * @param site + * @param sfc + * @return + */ + @GetMapping("/getScrapDtoBysfc") + public R getScrapDtoBysfc(String site,String sfc){ + + + return R.ok(anomalyService.getScrapDtoBysfc(site,sfc)); + } + + /** + * 生产报废的报废功能 + * @param sfcScrap + * @return + */ + @PostMapping("/scrap") + public R scrap(@RequestBody HashMap param){ + return R.ok(sfcScrapService.scrap(param)); + } + +} \ No newline at end of file diff --git a/production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java b/production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java new file mode 100644 index 00000000..70850ea0 --- /dev/null +++ b/production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java @@ -0,0 +1,18 @@ +package com.foreverwin.mesnac.production.mapper; + +import com.foreverwin.mesnac.production.model.SfcScrap; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + *

+ * 产品报废 Mapper 接口 + *

+ * + * @author zjw + * @since 2021-07-30 + */ +@Repository +public interface SfcScrapMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/production/src/main/java/com/foreverwin/mesnac/production/model/SfcScrap.java b/production/src/main/java/com/foreverwin/mesnac/production/model/SfcScrap.java new file mode 100644 index 00000000..be8fee96 --- /dev/null +++ b/production/src/main/java/com/foreverwin/mesnac/production/model/SfcScrap.java @@ -0,0 +1,232 @@ +package com.foreverwin.mesnac.production.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.activerecord.Model; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * 产品报废 + *

+ * + * @author zjw + * @since 2021-07-30 + */ + +@TableName("Z_SFC_SCRAP") + +public class SfcScrap extends Model { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "HANDLE", type = IdType.INPUT) + private String handle; + /** + * 站点 + */ + @TableField("SITE") + private String site; + /** + * 产品条码 + */ + @TableField("SFC") + private String sfc; + /** + * 工序 + */ + @TableField("OPERATION") + private String operation; + /** + * 步骤 + */ + @TableField("STEP_ID") + private String stepId; + /** + * 数量 + */ + @TableField("QTY") + private Double qty; + /** + * 类型(用,分割) + */ + @TableField("TYPE") + private String type; + /** + * 废品原因 + */ + @TableField("REASON") + private String reason; + /** + * 创建人 + */ + @TableField("CREATED_USER") + private String createdUser; + /** + * 创建时间 + */ + @TableField("CREATED_DATE_TIME") + private LocalDateTime createdDateTime; + /** + * 修改人 + */ + @TableField("MODIFIED_USER") + private String modifiedUser; + /** + * 修改日期 + */ + @TableField("MODIFIED_DATE_TIME") + private LocalDateTime modifiedDateTime; + + + public String getHandle() { + return handle; + } + + public void setHandle(String handle) { + this.handle = handle; + } + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getSfc() { + return sfc; + } + + public void setSfc(String sfc) { + this.sfc = sfc; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getStepId() { + return stepId; + } + + public void setStepId(String stepId) { + this.stepId = stepId; + } + + public Double getQty() { + return qty; + } + + public void setQty(Double qty) { + this.qty = qty; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public String getCreatedUser() { + return createdUser; + } + + public void setCreatedUser(String createdUser) { + this.createdUser = createdUser; + } + + public LocalDateTime getCreatedDateTime() { + return createdDateTime; + } + + public void setCreatedDateTime(LocalDateTime createdDateTime) { + this.createdDateTime = createdDateTime; + } + + public String getModifiedUser() { + return modifiedUser; + } + + public void setModifiedUser(String modifiedUser) { + this.modifiedUser = modifiedUser; + } + + public LocalDateTime getModifiedDateTime() { + return modifiedDateTime; + } + + public void setModifiedDateTime(LocalDateTime modifiedDateTime) { + this.modifiedDateTime = modifiedDateTime; + } + +public static final String HANDLE = "HANDLE"; + +public static final String SITE = "SITE"; + +public static final String SFC = "SFC"; + +public static final String OPERATION = "OPERATION"; + +public static final String STEP_ID = "STEP_ID"; + +public static final String QTY = "QTY"; + +public static final String TYPE = "TYPE"; + +public static final String REASON = "REASON"; + +public static final String CREATED_USER = "CREATED_USER"; + +public static final String CREATED_DATE_TIME = "CREATED_DATE_TIME"; + +public static final String MODIFIED_USER = "MODIFIED_USER"; + +public static final String MODIFIED_DATE_TIME = "MODIFIED_DATE_TIME"; + + + @Override + protected Serializable pkVal() { + return this.handle; + } + + @Override + public String toString() { + return "SfcScrap{" + + "handle = " + handle + + ", site = " + site + + ", sfc = " + sfc + + ", operation = " + operation + + ", stepId = " + stepId + + ", qty = " + qty + + ", type = " + type + + ", reason = " + reason + + ", createdUser = " + createdUser + + ", createdDateTime = " + createdDateTime + + ", modifiedUser = " + modifiedUser + + ", modifiedDateTime = " + modifiedDateTime + + "}"; + } +} \ No newline at end of file diff --git a/production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java b/production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java new file mode 100644 index 00000000..f2b53f63 --- /dev/null +++ b/production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java @@ -0,0 +1,32 @@ +package com.foreverwin.mesnac.production.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.foreverwin.mesnac.production.model.SfcScrap; +import com.foreverwin.modular.core.util.FrontPage; + +import java.util.HashMap; +import java.util.List; + +/** + *

+ * 产品报废 服务类 + *

+ * + * @author zjw + * @since 2021-07-30 + */ +public interface SfcScrapService extends IService { + + /** + * 分页查询 + * @param frontPage + * @return + */ + IPage selectPage(FrontPage frontPage, SfcScrap sfcScrap); + + List selectList(SfcScrap sfcScrap); + + List scrap(HashMap param) ; + +} \ No newline at end of file diff --git a/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcScrapServiceImpl.java b/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcScrapServiceImpl.java new file mode 100644 index 00000000..d975bd34 --- /dev/null +++ b/production/src/main/java/com/foreverwin/mesnac/production/service/impl/SfcScrapServiceImpl.java @@ -0,0 +1,148 @@ +package com.foreverwin.mesnac.production.service.impl; + +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.foreverwin.mesnac.common.enums.HandleEnum; +import com.foreverwin.mesnac.common.util.StringUtil; +import com.foreverwin.mesnac.meapi.mapper.SfcMapper; +import com.foreverwin.mesnac.meapi.model.Sfc; +import com.foreverwin.mesnac.production.mapper.SfcScrapMapper; +import com.foreverwin.mesnac.production.model.SfcScrap; +import com.foreverwin.mesnac.production.service.PodTemplateService; +import com.foreverwin.mesnac.production.service.SfcScrapService; +import com.foreverwin.modular.core.exception.BaseException; +import com.foreverwin.modular.core.meext.MEServices; +import com.foreverwin.modular.core.util.CommonMethods; +import com.foreverwin.modular.core.util.FrontPage; +import com.sap.me.production.ScrapDeleteServiceInterface; +import com.sap.me.production.ScrapSfcRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +/** + *

+ * 产品报废 服务实现类 + *

+ * + * @author zjw + * @since 2021-07-30 + */ +@Service +@Transactional(rollbackFor = Exception.class) +public class SfcScrapServiceImpl extends ServiceImpl implements SfcScrapService { + + + @Autowired + private SfcScrapMapper sfcScrapMapper; + + @Autowired + private SfcMapper sfcMapper; + + @Autowired + private PodTemplateService podTemplateService; + + @Override + public IPage selectPage(FrontPage frontPage, SfcScrap sfcScrap) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(sfcScrap); + return super.page(frontPage.getPagePlus(), queryWrapper); + } + + @Override + public List selectList(SfcScrap sfcScrap) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.setEntity(sfcScrap); + return super.list(queryWrapper); + } + + + @Override + public List scrap(HashMap param) { + String user = CommonMethods.getUser(); + LocalDateTime now = LocalDateTime.now(); + String reason = (String)param.get("reason"); + String site = (String)param.get("site"); + + //类型 + List _type = (List)param.get("type"); + StringBuilder type = new StringBuilder(); + for (int i = 0; i < _type.size(); i++) { + if(i == _type.size() - 1){ + type.append(_type.get(i)); + }else{ + type.append(_type.get(i)).append(","); + } + } + + + String str = JSONUtil.toJsonStr(param.get("sfcScrap")); + List _sfcScrapList = JSONArray.parseArray(str, SfcScrap.class); + List sfcScrapsList = new ArrayList<>(); + + + ScrapDeleteServiceInterface scrapDeleteServiceInterface = null; + //mes的公共接口 + try{ + scrapDeleteServiceInterface = MEServices.create("com.sap.me.production", "ScrapDeleteService", CommonMethods.getSite()); + }catch (Exception e){ + throw new BaseException("调用mes公共接口失败"+e.getMessage()); + } + + for (SfcScrap sfcScraps : + _sfcScrapList) { + SfcScrap sfcScrap = new SfcScrap(); + sfcScrap.setHandle(HandleEnum.SFC_SCRAP.getHandle(site,sfcScraps.getSfc())); + sfcScrap.setSite(site); + sfcScrap.setSfc(sfcScraps.getSfc()); + //设置数量用,并判断该sfc是否有效 + Sfc sfc = sfcMapper.selectById(HandleEnum.SFC.getHandle(site,sfcScrap.getSfc())); + if(sfc == null){ + throw new BaseException("该sfc不存在,不能报废"); + } + + + if(!StringUtil.isBlank(sfcScraps.getOperation())){ + String[] split = sfcScraps.getOperation().split("/"); + sfcScrap.setOperation(split[0]); + sfcScrap.setStepId(split[1]); + } + sfcScrap.setType(type.toString()); + sfcScrap.setReason(reason); + sfcScrap.setQty(sfc.getQty()); + sfcScrap.setCreatedUser(user); + sfcScrap.setCreatedDateTime(now); + sfcScrap.setModifiedUser(user); + sfcScrap.setModifiedDateTime(now); + + + + //向生产派工那边发送数据 + // podTemplateService.sendErp(sfcScrap.getSfc(),sfcScrap.getStepId(),BigDecimal.valueOf(0L),BigDecimal.valueOf(sfcScrap.getQty())); + + try{ + //调用mes公共接口,报废 + ScrapSfcRequest scrapSfcRequest = new ScrapSfcRequest(); + scrapSfcRequest.setSfcRef(sfc.getHandle()); + scrapSfcRequest.setQuantity(BigDecimal.valueOf(sfcScrap.getQty())); + scrapDeleteServiceInterface.scrapSfc(scrapSfcRequest); + }catch (Exception e){ + throw new BaseException("调用mes公共接口失败"+e.getMessage()); + } + + + sfcScrapsList.add(sfcScrap); + } + //保存 + this.saveBatch(sfcScrapsList); + return sfcScrapsList; + } +} \ No newline at end of file diff --git a/production/src/main/resources/mapper/SfcScrapMapper.xml b/production/src/main/resources/mapper/SfcScrapMapper.xml new file mode 100644 index 00000000..66bce553 --- /dev/null +++ b/production/src/main/resources/mapper/SfcScrapMapper.xml @@ -0,0 +1,434 @@ + + + + + + + + + + + + + + + + + + + + + + + HANDLE, SITE, SFC, OPERATION, STEP_ID, QTY, TYPE, REASON, CREATED_USER, CREATED_DATE_TIME, MODIFIED_USER, MODIFIED_DATE_TIME + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO Z_SFC_SCRAP + + HANDLE, + SITE, + SFC, + OPERATION, + STEP_ID, + QTY, + TYPE, + REASON, + CREATED_USER, + CREATED_DATE_TIME, + MODIFIED_USER, + MODIFIED_DATE_TIME, + VALUES + + #{handle}, + #{site}, + #{sfc}, + #{operation}, + #{stepId}, + #{qty}, + #{type}, + #{reason}, + #{createdUser}, + #{createdDateTime}, + #{modifiedUser}, + #{modifiedDateTime}, + + + + + INSERT INTO Z_SFC_SCRAP + + + VALUES + + #{handle}, + #{site}, + #{sfc}, + #{operation}, + #{stepId}, + #{qty}, + #{type}, + #{reason}, + #{createdUser}, + #{createdDateTime}, + #{modifiedUser}, + #{modifiedDateTime}, + + + + + + UPDATE Z_SFC_SCRAP + SITE=#{et.site}, + SFC=#{et.sfc}, + OPERATION=#{et.operation}, + STEP_ID=#{et.stepId}, + QTY=#{et.qty}, + TYPE=#{et.type}, + REASON=#{et.reason}, + CREATED_USER=#{et.createdUser}, + CREATED_DATE_TIME=#{et.createdDateTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + WHERE HANDLE=#{et.handle} and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL} + + + + + UPDATE Z_SFC_SCRAP + SITE=#{et.site}, + SFC=#{et.sfc}, + OPERATION=#{et.operation}, + STEP_ID=#{et.stepId}, + QTY=#{et.qty}, + TYPE=#{et.type}, + REASON=#{et.reason}, + CREATED_USER=#{et.createdUser}, + CREATED_DATE_TIME=#{et.createdDateTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + WHERE HANDLE=#{et.handle} and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL} + + + + + UPDATE Z_SFC_SCRAP + SITE=#{et.site}, + SFC=#{et.sfc}, + OPERATION=#{et.operation}, + STEP_ID=#{et.stepId}, + QTY=#{et.qty}, + TYPE=#{et.type}, + REASON=#{et.reason}, + CREATED_USER=#{et.createdUser}, + CREATED_DATE_TIME=#{et.createdDateTime}, + MODIFIED_USER=#{et.modifiedUser}, + MODIFIED_DATE_TIME=#{et.modifiedDateTime}, + + + + + HANDLE=#{ew.entity.handle} + AND SITE=#{ew.entity.site} + AND SFC=#{ew.entity.sfc} + AND OPERATION=#{ew.entity.operation} + AND STEP_ID=#{ew.entity.stepId} + AND QTY=#{ew.entity.qty} + AND TYPE=#{ew.entity.type} + AND REASON=#{ew.entity.reason} + AND CREATED_USER=#{ew.entity.createdUser} + AND CREATED_DATE_TIME=#{ew.entity.createdDateTime} + AND MODIFIED_USER=#{ew.entity.modifiedUser} + AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime} + + + ${ew.sqlSegment} + + + + + ${ew.sqlSegment} + + + + + DELETE FROM Z_SFC_SCRAP WHERE HANDLE=#{handle} + + + + DELETE FROM Z_SFC_SCRAP + + + + + ${k} = #{cm[${k}]} + + + + + + + + DELETE FROM Z_SFC_SCRAP + + + + + HANDLE=#{ew.entity.handle} + + AND SITE=#{ew.entity.site} + AND SFC=#{ew.entity.sfc} + AND OPERATION=#{ew.entity.operation} + AND STEP_ID=#{ew.entity.stepId} + AND QTY=#{ew.entity.qty} + AND TYPE=#{ew.entity.type} + AND REASON=#{ew.entity.reason} + AND CREATED_USER=#{ew.entity.createdUser} + AND CREATED_DATE_TIME=#{ew.entity.createdDateTime} + AND MODIFIED_USER=#{ew.entity.modifiedUser} + AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime} + + + ${ew.sqlSegment} + + + + + ${ew.sqlSegment} + + + + + DELETE FROM Z_SFC_SCRAP WHERE HANDLE IN ( + #{item} + ) + + + +