Commit 511bc08556703ef7480c3618f17044dd87e207ba
1 parent
7a68b122
feat(mes): 新增假期设置(cal_holiday)功能
从 ktg-mes 迁移 cal_holiday 到 yudao-module-mes,作为 CAL 日历排班模块首个实体。 支持将日期标记为假期(HOLIDAY)或工作日(WORKDAY),创建时自动 upsert(同一天更新而非重复插入)。 新增文件: - MesCalHolidayDO / Mapper / Service / Controller - MesCalHolidaySaveReqVO / RespVO / PageReqVO - mes_cal_holiday.sql(DDL + CAL根菜单5200 + 假期菜单5250~5255 + 字典 + 演示数据) 修改文件: - ErrorCodeConstants:新增 CAL_HOLIDAY_NOT_EXISTS - DictTypeConstants:新增 MES_CAL_HOLIDAY_TYPE
Showing
8 changed files
with
485 additions
and
0 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/holiday/MesCalHolidayController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.cal.holiday; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; | ||
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | ||
| 9 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidayPageReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidayRespVO; | ||
| 11 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidaySaveReqVO; | ||
| 12 | +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; | ||
| 13 | +import cn.iocoder.yudao.module.mes.service.cal.holiday.MesCalHolidayService; | ||
| 14 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 16 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 17 | +import jakarta.annotation.Resource; | ||
| 18 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 19 | +import jakarta.validation.Valid; | ||
| 20 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 21 | +import org.springframework.validation.annotation.Validated; | ||
| 22 | +import org.springframework.web.bind.annotation.*; | ||
| 23 | + | ||
| 24 | +import java.io.IOException; | ||
| 25 | +import java.util.List; | ||
| 26 | + | ||
| 27 | +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; | ||
| 28 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 29 | + | ||
| 30 | +@Tag(name = "管理后台 - MES 假期设置") | ||
| 31 | +@RestController | ||
| 32 | +@RequestMapping("/mes/cal/holiday") | ||
| 33 | +@Validated | ||
| 34 | +public class MesCalHolidayController { | ||
| 35 | + | ||
| 36 | + @Resource | ||
| 37 | + private MesCalHolidayService holidayService; | ||
| 38 | + | ||
| 39 | + // TODO @AI:是不是只有 save,没有 update 和 delete,以及 create? | ||
| 40 | + | ||
| 41 | + @PostMapping("/create") | ||
| 42 | + @Operation(summary = "创建假期设置", description = "如果该日期已存在记录,则更新") | ||
| 43 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:create')") | ||
| 44 | + public CommonResult<Long> createHoliday(@Valid @RequestBody MesCalHolidaySaveReqVO createReqVO) { | ||
| 45 | + return success(holidayService.createHoliday(createReqVO)); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + @PutMapping("/update") | ||
| 49 | + @Operation(summary = "更新假期设置") | ||
| 50 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:update')") | ||
| 51 | + public CommonResult<Boolean> updateHoliday(@Valid @RequestBody MesCalHolidaySaveReqVO updateReqVO) { | ||
| 52 | + holidayService.updateHoliday(updateReqVO); | ||
| 53 | + return success(true); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @DeleteMapping("/delete") | ||
| 57 | + @Operation(summary = "删除假期设置") | ||
| 58 | + @Parameter(name = "id", description = "编号", required = true) | ||
| 59 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:delete')") | ||
| 60 | + public CommonResult<Boolean> deleteHoliday(@RequestParam("id") Long id) { | ||
| 61 | + holidayService.deleteHoliday(id); | ||
| 62 | + return success(true); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @GetMapping("/get") | ||
| 66 | + @Operation(summary = "获得假期设置") | ||
| 67 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 68 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:query')") | ||
| 69 | + public CommonResult<MesCalHolidayRespVO> getHoliday(@RequestParam("id") Long id) { | ||
| 70 | + MesCalHolidayDO holiday = holidayService.getHoliday(id); | ||
| 71 | + return success(BeanUtils.toBean(holiday, MesCalHolidayRespVO.class)); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + // TODO @AI:对齐下,/Users/yunai/Java/ktg-mes 界面(不是后端),是否需要该接口。 | ||
| 75 | + @GetMapping("/page") | ||
| 76 | + @Operation(summary = "获得假期设置分页") | ||
| 77 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:query')") | ||
| 78 | + public CommonResult<PageResult<MesCalHolidayRespVO>> getHolidayPage(@Valid MesCalHolidayPageReqVO pageReqVO) { | ||
| 79 | + PageResult<MesCalHolidayDO> pageResult = holidayService.getHolidayPage(pageReqVO); | ||
| 80 | + return success(BeanUtils.toBean(pageResult, MesCalHolidayRespVO.class)); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @GetMapping("/list") | ||
| 84 | + @Operation(summary = "获得所有假期设置列表", description = "日历组件使用,返回全量数据") | ||
| 85 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:query')") | ||
| 86 | + public CommonResult<List<MesCalHolidayRespVO>> getHolidayList() { | ||
| 87 | + List<MesCalHolidayDO> list = holidayService.getHolidayList(); | ||
| 88 | + return success(BeanUtils.toBean(list, MesCalHolidayRespVO.class)); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + // TODO @AI:对齐下,/Users/yunai/Java/ktg-mes 界面(不是后端),是否需要该接口。 | ||
| 92 | + @GetMapping("/export-excel") | ||
| 93 | + @Operation(summary = "导出假期设置 Excel") | ||
| 94 | + @PreAuthorize("@ss.hasPermission('mes:cal-holiday:export')") | ||
| 95 | + @ApiAccessLog(operateType = EXPORT) | ||
| 96 | + public void exportHolidayExcel(@Valid MesCalHolidayPageReqVO pageReqVO, | ||
| 97 | + HttpServletResponse response) throws IOException { | ||
| 98 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 99 | + List<MesCalHolidayDO> list = holidayService.getHolidayPage(pageReqVO).getList(); | ||
| 100 | + // 导出 Excel | ||
| 101 | + ExcelUtils.write(response, "假期设置.xls", "数据", MesCalHolidayRespVO.class, | ||
| 102 | + BeanUtils.toBean(list, MesCalHolidayRespVO.class)); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/holiday/vo/MesCalHolidayPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | + | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 13 | + | ||
| 14 | +@Schema(description = "管理后台 - MES 假期设置分页 Request VO") | ||
| 15 | +@Data | ||
| 16 | +@EqualsAndHashCode(callSuper = true) | ||
| 17 | +@ToString(callSuper = true) | ||
| 18 | +public class MesCalHolidayPageReqVO extends PageParam { | ||
| 19 | + | ||
| 20 | + @Schema(description = "日期类型", example = "HOLIDAY") | ||
| 21 | + private String type; | ||
| 22 | + | ||
| 23 | + @Schema(description = "日期(起)") | ||
| 24 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 25 | + private LocalDateTime theDayStart; | ||
| 26 | + | ||
| 27 | + @Schema(description = "日期(止)") | ||
| 28 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 29 | + private LocalDateTime theDayEnd; | ||
| 30 | + | ||
| 31 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/holiday/vo/MesCalHolidayRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 5 | +import cn.iocoder.yudao.module.mes.enums.DictTypeConstants; | ||
| 6 | +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; | ||
| 7 | +import cn.idev.excel.annotation.ExcelProperty; | ||
| 8 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 9 | +import lombok.Data; | ||
| 10 | + | ||
| 11 | +import java.time.LocalDateTime; | ||
| 12 | + | ||
| 13 | +@Schema(description = "管理后台 - MES 假期设置 Response VO") | ||
| 14 | +@Data | ||
| 15 | +@ExcelIgnoreUnannotated | ||
| 16 | +public class MesCalHolidayRespVO { | ||
| 17 | + | ||
| 18 | + @Schema(description = "编号") | ||
| 19 | + @ExcelProperty("编号") | ||
| 20 | + private Long id; | ||
| 21 | + | ||
| 22 | + @Schema(description = "日期") | ||
| 23 | + @ExcelProperty("日期") | ||
| 24 | + private LocalDateTime theDay; | ||
| 25 | + | ||
| 26 | + @Schema(description = "日期类型") | ||
| 27 | + @ExcelProperty(value = "日期类型", converter = DictConvert.class) | ||
| 28 | + @DictFormat(DictTypeConstants.MES_CAL_HOLIDAY_TYPE) | ||
| 29 | + private String type; | ||
| 30 | + | ||
| 31 | + @Schema(description = "开始时间") | ||
| 32 | + @ExcelProperty("开始时间") | ||
| 33 | + private LocalDateTime startTime; | ||
| 34 | + | ||
| 35 | + @Schema(description = "结束时间") | ||
| 36 | + @ExcelProperty("结束时间") | ||
| 37 | + private LocalDateTime endTime; | ||
| 38 | + | ||
| 39 | + @Schema(description = "备注") | ||
| 40 | + @ExcelProperty("备注") | ||
| 41 | + private String remark; | ||
| 42 | + | ||
| 43 | + @Schema(description = "创建时间") | ||
| 44 | + @ExcelProperty("创建时间") | ||
| 45 | + private LocalDateTime createTime; | ||
| 46 | + | ||
| 47 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/holiday/vo/MesCalHolidaySaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import jakarta.validation.constraints.NotNull; | ||
| 6 | +import lombok.Data; | ||
| 7 | + | ||
| 8 | +import java.time.LocalDateTime; | ||
| 9 | + | ||
| 10 | +// TODO @AI:ktg 里,支持按照范围添加么?/cal/holiday 界面 | ||
| 11 | +@Schema(description = "管理后台 - MES 假期设置新增/修改 Request VO") | ||
| 12 | +@Data | ||
| 13 | +public class MesCalHolidaySaveReqVO { | ||
| 14 | + | ||
| 15 | + @Schema(description = "编号", example = "1024") | ||
| 16 | + private Long id; | ||
| 17 | + | ||
| 18 | + @Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 19 | + @NotNull(message = "日期不能为空") | ||
| 20 | + private LocalDateTime theDay; | ||
| 21 | + | ||
| 22 | + @Schema(description = "日期类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "HOLIDAY") | ||
| 23 | + @NotEmpty(message = "日期类型不能为空") | ||
| 24 | + private String type; | ||
| 25 | + | ||
| 26 | + @Schema(description = "开始时间") | ||
| 27 | + private LocalDateTime startTime; | ||
| 28 | + | ||
| 29 | + @Schema(description = "结束时间") | ||
| 30 | + private LocalDateTime endTime; | ||
| 31 | + | ||
| 32 | + @Schema(description = "备注") | ||
| 33 | + private String remark; | ||
| 34 | + | ||
| 35 | + @Schema(description = "预留字段1") | ||
| 36 | + private String attribute1; | ||
| 37 | + | ||
| 38 | + @Schema(description = "预留字段2") | ||
| 39 | + private String attribute2; | ||
| 40 | + | ||
| 41 | + @Schema(description = "预留字段3") | ||
| 42 | + private Integer attribute3; | ||
| 43 | + | ||
| 44 | + @Schema(description = "预留字段4") | ||
| 45 | + private Integer attribute4; | ||
| 46 | + | ||
| 47 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/cal/holiday/MesCalHolidayDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 7 | +import lombok.*; | ||
| 8 | + | ||
| 9 | +import java.time.LocalDateTime; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * MES 假期设置 DO | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +@TableName("mes_cal_holiday") | ||
| 17 | +@KeySequence("mes_cal_holiday_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 18 | +@Data | ||
| 19 | +@EqualsAndHashCode(callSuper = true) | ||
| 20 | +@ToString(callSuper = true) | ||
| 21 | +@Builder | ||
| 22 | +@NoArgsConstructor | ||
| 23 | +@AllArgsConstructor | ||
| 24 | +public class MesCalHolidayDO extends BaseDO { | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 编号 | ||
| 28 | + */ | ||
| 29 | + @TableId | ||
| 30 | + private Long id; | ||
| 31 | + /** | ||
| 32 | + * 日期 | ||
| 33 | + */ | ||
| 34 | + private LocalDateTime theDay; | ||
| 35 | + /** | ||
| 36 | + * 日期类型 | ||
| 37 | + * | ||
| 38 | + * 字典 {@link cn.iocoder.yudao.module.mes.enums.DictTypeConstants#MES_CAL_HOLIDAY_TYPE} | ||
| 39 | + */ | ||
| 40 | + private String type; | ||
| 41 | + /** | ||
| 42 | + * 开始时间 | ||
| 43 | + */ | ||
| 44 | + private LocalDateTime startTime; | ||
| 45 | + /** | ||
| 46 | + * 结束时间 | ||
| 47 | + */ | ||
| 48 | + private LocalDateTime endTime; | ||
| 49 | + /** | ||
| 50 | + * 备注 | ||
| 51 | + */ | ||
| 52 | + private String remark; | ||
| 53 | + /** | ||
| 54 | + * 预留字段1 | ||
| 55 | + */ | ||
| 56 | + private String attribute1; | ||
| 57 | + /** | ||
| 58 | + * 预留字段2 | ||
| 59 | + */ | ||
| 60 | + private String attribute2; | ||
| 61 | + /** | ||
| 62 | + * 预留字段3 | ||
| 63 | + */ | ||
| 64 | + private Integer attribute3; | ||
| 65 | + /** | ||
| 66 | + * 预留字段4 | ||
| 67 | + */ | ||
| 68 | + private Integer attribute4; | ||
| 69 | + | ||
| 70 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/holiday/MesCalHolidayMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.dal.mysql.cal.holiday; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 6 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidayPageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; | ||
| 8 | +import org.apache.ibatis.annotations.Mapper; | ||
| 9 | + | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * MES 假期设置 Mapper | ||
| 15 | + * | ||
| 16 | + * @author 芋道源码 | ||
| 17 | + */ | ||
| 18 | +@Mapper | ||
| 19 | +public interface MesCalHolidayMapper extends BaseMapperX<MesCalHolidayDO> { | ||
| 20 | + | ||
| 21 | + default PageResult<MesCalHolidayDO> selectPage(MesCalHolidayPageReqVO reqVO) { | ||
| 22 | + return selectPage(reqVO, new LambdaQueryWrapperX<MesCalHolidayDO>() | ||
| 23 | + .eqIfPresent(MesCalHolidayDO::getType, reqVO.getType()) | ||
| 24 | + .geIfPresent(MesCalHolidayDO::getTheDay, reqVO.getTheDayStart()) | ||
| 25 | + .leIfPresent(MesCalHolidayDO::getTheDay, reqVO.getTheDayEnd()) | ||
| 26 | + .orderByAsc(MesCalHolidayDO::getTheDay)); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + default MesCalHolidayDO selectByTheDay(LocalDateTime theDay) { | ||
| 30 | + return selectOne(MesCalHolidayDO::getTheDay, theDay); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + default List<MesCalHolidayDO> selectList() { | ||
| 34 | + return selectList(new LambdaQueryWrapperX<MesCalHolidayDO>() | ||
| 35 | + .orderByAsc(MesCalHolidayDO::getTheDay)); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/holiday/MesCalHolidayService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.cal.holiday; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidayPageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidaySaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; | ||
| 7 | +import jakarta.validation.Valid; | ||
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * MES 假期设置 Service 接口 | ||
| 13 | + * | ||
| 14 | + * @author 芋道源码 | ||
| 15 | + */ | ||
| 16 | +public interface MesCalHolidayService { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 创建假期设置(含 upsert 逻辑:如果该日期已存在记录,则更新) | ||
| 20 | + * | ||
| 21 | + * @param createReqVO 创建信息 | ||
| 22 | + * @return 编号 | ||
| 23 | + */ | ||
| 24 | + Long createHoliday(@Valid MesCalHolidaySaveReqVO createReqVO); | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 更新假期设置 | ||
| 28 | + * | ||
| 29 | + * @param updateReqVO 更新信息 | ||
| 30 | + */ | ||
| 31 | + void updateHoliday(@Valid MesCalHolidaySaveReqVO updateReqVO); | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 删除假期设置 | ||
| 35 | + * | ||
| 36 | + * @param id 编号 | ||
| 37 | + */ | ||
| 38 | + void deleteHoliday(Long id); | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 获得假期设置 | ||
| 42 | + * | ||
| 43 | + * @param id 编号 | ||
| 44 | + * @return 假期设置 | ||
| 45 | + */ | ||
| 46 | + MesCalHolidayDO getHoliday(Long id); | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 获得假期设置分页 | ||
| 50 | + * | ||
| 51 | + * @param pageReqVO 分页查询 | ||
| 52 | + * @return 假期设置分页 | ||
| 53 | + */ | ||
| 54 | + PageResult<MesCalHolidayDO> getHolidayPage(MesCalHolidayPageReqVO pageReqVO); | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 获得所有假期设置列表(用于日历显示,不分页) | ||
| 58 | + * | ||
| 59 | + * @return 假期设置列表 | ||
| 60 | + */ | ||
| 61 | + List<MesCalHolidayDO> getHolidayList(); | ||
| 62 | + | ||
| 63 | +} |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/holiday/MesCalHolidayServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.cal.holiday; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidayPageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.mes.controller.admin.cal.holiday.vo.MesCalHolidaySaveReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.cal.holiday.MesCalHolidayDO; | ||
| 8 | +import cn.iocoder.yudao.module.mes.dal.mysql.cal.holiday.MesCalHolidayMapper; | ||
| 9 | +import jakarta.annotation.Resource; | ||
| 10 | +import org.springframework.stereotype.Service; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | + | ||
| 13 | +import java.util.List; | ||
| 14 | + | ||
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 16 | +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_HOLIDAY_NOT_EXISTS; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * MES 假期设置 Service 实现类 | ||
| 20 | + * | ||
| 21 | + * @author 芋道源码 | ||
| 22 | + */ | ||
| 23 | +@Service | ||
| 24 | +@Validated | ||
| 25 | +public class MesCalHolidayServiceImpl implements MesCalHolidayService { | ||
| 26 | + | ||
| 27 | + @Resource | ||
| 28 | + private MesCalHolidayMapper holidayMapper; | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public Long createHoliday(MesCalHolidaySaveReqVO createReqVO) { | ||
| 32 | + // Upsert 逻辑:如果该日期已有记录,则更新 | ||
| 33 | + MesCalHolidayDO existing = holidayMapper.selectByTheDay(createReqVO.getTheDay()); | ||
| 34 | + if (existing != null) { | ||
| 35 | + MesCalHolidayDO updateObj = BeanUtils.toBean(createReqVO, MesCalHolidayDO.class); | ||
| 36 | + updateObj.setId(existing.getId()); | ||
| 37 | + holidayMapper.updateById(updateObj); | ||
| 38 | + return existing.getId(); | ||
| 39 | + } | ||
| 40 | + // 插入新记录 | ||
| 41 | + MesCalHolidayDO holiday = BeanUtils.toBean(createReqVO, MesCalHolidayDO.class); | ||
| 42 | + holidayMapper.insert(holiday); | ||
| 43 | + return holiday.getId(); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public void updateHoliday(MesCalHolidaySaveReqVO updateReqVO) { | ||
| 48 | + // 校验存在 | ||
| 49 | + validateHolidayExists(updateReqVO.getId()); | ||
| 50 | + // 更新 | ||
| 51 | + MesCalHolidayDO updateObj = BeanUtils.toBean(updateReqVO, MesCalHolidayDO.class); | ||
| 52 | + holidayMapper.updateById(updateObj); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public void deleteHoliday(Long id) { | ||
| 57 | + // 校验存在 | ||
| 58 | + validateHolidayExists(id); | ||
| 59 | + // 删除 | ||
| 60 | + holidayMapper.deleteById(id); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private void validateHolidayExists(Long id) { | ||
| 64 | + if (holidayMapper.selectById(id) == null) { | ||
| 65 | + throw exception(CAL_HOLIDAY_NOT_EXISTS); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @Override | ||
| 70 | + public MesCalHolidayDO getHoliday(Long id) { | ||
| 71 | + return holidayMapper.selectById(id); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + @Override | ||
| 75 | + public PageResult<MesCalHolidayDO> getHolidayPage(MesCalHolidayPageReqVO pageReqVO) { | ||
| 76 | + return holidayMapper.selectPage(pageReqVO); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public List<MesCalHolidayDO> getHolidayList() { | ||
| 81 | + return holidayMapper.selectList(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | +} |