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