|
@@ -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;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -46,12 +50,56 @@ public class DeviceChargingConfigServiceImpl extends ServiceImpl<DeviceChargingC
|
|
|
public R<List<DeviceChargingConfigDto.Vo>> list(@RequestBody @Validated DeviceChargingConfigDto.SelectList selectList) {
|
|
|
MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(selectList.getMercId())).getData();
|
|
|
LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceChargingConfig.class)
|
|
|
+ .in(DeviceChargingConfig::getDeviceType, selectList.getDeviceTypes())
|
|
|
.eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
|
|
|
.build();
|
|
|
List<DeviceChargingConfig> list = list(lambdaQueryWrapper);
|
|
|
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) {
|
|
@@ -105,4 +153,4 @@ public class DeviceChargingConfigServiceImpl extends ServiceImpl<DeviceChargingC
|
|
|
List<DeviceChargingConfig> list = list(lambdaQueryWrapper);
|
|
|
return R.ok(Beans.copy(DeviceChargingConfigDto.Vo.class, list));
|
|
|
}
|
|
|
-}
|
|
|
+}
|