生产报废导出word功能

master
赵嘉伟 4 years ago
parent 083a8379e5
commit 6431c44423

@ -1031,9 +1031,9 @@ public class AbnormalBillServiceImpl extends ServiceImpl<AbnormalBillMapper, Abn
@Override
public List<ScrapDto> 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("该产品条码的异常方案不是报废");
}

@ -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,

@ -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

@ -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<NcCodeMapper, NcCode> impleme
public List<NcCodeDto> findNcCodeDescriptionByNcCode(String ncCode) {
String site = CommonMethods.getSite();
String locale = LocaleContextHolder.getLocale().getLanguage();
ArrayList<String> ncCodeList = new ArrayList<>();
String[] split = ncCode.split(",");
return ncCodeMapper.findNcCodeDescriptionByNcCode(site,locale,split);

@ -220,6 +220,11 @@
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
<!-- axis 1.4 jar end -->
</dependencies>
</dependencyManagement>

@ -40,5 +40,10 @@
<groupId>com.foreverwin.mesnac</groupId>
<artifactId>integration</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
</dependency>
</dependencies>
</project>

@ -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());
// }
// }
}

@ -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;
/**
* <p>
* Mapper
@ -15,4 +18,6 @@ import org.springframework.stereotype.Repository;
@Repository
public interface SfcScrapMapper extends BaseMapper<SfcScrap> {
public Map<String,String> generatorWord(@Param("site")String site,@Param("locale")String locale,@Param("shopOrder")String shopOrder,@Param("sfc")String sfc);
}

@ -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<SfcScrap> {
List<SfcScrap> scrap(HashMap<String,Object> param) ;
public void generatorWord(String shopOrder, String sfc, HttpServletResponse response, HttpServletRequest request);
}

@ -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;
/**
* <p>
*
@ -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<SfcScrapMapper, SfcScrap> 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<SfcScrapMapper, SfcScrap> 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<String, String> 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();
}
}
}
}
}

@ -430,5 +430,24 @@
</foreach>)
</delete>
<!-- BaseMapper标准查询/修改/删除 -->
<select id="generatorWord" resultType="hashmap">
SELECT DISTINCT WC.WORK_CENTER WORK_CENTER,WO.VALUE WORK_ORDER,WO2.VALUE DWG_NO,ZSS.QTY QTY,ZSS.OPERATION OPERATION,
ZSS.REASON REASON,ZSS."TYPE" "TYPE",
CASE WHEN I1.VALUE != NULL THEN I1.VALUE * I.QTY_MULTIPLIER
WHEN I2.VALUE != NULL THEN I2.VALUE * I.QTY_MULTIPLIER
ELSE I.QTY_MULTIPLIER END WEIGHT,I.ITEM ITEM,S.SFC SFC,it.DESCRIPTION ITEM_DESCRIPTION,
SO.SHOP_ORDER SHOP_ORDER
FROM
SHOP_ORDER SO
LEFT JOIN WORK_CENTER WC ON SO.PLANNED_WORK_CENTER_BO = WC.HANDLE
LEFT JOIN CUSTOM_FIELDS WO ON WO.HANDLE = SO.HANDLE AND WO."ATTRIBUTE" = 'WORK_ORDER'
LEFT JOIN CUSTOM_FIELDS WO2 ON WO2.HANDLE = SO.PLANNED_ITEM_BO AND WO2."ATTRIBUTE" = 'DWG_NO'
INNER JOIN SFC S ON S.SFC = #{sfc} AND S.SITE = #{site}
LEFT JOIN Z_SFC_SCRAP ZSS ON ZSS.SFC = S.SFC
LEFT JOIN ITEM I ON I.HANDLE = SO.PLANNED_ITEM_BO
LEFT JOIN ITEM_T it ON it.ITEM_BO = I.HANDLE AND it.LOCALE = #{locale}
LEFT JOIN CUSTOM_FIELDS I1 ON I1.HANDLE = I.HANDLE AND I1."ATTRIBUTE" = 'PER_METER'
LEFT JOIN CUSTOM_FIELDS I2 ON I2.HANDLE = I.HANDLE AND I2."ATTRIBUTE" = 'PER_SQUARE_METER'
WHERE SO.SHOP_ORDER = #{shopOrder}
</select>
</mapper>

Loading…
Cancel
Save