/* * 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 implements IfsLogService { @Resource private IfsLogMapper ifsLogMapper; private final List 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 ifsLogs = ifsLogMapper.selectList(Wrappers.lambdaQuery().eq(IfsLog::getState, Boolean.FALSE).in(IfsLog::getProcedureName, orderInterfaceNames)); if (CollectionUtil.isEmpty(ifsLogs)) { return; } Map> 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 ifsLogList = new ArrayList<>(); List 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.lambdaQuery().eq(IfsLog::getProcedureName, type) .eq(IfsLog::getActive, true) .eq(IfsLog::getState,false)); inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList()); List receiveStdDataList = new ArrayList<>(); for (String inAttr: inAttrList) { JSONObject jsonObject = JSONObject.parseObject(inAttr); JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO"); for (int i = 0; i lambdaQuery().eq(IfsLog::getProcedureName, type) .eq(IfsLog::getActive, true) .eq(IfsLog::getState,false)); inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList()); List materialIssueStdDataList = new ArrayList<>(); for (String inAttr: inAttrList) { JSONObject jsonObject = JSONObject.parseObject(inAttr); JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO"); for (int i = 0; i lambdaQuery().eq(IfsLog::getProcedureName, type) .eq(IfsLog::getActive, true) .eq(IfsLog::getState,false)); inAttrList = ifsLogList.stream().map(IfsLog::getInAttr).collect(Collectors.toList()); List materialUnIssueStdDataList = new ArrayList<>(); for (String inAttr: inAttrList) { JSONObject jsonObject = JSONObject.parseObject(inAttr); JSONArray batchInfoArray = jsonObject.getJSONArray("BATCH_INFO"); for (int i = 0; i