cuijian
2025-06-16 ec1bf4658e36a17f971a54007920a44c5378b7dc
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package org.jeecg.modules.tms.controller;
 
import com.alibaba.fastjson.JSONArray;
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.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
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.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.jeecg.modules.tms.entity.*;
import org.jeecg.modules.tms.entity.dto.LossBoundFlowDto;
import org.jeecg.modules.tms.entity.dto.StocktakingBoundFlowDto;
import org.jeecg.modules.tms.entity.vo.ToolsStocktakingVo;
import org.jeecg.modules.tms.enums.OutBillStatus;
import org.jeecg.modules.tms.mapper.ToolsStocktakingBoundMapper;
import org.jeecg.modules.tms.service.IToolsStocktakingBoundDetailService;
import org.jeecg.modules.tms.service.IToolsStocktakingBoundService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
/**
 * @Description: 盘点单表
 * @Author: houjie
 * @Date: 2025-05-16
 * @Version: V1.0
 */
@Api(tags = "盘点单表")
@RestController
@RequestMapping("/tms/toolsStocktakingBound")
@Slf4j
public class ToolsStocktakingBoundController {
    @Autowired
    private IToolsStocktakingBoundService toolsStocktakingBoundService;
    @Autowired
    private IToolsStocktakingBoundDetailService toolsStocktakingBoundDetailService;
    @Autowired
    private ToolsStocktakingBoundMapper toolsStocktakingBoundMapper;
 
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
 
    /**
     * 分页列表查询
     *
     * @param toolsStocktakingBound
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "盘点单表-分页列表查询")
    @ApiOperation(value = "盘点单表-分页列表查询", notes = "盘点单表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ToolsStocktakingBound>> queryPageList(ToolsStocktakingBound toolsStocktakingBound,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              HttpServletRequest req) {
        QueryWrapper<ToolsStocktakingBound> queryWrapper = QueryGenerator.initQueryWrapper(toolsStocktakingBound, req.getParameterMap());
        Page<ToolsStocktakingBound> page = new Page<ToolsStocktakingBound>(pageNo, pageSize);
        IPage<ToolsStocktakingBound> pageList = toolsStocktakingBoundService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
 
 
    /**
     * 添加
     *
     * @param toolsStocktakingBound
     * @return
     */
    @AutoLog(value = "tms_stocktaking_bound-添加")
    @ApiOperation(value = "tms_stocktaking_bound-添加", notes = "tms_stocktaking_bound-添加")
    @PostMapping(value = "/add")
    @Transactional(rollbackFor = {Exception.class})
    public Result<String> add(@RequestBody ToolsStocktakingBound toolsStocktakingBound) {
        toolsStocktakingBound.setApprovalStatus(OutBillStatus.DRAFT.getValue());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser != null) {
            toolsStocktakingBound.setHandler(sysUser.getId());
        }
        toolsStocktakingBound.setOrderCode(businessCodeRuleService.generateBusinessCodeSeq("stocktakingBound"));
        //校验物料在原材料周转库存不存在
        List<ToolsStocktakingBoundDetail> toolsStocktakingBoundDetailList = toolsStocktakingBound.getToolsStocktakingBoundDetailList();
 
