diff --git a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index 58250bb17..5373fb7ca 100644 --- a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -214,4 +214,7 @@ public interface ErrorCodeConstants { ErrorCode DEVICE_LINE_CODE_EXISTS = new ErrorCode(100_501_0006, "设备产线编码已存在,请重新提交"); ErrorCode DEVICE_LINE_CODE_NOT_EXISTS = new ErrorCode(100_501_0007, "设备产线编码不能为空"); ErrorCode DEVICE_CRITICAL_COMPONENT_NOT_EXISTS = new ErrorCode(100_501_0008, "设备关键件明细不存在"); + + // ========== 打印机配置 TODO 补充编号 ========== + ErrorCode CONFIG_NOT_EXISTS = new ErrorCode(100_601_0001, "打印机配置不存在"); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/PrinterConfigController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/PrinterConfigController.java new file mode 100644 index 000000000..3073432f9 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/PrinterConfigController.java @@ -0,0 +1,98 @@ +package cn.iocoder.yudao.module.mes.controller.admin.printconfig; + +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigRespVO; +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.printconfig.PrinterConfigDO; +import cn.iocoder.yudao.module.mes.service.printconfig.PrinterConfigService; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.*; +import javax.servlet.http.*; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + + +@Tag(name = "管理后台 - 打印机配置") +@RestController +@RequestMapping("/printer/config") +@Validated +public class PrinterConfigController { + + @Resource + private PrinterConfigService configService; + + @PostMapping("/create") + @Operation(summary = "创建打印机配置") + @PreAuthorize("@ss.hasPermission('printer:config:create')") + public CommonResult createConfig(@Valid @RequestBody PrinterConfigSaveReqVO createReqVO) { + return success(configService.createConfig(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新打印机配置") + @PreAuthorize("@ss.hasPermission('printer:config:update')") + public CommonResult updateConfig(@Valid @RequestBody PrinterConfigSaveReqVO updateReqVO) { + configService.updateConfig(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除打印机配置") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('printer:config:delete')") + public CommonResult deleteConfig(@RequestParam("id") Integer id) { + configService.deleteConfig(id); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得打印机配置") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('printer:config:query')") + public CommonResult getConfig(@RequestParam("id") Integer id) { + PrinterConfigDO config = configService.getConfig(id); + return success(BeanUtils.toBean(config, PrinterConfigRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得打印机配置分页") + @PreAuthorize("@ss.hasPermission('printer:config:query')") + public CommonResult> getConfigPage(@Valid PrinterConfigPageReqVO pageReqVO) throws UnknownHostException { + PageResult pageResult = configService.getConfigPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, PrinterConfigRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出打印机配置 Excel") + @PreAuthorize("@ss.hasPermission('printer:config:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportConfigExcel(@Valid PrinterConfigPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = configService.getConfigPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "打印机配置.xls", "数据", PrinterConfigRespVO.class, + BeanUtils.toBean(list, PrinterConfigRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigPageReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigPageReqVO.java new file mode 100644 index 000000000..f79531ead --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigPageReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo; + +import lombok.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 打印机配置分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PrinterConfigPageReqVO extends PageParam { + + @Schema(description = "主机名(如PACKING-PC-01),不可修改", example = "李四") + private String hostName; + + @Schema(description = "系统打印机名称,关联下拉选项", example = "赵六") + private String systemPrinterName; + + @Schema(description = "是否默认:0-否,1-是") + private Boolean isDefault; + + @Schema(description = "是否启用:0-禁用,1-启用") + private Boolean isEnabled; + + @Schema(description = "备注,记录打印机用途说明,用户不可修改", example = "随便") + private String remark; + + @Schema(description = "创建时间") + private LocalDateTime createdAt; + + @Schema(description = "更新时间") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigRespVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigRespVO.java new file mode 100644 index 000000000..41670ee11 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigRespVO.java @@ -0,0 +1,46 @@ +package cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 打印机配置 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PrinterConfigRespVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14325") + @ExcelProperty("主键ID") + private Integer id; + + @Schema(description = "主机名(如PACKING-PC-01),不可修改", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @ExcelProperty("主机名(如PACKING-PC-01),不可修改") + private String hostName; + + @Schema(description = "系统打印机名称,关联下拉选项", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @ExcelProperty("系统打印机名称,关联下拉选项") + private String systemPrinterName; + + @Schema(description = "是否默认:0-否,1-是", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("是否默认:0-否,1-是") + private Boolean isDefault; + + @Schema(description = "是否启用:0-禁用,1-启用", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("是否启用:0-禁用,1-启用") + private Boolean isEnabled; + + @Schema(description = "备注,记录打印机用途说明,用户不可修改", example = "随便") + @ExcelProperty("备注,记录打印机用途说明,用户不可修改") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createdAt; + + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("更新时间") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigSaveReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigSaveReqVO.java new file mode 100644 index 000000000..69d3f60ba --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/printconfig/vo/PrinterConfigSaveReqVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import javax.validation.constraints.*; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 打印机配置新增/修改 Request VO") +@Data +public class PrinterConfigSaveReqVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14325") + private Integer id; + + @Schema(description = "主机名(如PACKING-PC-01),不可修改", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") + @NotEmpty(message = "主机名(如PACKING-PC-01),不可修改不能为空") + private String hostName; + + @Schema(description = "系统打印机名称,关联下拉选项", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六") + @NotEmpty(message = "系统打印机名称,关联下拉选项不能为空") + private String systemPrinterName; + + @Schema(description = "是否默认:0-否,1-是", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "是否默认:0-否,1-是不能为空") + private Boolean isDefault; + + @Schema(description = "是否启用:0-禁用,1-启用", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "是否启用:0-禁用,1-启用不能为空") + private Boolean isEnabled; + + @Schema(description = "备注,记录打印机用途说明,用户不可修改", example = "随便") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "创建时间不能为空") + private LocalDateTime createdAt; + + @Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "更新时间不能为空") + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/printconfig/PrinterConfigDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/printconfig/PrinterConfigDO.java new file mode 100644 index 000000000..7f5dbebe4 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/printconfig/PrinterConfigDO.java @@ -0,0 +1,59 @@ +package cn.iocoder.yudao.module.mes.dal.dataobject.printconfig; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 打印机配置 DO + * + * @author 必硕智能 + */ +@TableName("mes_printer_config") +@KeySequence("printer_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PrinterConfigDO extends BaseDO { + + /** + * 主键ID + */ + @TableId + private Integer id; + /** + * 主机名(如PACKING-PC-01),不可修改 + */ + private String hostName; + /** + * 系统打印机名称,关联下拉选项 + */ + private String systemPrinterName; + /** + * 是否默认:0-否,1-是 + */ + private Boolean isDefault; + /** + * 是否启用:0-禁用,1-启用 + */ + private Boolean isEnabled; + /** + * 备注,记录打印机用途说明,用户不可修改 + */ + private String remark; + /** + * 创建时间 + */ + private LocalDateTime createdAt; + /** + * 更新时间 + */ + private LocalDateTime updatedAt; + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/printconfig/PrinterConfigMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/printconfig/PrinterConfigMapper.java new file mode 100644 index 000000000..90456a99e --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/printconfig/PrinterConfigMapper.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.mes.dal.mysql.printconfig; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; + +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigPageReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.printconfig.PrinterConfigDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 打印机配置 Mapper + * + * @author 必硕智能 + */ +@Mapper +public interface PrinterConfigMapper extends BaseMapperX { + + default PageResult selectPage(PrinterConfigPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(PrinterConfigDO::getHostName, reqVO.getHostName()) + .likeIfPresent(PrinterConfigDO::getSystemPrinterName, reqVO.getSystemPrinterName()) + .eqIfPresent(PrinterConfigDO::getIsDefault, reqVO.getIsDefault()) + .eqIfPresent(PrinterConfigDO::getIsEnabled, reqVO.getIsEnabled()) + .eqIfPresent(PrinterConfigDO::getRemark, reqVO.getRemark()) + .eqIfPresent(PrinterConfigDO::getCreatedAt, reqVO.getCreatedAt()) + .eqIfPresent(PrinterConfigDO::getUpdatedAt, reqVO.getUpdatedAt()) + .orderByDesc(PrinterConfigDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigService.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigService.java new file mode 100644 index 000000000..b599ce919 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigService.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.mes.service.printconfig; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.printconfig.PrinterConfigDO; + +/** + * 打印机配置 Service 接口 + * + * @author 必硕智能 + */ +public interface PrinterConfigService { + + /** + * 创建打印机配置 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createConfig(@Valid PrinterConfigSaveReqVO createReqVO); + + /** + * 更新打印机配置 + * + * @param updateReqVO 更新信息 + */ + void updateConfig(@Valid PrinterConfigSaveReqVO updateReqVO); + + /** + * 删除打印机配置 + * + * @param id 编号 + */ + void deleteConfig(Integer id); + + /** + * 获得打印机配置 + * + * @param id 编号 + * @return 打印机配置 + */ + PrinterConfigDO getConfig(Integer id); + + /** + * 获得打印机配置分页 + * + * @param pageReqVO 分页查询 + * @return 打印机配置分页 + */ + PageResult getConfigPage(PrinterConfigPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigServiceImpl.java new file mode 100644 index 000000000..0b6361070 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/printconfig/PrinterConfigServiceImpl.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.mes.service.printconfig; + +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.printconfig.vo.PrinterConfigSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.printconfig.PrinterConfigDO; +import cn.iocoder.yudao.module.mes.dal.mysql.printconfig.PrinterConfigMapper; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CONFIG_NOT_EXISTS; + +/** + * 打印机配置 Service 实现类 + * + * @author 必硕智能 + */ +@Service +@Validated +public class PrinterConfigServiceImpl implements PrinterConfigService { + + @Resource + private PrinterConfigMapper printerConfigMapper; + + @Override + public Integer createConfig(PrinterConfigSaveReqVO createReqVO) { + // 插入 + PrinterConfigDO config = BeanUtils.toBean(createReqVO, PrinterConfigDO.class); + printerConfigMapper.insert(config); + // 返回 + return config.getId(); + } + + @Override + public void updateConfig(PrinterConfigSaveReqVO updateReqVO) { + // 校验存在 + validateConfigExists(updateReqVO.getId()); + // 更新 + PrinterConfigDO updateObj = BeanUtils.toBean(updateReqVO, PrinterConfigDO.class); + printerConfigMapper.updateById(updateObj); + } + + @Override + public void deleteConfig(Integer id) { + // 校验存在 + validateConfigExists(id); + // 删除 + printerConfigMapper.deleteById(id); + } + + private void validateConfigExists(Integer id) { + if (printerConfigMapper.selectById(id) == null) { + throw exception(CONFIG_NOT_EXISTS); + } + } + + @Override + public PrinterConfigDO getConfig(Integer id) { + return printerConfigMapper.selectById(id); + } + + @Override + public PageResult getConfigPage(PrinterConfigPageReqVO pageReqVO) { + return printerConfigMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/printconfig/PrinterConfigMapper.xml b/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/printconfig/PrinterConfigMapper.xml new file mode 100644 index 000000000..d975aaad3 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/resources/mapper/printconfig/PrinterConfigMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file