# ImportArrivalConfigController.java

    package cloud.wconnect.frontoffice.controller.clc;

    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.frontoffice.entity.clc.ClcArrivalDetailedFilterConfig;
    import cloud.wconnect.frontoffice.pojo.dto.clc.ImportArrivalConfigDTO;
    import cloud.wconnect.frontoffice.pojo.query.clc.ImportArrivalConfigQuery;
    import cloud.wconnect.frontoffice.service.clc.IClcArrivalDetailedFilterConfigService;
    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;

    /**
     * 控制层：Import Arrival Config
     *
     * @author yyt
     * 2023/7/25
     */
    @RestController
    @RequestMapping("/clc/import-arrival/filter-config")
    public class ImportArrivalConfigController {

        @Autowired
        private IClcArrivalDetailedFilterConfigService clcArrivalDetailedFilterConfigService;
        @Autowired
        private SessionContext sessionContext;

        /**
         * 获取导入 arrival 报告配置规则
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return 配置规则
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(497)
        @GetMapping
        public ListPagedDTO<ImportArrivalConfigDTO> list(String property, ImportArrivalConfigQuery query) {
            return clcArrivalDetailedFilterConfigService.listImportArrivalConfigDTO(sessionContext.getPropertyId(property), query);
        }

        /**
         * 新增、编辑配置规则
         *
         * @param id        配置 id
         * @param property  资产标识
         * @param configDTO 配置规则
         * @return {}
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(498)
        @PostMapping("/{id:\\d+}")
        public Map save(@PathVariable int id, String property, @Valid @RequestBody ImportArrivalConfigDTO configDTO) {
            Integer propertyId = sessionContext.getPropertyId(property);
            int userId = sessionContext.getLoginUserId();
            if (id == 0) {
                clcArrivalDetailedFilterConfigService.checkExist(propertyId, configDTO.getCompanyName(), null);

                clcArrivalDetailedFilterConfigService.save(propertyId, configDTO, userId);
            } else {
                ClcArrivalDetailedFilterConfig config = clcArrivalDetailedFilterConfigService.checkExist(id);

                clcArrivalDetailedFilterConfigService.checkExist(propertyId, configDTO.getCompanyName(), id);

                checkBelong(config, propertyId);

                clcArrivalDetailedFilterConfigService.update(id, configDTO, userId);
            }

            return Collections.emptyMap();
        }

        /**
         * 删除配置规则
         *
         * @param id       配置 id
         * @param property 资产标识
         * @return {}
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(499)
        @DeleteMapping("/{id:\\d+}")
        public Map delete(@PathVariable int id, String property) {
            ClcArrivalDetailedFilterConfig config = clcArrivalDetailedFilterConfigService.checkExist(id);

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

            clcArrivalDetailedFilterConfigService.delete(id);

            return Collections.emptyMap();
        }

        /**
         * 校验数据归属
         *
         * @param config     配置规则
         * @param propertyId 资产 id
         * @author yyt
         * @date 2023/7/25
         */
        private void checkBelong(ClcArrivalDetailedFilterConfig config, Integer propertyId) {
            if (!config.getPropertyId().equals(propertyId)) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(), "the property id parameter is different from " +
                        "the property id of the clcArrivalDetailedFilterConfig;propertyId:" + propertyId +
                        ",clcArrivalDetailedFilterConfigPropertyId:" + config.getPropertyId() +
                        ",clcArrivalDetailedFilterConfigId:" + config.getId());
            }
        }

    }