|  | @@ -1,5 +1,9 @@
 | 
	
		
			
				|  |  |  package org.jeecg.modules.cost.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.excel.EasyExcel;
 | 
	
		
			
				|  |  | +import com.alibaba.excel.ExcelWriter;
 | 
	
		
			
				|  |  | +import com.alibaba.excel.write.metadata.WriteSheet;
 | 
	
		
			
				|  |  | +import com.alibaba.excel.write.metadata.fill.FillConfig;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 | 
	
	
		
			
				|  | @@ -8,7 +12,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 | 
	
		
			
				|  |  |  import org.apache.poi.ss.formula.functions.T;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.usermodel.Workbook;
 | 
	
		
			
				|  |  | +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 | 
	
		
			
				|  |  |  import org.apache.shiro.SecurityUtils;
 | 
	
		
			
				|  |  |  import org.jeecg.common.api.vo.Result;
 | 
	
		
			
				|  |  |  import org.jeecg.common.aspect.annotation.AutoLog;
 | 
	
	
		
			
				|  | @@ -20,12 +27,15 @@ import org.jeecg.common.util.oConvertUtils;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.cost.entity.*;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.cost.service.*;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.cost.vo.SyCostAllocationPage;
 | 
	
		
			
				|  |  | +import org.jeecg.modules.demo.test.entity.JoaDemo;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.report.entity.FabricLoss;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.report.entity.SyFabricLossReport;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.report.mapper.FabricLossMapper;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.report.service.IFabricLossService;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.report.service.ISyFabricLossReportService;
 | 
	
		
			
				|  |  | +import org.jeecg.modules.scas.entity.SyCostAllocationSummary;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.system.controller.CommonController;
 | 
	
		
			
				|  |  | +import org.jeecgframework.poi.excel.ExcelExportUtil;
 | 
	
		
			
				|  |  |  import org.jeecgframework.poi.excel.ExcelImportUtil;
 | 
	
		
			
				|  |  |  import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 | 
	
		
			
				|  |  |  import org.jeecgframework.poi.excel.entity.ExportParams;
 | 
	
	
		
			
				|  | @@ -40,9 +50,10 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
 | 
	
		
			
				|  |  |  import org.springframework.web.servlet.ModelAndView;
 | 
	
		
			
				|  |  |  import springfox.documentation.spring.web.json.Json;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import javax.servlet.ServletOutputStream;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  | -import java.io.IOException;
 | 
	
		
			
				|  |  | +import java.io.*;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -374,8 +385,8 @@ public class SyCostAllocationController {
 | 
	
		
			
				|  |  |       * @param request
 | 
	
		
			
				|  |  |       * @param syCostAllocation
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    @RequestMapping(value = "/exportXls")
 | 
	
		
			
				|  |  | -    public ModelAndView exportXls(HttpServletRequest request, SyCostAllocation syCostAllocation) {
 | 
	
		
			
				|  |  | +    @RequestMapping(value = "/exportXls1")
 | 
	
		
			
				|  |  | +    public ModelAndView exportXls1(HttpServletRequest request, SyCostAllocation syCostAllocation) {
 | 
	
		
			
				|  |  |          // Step.1 组装查询条件
 | 
	
		
			
				|  |  |          QueryWrapper<SyCostAllocation> queryWrapper = QueryGenerator.initQueryWrapper(syCostAllocation, request.getParameterMap());
 | 
	
		
			
				|  |  |          LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 | 
	
	
		
			
				|  | @@ -564,4 +575,70 @@ public class SyCostAllocationController {
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 成本分配导出
 | 
	
		
			
				|  |  | +     * @param request
 | 
	
		
			
				|  |  | +     * @param response
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @RequestMapping(value = "/exportXlsSyCostAllocation")
 | 
	
		
			
				|  |  | +    public void exportXlsSyCostAllocation(@RequestBody SyCostAllocation syCostAllocation,
 | 
	
		
			
				|  |  | +                                  HttpServletRequest request, HttpServletResponse response) throws IOException {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //获取模板输入流
 | 
	
		
			
				|  |  | +        InputStream inStream = new FileInputStream("D:\\单证模板\\成本分配-"+syCostAllocation.getSheetName()+".xlsx");
 | 
	
		
			
				|  |  | +        //通过poi创建表对象
 | 
	
		
			
				|  |  | +        XSSFWorkbook workbook = new XSSFWorkbook(inStream);
 | 
	
		
			
				|  |  | +        //遍历复制sheet
 | 
	
		
			
				|  |  | +        ByteArrayOutputStream bos = new ByteArrayOutputStream();
 | 
	
		
			
				|  |  | +        //写到流
 | 
	
		
			
				|  |  | +        workbook.write(bos);
 | 
	
		
			
				|  |  | +        ServletOutputStream outputStream = response.getOutputStream();
 | 
	
		
			
				|  |  | +        ByteArrayInputStream is = new ByteArrayInputStream(bos.toByteArray());
 | 
	
		
			
				|  |  | +        ExcelWriter excelWriter = EasyExcel.write(outputStream).withTemplate(is).build();
 | 
	
		
			
				|  |  | +        //填充配置, 这里的意义是给模板中的集合数据添加新行, 保证导出不会错乱
 | 
	
		
			
				|  |  | +        FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //多发少发
 | 
	
		
			
				|  |  | +        if(oConvertUtils.isNotEmpty(syCostAllocation.getSyPilosityFewer())&& syCostAllocation.getSyPilosityFewer().size()!=0 ){
 | 
	
		
			
				|  |  | +            List<SyPilosityFewer> syTransferList= syCostAllocation.getSyPilosityFewer();
 | 
	
		
			
				|  |  | +            WriteSheet writeSheet1 = EasyExcel.writerSheet("多发少发").build();
 | 
	
		
			
				|  |  | +            excelWriter.fill(syTransferList, fillConfig, writeSheet1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //面料余下数量
 | 
	
		
			
				|  |  | +        if(oConvertUtils.isNotEmpty(syCostAllocation.getSyRemaining())&&syCostAllocation.getSyRemaining().size()!=0){
 | 
	
		
			
				|  |  | +            List<SyRemaining> syRemainingList= syCostAllocation.getSyRemaining();
 | 
	
		
			
				|  |  | +            WriteSheet writeSheet1 = EasyExcel.writerSheet("面料余下").build();
 | 
	
		
			
				|  |  | +            excelWriter.fill(syRemainingList, fillConfig, writeSheet1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //辅料余下数量
 | 
	
		
			
				|  |  | +        if( oConvertUtils.isNotEmpty(syCostAllocation.getSyRemainingIngreDeent()) && syCostAllocation.getSyRemainingIngreDeent().size()!=0){
 | 
	
		
			
				|  |  | +            List<SyRemainingIngreDeent> syRemainingList= syCostAllocation.getSyRemainingIngreDeent();
 | 
	
		
			
				|  |  | +            WriteSheet writeSheet1 = EasyExcel.writerSheet("辅料余下").build();
 | 
	
		
			
				|  |  | +            excelWriter.fill(syRemainingList, fillConfig, writeSheet1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //面料转入数量
 | 
	
		
			
				|  |  | +        if(oConvertUtils.isNotEmpty(syCostAllocation.getSyTransfer())&& syCostAllocation.getSyTransfer().size()!=0){
 | 
	
		
			
				|  |  | +            List<SyTransfer> syTransferList= syCostAllocation.getSyTransfer();
 | 
	
		
			
				|  |  | +            WriteSheet writeSheet1 = EasyExcel.writerSheet("面料转入").build();
 | 
	
		
			
				|  |  | +            excelWriter.fill(syTransferList, fillConfig, writeSheet1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //辅料转入数量
 | 
	
		
			
				|  |  | +        if( oConvertUtils.isNotEmpty(syCostAllocation.getSytransferIngreDeent()) && syCostAllocation.getSytransferIngreDeent().size()!=0){
 | 
	
		
			
				|  |  | +            List<SytransferIngreDeent> syRemainingList= syCostAllocation.getSytransferIngreDeent();
 | 
	
		
			
				|  |  | +            WriteSheet writeSheet1 = EasyExcel.writerSheet("辅料转入").build();
 | 
	
		
			
				|  |  | +            excelWriter.fill(syRemainingList, fillConfig, writeSheet1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //关流
 | 
	
		
			
				|  |  | +        excelWriter.finish();
 | 
	
		
			
				|  |  | +        inStream.close();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |