|
@@ -3,21 +3,30 @@ package com.xy.service;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
+import com.alipay.api.domain.Person;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.yitter.idgen.YitIdHelper;
|
|
|
+import com.xy.annotation.LogOperate;
|
|
|
import com.xy.device.EnumDeviceCharging;
|
|
|
import com.xy.device.EnumDeviceChargingConfigType;
|
|
|
import com.xy.dto.DeviceChargingConfigDto;
|
|
|
+import com.xy.dto.DeviceTypeAlgorithmBeforConfigDto;
|
|
|
+import com.xy.dto.MemberFeedBackDto;
|
|
|
import com.xy.dto.be.MercDto;
|
|
|
import com.xy.entity.DeviceChargingConfig;
|
|
|
+import com.xy.entity.DeviceTypeAlgorithmBeforConfig;
|
|
|
+import com.xy.error.CommRuntimeException;
|
|
|
import com.xy.mapper.DeviceChargingConfigMapper;
|
|
|
import com.xy.service.be.MercService;
|
|
|
import com.xy.utils.*;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -26,8 +35,11 @@ import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.xy.utils.Beans.copy;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -58,90 +70,127 @@ 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) {
|
|
|
+ public R<DeviceChargingConfigDto.DeviceManagerFeeConfigVO> listByFeeConfig(@RequestBody @Validated DeviceChargingConfigDto.ListByFeeConfigDTO dto) {
|
|
|
+ DeviceChargingConfigDto.DeviceManagerFeeConfigVO data = new DeviceChargingConfigDto.DeviceManagerFeeConfigVO();
|
|
|
+ List<Integer> deviceTypes = dto.getDeviceTypes();
|
|
|
+ //设备管理费-平台默认配置
|
|
|
+ List<DeviceChargingConfigDto.DeviceManagerFeePlatformVO> dmFeePlatforms = new ArrayList<>();
|
|
|
+ for (Integer type : deviceTypes) {//默认年费,赠送天数
|
|
|
+ DeviceChargingConfigDto.DeviceManagerFeePlatformVO vo = new DeviceChargingConfigDto.DeviceManagerFeePlatformVO();
|
|
|
+ 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);
|
|
|
+ vo.setDefFee(defaultMoney);
|
|
|
+ vo.setDefGiveDay(giveDays);
|
|
|
+ vo.setDeviceType(type);
|
|
|
+ dmFeePlatforms.add(vo);
|
|
|
+ }
|
|
|
MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(dto.getMercId())).getData();
|
|
|
+
|
|
|
+ // 设备管理费-商家自定义费用
|
|
|
+ List<DeviceChargingConfigDto.DeviceManagerFeeMercVO> dmFeeMercs = new ArrayList<>();
|
|
|
LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(dto, DeviceChargingConfig.class)
|
|
|
- .in(DeviceChargingConfig::getDeviceType, dto.getDeviceTypes())
|
|
|
- .eq(DeviceChargingConfig::getType, SysDictUtils.getValue(EnumDeviceChargingConfigType.Code.CODE.getCode(), EnumDeviceChargingConfigType.N_2.getCode(), Integer.class))
|
|
|
+ .in(DeviceChargingConfig::getDeviceType, deviceTypes)
|
|
|
.eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
|
|
|
.build();
|
|
|
//默认配置 type 2预充 1赠送天数
|
|
|
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));
|
|
|
- }
|
|
|
- //赠送天数
|
|
|
- LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper2 = new MybatisPlusQuery().eqWrapper(dto, DeviceChargingConfig.class)
|
|
|
- .in(DeviceChargingConfig::getDeviceType, dto.getDeviceTypes())
|
|
|
- .eq(DeviceChargingConfig::getType, SysDictUtils.getValue(EnumDeviceChargingConfigType.Code.CODE.getCode(), EnumDeviceChargingConfigType.N_1.getCode(), Integer.class))
|
|
|
- .eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
|
|
|
- .build();
|
|
|
- List<DeviceChargingConfig> list2 = list(lambdaQueryWrapper2);
|
|
|
- Map<Integer, DeviceChargingConfig> typeConfigMap2 = MapUtil.newHashMap();
|
|
|
- if (CollUtil.isNotEmpty(list2)) {
|
|
|
- typeConfigMap2 = list2.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) || (CollUtil.isNotEmpty(typeConfigMap2) && typeConfigMap2.get(type) != null)) {
|
|
|
- DeviceChargingConfig deviceChargingConfig = new DeviceChargingConfig();
|
|
|
- //存在自定义配置 预充
|
|
|
- if (CollUtil.isNotEmpty(typeConfigMap) && typeConfigMap.get(type) != null) {
|
|
|
- deviceChargingConfig = typeConfigMap.get(type);
|
|
|
- BeanUtil.copyProperties(deviceChargingConfig, vo);
|
|
|
+ for (DeviceChargingConfig dcc : list) {
|
|
|
+ Integer type = dcc.getType();
|
|
|
+ Integer deviceType = dcc.getDeviceType();
|
|
|
+ //预充
|
|
|
+ if (String.valueOf(type).equals(EnumDeviceChargingConfigType.N_2.getCode())) {
|
|
|
+ int defaultMoney = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), String.valueOf(deviceType), Integer.class);
|
|
|
+ //默认赠送天数
|
|
|
+ int giveDays = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_X.getCode(), Integer.class);
|
|
|
+ DeviceChargingConfigDto.DeviceManagerFeeMercVO vo = new DeviceChargingConfigDto.DeviceManagerFeeMercVO();
|
|
|
+ BeanUtil.copyProperties(dcc, vo);
|
|
|
vo.setDefFee(defaultMoney);
|
|
|
vo.setDefGiveDay(giveDays);
|
|
|
- vo.setFee(deviceChargingConfig.getConfigValue());
|
|
|
- vo.setGiveDay(giveDays);
|
|
|
+ vo.setFee(dcc.getConfigValue());
|
|
|
+ Optional<DeviceChargingConfig> dcObj = list.stream()
|
|
|
+ .filter(dc -> String.valueOf(dc.getType()).equals(EnumDeviceChargingConfigType.N_1.getCode()))
|
|
|
+ .filter(dc -> dc.getDeviceType().intValue() == deviceType.intValue())
|
|
|
+ .findFirst();
|
|
|
+ vo.setGiveDay(dcObj.get().getConfigValue());
|
|
|
+ dmFeeMercs.add(vo);
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //存在自定义配置 赠送天数
|
|
|
- if (CollUtil.isNotEmpty(typeConfigMap2) && typeConfigMap2.get(type) != null) {
|
|
|
- if (deviceChargingConfig != null) {
|
|
|
- DeviceChargingConfig deviceChargingConfig2 = typeConfigMap2.get(type);
|
|
|
- vo.setDefFee(defaultMoney);
|
|
|
- vo.setDefGiveDay(giveDays);
|
|
|
- vo.setGiveDay(deviceChargingConfig2.getConfigValue());
|
|
|
- voList.add(vo);
|
|
|
- } else {
|
|
|
- //未设置预充
|
|
|
- deviceChargingConfig = typeConfigMap2.get(type);
|
|
|
- BeanUtil.copyProperties(deviceChargingConfig, vo);
|
|
|
- vo.setDefFee(defaultMoney);
|
|
|
- vo.setDefGiveDay(giveDays);
|
|
|
- vo.setFee(defaultMoney);
|
|
|
- vo.setGiveDay(deviceChargingConfig.getConfigValue());
|
|
|
- voList.add(vo);
|
|
|
- }
|
|
|
+ data.setDmFeeMercs(dmFeeMercs);
|
|
|
+ data.setDmFeePlatforms(dmFeePlatforms);
|
|
|
+ return R.ok(data);
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ @PostMapping("save")
|
|
|
+ @ApiOperation("添加")
|
|
|
+ public R save(@RequestBody @Validated DeviceChargingConfigDto.Save save) {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
|
+ Integer deviceType = save.getDeviceType();
|
|
|
+ Long mercId = save.getMercId();
|
|
|
+ MercDto.Vo merc = R.feignCheckData(mercService.obj(new MercDto.Vo().setId(mercId)));
|
|
|
+ String mercCode = merc.getMercCode();
|
|
|
+ DeviceChargingConfig dc = this.getOne(Wrappers.<DeviceChargingConfig>lambdaQuery()
|
|
|
+ .eq(DeviceChargingConfig::getMercCode, mercCode)
|
|
|
+ .eq(DeviceChargingConfig::getDeviceType, deviceType)
|
|
|
+ .eq(DeviceChargingConfig::getType, EnumDeviceChargingConfigType.N_2.getCode())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (dc != null) {
|
|
|
+ throw new CommRuntimeException("该类型配置已存在,请勿重复添加!");
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- //不存在,则取字典默认值
|
|
|
- vo.setId(YitIdHelper.nextId());
|
|
|
- vo.setFee(defaultMoney);
|
|
|
- vo.setGiveDay(giveDays);
|
|
|
- vo.setDeviceType(type);
|
|
|
- vo.setMercCode(merc.getMercCode());
|
|
|
- vo.setDefFee(defaultMoney);
|
|
|
- vo.setDefGiveDay(giveDays);
|
|
|
- voList.add(vo);
|
|
|
- }
|
|
|
+ //默认赠送天数
|
|
|
+ int giveDays = SysDictUtils.getValue(EnumDeviceCharging.Code.CODE.getCode(), EnumDeviceCharging.N_X.getCode(), Integer.class);
|
|
|
+ //新增赠送天数
|
|
|
+ DeviceChargingConfig newDc = new DeviceChargingConfig().setDeviceType(deviceType).setConfigValue(giveDays).setMercCode(mercCode)
|
|
|
+ .setType(Integer.valueOf(EnumDeviceChargingConfigType.N_1.getCode())).setCreateTime(now)
|
|
|
+ .setUpdateTime(now).setMercCode(mercCode);
|
|
|
+ save(newDc);
|
|
|
|
|
|
+
|
|
|
+ DeviceChargingConfig saveInfo = copy(DeviceChargingConfig.class, save)
|
|
|
+ .setCreateTime(now)
|
|
|
+ .setUpdateTime(now).setMercCode(mercCode);
|
|
|
+ save(saveInfo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("update")
|
|
|
+ @ApiOperation("修改")
|
|
|
+ public R update(@RequestBody @Validated DeviceChargingConfigDto.Update update) {
|
|
|
+// DeviceChargingConfig dcc = getById(update.getId());
|
|
|
+ DeviceChargingConfig updateInfo = copy(DeviceChargingConfig.class, update)
|
|
|
+ .setUpdateTime(LocalDateTime.now());
|
|
|
+ updateById(updateInfo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("delete")
|
|
|
+ @ApiOperation("删除")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R delete(@RequestBody @Validated DeviceChargingConfigDto.Delete delete) {
|
|
|
+ Long id = delete.getId();
|
|
|
+ DeviceChargingConfig dcc = getById(delete.getId());
|
|
|
+ DeviceChargingConfig one = getOne(Wrappers.<DeviceChargingConfig>lambdaQuery()
|
|
|
+ .eq(DeviceChargingConfig::getMercCode, dcc.getMercCode())
|
|
|
+ .eq(DeviceChargingConfig::getDeviceType, dcc.getDeviceType())
|
|
|
+ .eq(DeviceChargingConfig::getType, Integer.valueOf(EnumDeviceChargingConfigType.N_1.getCode()))
|
|
|
+ );
|
|
|
+ if (one != null) {
|
|
|
+ removeById(one.getId());
|
|
|
}
|
|
|
- return R.ok(voList);
|
|
|
+ removeById(delete.getId());
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@PostMapping("saveOrUpdate")
|
|
|
@ApiOperation("添加或修改")
|
|
|
public R saveOrUpdate(@RequestBody @Validated DeviceChargingConfigDto.SaveOrUpdate saveOrUpdate) {
|