cy
2023-12-01 ed7d7e411534f3bcc649f681aa8c529672b31e89
feat: 报废
1个文件已添加
2个文件已修改
255 ■■■■■ 已修改文件
consum-base/src/main/java/com/consum/base/controller/DepFormScrappedController.java 180 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-base/src/main/java/com/consum/base/pojo/response/DepFormScrappedExtendVo.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-base/src/main/java/com/consum/base/service/DepFormScrappedServiceImpl.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-base/src/main/java/com/consum/base/controller/DepFormScrappedController.java
@@ -1,22 +1,41 @@
package com.consum.base.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ReflectUtil;
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.pojo.LDeptFormScrappedParam;
import com.consum.base.pojo.query.LDeptFormScrappedQry;
import com.consum.base.service.DepFormScrappedServiceImpl;
import com.consum.model.po.FinSysTenantUser;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.web.ResponseValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @ClassName DepFormScrappedController
@@ -65,6 +84,165 @@
            return ResponseValue.error("登录用户信息不存在");
        }
        param.setAgencyId(sysInfo.getTenantId());
        return ResponseValue.success(depFormScrappedService.queryList(param));
        GenericPager<Map<String, Object>> mapGenericPager = depFormScrappedService.queryList(param);
        // 处理一下数据
        List<Map<String, Object>> datas = mapGenericPager.getDatas();
        if (CollectionUtils.isEmpty(datas)) {
            return ResponseValue.success(mapGenericPager);
        }
        List<Map<String, Object>> maps = mergeData(datas);
        ReflectUtil.setFieldValue(mapGenericPager, "datas", maps);
        return ResponseValue.success(mapGenericPager);
    }
    private static List<Map<String, Object>> mergeData(List<Map<String, Object>> dataList) {
        Map<Long, Map<String, Object>> mergedDataMap = new HashMap<>();
        // 遍历原始数据进行合并
        for (Map<String, Object> data : dataList) {
            Long id = Convert.toLong(data.get("id"));
            HashMap hashMap = new HashMap();
            hashMap.put("baseGoodsTemplateId", data.get("operatorName"));
            hashMap.put("baseGoodsTemplateName", data.get("baseGoodsTemplateName"));
            hashMap.put("totalCount", data.get("totalCount"));
            hashMap.put("unit", data.get("unit"));
            if (!mergedDataMap.containsKey(id)) {
                // 如果id在合并数据中不存在,则新增一条记录
                Map<String, Object> mergedMap = new HashMap<>();
                mergedMap.put("departmentName", data.get("departmentName"));
                mergedMap.put("dealTime", data.get("dealTime"));
                mergedMap.put("businessFormCode", data.get("businessFormCode"));
                mergedMap.put("operatorName", data.get("operatorName"));
                mergedMap.put("id", data.get("id"));
                ArrayList<HashMap> goodsList = new ArrayList<>();
                goodsList.add(hashMap);
                mergedMap.put("goods", goodsList);
                mergedDataMap.put(id, mergedMap);
            } else {
                // 如果id在合并数据中已存在,则将k3追加到已存在记录的k3列表中
                Map<String, Object> mergedMap = mergedDataMap.get(id);
                ArrayList<HashMap> goodsList = (ArrayList<HashMap>) mergedMap.get("goods");
                goodsList.add(hashMap);
            }
        }
        // 将合并后的数据转换为List返回
        return new ArrayList<>(mergedDataMap.values());
    }
    /**
     * @Description 根据id查询详情
     */
    @ApiOperation(value = "根据id查询详情", notes = "根据id查询详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "报废单id", dataType = "Long", paramType = "query")
    })
    @GetMapping("/deptDetail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("报废单id为空");
        }
        return ResponseValue.success(this.depFormScrappedService.getById(id));
    }
    @ApiOperation(value = "导出报废单", notes = "导出报废单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "报废单id", dataType = "Long", paramType = "query")
    })
    @GetMapping("/deptList/export")
    public void export(Long id, HttpServletResponse response) throws Exception {
        if (id == null) {
            throw new RuntimeException("报废单id为空");
        }
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            throw new RuntimeException("登录用户信息不存在");
        }
        List<Map<String, Object>> export = depFormScrappedService.export(id, sysInfo.getTenantId());
        if (CollectionUtils.isEmpty(export)) {
            throw new RuntimeException("数据为空");
        }
        TemplateExportParams exportParams = new TemplateExportParams("import/deptScrapped.xlsx");
        exportParams.setHeadingStartRow(2);
        Map<String, Object> scrappedInfoExcelTemplate = export.get(0);
        Long dealTime = Convert.toLong(scrappedInfoExcelTemplate.get("dealTime"));
        String operatorName = Convert.toStr(scrappedInfoExcelTemplate.get("operatorName"));
        String businessFormCode = Convert.toStr(scrappedInfoExcelTemplate.get("businessFormCode"));
        Map<String, Object> map = new HashMap<>();
        map.put("code", businessFormCode);
        map.put("date", DateUtils.toShowDate(dealTime));
        map.put("name", operatorName);
        map.put("countNum", 0);
        map.put("totalAmount", 0);
        map.put("dataList", export);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, map);
        // 设置响应头
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("部门报废单.xlsx", "utf-8"));
        try (OutputStream outputStream = response.getOutputStream()) {
            workbook.write(outputStream);
            workbook.close();
        }
    }
    public static void main(String[] args) {
        TemplateExportParams exportParams = new TemplateExportParams("D:\\MyProjects\\jmy\\低值易耗品\\low-consum-manage\\deploy-jar-single\\src\\main\\resources\\import\\deptScrapped.xlsx");
        exportParams.setHeadingStartRow(2);
        List<Map<String, Object>> export = new ArrayList<>();
        // 创建第一条数据
        Map<String, Object> data1 = new HashMap<>();
        data1.put("agencyName", 1);
        data1.put("baseGoodsTemplateName", "Bob");
        data1.put("scrappedName", "Bob");
        data1.put("bz", "Bob");
        data1.put("baseGoodsModelsName", 30);
        data1.put("counts", 30);
        data1.put("totalPrice", 30);
        export.add(data1);
        // 创建第二条数据
        Map<String, Object> data2 = new HashMap<>();
        data2.put("agencyName", 2);
        data2.put("baseGoodsTemplateName", "Bob");
        data2.put("scrappedName", "Bob");
        data2.put("bz", "Bob");
        data2.put("baseGoodsModelsName", 30);
        data2.put("counts", 30);
        data2.put("totalPrice", 30);
        export.add(data2);
        Map<String, Object> map = new HashMap<>();
        map.put("code", "2023");
        map.put("date", "2023");
        map.put("name", "operatorName");
        map.put("countNum", 0);
        map.put("totalAmount", 0);
        map.put("maplist", export);
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, map);
        File file = new File("C:\\Users\\cy\\Desktop\\新建文件夹");
        OutputStream stream = null;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd");
            stream = new FileOutputStream(new File(file, "机构客户信息表.xls"));
            //document.write(stream);
            workbook.write(stream);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stream != null) ;
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
consum-base/src/main/java/com/consum/base/pojo/response/DepFormScrappedExtendVo.java
New file
@@ -0,0 +1,20 @@
package com.consum.base.pojo.response;
import com.consum.model.po.DepFormScrapped;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
 * @ClassName DepFormScrappedExtendVo
 * @Author cy
 * @Date 2023/12/1
 * @Description
 * @Version 1.0
 **/
