# WalkRoomAddressConfigController.java

    package cloud.wconnect.frontoffice.controller.walkroomrequest;

    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.frontoffice.entity.walkroomrequest.WalkRoomAddressConfig;
    import cloud.wconnect.frontoffice.entity.walkroomrequest.WalkRoomRequest;
    import cloud.wconnect.frontoffice.pojo.dto.walkroomrequest.WalkRoomAddressConfigDTO;
    import cloud.wconnect.frontoffice.service.walkroomrequest.IWalkRoomAddressConfigService;
    import cloud.wconnect.frontoffice.service.walkroomrequest.IWalkRoomRequestService;
    import com.google.common.collect.ImmutableMap;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import jakarta.validation.Valid;
    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * Walk Room Requests 功能的资产地址配置 前端控制器
     * </p>
     *
     * @author lichen
     * @date 2023/8/4
     */
    @RestController
    @RequestMapping("/walk-room-request/address-config")
    public class WalkRoomAddressConfigController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IWalkRoomAddressConfigService walkRoomAddressConfigService;
        @Autowired
        private IWalkRoomRequestService walkRoomRequestService;

        /**
         * 保存资产的地址
         *
         * @param property                 资产标识
         * @param walkRoomAddressConfigDTO 地址dto
         * @return java.util.Map
         * @author lichen
         * @date 2023/8/4
         */
        @ApiId(511)
        @PostMapping
        public Map save(String property, @Valid @RequestBody WalkRoomAddressConfigDTO walkRoomAddressConfigDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            walkRoomAddressConfigService.saveOrUpdateByUnique(propertyId, walkRoomAddressConfigDTO.getAddress());
            return Collections.emptyMap();
        }

        /**
         * 查询资产地址
         *
         * @param property 资产标识
         * @param id       walk room主键id
         * @return java.util.Map<java.lang.String, java.lang.String>
         * @author lichen
         * @date 2023/8/4
         */
        @ApiId(512)
        @GetMapping
        public Map<String, String> get(String property, @RequestParam(required = false) Long id) {
            Integer propertyId;
            if (Objects.isNull(id)) {
                //id为空时，查询当前资产的地址
                propertyId = sessionContext.getPropertyId(property);
            } else {
                //id不为空时，查询walk room数据的toPropertyId的地址
                WalkRoomRequest walkRoomRequest = walkRoomRequestService.getById(id);
                if (Objects.isNull(walkRoomRequest)) {
                    throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                            BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "Walk Room Requests not found");
                }
                propertyId = walkRoomRequest.getToPropertyId();
            }
            //查询资产配置的地址
            WalkRoomAddressConfig addressConfig = walkRoomAddressConfigService.getByPropertyId(propertyId);
            String address = Objects.nonNull(addressConfig) ? addressConfig.getAddress() : "";
            return ImmutableMap.of("address", address);
        }

    }