Explorar o código

设备管理费用配置查询

tanbin hai 1 ano
pai
achega
ad0f6d4586

+ 50 - 3
device-api-service/src/main/java/com/xy/service/DeviceChargingConfigServiceImpl.java

@@ -1,16 +1,18 @@
 package com.xy.service;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.yitter.idgen.YitIdHelper;
+import com.xy.device.EnumDeviceCharging;
 import com.xy.dto.DeviceChargingConfigDto;
 import com.xy.dto.be.MercDto;
 import com.xy.entity.DeviceChargingConfig;
 import com.xy.mapper.DeviceChargingConfigMapper;
 import com.xy.service.be.MercService;
-import com.xy.utils.Beans;
-import com.xy.utils.MybatisPlusQuery;
-import com.xy.utils.R;
+import com.xy.utils.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
@@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 
 /**
@@ -53,6 +57,49 @@ public class DeviceChargingConfigServiceImpl extends ServiceImpl<DeviceChargingC
         return R.ok(Beans.copy(DeviceChargingConfigDto.Vo.class, list));
     }
 
+    @PostMapping("listByFeeConfig")
+    @ApiOperation("设备管理费用配置查询")
+    public R<List<DeviceChargingConfigDto.FeeConfigVO>> listByFeeConfig(@RequestBody @Validated DeviceChargingConfigDto.ListByFeeConfigDTO dto) {
+        MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(dto.getMercId())).getData();
+        LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(dto, DeviceChargingConfig.class)
+                .in(DeviceChargingConfig::getDeviceType, dto.getDeviceTypes())
+                .eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
+                .build();
+        //默认配置
+        List<DeviceChargingConfig> list = list(lambdaQueryWrapper);
+        Map<Integer, DeviceChargingConfig> typeConfigMap = MapUtil.newHashMap();
+        if (CollUtil.isNotEmpty(list)) {
+            typeConfigMap = list.stream().collect(Collectors.toMap(DeviceChargingConfig::getDeviceType, c -> c));
+        }
+        List<DeviceChargingConfigDto.FeeConfigVO> voList = new ArrayList<>();
+        List<Integer> deviceTypes = dto.getDeviceTypes();
+        for (Integer type : deviceTypes) {//默认年费,赠送天数
+            DeviceChargingConfigDto.FeeConfigVO vo = new DeviceChargingConfigDto.FeeConfigVO();
+            int defaultMoney = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), String.valueOf(type), Integer.class);
+            //默认赠送天数
+            int giveDays = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_X.getCode(), Integer.class);
+            if (CollUtil.isNotEmpty(typeConfigMap) && typeConfigMap.get(type) != null) {
+                //存在自定义配置
+                DeviceChargingConfig deviceChargingConfig = typeConfigMap.get(type);
+                BeanUtil.copyProperties(deviceChargingConfig, vo);
+                vo.setDefFee(defaultMoney);
+                vo.setDefGiveDay(giveDays);
+                voList.add(vo);
+            } else {
+                //不存在,则取字典默认值
+                vo.setId(YitIdHelper.nextId());
+                vo.setConfigValue(defaultMoney);
+                vo.setDeviceType(type);
+                vo.setMercCode(merc.getMercCode());
+                vo.setDefFee(defaultMoney);
+                vo.setDefGiveDay(giveDays);
+                voList.add(vo);
+            }
+
+        }
+        return R.ok(voList);
+    }
+
     @PostMapping("saveOrUpdate")
     @ApiOperation("添加或修改")
     public R saveOrUpdate(@RequestBody @Validated DeviceChargingConfigDto.SaveOrUpdate saveOrUpdate) {

+ 27 - 0
device-api/src/main/java/com/xy/dto/DeviceChargingConfigDto.java

@@ -35,6 +35,21 @@ public class DeviceChargingConfigDto {
         private List<Integer> deviceTypes;
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class ListByFeeConfigDTO extends Vo {
+
+        @NotNull(message = "mercId不能为空")
+        @ApiModelProperty(value = "商户id", required = true)
+        private Long mercId;
+
+
+        @NotEmpty(message = "设备类型不可为空")
+        @ApiModelProperty(value = "设备类型", required = true)
+        private List<Integer> deviceTypes;
+    }
+
+
     @Data
     @Accessors(chain = true)
     public static class SaveOrUpdate {
@@ -101,4 +116,16 @@ public class DeviceChargingConfigDto {
 
     }
 
+    @Data
+    @Accessors(chain = true)
+    public static class FeeConfigVO extends Vo {
+
+        @ApiModelProperty(value = "默认赠送年费")
+        private Integer defFee;
+        @ApiModelProperty(value = "默认赠送天数")
+        private Integer defGiveDay;
+
+
+    }
+
 }