DeviceChargingConfigServiceImpl.java 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.xy.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.github.yitter.idgen.YitIdHelper;
  5. import com.xy.dto.DeviceChargingConfigDto;
  6. import com.xy.dto.be.MercDto;
  7. import com.xy.entity.DeviceChargingConfig;
  8. import com.xy.mapper.DeviceChargingConfigMapper;
  9. import com.xy.service.be.MercService;
  10. import com.xy.utils.Beans;
  11. import com.xy.utils.MybatisPlusQuery;
  12. import com.xy.utils.R;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.AllArgsConstructor;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.validation.annotation.Validated;
  18. import org.springframework.web.bind.annotation.PostMapping;
  19. import org.springframework.web.bind.annotation.RequestBody;
  20. import java.time.LocalDateTime;
  21. import java.util.List;
  22. /**
  23. * <p>
  24. * 设备计费配置表 服务实现类
  25. * </p>
  26. *
  27. * @author lijin
  28. * @since 2023-07-28
  29. */
  30. @Service
  31. @AllArgsConstructor
  32. @Api(tags = "设备计费配置表")
  33. public class DeviceChargingConfigServiceImpl extends ServiceImpl<DeviceChargingConfigMapper, DeviceChargingConfig> implements DeviceChargingConfigService {
  34. private MercService mercService;
  35. @PostMapping("list")
  36. @ApiOperation("集合查询")
  37. public R<List<DeviceChargingConfigDto.Vo>> list(@RequestBody @Validated DeviceChargingConfigDto.SelectList selectList) {
  38. MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(selectList.getMercId())).getData();
  39. LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(selectList, DeviceChargingConfig.class)
  40. .eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
  41. .build();
  42. List<DeviceChargingConfig> list = list(lambdaQueryWrapper);
  43. return R.ok(Beans.copy(DeviceChargingConfigDto.Vo.class, list));
  44. }
  45. @PostMapping("saveOrUpdate")
  46. @ApiOperation("添加或修改")
  47. public R saveOrUpdate(@RequestBody @Validated DeviceChargingConfigDto.SaveOrUpdate saveOrUpdate) {
  48. LocalDateTime now = LocalDateTime.now();
  49. MercDto.Vo merc = mercService.obj(new MercDto.Vo().setId(saveOrUpdate.getMercId())).getData();
  50. List<DeviceChargingConfigDto.SaveOrUpdate.ConfigValue> values = saveOrUpdate.getConfigValues();
  51. for (DeviceChargingConfigDto.SaveOrUpdate.ConfigValue value : values) {
  52. LambdaQueryWrapper<DeviceChargingConfig> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceChargingConfig>()
  53. .eq(DeviceChargingConfig::getMercCode, merc.getMercCode())
  54. .eq(DeviceChargingConfig::getDeviceType, saveOrUpdate.getDeviceType())
  55. .eq(DeviceChargingConfig::getType, value.getType());
  56. DeviceChargingConfig deviceChargingConfig = getOne(lambdaQueryWrapper);
  57. if (deviceChargingConfig == null) {
  58. if (value.getConfigValue() == -1) {
  59. continue;
  60. }
  61. deviceChargingConfig = new DeviceChargingConfig()
  62. .setId(YitIdHelper.nextId())
  63. .setMercCode(merc.getMercCode())
  64. .setDeviceType(saveOrUpdate.getDeviceType())
  65. .setConfigValue(value.getConfigValue())
  66. .setNote(saveOrUpdate.getNote())
  67. .setType(value.getType())
  68. .setCreateTime(now)
  69. .setUpdateTime(now);
  70. save(deviceChargingConfig);
  71. } else {
  72. if (value.getConfigValue() == -1) {
  73. removeById(deviceChargingConfig.getId());
  74. continue;
  75. }
  76. deviceChargingConfig.setConfigValue(value.getConfigValue())
  77. .setNote(saveOrUpdate.getNote())
  78. .setUpdateTime(now);
  79. updateById(deviceChargingConfig);
  80. }
  81. }
  82. return R.ok();
  83. }
  84. }