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 7ec9bd4e..77c72f39 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 @@ -1031,9 +1031,9 @@ public class AbnormalBillServiceImpl extends ServiceImpl getScrapDtoBysfc(String site, String sfc) { //判断该产品条码是否已经报废 - if(sfcScrapMapper.selectById(HandleEnum.SFC_SCRAP.getHandle(site,sfc)) != null){ - throw new BaseException("该产品条码已经报废"); - } +// if(sfcScrapMapper.selectById(HandleEnum.SFC_SCRAP.getHandle(site,sfc)) != null){ +// throw new BaseException("该产品条码已经报废"); +// } if(this.jgProductionIsScrap(site,sfc)){ throw new BaseException("该产品条码的异常方案不是报废"); } diff --git a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml index 76aaae97..82ebfd49 100644 --- a/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml +++ b/anomaly/src/main/resources/mapper/AbnormalBillMapper.xml @@ -978,6 +978,7 @@ SELECT S.SFC SFC, CASE WHEN S2.STATUS = '401' THEN '新建' WHEN S2.STATUS = '402' THEN '排队' WHEN S2.STATUS = '403' THEN '活动' + WHEN S2.STATUS = '407' THEN '报废' END STATUS, SUBSTR(SS.OPERATION_BO ,INSTR(SS.OPERATION_BO ,',',1)+1,(INSTR(SS.OPERATION_BO ,'#',1)-1)-(INSTR(SS.OPERATION_BO ,',',1)+1)) || '/' || SS.STEP_ID OPERATION, ZSD.RESRCE RESRCE,ZSD.SHOP_ORDER SHOP_ORDER, diff --git a/console/src/main/resources/application-local.yml b/console/src/main/resources/application-local.yml index 9b94113d..02dbcc6f 100644 --- a/console/src/main/resources/application-local.yml +++ b/console/src/main/resources/application-local.yml @@ -75,3 +75,7 @@ ftp: activeMq: sendWeChatMessage: tcp://localhost:61616?wireFormat.maxInactivityDuration=0 queue: send.weChat.notice +exportDocument: + filePath: /Users/zhaojiawei/Desktop/青岛项目后台/mesnac5.biz/production/src/main/resources/ + outputPath: /Users/zhaojiawei/Desktop/ + template: scrap.ftl \ No newline at end of file diff --git a/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcCodeServiceImpl.java b/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcCodeServiceImpl.java index e8b1b57c..b9d18b3c 100644 --- a/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcCodeServiceImpl.java +++ b/meapi/src/main/java/com/foreverwin/mesnac/meapi/service/impl/NcCodeServiceImpl.java @@ -19,7 +19,6 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; /** @@ -87,7 +86,6 @@ public class NcCodeServiceImpl extends ServiceImpl impleme public List findNcCodeDescriptionByNcCode(String ncCode) { String site = CommonMethods.getSite(); String locale = LocaleContextHolder.getLocale().getLanguage(); - ArrayList ncCodeList = new ArrayList<>(); String[] split = ncCode.split(","); return ncCodeMapper.findNcCodeDescriptionByNcCode(site,locale,split); diff --git a/pom.xml b/pom.xml index 324d6d35..64dc68e7 100644 --- a/pom.xml +++ b/pom.xml @@ -220,6 +220,11 @@ axis-saaj 1.4 + + org.freemarker + freemarker + 2.3.30 + diff --git a/production/pom.xml b/production/pom.xml index 052e6ba4..4314524f 100644 --- a/production/pom.xml +++ b/production/pom.xml @@ -40,5 +40,10 @@ com.foreverwin.mesnac integration + + org.freemarker + freemarker + 2.3.30 + \ No newline at end of file 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 index 3c129a57..b2bde6c1 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/controller/SfcScrapController.java @@ -10,6 +10,8 @@ import com.foreverwin.modular.core.util.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; @@ -28,6 +30,8 @@ public class SfcScrapController { @Autowired private AnomalyService anomalyService; + + /** * 根据id查询 * @@ -142,7 +146,7 @@ public class SfcScrapController { /** * 生产报废的报废功能 - * @param sfcScrap + * @param param * @return */ @PostMapping("/scrap") @@ -150,4 +154,30 @@ public class SfcScrapController { return R.ok(sfcScrapService.scrap(param)); } + /** + * 导出报废通知单 + * @param shopOrder 工单 + * @param sfc sfc + * @return + */ + @GetMapping("/generatorWord") + public R generatorWord(String shopOrder, String sfc, HttpServletRequest request, HttpServletResponse response){ + sfcScrapService.generatorWord(shopOrder,sfc,response,request); + return R.ok(); + } + + +// @PostMapping("/import") +// public String importFile(@PathParam("shopOrder") String shopOrder,@PathParam("sfc")String sfc, @RequestParam("file") MultipartFile multipartFile) { +// +// //----------------------------------------------------------------------------------------------------------------------------------------- +// try { +// String transInfo = masterDataImportService.importFile(multipartFile, importRequest); +// return new APResult().getResult(0, transInfo, transInfo); +// } catch (Exception e) { +// e.printStackTrace(); +// return new APResult().getResult(9999, e.getMessage(), e.getMessage()); +// } +// } + } \ 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 index 70850ea0..70b3cb9c 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/mapper/SfcScrapMapper.java @@ -1,9 +1,12 @@ package com.foreverwin.mesnac.production.mapper; -import com.foreverwin.mesnac.production.model.SfcScrap; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.foreverwin.mesnac.production.model.SfcScrap; +import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.Map; + /** *

* 产品报废 Mapper 接口 @@ -15,4 +18,6 @@ import org.springframework.stereotype.Repository; @Repository public interface SfcScrapMapper extends BaseMapper { + public Map generatorWord(@Param("site")String site,@Param("locale")String locale,@Param("shopOrder")String shopOrder,@Param("sfc")String sfc); + } \ 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 index f2b53f63..8903d827 100644 --- a/production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java +++ b/production/src/main/java/com/foreverwin/mesnac/production/service/SfcScrapService.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.foreverwin.mesnac.production.model.SfcScrap; import com.foreverwin.modular.core.util.FrontPage; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; @@ -29,4 +31,6 @@ public interface SfcScrapService extends IService { List scrap(HashMap param) ; + public void generatorWord(String shopOrder, String sfc, HttpServletResponse response, HttpServletRequest request); + } \ 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 index d975bd34..578cb5a1 100644 --- 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 @@ -19,15 +19,27 @@ 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 freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.Version; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; import java.math.BigDecimal; +import java.net.URLEncoder; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; + /** *

* 产品报废 服务实现类 @@ -38,9 +50,19 @@ import java.util.List; */ @Service @Transactional(rollbackFor = Exception.class) +@ConditionalOnProperty(prefix = "exportDocument", value = {"enabled"}, matchIfMissing = true) public class SfcScrapServiceImpl extends ServiceImpl implements SfcScrapService { + @Value("${exportDocument.filePath}") + private String filePath; + + @Value("${exportDocument.outputPath}") + private String outputPath; + + @Value("${exportDocument.template}") + private String templateDocument; + @Autowired private SfcScrapMapper sfcScrapMapper; @@ -145,4 +167,126 @@ public class SfcScrapServiceImpl extends ServiceImpl i this.saveBatch(sfcScrapsList); return sfcScrapsList; } + + + @Override + public void generatorWord(String shopOrder, String sfc, HttpServletResponse response, HttpServletRequest request) { + String site = CommonMethods.getSite(); + String user = CommonMethods.getUser(); + String locale = LocaleContextHolder.getLocale().getLanguage(); + + //判断该产品条码是否已经报废 + if(sfcScrapMapper.selectById(HandleEnum.SFC_SCRAP.getHandle(site,sfc)) == null){ + throw new BaseException("该产品还没有报废"); + } + + + /** + * 年 YEAR + * 月 MONTH + * 日 DAY + * SHOP_ORDER 生产订单号 + * WORK_CENTER 部门 + * OPERATION 操作者 + * ITEM 物料编码 + * WORK_ORDER 工作令 + * 产品名称 SFC + * 零件图号 DWG_NO + * 零件名称 ITEM_DESCRIPTION + * 废品件数 QTY + * 责任者 + * 报废工序 OPERATION + * 废品原因 REASON + * 废品标记 SCRAP_MARK + * 工废 GF + * 料废 LF + * 其他 QT + * 工件重量 WEIGHT + * 评定意见 OPINION + * + */ + LocalDateTime now = LocalDateTime.now(); + int year = now.getYear(); + int month = now.getMonth().getValue(); + int day = now.getDayOfMonth(); + Map wordMap = sfcScrapMapper.generatorWord(site,locale ,shopOrder, sfc); + wordMap.put("SCRAP_MARK","线下质量贴红色标签"); + wordMap.put("OPERATOR",user); + wordMap.put("GF",(wordMap.get("TYPE").contains("GF"))? "✔": ""); + wordMap.put("LF",(wordMap.get("TYPE").contains("LF"))? "✔": ""); + wordMap.put("OT",(wordMap.get("TYPE").contains("QT"))? "✔": ""); + wordMap.put("OPINION","报废"); + wordMap.put("YEAR",year + ""); + wordMap.put("MONTH",month + ""); + wordMap.put("DAY",day + ""); + File outFile = null; + try{ + + Configuration configuration = new Configuration(new Version("2.3.30")); + configuration.setDefaultEncoding("utf-8"); + //指定文件所在的路径 + configuration.setDirectoryForTemplateLoading(new File(filePath)); + //输出文档路径即名称 + outFile = new File(outputPath+sfc+".doc"); + //如果输出目标文件夹不存在,则创建 + if (!outFile.getParentFile().exists()){ + outFile.getParentFile().mkdirs(); + } + //以utf-8的编码读取ftl文件 + Template template = configuration.getTemplate(templateDocument, "utf-8"); + Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"), 1024000); + template.process(wordMap, out); + out.close(); + }catch(Exception e){ + throw new BaseException("导出word文档失败"+e.getMessage()); + } + + + String fileName = outFile.getName(); + String downLoadPath = outFile.getPath(); + java.io.BufferedInputStream bis = null; + java.io.BufferedOutputStream bos = null; + try{ + if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) { + fileName = URLEncoder.encode(fileName, "UTF-8"); + } else { + fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try { + long fileLength = new File(downLoadPath).length(); + response.setContentType("application/x-msdownload;"); + response.setHeader("Content-disposition", "attachment; filename=" + fileName); + response.setHeader("Content-Length", String.valueOf(fileLength)); + response.setContentType("application/octet-stream;charset=UTF-8"); + bis = new BufferedInputStream(new FileInputStream(downLoadPath)); + bos = new BufferedOutputStream(response.getOutputStream()); + byte[] buff = new byte[2048]; + int bytesRead; + while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { + bos.write(buff, 0, bytesRead); + } + } catch (Exception e) { +// errorMessage=e.getMessage(); + e.printStackTrace(); + } finally { + if (bis != null){ + try { + bis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (bos != null){ + try { + bos.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } } \ No newline at end of file diff --git a/production/src/main/resources/mapper/SfcScrapMapper.xml b/production/src/main/resources/mapper/SfcScrapMapper.xml index 66bce553..754aa1bc 100644 --- a/production/src/main/resources/mapper/SfcScrapMapper.xml +++ b/production/src/main/resources/mapper/SfcScrapMapper.xml @@ -430,5 +430,24 @@ ) - +