|
@@ -0,0 +1,472 @@
|
|
|
+package org.jeecg.modules.billet.rollOldAreas.controller;
|
|
|
+
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+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.commons.lang.StringUtils;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
+import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+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.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
+import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
|
|
|
+import org.jeecg.modules.billet.rollOldAreas.entity.RollOldAreasDetails;
|
|
|
+import org.jeecg.modules.billet.rollOldAreas.service.IRollOldAreasDetailsService;
|
|
|
+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.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 老区明细
|
|
|
+ * @Author: jeecg-boot
|
|
|
+ * @Date: 2025-07-16
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@Api(tags = "老区明细")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/billet/rollOldAreasDetails")
|
|
|
+@Slf4j
|
|
|
+public class RollOldAreasDetailsController extends JeecgController<RollOldAreasDetails, IRollOldAreasDetailsService> {
|
|
|
+ @Autowired
|
|
|
+ private IRollOldAreasDetailsService rollOldAreasDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictService sysDictService;
|
|
|
+ @Autowired
|
|
|
+ private BilletRulerConfigMapper billetRulerConfigMapper;
|
|
|
+ @Autowired
|
|
|
+ private IStorageBillPrintService storageBillPrintService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页列表查询
|
|
|
+ *
|
|
|
+ * @param rollOldAreasDetails
|
|
|
+ * @param pageNo
|
|
|
+ * @param pageSize
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "老区明细-分页列表查询")
|
|
|
+ @ApiOperation(value = "老区明细-分页列表查询", notes = "老区明细-分页列表查询")
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<RollOldAreasDetails>> queryPageList(RollOldAreasDetails rollOldAreasDetails,
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ QueryWrapper<RollOldAreasDetails> queryWrapper = QueryGenerator.initQueryWrapper(rollOldAreasDetails, req.getParameterMap());
|
|
|
+ Page<RollOldAreasDetails> page = new Page<RollOldAreasDetails>(pageNo, pageSize);
|
|
|
+ IPage<RollOldAreasDetails> pageList = rollOldAreasDetailsService.page(page, queryWrapper);
|
|
|
+ return Result.OK(pageList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ * @param rollOldAreasDetails
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "老区明细-添加")
|
|
|
+ @ApiOperation(value = "老区明细-添加", notes = "老区明细-添加")
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:add")
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<String> add(@RequestBody RollOldAreasDetails rollOldAreasDetails) {
|
|
|
+ rollOldAreasDetailsService.save(rollOldAreasDetails);
|
|
|
+ return Result.OK("添加成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ *
|
|
|
+ * @param rollOldAreasDetails
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "老区明细-编辑")
|
|
|
+ @ApiOperation(value = "老区明细-编辑", notes = "老区明细-编辑")
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:edit")
|
|
|
+ @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
|
|
+ public Result<String> edit(@RequestBody RollOldAreasDetails rollOldAreasDetails) {
|
|
|
+ rollOldAreasDetailsService.updateById(rollOldAreasDetails);
|
|
|
+ return Result.OK("编辑成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "老区明细-通过id删除")
|
|
|
+ @ApiOperation(value = "老区明细-通过id删除", notes = "老区明细-通过id删除")
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:delete")
|
|
|
+ @DeleteMapping(value = "/delete")
|
|
|
+ public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ rollOldAreasDetailsService.removeById(id);
|
|
|
+ return Result.OK("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AutoLog(value = "老区明细-批量删除")
|
|
|
+ @ApiOperation(value = "老区明细-批量删除", notes = "老区明细-批量删除")
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:deleteBatch")
|
|
|
+ @DeleteMapping(value = "/deleteBatch")
|
|
|
+ public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
|
|
+ this.rollOldAreasDetailsService.removeByIds(Arrays.asList(ids.split(",")));
|
|
|
+ return Result.OK("批量删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过id查询
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ //@AutoLog(value = "老区明细-通过id查询")
|
|
|
+ @ApiOperation(value = "老区明细-通过id查询", notes = "老区明细-通过id查询")
|
|
|
+ @GetMapping(value = "/queryById")
|
|
|
+ public Result<RollOldAreasDetails> queryById(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ RollOldAreasDetails rollOldAreasDetails = rollOldAreasDetailsService.getById(id);
|
|
|
+ if (rollOldAreasDetails == null) {
|
|
|
+ return Result.error("未找到对应数据");
|
|
|
+ }
|
|
|
+ return Result.OK(rollOldAreasDetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param rollOldAreasDetails
|
|
|
+ */
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:exportXls")
|
|
|
+ @RequestMapping(value = "/exportXls")
|
|
|
+ public ModelAndView exportXls(HttpServletRequest request, RollOldAreasDetails rollOldAreasDetails) {
|
|
|
+ return super.exportXls(request, rollOldAreasDetails, RollOldAreasDetails.class, "老区明细");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过excel导入数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequiresPermissions("billet:roll_old_areas_details:importExcel")
|
|
|
+ @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
|
|
+ public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ return super.importExcel(request, response, RollOldAreasDetails.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param storageBillPrint
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "老区工作台导出", notes = "老区工作台导出")
|
|
|
+ @GetMapping(value = "/exportOldXls")
|
|
|
+ public void exportOldXls(HttpServletResponse response, StorageBillPrint storageBillPrint) {
|
|
|
+ try {
|
|
|
+ QueryWrapper<StorageBillPrint> queryWrapper = new QueryWrapper<StorageBillPrint>();
|
|
|
+ // 铸机号查询条件
|
|
|
+ queryWrapper.eq("ccm_no", storageBillPrint.getCcmNo());
|
|
|
+ // 目的地
|
|
|
+ queryWrapper.eq("destination", "老区");
|
|
|
+ Boolean search = true; // 定义未传任何条件
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getChangeShiftId())) { // 班组取班组时间
|
|
|
+ // 根据铸机号、交班记录ID,获取交班记录中的班别、班次、创建时间
|
|
|
+ LambdaQueryWrapper<BilletHotsendChangeShift> changeQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ changeQueryWrapper.eq(BilletHotsendChangeShift::getId, storageBillPrint.getChangeShiftId()).eq(BilletHotsendChangeShift::getCcmNo, storageBillPrint.getCcmNo());
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(changeQueryWrapper);
|
|
|
+ if (billetHotsendChangeShift == null) {
|
|
|
+ throw new RuntimeException("未查询到交班记录,无法导出!");
|
|
|
+ }
|
|
|
+ Date startChnageTime = billetHotsendChangeShift.getCreateTime();
|
|
|
+ String classes = billetHotsendChangeShift.getShift() + "/" + billetHotsendChangeShift.getShiftGroup();
|
|
|
+ queryWrapper.eq("classes", classes);
|
|
|
+ Date endChnageTime = oConvertUtils.isNotEmpty(billetHotsendChangeShift.getChangeShiftTime()) ? billetHotsendChangeShift.getChangeShiftTime() : new Date();
|
|
|
+ // 修改时间范围查询条件为 >= startTime 且 <= endTime
|
|
|
+ queryWrapper.ge("arrival_time", startChnageTime) // 大于等于开始时间
|
|
|
+ .le("arrival_time", endChnageTime); // 小于等于结束时间
|
|
|
+ search = false;
|
|
|
+ } else if (oConvertUtils.isNotEmpty(storageBillPrint.getStartTime()) && oConvertUtils.isNotEmpty(storageBillPrint.getEndTime())) { // 时间范围
|
|
|
+ // 修改时间范围查询条件为 >= startTime 且 <= endTime
|
|
|
+ queryWrapper.ge("arrival_time", storageBillPrint.getStartTime()) // 大于等于开始时间
|
|
|
+ .le("arrival_time", storageBillPrint.getEndTime()); // 小于等于结束时间
|
|
|
+ search = false;
|
|
|
+ }
|
|
|
+ // 如果什么条件都没有默认当日
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getQueryDate()) || search == true) { // 具体时间
|
|
|
+ // 获取当前年月日
|
|
|
+ if (StringUtils.isBlank(storageBillPrint.getQueryDate())) {
|
|
|
+ storageBillPrint.setQueryDate(DateUtils.formatDate(new Date(), "yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ Date startArrivalTime = DateUtils.getStartOfDayByDate(DateUtils.getStartOfDay(storageBillPrint.getQueryDate()));
|
|
|
+ // 结束时间 减一个小时
|
|
|
+ Date endArrivalTime = DateUtils.getEndOfDayByDate(startArrivalTime);
|
|
|
+ log.info("查询时间范围:startTime={}, endTime={}", storageBillPrint.getStartTime(), storageBillPrint.getEndTime());
|
|
|
+ // 修改时间范围查询条件为 >= startTime 且 <= endTime
|
|
|
+ queryWrapper.ge("arrival_time", startArrivalTime) // 大于等于开始时间
|
|
|
+ .le("arrival_time", endArrivalTime); // 小于等于结束时间
|
|
|
+ }
|
|
|
+ // 炉号查询
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getHeatNo())) {
|
|
|
+ queryWrapper.like("heat_no", storageBillPrint.getHeatNo());
|
|
|
+ }
|
|
|
+ // 车辆查询
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getLicensePlate())) {
|
|
|
+ queryWrapper.like("license_plate", storageBillPrint.getLicensePlate());
|
|
|
+ }
|
|
|
+ // 定尺查询
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getSize())) {
|
|
|
+ queryWrapper.like("size", storageBillPrint.getSize());
|
|
|
+ }
|
|
|
+ // 热坯/冷坯查询
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getBtype())) {
|
|
|
+ queryWrapper.eq("btype", storageBillPrint.getBtype());
|
|
|
+ }
|
|
|
+ // 牌号查询
|
|
|
+ if (oConvertUtils.isNotEmpty(storageBillPrint.getBrandNum())) {
|
|
|
+ queryWrapper.eq("brand_num", storageBillPrint.getBrandNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.eq("withdraw_status", 0);
|
|
|
+ // 根据到站时间排序
|
|
|
+ queryWrapper.orderByDesc("arrival_time");
|
|
|
+ List<StorageBillPrint> exportList = storageBillPrintService.list(queryWrapper);
|
|
|
+
|
|
|
+ // 用于存储拆分后的新数据
|
|
|
+ List<StorageBillPrint> splitList = new ArrayList<>();
|
|
|
+ // 遍历原始数据,拆分heatNo字段
|
|
|
+ for (StorageBillPrint item : exportList) {
|
|
|
+ String heatNoJson = item.getHeatNo();
|
|
|
+ if (heatNoJson != null && !heatNoJson.isEmpty()) {
|
|
|
+ try {
|
|
|
+ // 使用FastJSON解析JSON字符串
|
|
|
+ JSONObject heatNoObj = JSON.parseObject(heatNoJson);
|
|
|
+
|
|
|
+ // 遍历JSON中的每个键值对
|
|
|
+ for (Map.Entry<String, Object> entry : heatNoObj.entrySet()) {
|
|
|
+ String heatNoKey = entry.getKey();
|
|
|
+ int quantity = Integer.parseInt(entry.getValue().toString());
|
|
|
+
|
|
|
+ // 复制原始对象
|
|
|
+ StorageBillPrint newItem = new StorageBillPrint();
|
|
|
+ BeanUtils.copyProperties(item, newItem);
|
|
|
+ // 设置新的heatNo和支数
|
|
|
+ newItem.setHeatNo(heatNoKey);
|
|
|
+ newItem.setAmountTotal(quantity);
|
|
|
+
|
|
|
+ // 添加到新列表
|
|
|
+ splitList.add(newItem);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 处理JSON解析异常
|
|
|
+ log.error("解析heatNo JSON失败: {}", heatNoJson, e);
|
|
|
+ // 如果解析失败,保留原始数据
|
|
|
+ splitList.add(item);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果heatNo为空,保留原始数据
|
|
|
+ splitList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步:根据size字段拆分
|
|
|
+ List<StorageBillPrint> finalList = new ArrayList<>();
|
|
|
+ for (StorageBillPrint item : splitList) {
|
|
|
+ String sizeStr = item.getSize();
|
|
|
+ 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<RollOldAreasDetails> queryWrapper3 = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper3.eq(RollOldAreasDetails::getStorageBillId, item.getId())
|
|
|
+ .eq(RollOldAreasDetails::getCcmNo, item.getCcmNo())
|
|
|
+ .eq(RollOldAreasDetails::getSize, sizes[i])
|
|
|
+ .eq(RollOldAreasDetails::getHeatNo, item.getHeatNo());
|
|
|
+ List<RollOldAreasDetails> rollOldAreasDetailsList = rollOldAreasDetailsService.list(queryWrapper3);
|
|
|
+ if (rollOldAreasDetailsList.size() > 0) {
|
|
|
+ newItem.setAmountTotal(rollOldAreasDetailsList.size());
|
|
|
+ newItem.setWeight(BigDecimal.valueOf(rollOldAreasDetailsList.stream().mapToDouble(RollOldAreasDetails::getBlankOutput).sum()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 设置单个定尺
|
|
|
+ newItem.setSize(sizes[i]);
|
|
|
+ finalList.add(newItem);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果定尺没有逗号分隔,直接添加
|
|
|
+ finalList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<StorageCenterExportRow> exportRows = new ArrayList<>();
|
|
|
+ finalList.forEach(x -> {
|
|
|
+ StorageCenterExportRow exportRow = new StorageCenterExportRow();
|
|
|
+ exportRow.setAmount(x.getAmountTotal());
|
|
|
+ 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 = safeToBigDecimal(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());
|
|
|
+
|
|
|
+ String brandNum = Optional.ofNullable(x.getBrandNum())
|
|
|
+ .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
|
|
|
+ .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
|
|
|
+ exportRow.setBrand(brandNum);
|
|
|
+
|
|
|
+ // 查询定尺规则
|
|
|
+ LambdaQueryWrapper<BilletRulerConfig> queryWrapperbilletRulerConfig = new LambdaQueryWrapper<BilletRulerConfig>().eq(BilletRulerConfig::getLength, Integer.valueOf(safeToInteger(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));
|
|
|
+ Integer amount = x.getAmountTotal();
|
|
|
+ BigDecimal totalWeight = (amount == null) ? BigDecimal.ZERO :
|
|
|
+ BigDecimal.valueOf(weight).multiply(BigDecimal.valueOf(amount));
|
|
|
+ exportRow.setTotalWeight(totalWeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static BigDecimal safeToBigDecimal(String str) {
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new BigDecimal(str);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Integer safeToInteger(String str) {
|
|
|
+ if (StringUtils.isBlank(str)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(str);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ try {
|
|
|
+ // 尝试转成小数再取整
|
|
|
+ return new BigDecimal(str).intValue();
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|