MrShi
2025-02-07 364d3221b9a8e6dd3a19701d30c4dc4239ef8abf
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
package com.doumee.cloud.admin;
 
import cn.emay.sdk.util.StringUtil;
import com.doumee.api.BaseController;
import com.doumee.config.annotation.CloudRequiredPermission;
import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageWrap;
import com.doumee.core.model.PageData;
import com.doumee.core.utils.Constants;
import com.doumee.dao.business.model.YwOutinbound;
import com.doumee.dao.business.model.YwOutinboundRecord;
import com.doumee.dao.business.vo.YwOutinboundExcelInVO;
import com.doumee.dao.business.vo.YwOutinboundExcelOutVO;
import com.doumee.service.business.YwOutinboundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author 江蹄蹄
 * @date 2025/01/06 11:05
 */
@Api(tags = "运维出入库信息表")
@RestController
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX+"/business/ywOutinbound")
public class YwOutinboundController extends BaseController {
 
    @Autowired
    private YwOutinboundService ywOutinboundService;
 
    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @CloudRequiredPermission("business:ywoutinbound:create")
    public ApiResponse create(@RequestBody YwOutinbound ywOutinbound,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        ywOutinbound.setLoginUserInfo(this.getLoginUser(token));
        return ApiResponse.success(ywOutinboundService.create(ywOutinbound));
    }
 
    @ApiOperation("根据ID删除")
    @GetMapping("/delete/{id}")
    @CloudRequiredPermission("business:ywoutinbound:delete")
    public ApiResponse deleteById(@PathVariable Integer id,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        ywOutinboundService.deleteById(id);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @CloudRequiredPermission("business:ywoutinbound:delete")
    public ApiResponse deleteByIdInBatch(@RequestParam String ids,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            idList.add(Integer.valueOf(id));
        }
        ywOutinboundService.deleteByIdInBatch(idList);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("根据ID修改")
    @PostMapping("/updateById")
    @CloudRequiredPermission("business:ywoutinbound:update")
    public ApiResponse updateById(@RequestBody YwOutinbound ywOutinbound,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        ywOutinbound.setLoginUserInfo(this.getLoginUser(token));
        ywOutinboundService.updateById(ywOutinbound);
        return ApiResponse.success(null);
    }
 
    @ApiOperation("分页查询")
    @PostMapping("/page")
    @CloudRequiredPermission("business:ywoutinbound:query")
    public ApiResponse<PageData<YwOutinbound>> findPage (@RequestBody PageWrap<YwOutinbound> pageWrap,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        return ApiResponse.success(ywOutinboundService.findPage(pageWrap));
    }
 
    @ApiOperation("导出Excel")
    @PostMapping("/exportExcel")
    @CloudRequiredPermission("business:ywoutinbound:exportExcel")
    public void exportExcel (@RequestBody PageWrap<YwOutinbound> pageWrap, HttpServletResponse response,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        List<YwOutinbound> ywOutinboundList = ywOutinboundService.findPage(pageWrap).getRecords();
        Integer inOut = pageWrap.getModel().getInOut();
        if(Constants.equalsInteger(inOut,Constants.ZERO)){
            List<YwOutinboundExcelInVO> inList = new ArrayList<>();
            for (YwOutinbound ywOutinbound:ywOutinboundList) {
                YwOutinboundExcelInVO inVO = new YwOutinboundExcelInVO();
                BeanUtils.copyProperties(ywOutinbound,inVO);
                List<YwOutinboundRecord> ywOutinboundRecordList = ywOutinbound.getRecordList();
                StringBuffer stringBuffer = new StringBuffer();
                for (YwOutinboundRecord ywOutinboundRecord:ywOutinboundRecordList) {
                    stringBuffer.append(ywOutinboundRecord.getMaterialName()+"["+ywOutinboundRecord.getMaterialCode()+"]*"+ywOutinboundRecord.getStock()+ywOutinboundRecord.getMaterialUnitName()+";");
                }
                inVO.setOutMaterialNum(stringBuffer.toString());
                inList.add(inVO);
            }
            ExcelExporter.build(YwOutinboundExcelInVO.class).export(inList, "入库信息表", response);
        }else{
            List<YwOutinboundExcelOutVO> outList = new ArrayList<>();
            for (YwOutinbound ywOutinbound:ywOutinboundList) {
                YwOutinboundExcelOutVO ywOutinboundExcelOutVO = new YwOutinboundExcelOutVO();
                BeanUtils.copyProperties(ywOutinbound,ywOutinboundExcelOutVO);
                List<YwOutinboundRecord> ywOutinboundRecordList = ywOutinbound.getRecordList();
                StringBuffer stringBuffer = new StringBuffer();
                for (YwOutinboundRecord ywOutinboundRecord:ywOutinboundRecordList) {
                    stringBuffer.append(ywOutinboundRecord.getMaterialName()+"["+ywOutinboundRecord.getMaterialCode()+"]*"+ywOutinboundRecord.getStock()+ywOutinboundRecord.getMaterialUnitName()+";");
                }
                ywOutinboundExcelOutVO.setOutMaterialNum(stringBuffer.toString());
                outList.add(ywOutinboundExcelOutVO);
            }
            ExcelExporter.build(YwOutinboundExcelOutVO.class).export(outList, "出库信息表", response);
        }
    }
 
    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    @CloudRequiredPermission("business:ywoutinbound:query")
    public ApiResponse findById(@PathVariable Integer id,@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        return ApiResponse.success(ywOutinboundService.getDetail(id));
    }
}