|
@@ -0,0 +1,120 @@
|
|
|
+package com.xy.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.yitter.idgen.YitIdHelper;
|
|
|
+import com.xy.collections.list.JArrayList;
|
|
|
+import com.xy.collections.map.JMap;
|
|
|
+import com.xy.dto.DeviceParamsConfigDto;
|
|
|
+import com.xy.dto.be.MercDto;
|
|
|
+import com.xy.entity.DeviceInfo;
|
|
|
+import com.xy.entity.DeviceParamsConfig;
|
|
|
+import com.xy.mapper.DeviceParamsConfigMapper;
|
|
|
+import com.xy.service.be.MercService;
|
|
|
+import com.xy.utils.Emptys;
|
|
|
+import com.xy.utils.MybatisPlusQuery;
|
|
|
+import com.xy.utils.PageBean;
|
|
|
+import com.xy.utils.R;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.xy.utils.Beans.copy;
|
|
|
+import static com.xy.utils.PlusBeans.toIPage;
|
|
|
+import static com.xy.utils.PlusBeans.toPageBean;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 机器默认参数表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author lijin
|
|
|
+ * @since 2025-06-30
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+@Api(tags = "机器默认参数表")
|
|
|
+public class DeviceParamsConfigServiceImpl extends ServiceImpl<DeviceParamsConfigMapper, DeviceParamsConfig> implements DeviceParamsConfigService {
|
|
|
+
|
|
|
+ private DeviceInfoServiceImpl deviceInfoService;
|
|
|
+
|
|
|
+ private MercService mercService;
|
|
|
+
|
|
|
+ @PostMapping("query")
|
|
|
+ @ApiOperation("查询默认参数")
|
|
|
+ public R<List<DeviceParamsConfigDto.Vo>> query(@RequestBody @Validated DeviceParamsConfigDto.Query query) {
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getById(query.getDeviceId());
|
|
|
+ // 查询设备参数
|
|
|
+ List<DeviceParamsConfig> deviceParamsConfigs1 = list(new LambdaQueryWrapper<DeviceParamsConfig>().eq(DeviceParamsConfig::getDeviceId, deviceInfo.getDeviceId()));
|
|
|
+ JMap<String, DeviceParamsConfig> cover = new JArrayList<>(deviceParamsConfigs1).toMap(DeviceParamsConfig::getCode).cover();
|
|
|
+ // 查询商家参数
|
|
|
+ List<DeviceParamsConfig> deviceParamsConfigs2 = list(new LambdaQueryWrapper<DeviceParamsConfig>().eq(DeviceParamsConfig::getMercId, deviceInfo.getMercId()));
|
|
|
+ for (DeviceParamsConfig deviceParamsConfig : deviceParamsConfigs2) {
|
|
|
+ if (cover.containsKey(deviceParamsConfig.getCode())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ cover.put(deviceParamsConfig.getCode(), deviceParamsConfig);
|
|
|
+ }
|
|
|
+ List<DeviceParamsConfigDto.Vo> vos = copy(DeviceParamsConfigDto.Vo.class, cover.getValues());
|
|
|
+ return R.ok(vos);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("page")
|
|
|
+ @ApiOperation("分页查询")
|
|
|
+ public R<PageBean<DeviceParamsConfigDto.Page.Vo>> page(@RequestBody DeviceParamsConfigDto.Page page) {
|
|
|
+ LambdaQueryWrapper<DeviceParamsConfig> lambdaQueryWrapper = new MybatisPlusQuery()
|
|
|
+ .eqWrapper(page, DeviceParamsConfig.class)
|
|
|
+ .build()
|
|
|
+ .orderByDesc(DeviceParamsConfig::getCreateTime);
|
|
|
+ IPage<DeviceParamsConfig> iPage = page(toIPage(page.getPage()), lambdaQueryWrapper);
|
|
|
+ PageBean<DeviceParamsConfigDto.Page.Vo> pageBean = toPageBean(DeviceParamsConfigDto.Page.Vo.class, iPage);
|
|
|
+ List<DeviceParamsConfigDto.Page.Vo> records = pageBean.getRecords();
|
|
|
+ if (Emptys.check(records)) {
|
|
|
+ List<Long> mercIds = new ArrayList<>();
|
|
|
+ for (DeviceParamsConfigDto.Page.Vo record : records) {
|
|
|
+ if (Emptys.check(record.getMercId()) && !mercIds.contains(record.getMercId())) {
|
|
|
+ mercIds.add(record.getMercId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Emptys.check(mercIds)) {
|
|
|
+ List<MercDto.Vo> mercs = mercService.list(new MercDto.SelectList()
|
|
|
+ .setMercIds(mercIds)
|
|
|
+ ).getData();
|
|
|
+ JMap<Long, MercDto.Vo> cover = new JArrayList<>(mercs).toMap(MercDto.Vo::getId).cover();
|
|
|
+ for (DeviceParamsConfigDto.Page.Vo record : records) {
|
|
|
+ if (Emptys.check(record.getMercId())) {
|
|
|
+ MercDto.Vo merc = cover.get(record.getMercId());
|
|
|
+ record.setMercName(merc.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.ok(pageBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("save")
|
|
|
+ @ApiOperation("保存")
|
|
|
+ public R save(@RequestBody @Validated DeviceParamsConfigDto.Save save) {
|
|
|
+ if ((!Emptys.check(save.getMercId()) && !Emptys.check(save.getDeviceId())) || Emptys.check(save.getMercId()) && Emptys.check(save.getDeviceId())) {
|
|
|
+ throw new RuntimeException("mercId和deviceId二选一");
|
|
|
+ }
|
|
|
+ DeviceParamsConfig deviceParamsConfig = getOne(new LambdaQueryWrapper<DeviceParamsConfig>().eq(Emptys.check(save.getMercId()), DeviceParamsConfig::getMercId, save.getMercId()).eq(Emptys.check(save.getDeviceId()), DeviceParamsConfig::getDeviceId, save.getDeviceId()).eq(DeviceParamsConfig::getCode, save.getCode()));
|
|
|
+ if (deviceParamsConfig == null) {
|
|
|
+ deviceParamsConfig = new DeviceParamsConfig().setId(YitIdHelper.nextId()).setCreateTime(LocalDateTime.now());
|
|
|
+ }
|
|
|
+ DeviceParamsConfig info = copy(deviceParamsConfig, save);
|
|
|
+ saveOrUpdate(info);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|