# ScheduleImportEmployeeFilterConfigController.java

    package cloud.wconnect.workperformance.controller.schedule;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.workperformance.entity.schedule.ScheduleImportEmployeeFilterConfig;
    import cloud.wconnect.workperformance.pojo.dto.schedule.ScheduleImportEmployeeFilterConfigDTO;
    import cloud.wconnect.workperformance.pojo.query.schedule.ImportEmployeeFilterConfigQuery;
    import cloud.wconnect.workperformance.service.schedule.IScheduleImportEmployeeFilterConfigService;
    import jakarta.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.Map;

    /**
     * <p>
     * 前端控制器
     * </p>
     *
     * @author yyt
     * @since 2023-07-11
     */
    @RestController
    @RequestMapping("/schedule/import-employee/filter-config")
    public class ScheduleImportEmployeeFilterConfigController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IScheduleImportEmployeeFilterConfigService scheduleImportEmployeeFilterConfigService;

        /**
         * 获取配置列表信息
         *
         * @param property 资产
         * @param query    查询条件
         * @return 过滤列表信息
         * @author yyt
         * @date 2023/7/11
         */
        @ApiId(473)
        @GetMapping
        public ListPagedDTO<ScheduleImportEmployeeFilterConfigDTO> listFilterConfig(String property, @Valid ImportEmployeeFilterConfigQuery query) {
            Integer propertyId = sessionContext.getPropertyId(property);
            return scheduleImportEmployeeFilterConfigService.listDTO(propertyId, query);
        }

        /**
         * 新增、编辑配置
         *
         * @param id              配置 id
         * @param filterConfigDTO 配置信息
         * @return {}
         * @author yyt
         * @date 2023/7/11
         */
        @ApiId(474)
        @PostMapping("/{id:\\d+}")
        public Map<String, Object> saveFilterConfig(@PathVariable int id, String property,
                                    @Valid @RequestBody ScheduleImportEmployeeFilterConfigDTO filterConfigDTO) {
            Integer propertyId = sessionContext.getPropertyId(property);
            int userId = sessionContext.getLoginUserId();
            if (id == 0) {
                scheduleImportEmployeeFilterConfigService.checkExist(propertyId, filterConfigDTO.getPositionId(), null);

                scheduleImportEmployeeFilterConfigService.save(propertyId, filterConfigDTO, userId);
            } else {
                scheduleImportEmployeeFilterConfigService.checkExist(propertyId, filterConfigDTO.getPositionId(), id);

                ScheduleImportEmployeeFilterConfig config = scheduleImportEmployeeFilterConfigService.getById(id);
                checkBelong(config, propertyId);

                scheduleImportEmployeeFilterConfigService.update(id, filterConfigDTO, userId);
            }

            return Collections.emptyMap();
        }

        /**
         * 删除配置
         *
         * @param id       配置 id
         * @param property 资产标识
         * @return {}
         * @author yyt
         * @date 2023/7/11
         */
        @ApiId(475)
        @DeleteMapping("/{id:\\d+}")
        public Map<String, Object> deleteFilterConfig(@PathVariable int id, String property) {
            ScheduleImportEmployeeFilterConfig config = scheduleImportEmployeeFilterConfigService.checkExist(id);

            checkBelong(config, sessionContext.getPropertyId(property));

            scheduleImportEmployeeFilterConfigService.delete(id);

            return Collections.emptyMap();
        }

        /**
         * 校验数据归属
         *
         * @param config          配置信息
         * @param paramPropertyId 资产
         * @author yyt
         * @date 2023/7/11
         */
        private void checkBelong(ScheduleImportEmployeeFilterConfig config, Integer paramPropertyId) {
            if (!config.getPropertyId().equals(paramPropertyId)) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(), "the property id parameter is different from " +
                        "the property id of the scheduleImportEmployeeFilterConfig;propertyId:" + paramPropertyId +
                        ",scheduleImportEmployeeFilterConfigPropertyId:" + config.getPropertyId() +
                        ",scheduleImportEmployeeFilterConfigId:" + config.getId());
            }
        }

    }