WangHan
2025-04-02 a8ba678a3fe5a39da2c732014cebbb66e408e97c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.consum.base.controller;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
 
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.PageUtil;
import com.consum.base.pojo.LWhFormScrappedParam;
import com.consum.base.pojo.excel.ScrappedInfoExcelTemplate;
import com.consum.base.pojo.query.LWhFormScrappedQry;
import com.consum.base.pojo.response.GoodsTemplateCountVO;
import com.consum.base.pojo.response.LWhFormScrappedExtendVO;
import com.consum.base.pojo.response.LWhFormScrappedVO;
import com.consum.base.service.LWhFormScrappedService;
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.po.LWhFormScrapped;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.web.ResponseValue;
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
 
 
 
 
 
/**
 * @Description 报废单
 * @Author 卢庆阳
 * @Date 2023/11/1
 */
// @Api(value = "报废单", tags = "报废单")
@RestController
@RequestMapping("/pc/l/wh/form/scrapped")
public class LWhFormScrappedController extends BaseController {
 
    @Autowired
    private LWhFormScrappedService lWhFormScrappedService;
 
    /**
     * @Description 新增报废单
     * @Author 卢庆阳
     * @Date 2023/11/1
     */
    // @ApiOperation(value = "新增报废单", notes = "新增报废单")
    // @ApiImplicitParams({@ApiImplicitParam(name = "param")})
    @PostMapping("/add")
    public ResponseValue add() {
        LWhFormScrappedParam param = CommonUtil.getObjFromReqBody(LWhFormScrappedParam.class);
        LWhFormScrappedParam query = new LWhFormScrappedParam();
        CommonUtil.copyProperties(param, query);
        param = query;
        FinSysTenantUser sysInfo = this.getSysInfo();
        int result = this.lWhFormScrappedService.add(param, this.getCurrentUser(), sysInfo);
        if (result > 0) {
            return ResponseValue.success(1);
        }
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 列表查询
     * @Author 卢庆阳
     * @Date 2023/11/02
     *       <p>
     *       </>1.查询报废单 2.查询报废单物品
     */
    // @ApiOperation(value = "列表查询", notes = "列表查询")
//    @ApiImplicitParams({
//        @ApiImplicitParam(name = "param", value = "查询条件", dataType = "LWhFormScrappedQry", paramType = "query")})
    @GetMapping("/list")
    public ResponseValue queryList() {
        LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
        LWhFormScrappedQry query = new LWhFormScrappedQry();
        CommonUtil.copyProperties(param, query);
        param = query;
 
        FinSysTenantUser sysInfo = getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        PageUtil genericPager = lWhFormScrappedService.queryList(param, sysInfo);
        List<LWhFormScrapped> data = genericPager.getDatas();
        List<LWhFormScrappedVO> result = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(data)) {
            data.forEach(item -> {
                LWhFormScrappedVO lWhFormScrappedVO = new LWhFormScrappedVO();
                BeanUtils.copyProperties(item, lWhFormScrappedVO);
                // 查询型号数量
                List<GoodsTemplateCountVO> scrappedCount =
                    lWhFormScrappedService.getScrappedCountByBusinessId(item.getId());
                lWhFormScrappedVO.setGoodTemplateInfo(scrappedCount);
                result.add(lWhFormScrappedVO);
            });
        }
        genericPager.setDatas(result);
        return ResponseValue.success(genericPager);
    }
 
    /**
     * @Description 根据id查询详情
     * @Author 卢庆阳
     * @Date 2023/11/2
     */
    // @ApiOperation(value = "根据id查询详情", notes = "根据id查询详情")
    // @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "报废单id", dataType = "Long", paramType = "query")})
    @GetMapping("/detail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("报废单id为空");
        }
        LWhFormScrappedExtendVO scrappedExtend = this.lWhFormScrappedService.getById(id);
        return ResponseValue.success(scrappedExtend);
    }
 
    /**
     * 报废明细
     *
     * @param
     * @return
     */
    // @ApiOperation(value = "报废明细", notes = "报废明细")
//    @ApiImplicitParams({
//        @ApiImplicitParam(name = "param", value = "查询条件", dataType = "LWhFormScrappedQry", paramType = "query")})
    @GetMapping("/list/detailList")
    public ResponseValue queryDetailList() {
        LWhFormScrappedQry param = CommonUtil.getObjFromReq(LWhFormScrappedQry.class);
        LWhFormScrappedQry query = new LWhFormScrappedQry();
        CommonUtil.copyProperties(param, query);
        param = query;
 
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        PageUtil pageUtil = lWhFormScrappedService.queryDetailList(param, sysInfo);
        return ResponseValue.success(pageUtil);
    }
 
    // @ApiOperation(value = "导出报废单", notes = "导出报废单")
//    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "报废单id", dataType = "Long", paramType = "query")})
    @GetMapping("/list/export")
    public ResponseValue<String> export(Long id, HttpServletResponse response) throws Exception {
        if (id == null) {
            throw new RuntimeException("报废单id为空");
        }
 
        List<ScrappedInfoExcelTemplate> export = lWhFormScrappedService.export(id);
        if (CollectionUtils.isEmpty(export)) {
            throw new RuntimeException("数据为空");
        }
        TemplateExportParams exportParams = new TemplateExportParams("import/报废登记单.xlsx");
        exportParams.setHeadingStartRow(2);
 
        Optional<ScrappedInfoExcelTemplate> first = export.stream().findFirst();
        ScrappedInfoExcelTemplate scrappedInfoExcelTemplate = first.get();
        Long dealTime = scrappedInfoExcelTemplate.getDealTime();
        String operatorName = scrappedInfoExcelTemplate.getOperatorName();
        String businessFormCode = scrappedInfoExcelTemplate.getBusinessFormCode();
 
        int countNum =
            export.stream().filter(item -> item.getNum() != null).mapToInt(ScrappedInfoExcelTemplate::getNum).sum();
        double totalAmount = export.stream().filter(item -> item.getTotalAmount() != null)
            .mapToDouble(ScrappedInfoExcelTemplate::getAmount).sum();
 
        Map<String, Object> map = new HashMap<>();
        map.put("code", businessFormCode);
        map.put("date", DateUtils.toShowDate(dealTime));
        map.put("name", operatorName);
        map.put("countNum", countNum);
        map.put("totalAmount", totalAmount);
 
        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ScrappedInfoExcelTemplate.class, export, map);
        String filePath = downLoadExcel("报废登记单", sheets);
        return ResponseValue.success("导出成功", filePath);
 
    }
 
}