Pārlūkot izejas kodu

新增炉次传递单列表的Excel导出

lingpeng.li 1 mēnesi atpakaļ
vecāks
revīzija
64066c1f0f

+ 84 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsend/controller/BilletHotsendBaseController.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.billet.billetHotsend.controller;
 
+import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -8,6 +9,7 @@ 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.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.base.controller.JeecgController;
@@ -15,20 +17,31 @@ import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
 import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
+import org.jeecg.modules.billet.billetHotsend.dto.BilletHotsendExportDTO;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletBasicInfoDetails;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsend;
 import org.jeecg.modules.billet.billetHotsend.entity.BilletHotsendDetailsVo;
 import org.jeecg.modules.billet.billetHotsend.entity.RealtimeStats;
 import org.jeecg.modules.billet.billetHotsend.service.IBilletHotsendBaseService;
 import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
+import org.jeecg.modules.carUnit.service.ISysDictService;
 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.io.IOException;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 /**
 * @Description: 钢坯热送基础信息
@@ -50,6 +63,9 @@ public class BilletHotsendBaseController extends JeecgController<BilletHotsend,
    @Autowired
    private IBilletBasicInfoService billetBasicInfoService;
 
+    @Autowired
+    private ISysDictService sysDictService;
+
    /**
     * 分页列表查询
     *
@@ -277,4 +293,72 @@ public class BilletHotsendBaseController extends JeecgController<BilletHotsend,
         List<BilletBasicInfoDetails> billetHotsendList = billetHotsendBaseService.queryBilletInfoByBilletNo(billetNo);
         return Result.OK(billetHotsendList);
     }
+
+    @AutoLog(value = "钢坯热送基础信息-EasyExcel导出")
+    @ApiOperation(value = "钢坯热送基础信息-EasyExcel导出", notes = "分页导出当前页数据")
+    @GetMapping("/exportExcel")
+    public void exportEasyExcel(HttpServletRequest request, HttpServletResponse response,
+                                BilletHotsend billetHotsend) throws IOException {
+
+        // 构造查询条件
+        QueryWrapper<BilletHotsend> queryWrapper = QueryGenerator.initQueryWrapper(billetHotsend, request.getParameterMap());
+
+        // 获取参数
+        String createTimeBegin = request.getParameter("createTime_begin");
+        String createTimeEnd = request.getParameter("createTime_end");
+
+        // 如果前端没有传时间范围,则默认查询最近一个月
+        if (StringUtils.isBlank(createTimeBegin) && StringUtils.isBlank(createTimeEnd)) {
+            LocalDateTime now = LocalDateTime.now();
+            LocalDateTime oneMonthAgo = now.minusMonths(1);
+            queryWrapper.between("create_time", oneMonthAgo, now);
+        }
+
+        // 时间格式与字典准备
+        AtomicInteger index = new AtomicInteger(1); // 序号从 1 开始
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        ZoneId zoneId = ZoneId.systemDefault();
+
+        List<BilletHotsend> billetHotsendList = billetHotsendBaseService.list(queryWrapper);
+
+        // 构造导出数据列表
+        List<BilletHotsendExportDTO> exportList = billetHotsendList.stream().map(item -> {
+            BilletHotsendExportDTO dto = new BilletHotsendExportDTO();
+            dto.setIndex(index.getAndIncrement());
+
+            dto.setCreateTime(item.getCreateTime() != null
+                    ? item.getCreateTime().toInstant().atZone(zoneId).toLocalDateTime().format(formatter)
+                    : "");
+
+            dto.setHeatNo(item.getHeatNo());
+            dto.setShiftGroup(sysDictService.queryDictTextByKey("lg_bz", item.getShiftGroup())); // 班组中文
+            dto.setShift(sysDictService.queryDictTextByKey("lg_bb", item.getShift())); // 班别中文
+            dto.setSteel(item.getSteel());
+            dto.setSpec(item.getSpec());
+            dto.setDecideWeight(BigDecimal.valueOf(item.getDecideWeight()));
+            dto.setAmountTotal(item.getAmountTotal());
+            dto.setBlankOutput(BigDecimal.valueOf(item.getBlankOutput()));
+            dto.setStackNum(item.getStackNum());
+            dto.setRollcluboneNum(item.getRollcluboneNum());
+            dto.setRollclubtwoNum(item.getRollclubtwoNum());
+            dto.setRollclubthreeNum(item.getRollclubthreeNum());
+            dto.setRollheightNum(item.getRollheightNum());
+            dto.setRolloutshippNum(item.getRolloutshippNum());
+            dto.setWasteNum(item.getWasteNum());
+            return dto;
+        }).collect(Collectors.toList());
+
+        // 设置响应头
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+        response.setCharacterEncoding("utf-8");
+        String fileName = URLEncoder.encode("钢坯热送信息导出", StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20");
+        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
+
+        // 导出数据
+        EasyExcel.write(response.getOutputStream(), BilletHotsendExportDTO.class)
+                .sheet("钢坯热送数据")
+                .doWrite(exportList);
+    }
+
+
 }

+ 68 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetHotsend/dto/BilletHotsendExportDTO.java

@@ -0,0 +1,68 @@
+package org.jeecg.modules.billet.billetHotsend.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class BilletHotsendExportDTO {
+
+    @ExcelProperty("序号")
+    private Integer index;
+
+    @ExcelProperty("日期")
+    @ColumnWidth(20)
+    private String createTime;
+
+    @ExcelProperty("炉号")
+    @ColumnWidth(10)
+    private String heatNo;
+
+    @ExcelProperty("班组")
+    private String shiftGroup;
+
+    @ExcelProperty("班别")
+    private String shift;
+
+    @ExcelProperty("钢种")
+    @ColumnWidth(11)
+    private String steel;
+
+    @ExcelProperty("规格")
+    @ColumnWidth(15)
+    private String spec;
+
+    @ExcelProperty("定重")
+    @ColumnWidth(12)
+    private BigDecimal decideWeight;
+
+    @ExcelProperty("总支数")
+    private Integer amountTotal;
+
+    @ExcelProperty("出坯量")
+    @ColumnWidth(12)
+    private BigDecimal blankOutput;
+
+    @ExcelProperty("堆垛")
+    private Integer stackNum;
+
+    @ExcelProperty("棒一")
+    private Integer rollcluboneNum;
+
+    @ExcelProperty("棒二")
+    private Integer rollclubtwoNum;
+
+    @ExcelProperty("棒三")
+    private Integer rollclubthreeNum;
+
+    @ExcelProperty("高线")
+    private Integer rollheightNum;
+
+    @ExcelProperty("上若")
+    private Integer rolloutshippNum;
+
+    @ExcelProperty("判废")
+    private Integer wasteNum;
+}

+ 9 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/carUnit/mapper/SysDictMapper.java

@@ -1,6 +1,7 @@
 package org.jeecg.modules.carUnit.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.carUnit.entity.SysDict;
 
 /**
@@ -13,4 +14,12 @@ import org.jeecg.modules.carUnit.entity.SysDict;
  */
 public interface SysDictMapper extends BaseMapper<SysDict> {
 
+    /**
+     * 通过字典code获取字典数据
+     * @param code
+     * @param key
+     * @return
+     */
+    public String queryDictTextByKey(@Param("code") String code, @Param("key") String key);
+
 }

