diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/BomReportApi.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/BomReportApi.java index 083a1bed..ce19c106 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/BomReportApi.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/BomReportApi.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.nflg.product.base.core.api.BaseApi; +import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.bomnew.constant.ReportConstant; import com.nflg.product.bomnew.pojo.query.ChildBomReportQuery; import com.nflg.product.bomnew.pojo.query.CompareReportQuery; @@ -13,6 +14,7 @@ import com.nflg.product.bomnew.pojo.vo.*; import com.nflg.product.bomnew.service.CompareReportService; import com.nflg.product.bomnew.service.ForwardReportService; import com.nflg.product.bomnew.service.ReverseReportService; +import com.nflg.product.bomnew.util.EecExcelUtil; import com.nflg.product.bomnew.util.VUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -132,6 +134,25 @@ public class BomReportApi extends BaseApi { } + @PostMapping("compareExport") + @ApiOperation("bom-比对导出") + public void compareExport(@RequestBody CompareReportQuery query,HttpServletResponse response) throws IOException { + + ResultVO resultBom1VO = checkQueryParam(query.getLeft()); + ResultVO resultBom2VO = checkQueryParam(query.getRight()); + + if (resultBom1VO != null) { + new NflgBusinessException(STATE.Error,resultBom1VO.getMsg()); + } + + if (resultBom2VO != null) { + new NflgBusinessException(STATE.Error,resultBom1VO.getMsg()); + } + + EecExcelUtil.setResponseExcelHeader(response, "BOM比对"); + compareReportService.compareBomExport( response.getOutputStream(),query); + + } @PostMapping("forwardExport") @ApiOperation("bom-正查导出") diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ReportConstant.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ReportConstant.java index 1a1c8422..316b990a 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ReportConstant.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/ReportConstant.java @@ -79,7 +79,7 @@ public class ReportConstant { @AllArgsConstructor @Getter - public enum SymbolEnum implements ValueEnum { + public static enum SymbolEnum implements ValueEnum { //比对 EQ(1, "相等"), diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/excel/CompareReportField.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/excel/CompareReportField.java deleted file mode 100644 index ef3ba1e7..00000000 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/excel/CompareReportField.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nflg.product.bomnew.excel; - -import com.alibaba.excel.annotation.ExcelProperty; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -import java.io.File; -import java.math.BigDecimal; - -@Data -public class CompareReportField { - -// @ApiModelProperty("汇总") -// @ExcelProperty(value="汇总") -// private Integer levelNum; - - @ApiModelProperty("物料编码") - @ExcelProperty(value="物料编码") - private String materialNo; - @ApiModelProperty("图号") - @ExcelProperty(value="图号") - private String drawingNo; - - - @ApiModelProperty("物料描述") - @ExcelProperty(value="物料描述") - private String materialDesc; - - @ApiModelProperty("数量") - @ExcelProperty(value = "数量") - private BigDecimal num; - - @ApiModelProperty("单位") - @ExcelProperty(value = "单位") - private String materialUnit; - @ApiModelProperty("层级") - @ExcelProperty(value="层级") - private Integer levelNum; - - @ApiModelProperty("比对结果") - @ExcelProperty("比对结果") - private File compareSymbol; - - - - - @ApiModelProperty("数量") - @ExcelProperty(value = "数量") - private BigDecimal num2; - @ApiModelProperty("单位") - @ExcelProperty(value = "单位") - private String materialUnit2; - @ApiModelProperty("层级") - @ExcelProperty(value="层级") - private Integer levelNum2; - -} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/CompareReportField.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/CompareReportField.java new file mode 100644 index 00000000..27624cdc --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/CompareReportField.java @@ -0,0 +1,70 @@ +package com.nflg.product.bomnew.pojo.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.ttzero.excel.annotation.ExcelColumn; +import org.ttzero.excel.annotation.MediaColumn; + +import java.io.File; +import java.math.BigDecimal; + +@Data +public class CompareReportField { + + @ApiModelProperty("汇总") + @ExcelColumn(value="汇总") + private String sumSymbol; + + @ApiModelProperty("物料编码") + // @ExcelProperty(value="物料编码") + @ExcelColumn(value="物料编码") + private String materialNo; + @ApiModelProperty("图号") + // @ExcelProperty(value="图号") + @ExcelColumn(value="图号") + private String drawingNo; + + + @ApiModelProperty("物料描述") + // @ExcelProperty(value="物料描述") + @ExcelColumn(value="物料描述") + private String materialDesc; + + @ApiModelProperty("数量") + // @ExcelProperty(value = "数量") + @ExcelColumn(value="数量") + private BigDecimal num; + + @ApiModelProperty("单位") + // @ExcelProperty(value = "单位") + @ExcelColumn(value="单位") + private String materialUnit; + @ApiModelProperty("层级") + // @ExcelProperty(value="层级") + @ExcelColumn(value="层级") + private Integer levelNum; + + @ApiModelProperty("比对结果") + //@ExcelProperty("比对结果") + @MediaColumn + @ExcelColumn(value="比对结果") + private File compareSymbol; + + + + + @ApiModelProperty("数量") + // @ExcelProperty(value = "数量2") + @ExcelColumn(value="数量 ") + private BigDecimal num2; + @ApiModelProperty("单位") + // @ExcelProperty(value = "单位2") + @ExcelColumn(value="单位 ") + private String materialUnit2; + @ApiModelProperty("层级") + @ExcelColumn(value="层级 ") + //@ExcelProperty(value="层级2") + private Integer levelNum2; + +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java index 889830fb..71309be2 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java @@ -36,6 +36,7 @@ import nflg.product.common.vo.ResultVO; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.ttzero.excel.entity.ListSheet; import org.ttzero.excel.entity.Workbook; import javax.annotation.Resource; @@ -223,7 +224,7 @@ public class BomNewPbomParentService extends ServiceImpl result = this.getBaseMapper().workDetailsExcel(userRoleService.getUserFactory()); materialMainService.intiMaterialInfo(result, BomNewPbomWorkExcelVO::getMaterialNo, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); - new Workbook().addSheet(result).writeTo(response.getOutputStream()); + new Workbook().addSheet(new ListSheet<>(result)).writeTo(response.getOutputStream()); } /** @@ -238,7 +239,7 @@ public class BomNewPbomParentService extends ServiceImpl result = this.getBaseMapper().releaseListExcel(query); materialMainService.intiMaterialInfo(result, BomNewPbomWorkExcelVO::getMaterialNo, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT); - new Workbook().addSheet(result).writeTo(response.getOutputStream()); + new Workbook().addSheet(new ListSheet<>(result)).writeTo(response.getOutputStream()); } public List getChild(Long rowId) { @@ -396,7 +397,7 @@ public class BomNewPbomParentService extends ServiceImpl child = this.getChild(bomRowId); List result = Convert.toList(BomNewPbomEditExcelVO.class, child); - new Workbook().addSheet(result).writeTo(response.getOutputStream()); + new Workbook().addSheet(new ListSheet<>(result)).writeTo(response.getOutputStream()); } @@ -408,8 +409,7 @@ public class BomNewPbomParentService extends ServiceImpl result = Convert.toList(BomNewPbomEditExcelVO.class, child); - new Workbook().addSheet(result).writeTo(response.getOutputStream()); - + new Workbook().addSheet(new ListSheet<>(result)).writeTo(response.getOutputStream() ); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/CompareReportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/CompareReportService.java index d472b578..04d5859e 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/CompareReportService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/CompareReportService.java @@ -2,21 +2,24 @@ package com.nflg.product.bomnew.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.lang.TypeReference; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.support.ExcelTypeEnum; import com.nflg.product.bomnew.constant.ReportConstant; -import com.nflg.product.bomnew.excel.CompareReportField; +import com.nflg.product.bomnew.pojo.vo.*; import com.nflg.product.bomnew.pojo.query.CompareReportQuery; -import com.nflg.product.bomnew.pojo.vo.CompareReportListVO; -import com.nflg.product.bomnew.pojo.vo.CompareReportVO; -import com.nflg.product.bomnew.pojo.vo.ForwardReportVO; -import com.nflg.product.bomnew.pojo.vo.ReportBomVO; +import com.nflg.product.bomnew.util.EecExcelUtil; import com.nflg.product.bomnew.util.VUtils; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; +import org.ttzero.excel.entity.ListSheet; +import java.io.*; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -28,6 +31,9 @@ import java.util.stream.Collectors; public class CompareReportService { + public CompareReportService() throws IOException { + } + public CompareReportListVO compareBom(CompareReportQuery query) { ReportBomVO left = SpringUtil.getBean(ForwardReportService.class).factoryBomType(query.getLeft()); ReportBomVO right = SpringUtil.getBean(ForwardReportService.class).factoryBomType(query.getRight()); @@ -56,32 +62,154 @@ public class CompareReportService { } - - public void compareBomExport(CompareReportQuery query) { + /** + * 比较导出 + * ∑ + * @param query + */ + public void compareBomExport(OutputStream filePath,CompareReportQuery query) throws IOException { CompareReportListVO list=compareBom(query); if(CollUtil.isEmpty(list.getChildNodes())){ return; } + List excelList=new ArrayList<>(); for (CompareReportVO compareReportVO: list.getChildNodes()) { CompareReportField compareReportField=null; if(compareReportVO.getLeft()!=null){ compareReportField= Convert.convert(CompareReportField.class,compareReportVO.getLeft()); + }else{ + compareReportField= Convert.convert(CompareReportField.class,compareReportVO.getLeft()); + } + if(compareReportField==null){ + continue; + } + excelList.add(compareReportField); + + + if(ObjectUtil.equal(compareReportVO.getSymbol(),ReportConstant.SymbolEnum.EQ.getValue()) + ||ObjectUtil.equal(compareReportVO.getSymbol(),ReportConstant.SymbolEnum.NON_EQ.getValue())) { + + compareReportField.setLevelNum(compareReportVO.getLeft().getLevelNum()); + compareReportField.setNum(compareReportVO.getLeft().getNum()); + compareReportField.setMaterialUnit(compareReportVO.getLeft().getMaterialUnit()); + + compareReportField.setLevelNum2(compareReportVO.getRight().getLevelNum()); + compareReportField.setNum2(compareReportVO.getRight().getNum()); + compareReportField.setMaterialUnit2(compareReportVO.getRight().getMaterialUnit()); + + if(ObjectUtil.equal(compareReportVO.getLeft().getTag(),ReportConstant.TagEnum.SIGMA.getValue()) + ||ObjectUtil.equal(compareReportVO.getRight().getTag(),ReportConstant.TagEnum.SIGMA.getValue()) + ) { + compareReportField.setSumSymbol("Σ"); + } + + + }else if (ObjectUtil.equal(compareReportVO.getSymbol(),ReportConstant.SymbolEnum.L_NULL.getValue())){ + + compareReportField.setLevelNum(compareReportVO.getLeft().getLevelNum()); + compareReportField.setNum(compareReportVO.getLeft().getNum()); + compareReportField.setMaterialUnit(compareReportVO.getLeft().getMaterialUnit()); + + + if(ObjectUtil.equal(compareReportVO.getLeft().getTag(),ReportConstant.TagEnum.SIGMA.getValue()) + + ) { + compareReportField.setSumSymbol("Σ"); + } + compareReportField.setLevelNum2(null); + compareReportField.setNum2(null); + compareReportField.setMaterialUnit2(null); + + }else if (ObjectUtil.equal(compareReportVO.getSymbol(),ReportConstant.SymbolEnum.NULL_R.getValue())){ + + compareReportField.setLevelNum(null); + compareReportField.setNum(null); + compareReportField.setMaterialUnit(null); + + compareReportField.setLevelNum2(compareReportVO.getRight().getLevelNum()); + compareReportField.setNum2(compareReportVO.getRight().getNum()); + compareReportField.setMaterialUnit2(compareReportVO.getRight().getMaterialUnit()); + if(ObjectUtil.equal(compareReportVO.getRight().getTag(),ReportConstant.TagEnum.SIGMA.getValue()) + + ) { + compareReportField.setSumSymbol("Σ"); + } + } + compareReportField.setCompareSymbol(getFile(compareReportVO.getSymbol())); + + if(compareReportVO.getLeft()!=null){ + + } } - } +// EasyExcel.write(filePath) +// .needHead(true) +// .excelType(ExcelTypeEnum.XLSX) +// .autoCloseStream(Boolean.FALSE) +// +// .sheet("Mbom") +// .doWrite(excelList); + + +// final ListSheet listSheet = new ListSheet() { +// Long n = 0L; +// Long pages = 1L; +// +// @Override +// protected List more() { +// return n++ < pages ? excelList : null; +// } +// }; + ListSheet listSheet = new ListSheet(excelList); + + EecExcelUtil.eecExcel("BOM比对", listSheet, filePath); + + } + + +File getFile(Integer type) throws IOException { + + String filePath="0.png"; + if(ObjectUtil.equal(type,ReportConstant.SymbolEnum.EQ.getValue()) + ) { + + filePath="1.png"; + + } else if (ObjectUtil.equal(type,ReportConstant.SymbolEnum.NON_EQ.getValue())) { + filePath="0.png"; + + }else if (ObjectUtil.equal(type,ReportConstant.SymbolEnum.L_NULL.getValue())){ + filePath="2.png"; + + + }else if (ObjectUtil.equal(type,ReportConstant.SymbolEnum.NULL_R.getValue())){ + filePath="2.png"; + } + + + ClassPathResource resource = new ClassPathResource("template/"+filePath); + + File input = resource.getFile(); + + return input; +} + + + + /** * 左倾斜 或右倾斜 * @param leftNode diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/template/0.png b/nflg_project_dev/nflg-bom-new/src/main/resources/template/0.png new file mode 100644 index 00000000..fbe555de Binary files /dev/null and b/nflg_project_dev/nflg-bom-new/src/main/resources/template/0.png differ diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/template/1.png b/nflg_project_dev/nflg-bom-new/src/main/resources/template/1.png new file mode 100644 index 00000000..02f5dc09 Binary files /dev/null and b/nflg_project_dev/nflg-bom-new/src/main/resources/template/1.png differ diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/template/2.png b/nflg_project_dev/nflg-bom-new/src/main/resources/template/2.png new file mode 100644 index 00000000..02d6533f Binary files /dev/null and b/nflg_project_dev/nflg-bom-new/src/main/resources/template/2.png differ diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/template/sum.png b/nflg_project_dev/nflg-bom-new/src/main/resources/template/sum.png new file mode 100644 index 00000000..bcae4d36 Binary files /dev/null and b/nflg_project_dev/nflg-bom-new/src/main/resources/template/sum.png differ diff --git a/nflg_project_dev/pom.xml b/nflg_project_dev/pom.xml index 70f5eb88..5c5c19b8 100644 --- a/nflg_project_dev/pom.xml +++ b/nflg_project_dev/pom.xml @@ -57,7 +57,7 @@ 2.9.0 5.6.5 1.9.3 - 0.4.14 + 0.5.13 1.3.17