@Data
public class DepFormScrappedExtendVo extends DepFormScrapped {
    //报废商品信息
    private List<Map> goods;
}
consum-base/src/main/java/com/consum/base/service/DepFormScrappedServiceImpl.java
@@ -8,7 +8,9 @@
import com.consum.base.pojo.DepFormScrappedModelParam;
import com.consum.base.pojo.LDeptFormScrappedParam;
import com.consum.base.pojo.query.LDeptFormScrappedQry;
import com.consum.base.pojo.response.DepFormScrappedExtendVo;
import com.consum.model.po.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
@@ -17,6 +19,7 @@
import com.walker.infrastructure.utils.StringUtils;
import com.walker.jdbc.service.BaseServiceImpl;
import com.walker.web.ResponseValue;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -187,7 +190,7 @@
    /**
     * @Description 列表查询
     */
    private static String QUERY_LIST = "SELECT scrap.id,scrap.BUSINESS_FORM_CODE,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME,SUM(model.COUNTS) total_Count FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID where 1=1";
    private static String QUERY_LIST = "SELECT scrap.id,scrap.BUSINESS_FORM_CODE,scrap.AGENCY_NAME,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME,SUM(model.COUNTS) total_Count,model.unit FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID where 1=1";
    private static String QUERY_LIST_END = " GROUP BY scrap.id,scrap.BUSINESS_FORM_CODE,scrap.DEPARTMENT_NAME,scrap.OPERATOR_NAME,scrap.DEAL_TIME,model.BASE_GOODS_TEMPLATE_ID,model.BASE_GOODS_TEMPLATE_NAME ORDER BY scrap.DEAL_TIME DESC";
    public GenericPager<Map<String, Object>> queryList(LDeptFormScrappedQry param) {
@@ -225,4 +228,54 @@
        sql.append(QUERY_LIST_END);
        return selectSplit(sql.toString(), paramts, param.getPageNum(), param.getPageSize(), new MapperUtil());
    }
    /**
     * @Description 根据id查询详情
     */
    public DepFormScrappedExtendVo getById(Long id) {
        DepFormScrappedExtendVo scrappedExtend = new DepFormScrappedExtendVo();
        //1.查询报废单
        DepFormScrapped lWhFormScrapped = this.get(new DepFormScrapped(id));
        if (lWhFormScrapped != null) {
            BeanUtils.copyProperties(lWhFormScrapped, scrappedExtend);
        }
        ObjectMapper objectMapper = new ObjectMapper();
        //2.查询报废单物品
        DepFormScrappedGoods goodsQuery = new DepFormScrappedGoods();
        List<DepFormScrappedGoods> formScrappedGoodsList = select(goodsQuery);
        List<Map> goodsList = new ArrayList<>();
        for (DepFormScrappedGoods scrappedGoods : formScrappedGoodsList) {
            Map<String, Object> scrappedGoodsMap = objectMapper.convertValue(scrappedGoods, Map.class);
            // 查询规格型号
            Long scrappedGoodsId = scrappedGoods.getId();
            DepFormScrappedModel depFormScrappedModel = new DepFormScrappedModel();
            depFormScrappedModel.setDepFormScrappedGoodsId(scrappedGoodsId);
            List<DepFormScrappedModel> scrappedModelList = select(depFormScrappedModel);
            scrappedGoodsMap.put("models", scrappedModelList);
            goodsList.add(scrappedGoodsMap);
        }
        scrappedExtend.setGoods(goodsList);
        return scrappedExtend;
    }
    private static String EXPORT_SQL = "SELECT scrap.BUSINESS_FORM_CODE,scrap.DEAL_TIME,scrap.OPERATOR_NAME,scrap.AGENCY_NAME,model.BASE_GOODS_TEMPLATE_NAME,model.BASE_GOODS_MODELS_NAME,scrap.OUT_WAREHOUSE_NAME,model.COUNTS,2 AS TOTAL_PRICE,model.SCRAPPED_NAME,NULL AS bz FROM DEP_FORM_SCRAPPED scrap LEFT JOIN DEP_FORM_SCRAPPED_MODEL model ON scrap.id=model.DEP_FORM_SCRAPPED_ID WHERE 1=1 ";
    private static String EXPORT_SQL_END = "order by scrap.BUSINESS_FORM_CODE desc ";
    public List<Map<String, Object>> export(Long id, String agencyId) {
        HashMap<String, Object> paramts = new HashMap<>();
        StringBuilder sql = new StringBuilder(EXPORT_SQL);
        //报废单号
        if (id != null) {
            sql.append(" and scrap.id = :id");
            paramts.put("id", id);
        }
        //机构
        sql.append(" and scrap.AGENCY_ID = :agencyId ");
        if (agencyId != null) {
            paramts.put("agencyId", agencyId);
        }
        return select(sql.append(EXPORT_SQL_END).toString(), paramts, new MapperUtil());
    }
}