|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
+import com.xy.collections.map.JMap;
|
|
|
import com.xy.dto.DeviceQualityDto;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.DeviceQuality;
|
|
@@ -15,7 +16,7 @@ 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.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
@@ -70,22 +71,33 @@ public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, D
|
|
|
|
|
|
@PostMapping("save")
|
|
|
@ApiOperation("添加")
|
|
|
- public R save(@RequestBody @Validated DeviceQualityDto.Save save) {
|
|
|
- DeviceQuality deviceQuality = new DeviceQuality().setDeviceId(save.getDeviceId());
|
|
|
- DeviceInfo deviceInfo = deviceInfoMapper.selectById(deviceQuality.getDeviceId());
|
|
|
- if (deviceInfo == null) {
|
|
|
- return R.fail("设备不存在");
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R save(@RequestBody List<DeviceQualityDto.Vo> vos) {
|
|
|
+ List<DeviceQualityDto.Vo> updates = new ArrayList<>();
|
|
|
+ List<DeviceQuality> saves = new ArrayList<>();
|
|
|
+ List<DeviceInfo> deviceInfos = deviceInfoMapper.selectList(new LambdaQueryWrapper<DeviceInfo>().in(DeviceInfo::getDeviceId, new JArrayList<>(vos).getProperty(DeviceQualityDto.Vo::getDeviceId)));
|
|
|
+ JMap<Long, DeviceInfo> deviceInfoJMap = new JArrayList<>(deviceInfos).toMap(DeviceInfo::getDeviceId).cover();
|
|
|
+ for (DeviceQualityDto.Vo save : vos) {
|
|
|
+ DeviceQuality deviceQuality = new DeviceQuality().setDeviceId(save.getDeviceId());
|
|
|
+ DeviceInfo deviceInfo = deviceInfoJMap.get(deviceQuality.getDeviceId());
|
|
|
+ if (deviceInfo == null) {
|
|
|
+ return R.fail(save.getDeviceId() + "设备不存在");
|
|
|
+ }
|
|
|
+ deviceQuality.setDeviceType(deviceInfo.getDeviceType())
|
|
|
+ .setCreateTime(LocalDateTime.now());
|
|
|
+ List<DeviceQuality> list = list(new LambdaQueryWrapper<DeviceQuality>().eq(DeviceQuality::getDeviceId, deviceQuality.getDeviceId()));
|
|
|
+ if (Emptys.check(list)) {
|
|
|
+ JList<Integer> qualityIds = new JArrayList<>(list).getProperty(DeviceQuality::getQualityId);
|
|
|
+ List<DeviceQualityDto.Vo> vos2 = new ArrayList<>(qualityIds.size());
|
|
|
+ qualityIds.forEach(qualityId -> vos2.add(new DeviceQualityDto.Vo().setQualityId(qualityId).setShowStatus(false)));
|
|
|
+ updates.addAll(vos2);
|
|
|
+ }
|
|
|
+ saves.add(deviceQuality);
|
|
|
}
|
|
|
- deviceQuality.setDeviceType(deviceInfo.getDeviceType())
|
|
|
- .setCreateTime(LocalDateTime.now());
|
|
|
- List<DeviceQuality> list = list(new LambdaQueryWrapper<DeviceQuality>().eq(DeviceQuality::getDeviceId, deviceQuality.getDeviceId()));
|
|
|
- if (Emptys.check(list)) {
|
|
|
- JList<Integer> qualityIds = new JArrayList<>(list).getProperty(DeviceQuality::getQualityId);
|
|
|
- List<DeviceQualityDto.Vo> vos = new ArrayList<>(qualityIds.size());
|
|
|
- qualityIds.forEach(qualityId -> vos.add(new DeviceQualityDto.Vo().setQualityId(qualityId).setShowStatus(false)));
|
|
|
- update(vos);
|
|
|
+ if (Emptys.check(updates)) {
|
|
|
+ update(updates);
|
|
|
}
|
|
|
- save(deviceQuality);
|
|
|
+ saveBatch(saves);
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
@@ -102,16 +114,16 @@ public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, D
|
|
|
|
|
|
@PostMapping("getQrCode")
|
|
|
@ApiOperation("获取二维码")
|
|
|
- public R<String> getQrCode(@RequestBody DeviceQualityDto.Save save) {
|
|
|
- String deviceId = save.getDeviceId().toString();
|
|
|
+ public R<String> getQrCode(@RequestBody DeviceQualityDto.Qrcode qrcode) {
|
|
|
+ String deviceId = qrcode.getDeviceId().toString();
|
|
|
String base64 = QRCodeUtils.create(deviceId, 400, 400, "back1.png", deviceId).base64();
|
|
|
return R.ok(base64);
|
|
|
}
|
|
|
|
|
|
@PostMapping("exportQrCode")
|
|
|
@ApiOperation("导出二维码")
|
|
|
- public void exportQrCode(@RequestBody DeviceQualityDto.Save save) {
|
|
|
- String deviceId = save.getDeviceId().toString();
|
|
|
+ public void exportQrCode(@RequestBody DeviceQualityDto.Qrcode qrcode) {
|
|
|
+ String deviceId = qrcode.getDeviceId().toString();
|
|
|
QRCodeUtils.create(deviceId, 400, 400, "back1.png", deviceId).download(deviceId);
|
|
|
}
|
|
|
|