3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
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
package cn.iocoder.yudao.module.mes.controller.admin.wm.barcode;
 
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
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.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.MesWmBarcodePageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.MesWmBarcodeRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.wm.barcode.vo.MesWmBarcodeSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.wm.barcode.MesWmBarcodeDO;
import cn.iocoder.yudao.module.mes.service.wm.barcode.MesWmBarcodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@Tag(name = "管理后台 - MES 条码清单")
@RestController
@RequestMapping("/mes/wm/barcode")
@Validated
public class MesWmBarcodeController {
 
    @Resource
    private MesWmBarcodeService barcodeService;
 
    @PostMapping("/create")
    @Operation(summary = "创建条码")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:create')")
    public CommonResult<Long> createBarcode(@Valid @RequestBody MesWmBarcodeSaveReqVO createReqVO) {
        return success(barcodeService.createBarcode(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新条码")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:update')")
    public CommonResult<Boolean> updateBarcode(@Valid @RequestBody MesWmBarcodeSaveReqVO updateReqVO) {
        barcodeService.updateBarcode(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除条码")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:delete')")
    public CommonResult<Boolean> deleteBarcode(@RequestParam("id") Long id) {
        barcodeService.deleteBarcode(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得条码")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<MesWmBarcodeRespVO> getBarcode(@RequestParam("id") Long id) {
        MesWmBarcodeDO barcode = barcodeService.getBarcode(id);
        return success(BeanUtils.toBean(barcode, MesWmBarcodeRespVO.class));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得条码分页")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<PageResult<MesWmBarcodeRespVO>> getBarcodePage(@Valid MesWmBarcodePageReqVO pageReqVO) {
        PageResult<MesWmBarcodeDO> pageResult = barcodeService.getBarcodePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, MesWmBarcodeRespVO.class));
    }
 
    @GetMapping("/get-by-business")
    @Operation(summary = "根据业务对象获取条码信息", description = "前端用于生成条码图片")
    @Parameter(name = "bizType", description = "业务类型", required = true, example = "102")
    @Parameter(name = "bizId", description = "业务编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<MesWmBarcodeRespVO> getBarcodeByBusiness(
            @RequestParam("bizType") Integer bizType,
            @RequestParam("bizId") Long bizId) {
        MesWmBarcodeDO barcode = barcodeService.getBarcodeByBizTypeAndBizId(bizType, bizId);
        return success(BeanUtils.toBean(barcode, MesWmBarcodeRespVO.class));
    }
 
    @GetMapping("/generate-content")
    @Operation(summary = "生成条码内容")
    @Parameter(name = "bizType", description = "业务类型", required = true, example = "1")
    @Parameter(name = "bizCode", description = "业务编码", required = true, example = "WO202403070001")
    @Parameter(name = "bizName", description = "业务名称", required = false, example = "一号车间")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<String> generateBarcodeContent(@RequestParam("bizType") @NotNull(message = "业务类型不能为空") Integer bizType,
                                                        @RequestParam("bizCode") @NotBlank(message = "业务编码不能为空") String bizCode,
                                                        @RequestParam(value = "bizName", required = false) String bizName) {
        String content = barcodeService.generateBarcodeContent(bizType, bizCode, bizName);
        return success(content);
    }
 
    @PostMapping("/render")
    @Operation(summary = "生成条码/二维码图片", description = "服务端 zxing 成图,返回 PNG Base64 供即时预览;不落库")
    @Parameter(name = "content", description = "条码内容", required = true)
    @Parameter(name = "format", description = "条码格式(1 二维码 / 2 EAN13 / 3 CODE39 / 4 UPC-A / 空默认 CODE128)", required = false)
    @Parameter(name = "width", description = "图片宽度", required = false)
    @Parameter(name = "height", description = "图片高度", required = false)
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<String> renderBarcodeImage(@RequestParam("content") @NotBlank(message = "条码内容不能为空") String content,
                                                   @RequestParam(value = "format", required = false) Integer format,
                                                   @RequestParam(value = "width", required = false) Integer width,
                                                   @RequestParam(value = "height", required = false) Integer height) {
        return success(barcodeService.renderBarcodeImage(content, format, width, height));
    }
 
    @PostMapping("/parse")
    @Operation(summary = "解析条码内容", description = "按条码内容精确命中或模板反解,返回业务字段")
    @Parameter(name = "content", description = "扫描到的条码内容", required = true)
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:query')")
    public CommonResult<Map<String, Object>> parseBarcodeContent(@RequestParam("content") @NotBlank(message = "条码内容不能为空") String content) {
        return success(barcodeService.parseBarcodeContent(content));
    }
 
    @GetMapping("/export-excel")
    @Operation(summary = "导出条码清单 Excel")
    @PreAuthorize("@ss.hasPermission('mes:wm-barcode:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportBarcodeExcel(@Valid MesWmBarcodePageReqVO pageReqVO,
                                   HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<MesWmBarcodeDO> list = barcodeService.getBarcodePage(pageReqVO).getList();
        List<MesWmBarcodeRespVO> voList = BeanUtils.toBean(list, MesWmBarcodeRespVO.class);
        ExcelUtils.write(response, "条码清单.xls", "数据", MesWmBarcodeRespVO.class, voList);
    }
 
}