zhou zhou
17 小时以前 28c6a76ead9b65a0b5861d70f0838ef2a46f5c45
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
package com.vincent.rsf.server.manager.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.common.annotation.OperationLog;
import com.vincent.rsf.server.manager.entity.MatnrPrintTemplate;
import com.vincent.rsf.server.manager.service.MatnrPrintTemplateService;
import com.vincent.rsf.server.manager.utils.buildPageRowsUtils;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
import java.util.List;
import java.util.Map;
 
@RestController
@Api(tags = "物料打印模板接口")
public class MatnrPrintTemplateController extends BaseController {
 
    private final MatnrPrintTemplateService matnrPrintTemplateService;
 
    public MatnrPrintTemplateController(MatnrPrintTemplateService matnrPrintTemplateService) {
        this.matnrPrintTemplateService = matnrPrintTemplateService;
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:list')")
    @ApiOperation("查询物料打印模板列表")
    @PostMapping("/matnrPrintTemplate/list")
    public R list(@RequestBody(required = false) Map<String, Object> params) {
        List<MatnrPrintTemplate> templates = matnrPrintTemplateService.listCurrentTenantTemplates();
        return R.ok().add(buildPageRowsUtils.rowsMap(templates));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:list')")
    @ApiOperation("获取物料打印模板详情")
    @GetMapping("/matnrPrintTemplate/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.ok(buildPageRowsUtils.rowsMap(matnrPrintTemplateService.getCurrentTenantTemplate(id)));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:list')")
    @ApiOperation("获取默认物料打印模板")
    @GetMapping("/matnrPrintTemplate/default")
    public R getDefaultTemplate() {
        MatnrPrintTemplate template = matnrPrintTemplateService.getCurrentTenantDefaultTemplate();
        if (template == null) {
            return R.ok();
        }
        return R.ok(buildPageRowsUtils.rowsMap(template));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:save')")
    @OperationLog("Create 物料打印模板")
    @ApiOperation("保存物料打印模板")
    @PostMapping("/matnrPrintTemplate/save")
    public R save(@RequestBody Map<String, Object> params) {
        MatnrPrintTemplate template = JSONObject.parseObject(JSONObject.toJSONString(params), MatnrPrintTemplate.class);
        if (template == null) {
            throw new CoolException("模板参数不能为空");
        }
        MatnrPrintTemplate saved = matnrPrintTemplateService.saveTemplate(template);
        return R.ok("Create Success").add(buildPageRowsUtils.rowsMap(saved));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:update')")
    @OperationLog("Update 物料打印模板")
    @ApiOperation("更新物料打印模板")
    @PostMapping("/matnrPrintTemplate/update")
    @Transactional(rollbackFor = Exception.class)
    public R update(@RequestBody Map<String, Object> params) {
        MatnrPrintTemplate template = JSONObject.parseObject(JSONObject.toJSONString(params), MatnrPrintTemplate.class);
        if (template == null || template.getId() == null) {
            throw new CoolException("模板ID不能为空");
        }
        MatnrPrintTemplate updated = matnrPrintTemplateService.updateTemplate(template);
        return R.ok("Update Success").add(buildPageRowsUtils.rowsMap(updated));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:remove')")
    @OperationLog("Delete 物料打印模板")
    @ApiOperation("删除物料打印模板")
    @PostMapping("/matnrPrintTemplate/remove/{ids}")
    public R remove(@PathVariable Long[] ids) {
        matnrPrintTemplateService.removeTemplates(Arrays.asList(ids));
        return R.ok("Delete Success").add(buildPageRowsUtils.rowsMap(ids));
    }
 
    @PreAuthorize("hasAuthority('manager:matnrPrintTemplate:update')")
    @OperationLog("Set Default 物料打印模板")
    @ApiOperation("设置默认物料打印模板")
    @PostMapping("/matnrPrintTemplate/default/{id}")
    public R setDefault(@PathVariable("id") Long id) {
        matnrPrintTemplateService.setDefaultTemplate(id);
        return R.ok("Update Success");
    }
}