        toolsStocktakingBoundService.save(toolsStocktakingBound);
        for (int i = 0; i < toolsStocktakingBoundDetailList.size(); i++) {
            ToolsStocktakingBoundDetail toolsStocktakingBoundDetail = toolsStocktakingBoundDetailList.get(i);
            toolsStocktakingBoundDetail.setAvailableQuantity(toolsStocktakingBoundDetail.getBookQuantity());
            toolsStocktakingBoundDetail.setPracticalQuantity(toolsStocktakingBoundDetail.getPracticalQuantity());
            toolsStocktakingBoundDetail.setSurplusDeficit(toolsStocktakingBoundDetail.getSurplusDeficit());
            toolsStocktakingBoundDetail.setStocktakingDate(toolsStocktakingBoundDetail.getStocktakingDate());
            toolsStocktakingBoundDetail.setRemark(toolsStocktakingBoundDetail.getRemark());
            toolsStocktakingBoundDetail.setToolId(toolsStocktakingBoundDetail.getToolId());
            toolsStocktakingBoundDetail.setToolCode(toolsStocktakingBoundDetail.getToolCode());
            toolsStocktakingBoundDetail.setStocktakingBoundId(toolsStocktakingBound.getId());
            toolsStocktakingBoundDetailService.save(toolsStocktakingBoundDetail);
        }
        return Result.OK();
 
 
    }
 
 
    @ApiOperation(value = "工具盘点明细-通过主表ID查询", notes = "工具盘点明细-通过主表ID查询")
    @GetMapping(value = "/listToolsStocktakingBoundControllerDetailsByMainId")
    public Result<IPage<ToolsStocktakingBoundDetail>> listToolsStocktakingBoundControllerDetailsByMainId(BaseTools baseTools,
                                                                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                                                         HttpServletRequest req) {
        Map<String, String[]> parameterMap = req.getParameterMap();
        Page<ToolsStocktakingBoundDetail> page = new Page<ToolsStocktakingBoundDetail>(pageNo, pageSize);
        IPage<ToolsStocktakingBoundDetail> pageList = toolsStocktakingBoundDetailService.selectByMainId(page, parameterMap);
 
        return Result.OK(pageList);
    }
 
 
    @AutoLog(value = "tms_stocktaking_bound-提交盘点单")
    @ApiOperation(value = "tms_stocktaking_bound-提交盘点单", notes = "tms_stocktaking_bound-提交盘点单")
    @GetMapping(value = "/submit")
    public Result<String> submit(@RequestParam(name = "id") String id) {
 
 
        toolsStocktakingBoundService.submintOrder(id);
        return Result.OK("提交成功");
    }
 
    /**
     * 审批流程
     * @param stocktakingBoundFlowDto
     * @return
     */
    @AutoLog(value = "审批流程")
    @ApiOperation(value = "报损单-审批流程", notes = "报损单-审批流程")
    @PostMapping("/approval")
    public Result<?> approval(@RequestBody StocktakingBoundFlowDto stocktakingBoundFlowDto) {
        toolsStocktakingBoundService.approvalProcess(stocktakingBoundFlowDto);
        return Result.OK("操作成功");
    }
    /**
     * 编辑
     *
     * @param toolsStocktakingBound
     * @return
     */
    @AutoLog(value = "盘点单表-编辑")
    @ApiOperation(value = "盘点单表-编辑", notes = "盘点单表-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    @Transactional(rollbackFor = {Exception.class})
    public Result<String> edit(@RequestBody ToolsStocktakingBound toolsStocktakingBound) {
 
        toolsStocktakingBoundService.updateById(toolsStocktakingBound);
        // 删除申请单明细数据
                toolsStocktakingBoundDetailService.remove(new LambdaQueryWrapper<ToolsStocktakingBoundDetail>()
                .eq(ToolsStocktakingBoundDetail::getStocktakingBoundId, toolsStocktakingBound.getId()));
 
        List<ToolsStocktakingBoundDetail> detailList = toolsStocktakingBound.getToolsStocktakingBoundDetailList();
        if (CollectionUtils.isEmpty(detailList)) {
            return Result.error("明细不能为空");
        }
        for (ToolsStocktakingBoundDetail item : detailList) {
            item.setStocktakingBoundId(toolsStocktakingBound.getId());
            item.setToolId(item.getToolId());
            item.setToolCode(item.getToolCode());
            item.setRemark(item.getRemark());
            item.setStocktakingDate(item.getStocktakingDate());
            item.setBookQuantity(item.getBookQuantity());
            item.setAvailableQuantity(item.getAvailableQuantity());
            item.setPracticalQuantity(item.getPracticalQuantity());
            item.setSurplusDeficit(item.getSurplusDeficit());
            item.setDifferenceValue(item.getDifferenceValue());
            item.setParamaTableName(item.getParamaTableName());
            item.setForeignLanguageName(item.getForeignLanguageName());
            item.setChineseName(item.getChineseName());
            item.setSupplierId(item.getSupplierId());
            item.setStorageLocation(item.getStorageLocation());
            item.setToolMaterial(item.getToolMaterial());
            item.setToolModel(item.getToolModel());
            item.setPositionCode(item.getPositionCode());
            item.setClassifyId(item.getClassifyId());
            item.setApplicationType(item.getApplicationType());
            toolsStocktakingBoundDetailService.saveOrUpdate(item);
        }
        toolsStocktakingBoundDetailService.saveOrUpdateBatch(detailList);
        return Result.OK("操作成功!");
 
    }
 
 
    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "盘点单表-通过id删除")
    @ApiOperation(value = "盘点单表-通过id删除", notes = "盘点单表-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        toolsStocktakingBoundService.delMain(id);
        return Result.OK("删除成功!");
    }
 
    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "盘点单表-批量删除")
    @ApiOperation(value = "盘点单表-批量删除", notes = "盘点单表-批量删除")
 
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.toolsStocktakingBoundService.delBatchMain(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }
 
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "盘点单表-通过id查询")
    @ApiOperation(value = "盘点单表-通过id查询", notes = "盘点单表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ToolsStocktakingBound> queryById(@RequestParam(name = "id", required = true) String id) {
        ToolsStocktakingBound toolsStocktakingBound = toolsStocktakingBoundService.getById(id);
        if (toolsStocktakingBound == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(toolsStocktakingBound);
 
    }
 
 
    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<ToolsStocktakingVo> list = ExcelImportUtil.importExcel(file.getInputStream(), ToolsStocktakingVo.class, params);
                for (ToolsStocktakingVo page : list) {
                    ToolsStocktakingBound po = new ToolsStocktakingBound();
                    BeanUtils.copyProperties(page, po);
                    toolsStocktakingBoundService.saveMain(po, page.getToolsStocktakingBoundDetailList());
                }
                return Result.OK("文件导入成功!数据行数:" + list.size());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                return Result.error("文件导入失败:" + e.getMessage());
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return Result.OK("文件导入失败!");
    }
 
    /**
     * 工具台账-盘点子页面列表查询
     *
     * @param toolsStocktakingBound
     * @param pageNo
     * @param pageSize
     * @param query
     * @return
     */
    @ApiOperation(value="工具台账-盘点子页面列表查询", notes="工具台账-盘点子页面列表查询")
    @GetMapping(value = "/toolsStocktakingList")
    public Result<?> toolsStocktakingList(ToolsStocktakingBound toolsStocktakingBound,
                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                        @RequestParam Map<String, String> query) {
        IPage<Map<String, Object>> pageList = toolsStocktakingBoundDetailService.toolsStocktakingList(pageNo,pageSize, query);
        return Result.OK(pageList);
    }
 
}