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)));
|
}
|
}
|