| | |
| | | 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.pro.route.vo.MesProRouteImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteFullExcelVO; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteFullExcelService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteFullImportService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteWorkbookService; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteImportRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRoutePageReqVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pro.route.MesProRouteProductMapper; |
| | | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | |
| | | 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; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
| | |
| | | |
| | | @Resource |
| | | private MesProRouteService routeService; |
| | | @Resource |
| | | private MesProRouteFullExcelService fullExcelService; |
| | | @Resource |
| | | private MesProRouteFullImportService fullImportService; |
| | | @Resource |
| | | private MesProRouteWorkbookService routeWorkbookService; |
| | | @Resource |
| | | private MesProRouteProductMapper routeProductMapper; |
| | | @Resource |
| | | private MesMdItemService itemService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建工艺路线") |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得工艺路线") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-route:query')") |
| | | public CommonResult<MesProRouteRespVO> getRoute(@RequestParam("id") Long id) { |
| | | MesProRouteDO route = routeService.getRoute(id); |
| | | return success(BeanUtils.toBean(route, MesProRouteRespVO.class)); |
| | |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得工艺路线分页") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-route:query')") |
| | | public CommonResult<PageResult<MesProRouteRespVO>> getRoutePage(@Valid MesProRoutePageReqVO pageReqVO) { |
| | | PageResult<MesProRouteDO> pageResult = routeService.getRoutePage(pageReqVO); |
| | | return success(BeanUtils.toBean(pageResult, MesProRouteRespVO.class)); |
| | | PageResult<MesProRouteRespVO> response = BeanUtils.toBean(pageResult, MesProRouteRespVO.class); |
| | | if (!pageResult.getList().isEmpty()) { |
| | | var routeIds = pageResult.getList().stream().map(MesProRouteDO::getId).toList(); |
| | | var references = routeProductMapper.selectList(new LambdaQueryWrapperX<MesProRouteProductDO>() |
| | | .in(MesProRouteProductDO::getRouteId, routeIds).eq(MesProRouteProductDO::getTemplateReference, true)); |
| | | var items = itemService.getItemMap(references.stream().map(MesProRouteProductDO::getItemId).toList()); |
| | | var byRoute = references.stream().collect(java.util.stream.Collectors.toMap( |
| | | MesProRouteProductDO::getRouteId, r -> r, (first, ignored) -> first)); |
| | | response.getList().forEach(vo -> { |
| | | var reference = byRoute.get(vo.getId()); |
| | | MesMdItemDO item = reference == null ? null : items.get(reference.getItemId()); |
| | | if (item != null) { vo.setReferenceProductCode(item.getCode()); vo.setReferenceProductName(item.getName()); } |
| | | }); |
| | | } |
| | | return success(response); |
| | | } |
| | | |
| | | @GetMapping("/simple-list") |
| | |
| | | ExcelUtils.write(response, "工艺路线.xls", "数据", MesProRouteRespVO.class, data); |
| | | } |
| | | |
| | | @GetMapping("/get-full-import-template") |
| | | @Operation(summary = "下载指定工艺路线参考产品、工序、产出和投料的完整模板") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-route:import')") |
| | | public void fullImportTemplate(@RequestParam("routeId") Long routeId, HttpServletResponse response) throws IOException { |
| | | List<MesProRouteFullExcelVO> rows = fullExcelService.exportRouteReference(routeId); |
| | | routeWorkbookService.write(response, rows); |
| | | } |
| | | |
| | | @PostMapping("/import-full") |
| | | @Operation(summary = "按路线事务导入完整工艺流程") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-route:import')") |
| | | public CommonResult<MesProRouteImportRespVO> importFull(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws IOException { |
| | | return success(fullImportService.importRows(routeWorkbookService.read(file), updateSupport)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得工艺路线导入模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 手动创建导出 demo |
| | | List<MesProRouteImportExcelVO> list = Collections.singletonList( |
| | | MesProRouteImportExcelVO.builder() |
| | | .code("ROUTE001").name("示例工艺路线").description("").remark("").build() |
| | | ); |
| | | // 输出 |
| | | ExcelUtils.write(response, "工艺路线导入模板.xls", "工艺路线列表", MesProRouteImportExcelVO.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-route:import')") |
| | | public CommonResult<MesProRouteImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, |
| | | defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | List<MesProRouteImportExcelVO> list = ExcelUtils.read(file, MesProRouteImportExcelVO.class); |
| | | return success(routeService.importRouteList(list, updateSupport)); |
| | | } |
| | | |
| | | } |