+ 6 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/carUnit/mapper/xml/SysDictMapper.xml

@@ -2,5 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.carUnit.mapper.SysDictMapper">
 
+    <!-- 通过字典code获取字典数据 -->
+    <select id="queryDictTextByKey" parameterType="String"  resultType="String">
+        select s.item_text from sys_dict_item s
+        where s.dict_id = (select id from sys_dict where dict_code = #{code})
+          and s.item_value = #{key}
+    </select>
 
 </mapper>

+ 8 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/carUnit/service/ISysDictService.java

@@ -13,4 +13,12 @@ import org.jeecg.modules.carUnit.entity.SysDict;
  */
 public interface ISysDictService extends IService<SysDict> {
 
+    /**
+     * 通过字典code及字典项的value获取字典文本
+     * @param code
+     * @param key
+     * @return
+     */
+    public String queryDictTextByKey(String code, String key);
+
 }

+ 19 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/carUnit/service/impl/SysDictServiceImpl.java

@@ -2,9 +2,12 @@ package org.jeecg.modules.carUnit.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.constant.CacheConstant;
 import org.jeecg.modules.carUnit.entity.SysDict;
 import org.jeecg.modules.carUnit.mapper.SysDictMapper;
 import org.jeecg.modules.carUnit.service.ISysDictService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 /**
@@ -19,5 +22,21 @@ import org.springframework.stereotype.Service;
 @Slf4j
 public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {
 
+    @Autowired
+    private SysDictMapper sysDictMapper;
+    /**
+     * 通过查询指定code 获取字典值text
+     * @param code
+     * @param key
+     * @return
+     */
+
+    @Override
+    @Cacheable(value = CacheConstant.SYS_DICT_CACHE,key = "#code+':'+#key", unless = "#result == null ")
+    public String queryDictTextByKey(String code, String key) {
+        log.debug("无缓存dictText的时候调用这里!");
+        return sysDictMapper.queryDictTextByKey(code, key);
+    }
+
 
 }