|
@@ -1,5 +1,6 @@
|
|
|
package org.jeecg.modules.billet.storageBill.controller;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -19,7 +20,10 @@ import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.common.util.SpringContextUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletRulerConfig;
|
|
|
+import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletRulerConfigMapper;
|
|
|
import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
|
|
|
import org.jeecg.modules.billet.rollClubThree.service.IRollClubThreeDetailsService;
|
|
|
import org.jeecg.modules.billet.rollClubTwo.entity.RollClubTwoDetails;
|
|
@@ -32,6 +36,12 @@ import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippDetailsService
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBill;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
|
|
|
import org.jeecg.modules.billet.storageBill.service.IStorageBillPrintService;
|
|
|
+import org.jeecg.modules.billet.storageBill.vo.StorageCenterExportRow;
|
|
|
+import org.jeecg.modules.carUnit.entity.SysDict;
|
|
|
+import org.jeecg.modules.carUnit.entity.SysDictItem;
|
|
|
+import org.jeecg.modules.carUnit.mapper.CarUnitMapper;
|
|
|
+import org.jeecg.modules.carUnit.service.ISysDictItemService;
|
|
|
+import org.jeecg.modules.carUnit.service.ISysDictService;
|
|
|
import org.jeecg.modules.deviceSbm.entity.DeviceInformation;
|
|
|
import org.jeecg.modules.deviceSbm.entity.DeviceRegion;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
@@ -45,6 +55,9 @@ import org.springframework.web.servlet.ModelAndView;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -72,6 +85,9 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
|
|
|
|
|
|
@Autowired
|
|
|
private IRollDeputyCrossDetailsService rollDeputyCrossDetailsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ BilletRulerConfigMapper billetRulerConfigMapper;
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
@@ -174,11 +190,11 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
|
|
|
/**
|
|
|
* 导出excel
|
|
|
*
|
|
|
- * @param request
|
|
|
+ * @param response
|
|
|
* @param storageBillPrint
|
|
|
*/
|
|
|
@RequestMapping(value = "/exportXls")
|
|
|
- public ModelAndView exportXls(HttpServletRequest request, StorageBillPrint storageBillPrint) {
|
|
|
+ public void exportXls(HttpServletResponse response, StorageBillPrint storageBillPrint) {
|
|
|
try {
|
|
|
QueryWrapper<StorageBillPrint> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
@@ -245,11 +261,12 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
|
|
|
if (sizeStr != null && sizeStr.contains(",")) {
|
|
|
// 按逗号分割定尺字符串
|
|
|
String[] sizes = sizeStr.split(",");
|
|
|
-
|
|
|
for (int i = 0; i < sizes.length; i++) {
|
|
|
// 复制对象
|
|
|
StorageBillPrint newItem = new StorageBillPrint();
|
|
|
BeanUtils.copyProperties(item, newItem);
|
|
|
+ newItem.setAmountTotal(0);
|
|
|
+ newItem.setWeight(BigDecimal.ZERO);
|
|
|
// 根据装运单ID、炉号、铸机号、定尺、目的地查询对应的明细信息
|
|
|
if ("棒二".equals(item.getDestination())){
|
|
|
LambdaQueryWrapper<RollClubTwoDetails> queryWrapper2 = new LambdaQueryWrapper<>();
|
|
@@ -305,23 +322,53 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
|
|
|
finalList.add(item);
|
|
|
}
|
|
|
}
|
|
|
+ List<StorageCenterExportRow> exportRows = new ArrayList<>();
|
|
|
+ finalList.forEach(x -> {
|
|
|
+ StorageCenterExportRow exportRow = new StorageCenterExportRow();
|
|
|
+ exportRow.setAmount(x.getAmountTotal());
|
|
|
+ exportRow.setBrand(x.getBrandNum());
|
|
|
+ exportRow.setCcmNo(Integer.valueOf(x.getCcmNo()));
|
|
|
+ exportRow.setEndPoint(x.getDestination());
|
|
|
+ exportRow.setFactoryDate(DateUtils.date2Str(x.getArrivalTime(), DateUtils.datetimeFormat.get()));
|
|
|
+ exportRow.setHeatNo(x.getHeatNo());
|
|
|
+ exportRow.setLicensePlate(x.getLicensePlate());
|
|
|
+ BigDecimal result = new BigDecimal(x.getSize()).divide(BigDecimal.valueOf(1000));
|
|
|
+ if (result != null) {
|
|
|
+ exportRow.setSize("170*170*" + result.toPlainString());
|
|
|
+ }
|
|
|
+ exportRow.setSpec(x.getName());
|
|
|
+ exportRow.setTransportUnit(getTransportUnitNameByCarNumber(x.getLicensePlate()));
|
|
|
+ exportRow.setTotalWeight(x.getWeight());
|
|
|
|
|
|
- // Step.3 AutoPoi 导出Excel
|
|
|
- ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
- //此处设置的filename无效 ,前端会重更新设置一下
|
|
|
- mv.addObject(NormalExcelConstants.FILE_NAME, "装运打印信息列表");
|
|
|
- mv.addObject(NormalExcelConstants.CLASS, StorageBillPrint.class);
|
|
|
- ExportParams exportParams=new ExportParams("储运中心数据" + "报表", "admin", "装运打印信息");
|
|
|
- mv.addObject(NormalExcelConstants.PARAMS,exportParams);
|
|
|
- mv.addObject(NormalExcelConstants.DATA_LIST, finalList);
|
|
|
- return mv;
|
|
|
+ // 查询定尺规则
|
|
|
+ LambdaQueryWrapper<BilletRulerConfig> queryWrapperbilletRulerConfig = new LambdaQueryWrapper<BilletRulerConfig>().eq(BilletRulerConfig::getLength, Integer.valueOf(x.getSize()));
|
|
|
+ BilletRulerConfig billetRulerConfig = billetRulerConfigMapper.selectOne(queryWrapperbilletRulerConfig);
|
|
|
+ Double weight = 0.0;
|
|
|
+ if (oConvertUtils.isEmpty(billetRulerConfig)) {
|
|
|
+ exportRow.setWeightPerPiece(new BigDecimal(0.0));
|
|
|
+ } else {
|
|
|
+ weight = billetRulerConfig.getWeight();
|
|
|
+ exportRow.setWeightPerPiece(BigDecimal.valueOf(weight));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String btype = Optional.ofNullable(x.getBtype()).orElse("");
|
|
|
+ exportRow.setBtype("0".equals(btype) ? "热坯" : "凉坯");
|
|
|
+ exportRows.add(exportRow);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置响应
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = URLEncoder.encode("储运中心装运打印信息", String.valueOf(StandardCharsets.UTF_8)).replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
+
|
|
|
+ // 导出
|
|
|
+ EasyExcel.write(response.getOutputStream(), StorageCenterExportRow.class)
|
|
|
+ .sheet("装运打印信息")
|
|
|
+ .doWrite(exportRows);
|
|
|
}catch (Exception e){
|
|
|
- log.error("导出Excel失败:", e);
|
|
|
- // 返回错误信息
|
|
|
- ModelAndView mv = new ModelAndView();
|
|
|
- mv.addObject("message", "导出失败:" + e.getMessage());
|
|
|
- mv.setViewName("error/500");
|
|
|
- return mv;
|
|
|
+ log.error("导出Excel失败:", e);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -339,4 +386,47 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
|
|
|
return super.importExcel(request, response, StorageBillPrint.class);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static String getTransportUnitNameByCarNumber(String carNumber) {
|
|
|
+ if (StringUtils.isBlank(carNumber)) return "";
|
|
|
+
|
|
|
+ CarUnitMapper carUnitMapper = SpringContextUtils.getBean(CarUnitMapper.class);
|
|
|
+ ISysDictItemService sysDictItemService = SpringContextUtils.getBean(ISysDictItemService.class);
|
|
|
+ // 查询 unitCode
|
|
|
+ String unitCode = carUnitMapper.getUnitByCarNumber(carNumber);
|
|
|
+ if (StringUtils.isBlank(unitCode)) return "其他";
|
|
|
+
|
|
|
+ // 查询 car_unit_type 下所有字典项(item_text + item_value)
|
|
|
+ String dictId = getDictId("car_unit_type");
|
|
|
+ if (StringUtils.isBlank(dictId)) return "其他";
|
|
|
+
|
|
|
+ List<SysDictItem> sysDictItems = sysDictItemService.list(
|
|
|
+ new LambdaQueryWrapper<SysDictItem>()
|
|
|
+ .eq(SysDictItem::getDictId, dictId)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 遍历匹配 unitCode 是否在 item_value 中
|
|
|
+ for (SysDictItem item : sysDictItems) {
|
|
|
+ if (unitCode.equals(item.getItemValue())) {
|
|
|
+ return item.getItemText(); // 匹配成功返回单位名称(如“辉腾”)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return "其他";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getDictId(String dictCode) {
|
|
|
+ ISysDictService sysDictService = SpringContextUtils.getBean(ISysDictService.class);
|
|
|
+ SysDict dict = sysDictService.getOne(
|
|
|
+ new LambdaQueryWrapper<SysDict>()
|
|
|
+ .eq(SysDict::getDictCode, dictCode)
|
|
|
+ .last("LIMIT 1")
|
|
|
+ );
|
|
|
+ return dict != null ? dict.getId() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static BigDecimal calcWeightPerPiece(BigDecimal total, Integer amount) {
|
|
|
+ if (total == null || amount == null || amount == 0) return BigDecimal.ZERO;
|
|
|
+ return total.divide(BigDecimal.valueOf(amount), 4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
}
|