# WalkRoomLogoConfigServiceImpl.java

    package cloud.wconnect.frontoffice.service.walkroomrequest.impl;

    import cloud.wconnect.commonlib.util.S3Utils;
    import cloud.wconnect.frontoffice.cons.S3BucketFunctionCons;
    import cloud.wconnect.frontoffice.entity.walkroomrequest.WalkRoomLogoConfig;
    import cloud.wconnect.frontoffice.mapper.walkroomrequest.WalkRoomLogoConfigMapper;
    import cloud.wconnect.frontoffice.pojo.dto.walkroomrequest.WalkRoomLogoConfigDTO;
    import cloud.wconnect.frontoffice.service.walkroomrequest.IWalkRoomLogoConfigService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Service;

    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * walk room打印logo配置表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-07-27
     */
    @Service
    @DS("logbook")
    public class WalkRoomLogoConfigServiceImpl extends ServiceImpl<WalkRoomLogoConfigMapper, WalkRoomLogoConfig> implements IWalkRoomLogoConfigService {

        @Value("${aws-s3.region}")
        private String region;
        @Value("#{${aws-s3.function-bucket}}")
        private Map<String, Map<String, Object>> bucketMap;

        /**
         * 保存打印logo
         *
         * @param propertyId    资产id
         * @param logoConfigDTO logo配置dto
         * @return java.util.Map
         * @author lichen
         * @date 2025/12/30
         */
        @Override
        public Integer save(int propertyId, WalkRoomLogoConfigDTO logoConfigDTO) {
            //根据资产id查询logo配置
            WalkRoomLogoConfig oriWalkRoomLogoConfig = getByPropertyId(propertyId);
            if (Objects.nonNull(oriWalkRoomLogoConfig)) {
                oriWalkRoomLogoConfig.setLogo(logoConfigDTO.getLogo());
                boolean result = updateById(oriWalkRoomLogoConfig);
                if (result) {
                    //根据资产log url获取s3key
                    String delS3Key = S3Utils.getS3KeyByUrl(oriWalkRoomLogoConfig.getLogo());
                    //刪除原来的S3文件
                    S3Utils.deleteFile(region, bucketMap.get(S3BucketFunctionCons.WALK_ROOM_REQUESTS), delS3Key);
                }
                return oriWalkRoomLogoConfig.getId();
            } else {
                WalkRoomLogoConfig walkRoomLogoConfig = new WalkRoomLogoConfig().setPropertyId(propertyId).setLogo(logoConfigDTO.getLogo());
                save(walkRoomLogoConfig);
                return walkRoomLogoConfig.getId();
            }
        }

        /**
         * 根据资产id查询logo配置
         *
         * @param propertyId 资产id
         * @return java.util.Map
         * @author lichen
         * @date 2025/12/30
         */
        @Override
        public WalkRoomLogoConfig getByPropertyId(int propertyId) {
            return getOne(new LambdaQueryWrapper<WalkRoomLogoConfig>()
                    .eq(WalkRoomLogoConfig::getPropertyId, propertyId));
        }
    }