xiaoyi
5 天以前 883f5e73fbe7458fd760dbe8560dd5d8757e04cd
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/card/MesProCardController.java
@@ -9,6 +9,8 @@
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
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.pro.card.vo.MesProCardImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.card.vo.MesProCardImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.card.vo.MesProCardPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.card.vo.MesProCardRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.card.vo.MesProCardSaveReqVO;
@@ -22,6 +24,7 @@
import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
@@ -29,6 +32,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Collections;
@@ -108,7 +112,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得生产流转卡")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-card:query')")
    public CommonResult<MesProCardRespVO> getCard(@RequestParam("id") Long id) {
        MesProCardDO card = cardService.getCard(id);
        if (card == null) {
@@ -119,7 +122,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得生产流转卡分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-card:query')")
    public CommonResult<PageResult<MesProCardRespVO>> getCardPage(@Valid MesProCardPageReqVO pageReqVO) {
        PageResult<MesProCardDO> pageResult = cardService.getCardPage(pageReqVO);
        return success(new PageResult<>(buildCardRespVOList(pageResult.getList()), pageResult.getTotal()));
@@ -138,6 +140,31 @@
        ExcelUtils.write(response, "生产流转卡.xls", "数据", MesProCardRespVO.class, voList);
    }
    @GetMapping("/get-import-template")
    @Operation(summary = "获得生产流转卡导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        List<MesProCardImportExcelVO> list = Collections.singletonList(
                MesProCardImportExcelVO.builder()
                        .code("CARD-001").workOrderCode("").itemCode("").batchCode("")
                        .transferedQuantity(new java.math.BigDecimal("100")).remark("").build()
        );
        ExcelUtils.write(response, "生产流转卡导入模板.xls", "生产流转卡列表", MesProCardImportExcelVO.class, list);
    }
    @PostMapping("/import")
    @Operation(summary = "导入生产流转卡")
    @Parameters({
            @Parameter(name = "file", description = "Excel 文件", required = true),
            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
    })
    @PreAuthorize("@ss.hasPermission('mes:pro-card:import')")
    public CommonResult<MesProCardImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                            @RequestParam(value = "updateSupport", required = false,
                                                                    defaultValue = "false") Boolean updateSupport) throws Exception {
        List<MesProCardImportExcelVO> list = ExcelUtils.read(file, MesProCardImportExcelVO.class);
        return success(cardService.importCardList(list, updateSupport));
    }
    // ==================== 拼接 VO ====================
    private List<MesProCardRespVO> buildCardRespVOList(List<MesProCardDO> list) {