add mold
parent
becedb5388
commit
1ea1f11eb9
@ -0,0 +1,140 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
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 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.*;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldBrandDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import cn.iocoder.yudao.module.erp.service.mold.MoldBrandService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Tag(name = "管理后台 - 模具型号")
|
||||
@RestController
|
||||
@RequestMapping("/erp/mold-brand")
|
||||
@Validated
|
||||
public class MoldBrandController {
|
||||
|
||||
@Resource
|
||||
private MoldBrandService moldBrandService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建模具型号")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:create')")
|
||||
public CommonResult<Long> createMoldBrand(@Valid @RequestBody MoldBrandSaveReqVO createReqVO) {
|
||||
return success(moldBrandService.createMoldBrand(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新模具型号")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:update')")
|
||||
public CommonResult<Boolean> updateMoldBrand(@Valid @RequestBody MoldBrandSaveReqVO updateReqVO) {
|
||||
moldBrandService.updateMoldBrand(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除模具型号")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:delete')")
|
||||
public CommonResult<Boolean> deleteMoldBrand(@RequestParam("id") Long id) {
|
||||
moldBrandService.deleteMoldBrand(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得模具型号")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
|
||||
public CommonResult<MoldBrandRespVO> getMoldBrand(@RequestParam("id") Long id) {
|
||||
MoldBrandDO moldBrand = moldBrandService.getMoldBrand(id);
|
||||
return success(BeanUtils.toBean(moldBrand, MoldBrandRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得模具型号分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
|
||||
public CommonResult<PageResult<MoldBrandRespVO>> getMoldBrandPage(@Valid MoldBrandPageReqVO pageReqVO) {
|
||||
PageResult<MoldBrandDO> pageResult = moldBrandService.getMoldBrandPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, MoldBrandRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出模具型号 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportMoldBrandExcel(@Valid MoldBrandPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<MoldBrandDO> list = moldBrandService.getMoldBrandPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "模具型号.xls", "数据", MoldBrandRespVO.class,
|
||||
BeanUtils.toBean(list, MoldBrandRespVO.class));
|
||||
}
|
||||
|
||||
// ==================== 子表(模具) ====================
|
||||
|
||||
@GetMapping("/mold/page")
|
||||
@Operation(summary = "获得模具分页")
|
||||
@Parameter(name = "brandId", description = "型号id")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
|
||||
public CommonResult<PageResult<MoldDO>> getMoldPage(PageParam pageReqVO,
|
||||
@RequestParam("brandId") Long brandId) {
|
||||
return success(moldBrandService.getMoldPage(pageReqVO, brandId));
|
||||
}
|
||||
|
||||
@PostMapping("/mold/create")
|
||||
@Operation(summary = "创建模具")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:create')")
|
||||
public CommonResult<Long> createMold(@Valid @RequestBody MoldDO mold) {
|
||||
return success(moldBrandService.createMold(mold));
|
||||
}
|
||||
|
||||
@PutMapping("/mold/update")
|
||||
@Operation(summary = "更新模具")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:update')")
|
||||
public CommonResult<Boolean> updateMold(@Valid @RequestBody MoldDO mold) {
|
||||
moldBrandService.updateMold(mold);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/mold/delete")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@Operation(summary = "删除模具")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:delete')")
|
||||
public CommonResult<Boolean> deleteMold(@RequestParam("id") Long id) {
|
||||
moldBrandService.deleteMold(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/mold/get")
|
||||
@Operation(summary = "获得模具")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
|
||||
public CommonResult<MoldDO> getMold(@RequestParam("id") Long id) {
|
||||
return success(moldBrandService.getMold(id));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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 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.*;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import cn.iocoder.yudao.module.erp.service.mold.MoldService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Tag(name = "管理后台 - 模具")
|
||||
@RestController
|
||||
@RequestMapping("/erp/mold")
|
||||
@Validated
|
||||
public class MoldController {
|
||||
|
||||
@Resource
|
||||
private MoldService moldService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建模具")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:create')")
|
||||
public CommonResult<Long> createMold(@Valid @RequestBody MoldSaveReqVO createReqVO) {
|
||||
return success(moldService.createMold(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新模具")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:update')")
|
||||
public CommonResult<Boolean> updateMold(@Valid @RequestBody MoldSaveReqVO updateReqVO) {
|
||||
moldService.updateMold(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除模具")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:delete')")
|
||||
public CommonResult<Boolean> deleteMold(@RequestParam("id") Long id) {
|
||||
moldService.deleteMold(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得模具")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:query')")
|
||||
public CommonResult<MoldRespVO> getMold(@RequestParam("id") Long id) {
|
||||
MoldDO mold = moldService.getMold(id);
|
||||
return success(BeanUtils.toBean(mold, MoldRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得模具分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:query')")
|
||||
public CommonResult<PageResult<MoldRespVO>> getMoldPage(@Valid MoldPageReqVO pageReqVO) {
|
||||
PageResult<MoldDO> pageResult = moldService.getMoldPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, MoldRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出模具 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:mold:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportMoldExcel(@Valid MoldPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<MoldDO> list = moldService.getMoldPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "模具.xls", "数据", MoldRespVO.class,
|
||||
BeanUtils.toBean(list, MoldRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 模具型号分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MoldBrandPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "型号编码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "型号名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "规格", example = "2")
|
||||
private String moldType;
|
||||
|
||||
@Schema(description = "产品ID", example = "2336")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "预期寿命(小时)")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private BigDecimal[] useTime;
|
||||
|
||||
@Schema(description = "维保模式", example = "2")
|
||||
private Integer maintainType;
|
||||
|
||||
@Schema(description = "维保周期")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private BigDecimal[] maintainTime;
|
||||
|
||||
@Schema(description = "模具系数")
|
||||
private Long moldSize;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - 模具型号 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class MoldBrandRespVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24140")
|
||||
@ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "型号编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("型号编码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "型号名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("型号名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("规格")
|
||||
private String moldType;
|
||||
|
||||
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
|
||||
@ExcelProperty("产品ID")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "预期寿命(小时)")
|
||||
@ExcelProperty("预期寿命(小时)")
|
||||
private BigDecimal useTime;
|
||||
|
||||
@Schema(description = "维保模式", example = "2")
|
||||
@ExcelProperty(value = "维保模式", converter = DictConvert.class)
|
||||
@DictFormat("maintain_type") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer maintainType;
|
||||
|
||||
@Schema(description = "维保周期")
|
||||
@ExcelProperty("维保周期")
|
||||
private BigDecimal maintainTime;
|
||||
|
||||
@Schema(description = "模具系数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("模具系数")
|
||||
private Long moldSize;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.math.BigDecimal;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 模具型号新增/修改 Request VO")
|
||||
@Data
|
||||
public class MoldBrandSaveReqVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24140")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "型号编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "型号编码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "型号名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@NotEmpty(message = "型号名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotEmpty(message = "规格不能为空")
|
||||
private String moldType;
|
||||
|
||||
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
|
||||
@NotNull(message = "产品ID不能为空")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "预期寿命(小时)")
|
||||
private BigDecimal useTime;
|
||||
|
||||
@Schema(description = "维保模式", example = "2")
|
||||
private Integer maintainType;
|
||||
|
||||
@Schema(description = "维保周期")
|
||||
private BigDecimal maintainTime;
|
||||
|
||||
@Schema(description = "模具系数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "模具系数不能为空")
|
||||
private Long moldSize;
|
||||
|
||||
@Schema(description = "备注", example = "你说的对")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否启用不能为空")
|
||||
private Boolean isEnable;
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 模具分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MoldPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "模具编码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "模具名称", example = "芋艿")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位ID", example = "19527")
|
||||
private Long unitId;
|
||||
|
||||
@Schema(description = "机台ID", example = "24428")
|
||||
private Long machineId;
|
||||
|
||||
@Schema(description = "使用时间(小时)")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private BigDecimal[] useTime;
|
||||
|
||||
@Schema(description = "入库时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] inTime;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "模具图片")
|
||||
private String images;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "型号id", example = "15258")
|
||||
private Long brandId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
@Schema(description = "管理后台 - 模具 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class MoldRespVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "32278")
|
||||
@ExcelProperty("ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "模具编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("模具编码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "模具名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@ExcelProperty("模具名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19527")
|
||||
@ExcelProperty("单位ID")
|
||||
private Long unitId;
|
||||
|
||||
@Schema(description = "机台ID", example = "24428")
|
||||
@ExcelProperty("机台ID")
|
||||
private Long machineId;
|
||||
|
||||
@Schema(description = "使用时间(小时)")
|
||||
@ExcelProperty("使用时间(小时)")
|
||||
private BigDecimal useTime;
|
||||
|
||||
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("入库时间")
|
||||
private LocalDateTime inTime;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat("erp_mold_status") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "模具图片")
|
||||
@ExcelProperty("模具图片")
|
||||
private String images;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("是否启用")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "型号id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15258")
|
||||
@ExcelProperty("型号id")
|
||||
private Long brandId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.mold.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 模具新增/修改 Request VO")
|
||||
@Data
|
||||
public class MoldSaveReqVO {
|
||||
|
||||
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "32278")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "模具编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "模具编码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "模具名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
@NotEmpty(message = "模具名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19527")
|
||||
@NotNull(message = "单位ID不能为空")
|
||||
private Long unitId;
|
||||
|
||||
@Schema(description = "机台ID", example = "24428")
|
||||
private Long machineId;
|
||||
|
||||
@Schema(description = "使用时间(小时)")
|
||||
private BigDecimal useTime;
|
||||
|
||||
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "入库时间不能为空")
|
||||
private LocalDateTime inTime;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "模具图片")
|
||||
private String images;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "是否启用", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "是否启用不能为空")
|
||||
private Boolean isEnable;
|
||||
|
||||
@Schema(description = "型号id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15258")
|
||||
@NotNull(message = "型号id不能为空")
|
||||
private Long brandId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.mold;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
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("erp_mold_brand")
|
||||
@KeySequence("erp_mold_brand_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MoldBrandDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 型号编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 型号名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
private String moldType;
|
||||
/**
|
||||
* 产品ID
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 预期寿命(小时)
|
||||
*/
|
||||
private BigDecimal useTime;
|
||||
/**
|
||||
* 维保模式
|
||||
*
|
||||
* 枚举 {@link TODO maintain_type 对应的类}
|
||||
*/
|
||||
private Integer maintainType;
|
||||
/**
|
||||
* 维保周期
|
||||
*/
|
||||
private BigDecimal maintainTime;
|
||||
/**
|
||||
* 模具系数
|
||||
*/
|
||||
private Long moldSize;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean isEnable;
|
||||
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.mold;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
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("erp_mold")
|
||||
@KeySequence("erp_mold_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MoldDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 模具编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 模具名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 单位ID
|
||||
*/
|
||||
private Long unitId;
|
||||
/**
|
||||
* 机台ID
|
||||
*/
|
||||
private Long machineId;
|
||||
/**
|
||||
* 使用时间(小时)
|
||||
*/
|
||||
private BigDecimal useTime;
|
||||
/**
|
||||
* 入库时间
|
||||
*/
|
||||
private LocalDateTime inTime;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link TODO erp_mold_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 模具图片
|
||||
*/
|
||||
private String images;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean isEnable;
|
||||
/**
|
||||
* 型号id
|
||||
*/
|
||||
private Long brandId;
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.mold;
|
||||
|
||||
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.erp.dal.dataobject.mold.MoldBrandDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
|
||||
/**
|
||||
* 模具型号 Mapper
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Mapper
|
||||
public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {
|
||||
|
||||
default PageResult<MoldBrandDO> selectPage(MoldBrandPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<MoldBrandDO>()
|
||||
.eqIfPresent(MoldBrandDO::getCode, reqVO.getCode())
|
||||
.likeIfPresent(MoldBrandDO::getName, reqVO.getName())
|
||||
.eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
|
||||
.eqIfPresent(MoldBrandDO::getProductId, reqVO.getProductId())
|
||||
.betweenIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
|
||||
.eqIfPresent(MoldBrandDO::getMaintainType, reqVO.getMaintainType())
|
||||
.betweenIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
|
||||
.eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
|
||||
.eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())
|
||||
.betweenIfPresent(MoldBrandDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(MoldBrandDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.mold;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 模具 Mapper
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Mapper
|
||||
public interface MoldMapper extends BaseMapperX<MoldDO> {
|
||||
|
||||
default PageResult<MoldDO> selectPage(PageParam reqVO, Long brandId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<MoldDO>()
|
||||
.eq(MoldDO::getBrandId, brandId)
|
||||
.orderByDesc(MoldDO::getId));
|
||||
}
|
||||
|
||||
default int deleteByBrandId(Long brandId) {
|
||||
return delete(MoldDO::getBrandId, brandId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package cn.iocoder.yudao.module.erp.framework.bean;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MoldStatusEnum implements IntArrayValuable {
|
||||
|
||||
ENABLE(0, "开启"),
|
||||
DISABLE(1, "关闭");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(MoldStatusEnum::getStatus).toArray();
|
||||
|
||||
/**
|
||||
* 状态值
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 状态名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
public static boolean isEnable(Integer status) {
|
||||
return ObjUtil.equal(ENABLE.status, status);
|
||||
}
|
||||
|
||||
public static boolean isDisable(Integer status) {
|
||||
return ObjUtil.equal(DISABLE.status, status);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldBrandDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 模具型号 Service 接口
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
public interface MoldBrandService {
|
||||
|
||||
/**
|
||||
* 创建模具型号
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createMoldBrand(@Valid MoldBrandSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新模具型号
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateMoldBrand(@Valid MoldBrandSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除模具型号
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteMoldBrand(Long id);
|
||||
|
||||
/**
|
||||
* 获得模具型号
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 模具型号
|
||||
*/
|
||||
MoldBrandDO getMoldBrand(Long id);
|
||||
|
||||
/**
|
||||
* 获得模具型号分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 模具型号分页
|
||||
*/
|
||||
PageResult<MoldBrandDO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 子表(模具) ====================
|
||||
|
||||
/**
|
||||
* 获得模具分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @param brandId 型号id
|
||||
* @return 模具分页
|
||||
*/
|
||||
PageResult<MoldDO> getMoldPage(PageParam pageReqVO, Long brandId);
|
||||
|
||||
/**
|
||||
* 创建模具
|
||||
*
|
||||
* @param mold 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createMold(@Valid MoldDO mold);
|
||||
|
||||
/**
|
||||
* 更新模具
|
||||
*
|
||||
* @param mold 更新信息
|
||||
*/
|
||||
void updateMold(@Valid MoldDO mold);
|
||||
|
||||
/**
|
||||
* 删除模具
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteMold(Long id);
|
||||
|
||||
/**
|
||||
* 获得模具
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 模具
|
||||
*/
|
||||
MoldDO getMold(Long id);
|
||||
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldBrandDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
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 cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldBrandMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldMapper;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 模具型号 Service 实现类
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class MoldBrandServiceImpl implements MoldBrandService {
|
||||
|
||||
@Resource
|
||||
private MoldBrandMapper moldBrandMapper;
|
||||
@Resource
|
||||
private MoldMapper moldMapper;
|
||||
|
||||
@Override
|
||||
public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
MoldBrandDO moldBrand = BeanUtils.toBean(createReqVO, MoldBrandDO.class);
|
||||
moldBrandMapper.insert(moldBrand);
|
||||
// 返回
|
||||
return moldBrand.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMoldBrand(MoldBrandSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateMoldBrandExists(updateReqVO.getId());
|
||||
// 更新
|
||||
MoldBrandDO updateObj = BeanUtils.toBean(updateReqVO, MoldBrandDO.class);
|
||||
moldBrandMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteMoldBrand(Long id) {
|
||||
// 校验存在
|
||||
validateMoldBrandExists(id);
|
||||
// 删除
|
||||
moldBrandMapper.deleteById(id);
|
||||
|
||||
// 删除子表
|
||||
deleteMoldByBrandId(id);
|
||||
}
|
||||
|
||||
private void validateMoldBrandExists(Long id) {
|
||||
if (moldBrandMapper.selectById(id) == null) {
|
||||
throw exception(MOLD_BRAND_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoldBrandDO getMoldBrand(Long id) {
|
||||
return moldBrandMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MoldBrandDO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
|
||||
return moldBrandMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(模具) ====================
|
||||
|
||||
@Override
|
||||
public PageResult<MoldDO> getMoldPage(PageParam pageReqVO, Long brandId) {
|
||||
return moldMapper.selectPage(pageReqVO, brandId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createMold(MoldDO mold) {
|
||||
moldMapper.insert(mold);
|
||||
return mold.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMold(MoldDO mold) {
|
||||
// 校验存在
|
||||
validateMoldExists(mold.getId());
|
||||
// 更新
|
||||
moldMapper.updateById(mold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMold(Long id) {
|
||||
// 校验存在
|
||||
validateMoldExists(id);
|
||||
// 删除
|
||||
moldMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoldDO getMold(Long id) {
|
||||
return moldMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void validateMoldExists(Long id) {
|
||||
if (moldMapper.selectById(id) == null) {
|
||||
throw exception(MOLD_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteMoldByBrandId(Long brandId) {
|
||||
moldMapper.deleteByBrandId(brandId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 模具 Service 接口
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
public interface MoldService {
|
||||
|
||||
/**
|
||||
* 创建模具
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createMold(@Valid MoldSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新模具
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateMold(@Valid MoldSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除模具
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteMold(Long id);
|
||||
|
||||
/**
|
||||
* 获得模具
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 模具
|
||||
*/
|
||||
MoldDO getMold(Long id);
|
||||
|
||||
/**
|
||||
* 获得模具分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 模具分页
|
||||
*/
|
||||
PageResult<MoldDO> getMoldPage(MoldPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
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 cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldMapper;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 模具 Service 实现类
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class MoldServiceImpl implements MoldService {
|
||||
|
||||
@Resource
|
||||
private MoldMapper moldMapper;
|
||||
|
||||
@Override
|
||||
public Long createMold(MoldSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
MoldDO mold = BeanUtils.toBean(createReqVO, MoldDO.class);
|
||||
moldMapper.insert(mold);
|
||||
// 返回
|
||||
return mold.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMold(MoldSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateMoldExists(updateReqVO.getId());
|
||||
// 更新
|
||||
MoldDO updateObj = BeanUtils.toBean(updateReqVO, MoldDO.class);
|
||||
moldMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMold(Long id) {
|
||||
// 校验存在
|
||||
validateMoldExists(id);
|
||||
// 删除
|
||||
moldMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateMoldExists(Long id) {
|
||||
if (moldMapper.selectById(id) == null) {
|
||||
throw exception(MOLD_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoldDO getMold(Long id) {
|
||||
return moldMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MoldDO> getMoldPage(MoldPageReqVO pageReqVO) {
|
||||
return moldMapper.selectPage(pageReqVO, pageReqVO.getBrandId());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,168 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldBrandDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldBrandMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link MoldBrandServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Import(MoldBrandServiceImpl.class)
|
||||
public class MoldBrandServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private MoldBrandServiceImpl moldBrandService;
|
||||
|
||||
@Resource
|
||||
private MoldBrandMapper moldBrandMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateMoldBrand_success() {
|
||||
// 准备参数
|
||||
MoldBrandSaveReqVO createReqVO = randomPojo(MoldBrandSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long moldBrandId = moldBrandService.createMoldBrand(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(moldBrandId);
|
||||
// 校验记录的属性是否正确
|
||||
MoldBrandDO moldBrand = moldBrandMapper.selectById(moldBrandId);
|
||||
assertPojoEquals(createReqVO, moldBrand, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMoldBrand_success() {
|
||||
// mock 数据
|
||||
MoldBrandDO dbMoldBrand = randomPojo(MoldBrandDO.class);
|
||||
moldBrandMapper.insert(dbMoldBrand);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
MoldBrandSaveReqVO updateReqVO = randomPojo(MoldBrandSaveReqVO.class, o -> {
|
||||
o.setId(dbMoldBrand.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
moldBrandService.updateMoldBrand(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
MoldBrandDO moldBrand = moldBrandMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, moldBrand);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMoldBrand_notExists() {
|
||||
// 准备参数
|
||||
MoldBrandSaveReqVO updateReqVO = randomPojo(MoldBrandSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> moldBrandService.updateMoldBrand(updateReqVO), MOLD_BRAND_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMoldBrand_success() {
|
||||
// mock 数据
|
||||
MoldBrandDO dbMoldBrand = randomPojo(MoldBrandDO.class);
|
||||
moldBrandMapper.insert(dbMoldBrand);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbMoldBrand.getId();
|
||||
|
||||
// 调用
|
||||
moldBrandService.deleteMoldBrand(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(moldBrandMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMoldBrand_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> moldBrandService.deleteMoldBrand(id), MOLD_BRAND_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetMoldBrandPage() {
|
||||
// mock 数据
|
||||
MoldBrandDO dbMoldBrand = randomPojo(MoldBrandDO.class, o -> { // 等会查询到
|
||||
o.setCode(null);
|
||||
o.setName(null);
|
||||
o.setMoldType(null);
|
||||
o.setProductId(null);
|
||||
o.setUseTime(null);
|
||||
o.setMaintainType(null);
|
||||
o.setMaintainTime(null);
|
||||
o.setMoldSize(null);
|
||||
o.setRemark(null);
|
||||
o.setIsEnable(null);
|
||||
o.setCreateTime(null);
|
||||
});
|
||||
moldBrandMapper.insert(dbMoldBrand);
|
||||
// 测试 code 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setCode(null)));
|
||||
// 测试 name 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setName(null)));
|
||||
// 测试 moldType 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setMoldType(null)));
|
||||
// 测试 productId 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setProductId(null)));
|
||||
// 测试 useTime 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setUseTime(null)));
|
||||
// 测试 maintainType 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setMaintainType(null)));
|
||||
// 测试 maintainTime 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setMaintainTime(null)));
|
||||
// 测试 moldSize 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setMoldSize(null)));
|
||||
// 测试 remark 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setRemark(null)));
|
||||
// 测试 isEnable 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setIsEnable(null)));
|
||||
// 测试 createTime 不匹配
|
||||
moldBrandMapper.insert(cloneIgnoreId(dbMoldBrand, o -> o.setCreateTime(null)));
|
||||
// 准备参数
|
||||
MoldBrandPageReqVO reqVO = new MoldBrandPageReqVO();
|
||||
reqVO.setCode(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setMoldType(null);
|
||||
reqVO.setProductId(null);
|
||||
reqVO.setMaintainType(null);
|
||||
reqVO.setMoldSize(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setIsEnable(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
|
||||
// 调用
|
||||
PageResult<MoldBrandDO> pageResult = moldBrandService.getMoldBrandPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbMoldBrand, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,176 @@
|
||||
package cn.iocoder.yudao.module.erp.service.mold;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.mold.vo.*;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldMapper;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.hutool.core.util.RandomUtil.*;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* {@link MoldServiceImpl} 的单元测试类
|
||||
*
|
||||
* @author 内蒙必硕
|
||||
*/
|
||||
@Import(MoldServiceImpl.class)
|
||||
public class MoldServiceImplTest extends BaseDbUnitTest {
|
||||
|
||||
@Resource
|
||||
private MoldServiceImpl moldService;
|
||||
|
||||
@Resource
|
||||
private MoldMapper moldMapper;
|
||||
|
||||
@Test
|
||||
public void testCreateMold_success() {
|
||||
// 准备参数
|
||||
MoldSaveReqVO createReqVO = randomPojo(MoldSaveReqVO.class).setId(null);
|
||||
|
||||
// 调用
|
||||
Long moldId = moldService.createMold(createReqVO);
|
||||
// 断言
|
||||
assertNotNull(moldId);
|
||||
// 校验记录的属性是否正确
|
||||
MoldDO mold = moldMapper.selectById(moldId);
|
||||
assertPojoEquals(createReqVO, mold, "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMold_success() {
|
||||
// mock 数据
|
||||
MoldDO dbMold = randomPojo(MoldDO.class);
|
||||
moldMapper.insert(dbMold);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
MoldSaveReqVO updateReqVO = randomPojo(MoldSaveReqVO.class, o -> {
|
||||
o.setId(dbMold.getId()); // 设置更新的 ID
|
||||
});
|
||||
|
||||
// 调用
|
||||
moldService.updateMold(updateReqVO);
|
||||
// 校验是否更新正确
|
||||
MoldDO mold = moldMapper.selectById(updateReqVO.getId()); // 获取最新的
|
||||
assertPojoEquals(updateReqVO, mold);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMold_notExists() {
|
||||
// 准备参数
|
||||
MoldSaveReqVO updateReqVO = randomPojo(MoldSaveReqVO.class);
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> moldService.updateMold(updateReqVO), MOLD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMold_success() {
|
||||
// mock 数据
|
||||
MoldDO dbMold = randomPojo(MoldDO.class);
|
||||
moldMapper.insert(dbMold);// @Sql: 先插入出一条存在的数据
|
||||
// 准备参数
|
||||
Long id = dbMold.getId();
|
||||
|
||||
// 调用
|
||||
moldService.deleteMold(id);
|
||||
// 校验数据不存在了
|
||||
assertNull(moldMapper.selectById(id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMold_notExists() {
|
||||
// 准备参数
|
||||
Long id = randomLongId();
|
||||
|
||||
// 调用, 并断言异常
|
||||
assertServiceException(() -> moldService.deleteMold(id), MOLD_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
||||
public void testGetMoldPage() {
|
||||
// mock 数据
|
||||
MoldDO dbMold = randomPojo(MoldDO.class, o -> { // 等会查询到
|
||||
o.setCode(null);
|
||||
o.setName(null);
|
||||
o.setUnitId(null);
|
||||
o.setMachineId(null);
|
||||
o.setUseTime(null);
|
||||
o.setInTime(null);
|
||||
o.setStatus(null);
|
||||
o.setImages(null);
|
||||
o.setRemark(null);
|
||||
o.setIsEnable(null);
|
||||
o.setCreateTime(null);
|
||||
o.setBrandId(null);
|
||||
});
|
||||
moldMapper.insert(dbMold);
|
||||
// 测试 code 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setCode(null)));
|
||||
// 测试 name 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setName(null)));
|
||||
// 测试 unitId 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setUnitId(null)));
|
||||
// 测试 machineId 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setMachineId(null)));
|
||||
// 测试 useTime 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setUseTime(null)));
|
||||
// 测试 inTime 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setInTime(null)));
|
||||
// 测试 status 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setStatus(null)));
|
||||
// 测试 images 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setImages(null)));
|
||||
// 测试 remark 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setRemark(null)));
|
||||
// 测试 isEnable 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setIsEnable(null)));
|
||||
// 测试 createTime 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setCreateTime(null)));
|
||||
// 测试 brandId 不匹配
|
||||
moldMapper.insert(cloneIgnoreId(dbMold, o -> o.setBrandId(null)));
|
||||
// 准备参数
|
||||
MoldPageReqVO reqVO = new MoldPageReqVO();
|
||||
reqVO.setCode(null);
|
||||
reqVO.setName(null);
|
||||
reqVO.setUnitId(null);
|
||||
reqVO.setMachineId(null);
|
||||
|
||||
reqVO.setInTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setImages(null);
|
||||
reqVO.setRemark(null);
|
||||
reqVO.setIsEnable(null);
|
||||
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
|
||||
reqVO.setBrandId(null);
|
||||
|
||||
// 调用
|
||||
PageResult<MoldDO> pageResult = moldService.getMoldPage(reqVO);
|
||||
// 断言
|
||||
assertEquals(1, pageResult.getTotal());
|
||||
assertEquals(1, pageResult.getList().size());
|
||||
assertPojoEquals(dbMold, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
CREATE TABLE
|
||||
IF
|
||||
NOT EXISTS "erp_mold_brand"
|
||||
(
|
||||
"id" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
|
||||
"code" VARCHAR NOT NULL,
|
||||
"name" VARCHAR NOT NULL,
|
||||
"mold_type" VARCHAR NOT NULL,
|
||||
"product_id" BIGINT NOT NULL,
|
||||
"use_time" VARCHAR,
|
||||
"maintain_type" INT,
|
||||
"maintain_time" VARCHAR,
|
||||
"mold_size" BIGINT NOT NULL,
|
||||
"remark" VARCHAR,
|
||||
"is_enable" bit NOT NULL,
|
||||
"creator" VARCHAR DEFAULT '',
|
||||
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updater" VARCHAR DEFAULT '',
|
||||
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" BIGINT,
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '模具型号表';
|
||||
Loading…
Reference in New Issue