|
@@ -1,9 +1,30 @@
|
|
|
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.xy.collections.list.JArrayList;
|
|
|
+import com.xy.collections.list.JList;
|
|
|
+import com.xy.dto.DeviceQualityDto;
|
|
|
+import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.DeviceQuality;
|
|
|
+import com.xy.mapper.DeviceInfoMapper;
|
|
|
import com.xy.mapper.DeviceQualityMapper;
|
|
|
+import com.xy.utils.*;
|
|
|
+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.GetMapping;
|
|
|
+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.PlusBeans.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -14,6 +35,72 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2023-01-05
|
|
|
*/
|
|
|
@Service
|
|
|
-public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, DeviceQuality> {
|
|
|
+@AllArgsConstructor
|
|
|
+@Api(tags = "设备-质检")
|
|
|
+public class DeviceQualityServiceImpl extends ServiceImpl<DeviceQualityMapper, DeviceQuality> implements DeviceQualityService {
|
|
|
+
|
|
|
+ private DeviceInfoMapper deviceInfoMapper;
|
|
|
+
|
|
|
+ @PostMapping("page")
|
|
|
+ @ApiOperation("分页查询")
|
|
|
+ public R<PageBean<DeviceQualityDto.Vo>> page(@RequestBody DeviceQualityDto.Page page) {
|
|
|
+ PageBean pageBean = page.getPage();
|
|
|
+ LambdaQueryWrapper<DeviceQuality> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceQuality.class)
|
|
|
+ .ge(DeviceQuality::getUpdateTime, page.getBeginUpdateTime())
|
|
|
+ .le(DeviceQuality::getUpdateTime, page.getEndUpdateTime())
|
|
|
+ .build()
|
|
|
+ .orderByDesc(Emptys.check(pageBean.getOrders()), DeviceQuality::getCreateTime);
|
|
|
+ IPage<DeviceQuality> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
|
|
|
+ return R.ok(toPageBean(DeviceQualityDto.Vo.class, iPage));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("update")
|
|
|
+ @ApiOperation("修改")
|
|
|
+ public R update(@RequestBody List<DeviceQualityDto.Vo> vos) {
|
|
|
+ List<DeviceQuality> deviceQualities = copy(DeviceQuality.class, vos);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ for (DeviceQuality deviceQuality : deviceQualities) {
|
|
|
+ if (deviceQuality.getQualityState() != null || deviceQuality.getFactoryState() != null) {
|
|
|
+ deviceQuality.setQualityAuditUserId(AuthorizeUtils.getLoginId(Long.class));
|
|
|
+ }
|
|
|
+ deviceQuality.setUpdateTime(now);
|
|
|
+ }
|
|
|
+ updateBatchById(deviceQualities);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @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("设备不存在");
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ save(deviceQuality);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("getQrCode")
|
|
|
+ @ApiOperation("获取二维码")
|
|
|
+ public R<String> getQrCode(Long deviceId) {
|
|
|
+ String base64 = QRCodeUtils.create(deviceId.toString(), 200, 200).base64();
|
|
|
+ return R.ok(base64);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("exportQrCode")
|
|
|
+ @ApiOperation("导出二维码")
|
|
|
+ public void exportQrCode(Long deviceId) {
|
|
|
+ QRCodeUtils.create(deviceId.toString(), 200, 200).download(deviceId.toString());
|
|
|
+ }
|
|
|
|
|
|
}
|