xiaoyi
2 天以前 b5e1bceabb36fe1d1e5e88397280d12e7044c6dd
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
package cn.iocoder.yudao.module.mes.controller.admin.pd.knowledge;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mes.dal.dataobject.pd.knowledge.KnowledgeDO;
import cn.iocoder.yudao.module.mes.service.pd.knowledge.KnowledgeMatch;
import cn.iocoder.yudao.module.mes.service.pd.knowledge.KnowledgeSearchService;
import cn.iocoder.yudao.module.mes.service.pd.knowledge.KnowledgeWriteService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
 
@RestController
@RequestMapping("/mes/pd/knowledge")
public class KnowledgeController {
    @Resource private KnowledgeSearchService searchService;
    @Resource private KnowledgeWriteService writeService;
 
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:query')")
    public CommonResult<PageResult<KnowledgeDO>> page(PageParam page,
            @RequestParam(value = "name", required = false) String name) {
        return success(searchService.page(page, name));
    }
 
    @GetMapping("/get")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:query')")
    public CommonResult<KnowledgeSearchService.Detail> get(@RequestParam("id") Long id) {
        return success(searchService.get(id));
    }
 
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:create')")
    public CommonResult<Long> create(@RequestBody KnowledgeWriteService.SaveRequest input) {
        return success(writeService.create(input));
    }
 
    @PutMapping("/update")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:update')")
    public CommonResult<Boolean> update(@RequestBody KnowledgeWriteService.SaveRequest input) {
        writeService.update(input);
        return success(true);
    }
 
    @PutMapping("/publish")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:publish')")
    public CommonResult<Boolean> publish(@RequestParam("id") Long id) {
        writeService.publish(id);
        return success(true);
    }
 
    @PostMapping("/revise")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:create')")
    public CommonResult<Long> revise(@RequestParam("id") Long id) {
        return success(writeService.revise(id));
    }
 
    @PostMapping("/reference-route")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:reference')")
    public CommonResult<Boolean> referenceRoute(@RequestParam("id") Long id, @RequestParam("routeId") Long routeId) {
        writeService.referenceRoute(id, routeId);
        return success(true);
    }
 
    @GetMapping("/match")
    @PreAuthorize("@ss.hasPermission('mes:pd-knowledge:query')")
    public CommonResult<List<KnowledgeDO>> match(
            @RequestParam(value = "productId", required = false) Long productId,
            @RequestParam(value = "bomId", required = false) Long bomId,
            @RequestParam(value = "voltage", required = false) BigDecimal voltage,
            @RequestParam(value = "market", required = false) String market,
            @RequestParam(value = "standards", required = false) Set<String> standards) {
        if (market != null && !Set.of("DOMESTIC", "EXPORT").contains(market)) {
            throw invalidParamException("内外销类型不正确");
        }
        if (voltage != null && voltage.signum() < 0) {
            throw invalidParamException("电压不能小于零");
        }
        return success(searchService.match(new KnowledgeMatch.Request(productId, bomId, voltage, market, standards)));
    }
}