/*
|
* Copyright (c) 2018-2025, ztt All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the pig4cloud.com developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: ztt
|
*/
|
package com.chinaztt.mes.basic.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.ExcelWriter;
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.chinaztt.mes.basic.entity.IfsLog;
|
import com.chinaztt.mes.basic.excel.MaterialIssueStdData;
|
import com.chinaztt.mes.basic.excel.MaterialUnIssueStdData;
|
import com.chinaztt.mes.basic.excel.ReceiveStdData;
|
import com.chinaztt.mes.basic.mapper.IfsLogMapper;
|
import com.chinaztt.mes.basic.service.IfsLogService;
|
import com.chinaztt.mes.common.wrapper.QueryWrapperUtil;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.net.URLEncoder;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* ifs请求日志
|
*
|
* @author shz
|
* @date 2022-08-25 16:49:17
|
*/
|
@Service
|
public class IfsLogServiceImpl extends ServiceImpl<IfsLogMapper, IfsLog> implements IfsLogService {
|
|
@Resource
|
private IfsLogMapper ifsLogMapper;
|
|
private final List<String> orderInterfaceNames = Arrays.asList("IMPORT_SHOP_ORDER_STD", "IMPORT_SO_SMA_SOPER_STD",
|
"IMPORT_SHOP_MATERIAL_ALLOC_STD", "MODIFY_SHOP_MATERIAL_ALLOC_STD", "REMOVE_SHOP_MATERIAL_ALLOC_STD",
|
"IMPORT_SHOP_OPERATION_STD", "MODIFY_SHOP_OPERATION_STD", "REMOVE_SHOP_OPERATION_STD",
|
"MODIFY_SO_PRE_CLOSE_STD", "IMPORT_SO_MATERIAL_ISSUE_STD", "IMPORT_SO_MATERIAL_UNISSUE_STD",
|
"IMPORT_SO_OPER_REPORT_STD", "IMPORT_SO_RECEIVE_STD", "IMPORT_SO_UNRECEIVE_STD",
|
"IMPORT_SO_OPER_SCRAP_STD", "IMPORT_SO_OPER_UNSCRAP_STD", "MODIFY_SO_STATE_STD");
|
|
@Override
|
public void refreshIfsLogOrderNo() {
|
List<IfsLog> ifsLogs = ifsLogMapper.selectList(Wrappers.<IfsLog>lambdaQuery().eq(IfsLog::getState,
|
Boolean.FALSE).in(IfsLog::getProcedureName, orderInterfaceNames));
|
if (CollectionUtil.isEmpty(ifsLogs)) {
|
return;
|
}
|
Map<String, List<IfsLog>> ifsLogMap = ifsLogs.stream().collect(Collectors.groupingBy(IfsLog::getProcedureName));
|
|
|
}
|
|
|
@Override
|
public void export(HttpServletResponse response, String type) throws IOException {
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding("UTF-8");
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
String fileName = URLEncoder.encode("ifs缓存解析", "UTF-8");
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
try {
|
//新建ExcelWriter
|
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
|
WriteSheet mainSheet = null;
|
List<IfsLog> ifsLogList = new ArrayList<>();
|
List<String> inAttrList = new ArrayList<>();
|
|
switch (type){
|
case "IMPORT_SO_RECEIVE_STD": case "IMPORT_SO_UNRECEIVE_STD":
|
//获取sheet0对象
|
mainSheet = EasyExcel.writerSheet(0, "ifs缓存解析").head(ReceiveStdData.class).build();
|
ifsLogList = ifsLogMapper.selectList(Wrappers.<IfsLog>lambdaQuery().eq(IfsLog::getProcedureName, type)
|
.eq(IfsLog::getActive, true)
|
.eq(IfsLog::getState,false));
|
inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList());
|
List<ReceiveStdData> receiveStdDataList = new ArrayList<>();
|
for (String inAttr: inAttrList) {
|
JSONObject jsonObject = JSONObject.parseObject(inAttr);
|
JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO");
|
for (int i = 0; i <batchInfoArray.size() ; i++) {
|
ReceiveStdData receiveStdData = new ReceiveStdData();
|
JSONObject batchInfoObject = batchInfoArray.getJSONObject(i);
|
receiveStdData.setPartNo(batchInfoObject.getString("PART_NO"));
|
receiveStdData.setQuantity(batchInfoObject.getString("QUANTITY"));
|
receiveStdData.setOrderNo(batchInfoObject.getString("ORDER_NO"));
|
receiveStdData.setLotBatchNo(batchInfoObject.getString("LOT_BATCH_NO"));
|
receiveStdData.setWaivDevRejNo(batchInfoObject.getString("WAIV_DEV_REJ_NO"));
|
receiveStdData.setLocationNo(batchInfoObject.getString("LOCATION_NO"));
|
receiveStdData.setEngChgLevel(batchInfoObject.getString("ENG_CHG_LEVEL"));
|
String mesParams = jsonObject.getString("mesParams");
|
if(StringUtils.isNotBlank(mesParams)){
|
receiveStdData.setProductMainId(mesParams.substring(mesParams.indexOf(":")+1,mesParams.indexOf("}")));
|
}
|
receiveStdData.setSysModel(jsonObject.getString("SYSMODEL"));
|
receiveStdDataList.add(receiveStdData);
|
}
|
}
|
excelWriter.write(receiveStdDataList, mainSheet);
|
break;
|
case "IMPORT_SO_MATERIAL_ISSUE_STD":
|
//获取sheet0对象
|
mainSheet = EasyExcel.writerSheet(0, "ifs缓存解析").head(MaterialIssueStdData.class).build();
|
ifsLogList = ifsLogMapper.selectList(Wrappers.<IfsLog>lambdaQuery().eq(IfsLog::getProcedureName, type)
|
.eq(IfsLog::getActive, true)
|
.eq(IfsLog::getState,false));
|
inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList());
|
List<MaterialIssueStdData> materialIssueStdDataList = new ArrayList<>();
|
for (String inAttr: inAttrList) {
|
JSONObject jsonObject = JSONObject.parseObject(inAttr);
|
JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO");
|
for (int i = 0; i <batchInfoArray.size() ; i++) {
|
MaterialIssueStdData materialIssueStdData = new MaterialIssueStdData();
|
JSONObject batchInfoObject = batchInfoArray.getJSONObject(i);
|
materialIssueStdData.setPartNo(batchInfoObject.getString("PART_NO"));
|
materialIssueStdData.setQtyToIssue(batchInfoObject.getString("QTY_TO_ISSUE"));
|
materialIssueStdData.setOrderNo(batchInfoObject.getString("ORDER_NO"));
|
materialIssueStdData.setLotBatchNo(batchInfoObject.getString("LOT_BATCH_NO"));
|
materialIssueStdData.setWaivDevRejNo(batchInfoObject.getString("WAIV_DEV_REJ_NO"));
|
materialIssueStdData.setLocationNo(batchInfoObject.getString("LOCATION_NO"));
|
materialIssueStdData.setEngChgLevel(batchInfoObject.getString("ENG_CHG_LEVEL"));
|
materialIssueStdData.setLineItemNo(batchInfoObject.getString("LINE_ITEM_NO"));
|
String mesParams = jsonObject.getString("mesParams");
|
if(StringUtils.isNotBlank(mesParams)){
|
materialIssueStdData.setProductMainId(mesParams.substring(mesParams.indexOf(":")+1,mesParams.indexOf("}")));
|
}
|
materialIssueStdData.setSysModel(jsonObject.getString("SYSMODEL"));
|
materialIssueStdDataList.add(materialIssueStdData);
|
}
|
}
|
excelWriter.write(materialIssueStdDataList, mainSheet);
|
break;
|
case "IMPORT_SO_MATERIAL_UNISSUE_STD":
|
//获取sheet0对象
|
mainSheet = EasyExcel.writerSheet(0, "ifs缓存解析").head(MaterialUnIssueStdData.class).build();
|
ifsLogList = ifsLogMapper.selectList(Wrappers.<IfsLog>lambdaQuery().eq(IfsLog::getProcedureName, type)
|
.eq(IfsLog::getActive, true)
|
.eq(IfsLog::getState,false));
|
inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList());
|
List<MaterialUnIssueStdData> materialUnIssueStdDataList = new ArrayList<>();
|
for (String inAttr: inAttrList) {
|
JSONObject jsonObject = JSONObject.parseObject(inAttr);
|
JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO");
|
for (int i = 0; i <batchInfoArray.size() ; i++) {
|
MaterialUnIssueStdData materialUnIssueStdData = new MaterialUnIssueStdData();
|
JSONObject batchInfoObject = batchInfoArray.getJSONObject(i);
|
materialUnIssueStdData.setPartNo(batchInfoObject.getString("PART_NO"));
|
materialUnIssueStdData.setQtyToUnIssue(batchInfoObject.getString("QTY_TO_UNISSUE"));
|
materialUnIssueStdData.setOrderNo(batchInfoObject.getString("ORDER_NO"));
|
materialUnIssueStdData.setLotBatchNo(batchInfoObject.getString("LOT_BATCH_NO"));
|
materialUnIssueStdData.setWaivDevRejNo(batchInfoObject.getString("WAIV_DEV_REJ_NO"));
|
materialUnIssueStdData.setLocationNo(batchInfoObject.getString("LOCATION_NO"));
|
materialUnIssueStdData.setEngChgLevel(batchInfoObject.getString("ENG_CHG_LEVEL"));
|
materialUnIssueStdData.setLineItemNo(batchInfoObject.getString("LINE_ITEM_NO"));
|
String mesParams = jsonObject.getString("mesParams");
|
if(StringUtils.isNotBlank(mesParams)){
|
materialUnIssueStdData.setProductMainId(mesParams.substring(mesParams.indexOf(":")+1,mesParams.indexOf("}")));
|
}
|
materialUnIssueStdData.setSysModel(jsonObject.getString("SYSMODEL"));
|
materialUnIssueStdDataList.add(materialUnIssueStdData);
|
}
|
}
|
excelWriter.write(materialUnIssueStdDataList, mainSheet);
|
break;
|
}
|
//关闭流
|
excelWriter.finish();
|
} catch (IOException e) {
|
throw new RuntimeException("导出失败");
|
}
|
}
|
}
|