# SpecialEventController.java

    package cloud.wconnect.workperformance.controller.sva;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.group.Addition;
    import cloud.wconnect.commonlib.pojo.dto.group.Edition;
    import cloud.wconnect.workperformance.entity.sva.setting.SpecialEvent;
    import cloud.wconnect.workperformance.pojo.dto.sva.specialevent.SpecialEventDTO;
    import cloud.wconnect.workperformance.pojo.query.sva.specialevent.SpecialEventQuery;
    import cloud.wconnect.workperformance.service.sva.setting.ISpecialEventService;
    import com.google.common.collect.ImmutableMap;
    import jakarta.annotation.Resource;
    import jakarta.validation.Valid;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.List;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * 控制器类：特殊事件
     * </p>
     *
     * @author zc
     * @since 2023-03-14
     */
    @RestController
    @RequestMapping("/sva/setting/special/event")
    public class SpecialEventController {
        @Resource
        private ISpecialEventService specialEventService;
        @Resource
        private SessionContext sessionContext;

        /**
         * 新增 Special Event
         *
         * @param property        资产标识
         * @param specialEventDTO Special Event 数据
         * @return Special Event id
         * @author zc
         * @date 2023/3/14
         */
        @ApiId(97)
        @PostMapping
        public Map<Object, Object> insert(@RequestParam String property, @RequestBody @Validated(Addition.class) SpecialEventDTO specialEventDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            return ImmutableMap.of("id", specialEventService.insert(propertyId, sessionContext.getLoginUserId(), specialEventDTO));
        }

        /**
         * 编辑 Special Event
         *
         * @param property        资产标识
         * @param specialEventDTO Special Event 数据
         * @return empty map
         * @author zc
         * @date 2023/3/14
         */
        @ApiId(98)
        @PutMapping
        public Map<Object, Object> update(@RequestParam String property, @RequestBody @Validated(Edition.class) SpecialEventDTO specialEventDTO) {
            SpecialEvent specialEvent = specialEventService.getById(specialEventDTO.getId());
            if (Objects.isNull(specialEvent)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The special event to be update is not found; specialEventId: " + specialEventDTO.getId());
            }
            int propertyId = sessionContext.getPropertyId(property);
            // 校验数据归属
            specialEventService.checkBelong(propertyId, specialEvent);

            specialEventService.update(sessionContext.getLoginUserId(), specialEventDTO);
            return Collections.emptyMap();
        }

        /**
         * 删除 Special Event
         *
         * @param property 资产标识
         * @param id       Special Event id
         * @return empty map
         * @author zc
         * @date 2023/3/14
         */
        @ApiId(96)
        @DeleteMapping("/{id:\\d+}")
        public Map<Object, Object> remove(@RequestParam String property, @PathVariable int id) {
            SpecialEvent specialEvent = specialEventService.getById(id);
            if (Objects.isNull(specialEvent)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The special event to be remove is not found; specialEventId: " + id);
            }
            int propertyId = sessionContext.getPropertyId(property);
            // 校验数据归属
            specialEventService.checkBelong(propertyId, specialEvent);

            specialEventService.removeById(id);
            return Collections.emptyMap();
        }

        /**
         * 获取指定日期范围内的 Special Event 集合
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return Special Event 集合
         * @author zc
         * @date 2023/3/14
         */
        @ApiId(99)
        @GetMapping("/list")
        public List<SpecialEventDTO> list(@RequestParam String property, @Valid SpecialEventQuery query) {
            int propertyId = sessionContext.getPropertyId(property);
            return specialEventService.list(propertyId, query);
        }
    }