diff --git a/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java b/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java index 3cb735ea..0b8f2ffb 100644 --- a/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java +++ b/device/src/main/java/com/njcn/gather/device/device/controller/PqDevController.java @@ -1,4 +1,4 @@ -package com.njcn.gather.machine.device.controller; +package com.njcn.gather.device.device.controller; import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ImportParams; @@ -12,16 +12,17 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.LogUtil; -import com.njcn.gather.machine.device.pojo.param.PqDevParam; -import com.njcn.gather.machine.device.pojo.po.PqDev; -import com.njcn.gather.machine.device.pojo.vo.PqDevExcel; -import com.njcn.gather.machine.device.service.IPqDevService; -import com.njcn.gather.machine.pojo.enums.MachineResponseEnum; +import com.njcn.gather.device.device.pojo.param.PqDevParam; +import com.njcn.gather.device.device.pojo.vo.PqDevExcel; +import com.njcn.gather.device.device.service.IPqDevService; +import com.njcn.gather.device.device.pojo.po.PqDev; +import com.njcn.gather.device.pojo.enums.DeviceResponseEnum; import com.njcn.web.controller.BaseController; import com.njcn.web.utils.HttpResultUtil; import com.njcn.web.utils.PoiUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -126,14 +127,14 @@ public class PqDevController extends BaseController { if (excelImportResult.isVerifyFail()) { // 此处前端要做特殊处理,具体可以参考技术监督的数据导入 PoiUtil.exportFileByWorkbook(excelImportResult.getFailWorkbook(), "非法被检设备数据.xlsx", response); - throw new BusinessException(MachineResponseEnum.IMPORT_DATA_FAIL); + throw new BusinessException(DeviceResponseEnum.IMPORT_DATA_FAIL); } else { //批量录入数据 List sgEventExcels = excelImportResult.getList(); pqDevService.importPqDevData(sgEventExcels); } } catch (Exception e) { - throw new BusinessException(MachineResponseEnum.IMPORT_DATA_FAIL); + throw new BusinessException(DeviceResponseEnum.IMPORT_DATA_FAIL); } return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } @@ -141,8 +142,47 @@ public class PqDevController extends BaseController { @OperateInfo(info = LogEnum.BUSINESS_COMMON) @PostMapping("/export") @ApiOperation("导出被检设备数据") - @ApiImplicitParam(name = "queryParam", value = "查询参数",required = true) + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) public void export(@RequestBody @Validated PqDevParam.PqDevQueryParam queryParam) { pqDevService.exportPqDevData(queryParam); } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/listUnbound") + @ApiOperation("查询出所有未绑定的设备") + public HttpResult> listUnbound() { + String methodDescribe = getMethodDescribe("listUnbound"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, null); + List result = pqDevService.listUnbound(); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @PostMapping("/listBoundByPlanId") + @ApiOperation("根据计划id查询出所有已绑定的设备") + @ApiImplicitParam(name = "planId", value = "计划id", required = true) + public HttpResult> listBoundByPlanId(@RequestParam("planId") String planId) { + String methodDescribe = getMethodDescribe("listBoundByPlanId"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId); + List result = pqDevService.listBoundByPlanId(planId); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE) + @PostMapping("/bindPlan") + @ApiOperation("设备绑定计划") + @ApiImplicitParams({ + @ApiImplicitParam(name = "planId", value = "计划id", required = true), + @ApiImplicitParam(name = "pqDevId", value = "被检设备id", required = true) + }) + public HttpResult bindPlan(@RequestBody PqDevParam.PqDevBindPlanParam bindPlanParam) { + String methodDescribe = getMethodDescribe("bindPlan"); + LogUtil.njcnDebug(log, "{},绑定计划数据为:planId={}, pqDevId={}", methodDescribe, bindPlanParam.getPlanId(), String.join(StrUtil.COMMA, bindPlanParam.getPqDevIds())); + boolean result = pqDevService.bindPlan(bindPlanParam.getPlanId(), bindPlanParam.getPqDevIds()); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } } diff --git a/device/src/main/java/com/njcn/gather/device/device/mapper/PqDevMapper.java b/device/src/main/java/com/njcn/gather/device/device/mapper/PqDevMapper.java index 52bf71d8..e1a6b1a6 100644 --- a/device/src/main/java/com/njcn/gather/device/device/mapper/PqDevMapper.java +++ b/device/src/main/java/com/njcn/gather/device/device/mapper/PqDevMapper.java @@ -1,7 +1,7 @@ -package com.njcn.gather.machine.device.mapper; +package com.njcn.gather.device.device.mapper; import com.github.yulichang.base.MPJBaseMapper; -import com.njcn.gather.machine.device.pojo.po.PqDev; +import com.njcn.gather.device.device.pojo.po.PqDev; /** * @author caozehui diff --git a/device/src/main/java/com/njcn/gather/device/device/mapper/mapping/PqDevMapper.xml b/device/src/main/java/com/njcn/gather/device/device/mapper/mapping/PqDevMapper.xml index 09d4a1f1..ad06399d 100644 --- a/device/src/main/java/com/njcn/gather/device/device/mapper/mapping/PqDevMapper.xml +++ b/device/src/main/java/com/njcn/gather/device/device/mapper/mapping/PqDevMapper.xml @@ -1,6 +1,6 @@ - + diff --git a/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java b/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java index b8b1d9e7..f5589d48 100644 --- a/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java +++ b/device/src/main/java/com/njcn/gather/device/device/pojo/param/PqDevParam.java @@ -1,7 +1,7 @@ -package com.njcn.gather.machine.device.pojo.param; +package com.njcn.gather.device.device.pojo.param; import com.njcn.common.pojo.constant.PatternRegex; -import com.njcn.gather.machine.pojo.constant.MachineValidMessage; +import com.njcn.gather.device.pojo.constant.DeviceValidMessage; import com.njcn.web.pojo.annotation.DateTimeStrValid; import com.njcn.web.pojo.param.BaseParam; import io.swagger.annotations.ApiModelProperty; @@ -11,6 +11,7 @@ import lombok.EqualsAndHashCode; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; +import java.util.List; /** * @author caozehui @@ -20,66 +21,66 @@ import javax.validation.constraints.Pattern; public class PqDevParam { @ApiModelProperty(value = "名称", required = true) - @NotBlank(message = MachineValidMessage.NAME_NOT_BLANK) - @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = MachineValidMessage.NAME_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.NAME_NOT_BLANK) + @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DeviceValidMessage.NAME_FORMAT_ERROR) private String name; @ApiModelProperty(value = "设备模式,字典表(数字、模拟、比对)", required = true) - @NotBlank(message = MachineValidMessage.PATTERN_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.PATTERN_NOT_BLANK) private String pattern; @ApiModelProperty(value = "设备类型,字典表", required = true) - @NotBlank(message = MachineValidMessage.DEV_TYPE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.DEV_TYPE_NOT_BLANK) private String devType; @ApiModelProperty(value = "设备通道数", required = true) - @NotNull(message = MachineValidMessage.DEV_CHNS_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_CHNS_NOT_NULL) private Integer devChns; @ApiModelProperty(value = "额定电压(V)", required = true) - @NotNull(message = MachineValidMessage.DEV_VOLT_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_VOLT_NOT_NULL) private Float devVolt; @ApiModelProperty(value = "额定电流(A)", required = true) - @NotNull(message = MachineValidMessage.DEV_CURR_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_CURR_NOT_NULL) private Float devCurr; @ApiModelProperty(value = "生产厂家,字典表", required = true) - @NotBlank(message = MachineValidMessage.MANUFACTURER_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.MANUFACTURER_NOT_BLANK) private String manufacturer; @ApiModelProperty(value = "生产日期", required = true) - @NotBlank(message = MachineValidMessage.CREATEDATETIME_NOT_NULL) - @DateTimeStrValid(format = "yyyy-MM-dd", message = MachineValidMessage.CREATEDATETIME_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.CREATEDATETIME_NOT_NULL) + @DateTimeStrValid(format = "yyyy-MM-dd", message = DeviceValidMessage.CREATEDATETIME_FORMAT_ERROR) private String createDate; @ApiModelProperty(value = "出厂编号", required = true) - @NotBlank(message = MachineValidMessage.FACTORYNO_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.FACTORYNO_NOT_BLANK) private String createId; @ApiModelProperty(value = "固件版本", required = true) - @NotBlank(message = MachineValidMessage.FIRMWARE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.FIRMWARE_NOT_BLANK) private String hardwareVersion; @ApiModelProperty(value = "软件版本", required = true) - @NotBlank(message = MachineValidMessage.SOFTWARE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.SOFTWARE_NOT_BLANK) private String softwareVersion; @ApiModelProperty(value = "通讯协议", required = true) - @NotBlank(message = MachineValidMessage.PROTOCOL_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.PROTOCOL_NOT_BLANK) private String protocol; @ApiModelProperty(value = "IP地址", required = true) - @NotBlank(message = MachineValidMessage.IP_NOT_BLANK) - @Pattern(regexp = PatternRegex.IP_REGEX, message = MachineValidMessage.IP_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.IP_NOT_BLANK) + @Pattern(regexp = PatternRegex.IP_REGEX, message = DeviceValidMessage.IP_FORMAT_ERROR) private String ip; @ApiModelProperty(value = "端口号", required = true) - @NotNull(message = MachineValidMessage.PORT_NOT_NULL) + @NotNull(message = DeviceValidMessage.PORT_NOT_NULL) private Integer port; @ApiModelProperty(value = "装置是否为加密版本", required = true) - @NotNull(message = MachineValidMessage.ENCRYPTION_NOT_NULL) + @NotNull(message = DeviceValidMessage.ENCRYPTION_NOT_NULL) private Integer encryption; @ApiModelProperty("装置识别码(3ds加密)") @@ -92,7 +93,7 @@ public class PqDevParam { private String sampleId; @ApiModelProperty(value = "送样日期") - @DateTimeStrValid(message = MachineValidMessage.ARRIVE_DATE_TIME_FORMAT_ERROR) + @DateTimeStrValid(message = DeviceValidMessage.ARRIVE_DATE_TIME_FORMAT_ERROR) private String arrivedDate; @ApiModelProperty("所属地市名称") @@ -123,7 +124,7 @@ public class PqDevParam { private String qrCode; @ApiModelProperty(value = "复检次数,默认为0", required = true) - @NotNull(message = MachineValidMessage.RECHECK_NUM_NOT_NULL) + @NotNull(message = DeviceValidMessage.RECHECK_NUM_NOT_NULL) private Integer reCheckNum; @@ -135,8 +136,8 @@ public class PqDevParam { public static class PqDevUpdateParam extends PqDevParam { @ApiModelProperty("id") - @NotBlank(message = MachineValidMessage.ID_NOT_BLANK) - @Pattern(regexp = PatternRegex.SYSTEM_ID, message = MachineValidMessage.ID_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR) private String id; } @@ -148,10 +149,23 @@ public class PqDevParam { @EqualsAndHashCode(callSuper = true) public static class PqDevQueryParam extends BaseParam { @ApiModelProperty("名称") - @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = MachineValidMessage.NAME_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DeviceValidMessage.NAME_FORMAT_ERROR) private String name; @ApiModelProperty("设备类型") private String devType; } + + @Data + public static class PqDevBindPlanParam { + @ApiModelProperty("planId") + @NotNull(message = DeviceValidMessage.PLAN_ID_NOT_NULL) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR) + private String planId; + + @ApiModelProperty("pqDevIds") + @NotNull(message = DeviceValidMessage.PQ_DEV_IDS_NOT_NULL) + private List pqDevIds; + } + } diff --git a/device/src/main/java/com/njcn/gather/device/device/pojo/po/PqDev.java b/device/src/main/java/com/njcn/gather/device/device/pojo/po/PqDev.java index 7738eb28..2f93eb39 100644 --- a/device/src/main/java/com/njcn/gather/device/device/pojo/po/PqDev.java +++ b/device/src/main/java/com/njcn/gather/device/device/pojo/po/PqDev.java @@ -1,4 +1,4 @@ -package com.njcn.gather.machine.device.pojo.po; +package com.njcn.gather.device.device.pojo.po; import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; @@ -191,5 +191,10 @@ public class PqDev extends BaseEntity implements Serializable { * 状态:0-删除 1-正常 */ private Integer state; + + /** + * 检测计划id + */ + private String planId; } diff --git a/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java b/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java index e66c36fa..3445668e 100644 --- a/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java +++ b/device/src/main/java/com/njcn/gather/device/device/pojo/vo/PqDevExcel.java @@ -1,8 +1,8 @@ -package com.njcn.gather.machine.device.pojo.vo; +package com.njcn.gather.device.device.pojo.vo; import cn.afterturn.easypoi.excel.annotation.Excel; import com.njcn.common.pojo.constant.PatternRegex; -import com.njcn.gather.machine.pojo.constant.MachineValidMessage; +import com.njcn.gather.device.pojo.constant.DeviceValidMessage; import lombok.Data; import javax.validation.constraints.NotBlank; @@ -21,66 +21,66 @@ public class PqDevExcel implements Serializable { private static final long serialVersionUID = 1L; @Excel(name = "名称", width = 20) - @NotBlank(message = MachineValidMessage.NAME_NOT_BLANK) - @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = MachineValidMessage.NAME_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.NAME_NOT_BLANK) + @Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DeviceValidMessage.NAME_FORMAT_ERROR) private String name; @Excel(name = "设备模式", width = 20) - @NotBlank(message = MachineValidMessage.PATTERN_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.PATTERN_NOT_BLANK) private String pattern; @Excel(name = "设备类型", width = 20) - @NotBlank(message = MachineValidMessage.DEV_TYPE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.DEV_TYPE_NOT_BLANK) private String devType; @Excel(name = "设备通道数", width = 20) - @NotNull(message = MachineValidMessage.DEV_CHNS_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_CHNS_NOT_NULL) private Integer devChns; @Excel(name = "额定电压(V)", width = 15) - @NotNull(message = MachineValidMessage.DEV_VOLT_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_VOLT_NOT_NULL) private Float devVolt; @Excel(name = "额定电流(A)", width = 15) - @NotNull(message = MachineValidMessage.DEV_CURR_NOT_NULL) + @NotNull(message = DeviceValidMessage.DEV_CURR_NOT_NULL) private Float devCurr; @Excel(name = "生产厂家", width = 20) - @NotBlank(message = MachineValidMessage.MANUFACTURER_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.MANUFACTURER_NOT_BLANK) private String manufacturer; @Excel(name = "生产日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd") - @NotNull(message = MachineValidMessage.CREATEDATETIME_NOT_NULL) - //@DateTimeStrValid(format = "yyyy-MM-dd", message = MachineValidMessage.CREATEDATETIME_FORMAT_ERROR) + @NotNull(message = DeviceValidMessage.CREATEDATETIME_NOT_NULL) + //@DateTimeStrValid(format = "yyyy-MM-dd", message = DeviceValidMessage.CREATEDATETIME_FORMAT_ERROR) private LocalDate createDate; @Excel(name = "出厂编号", width = 40) - @NotBlank(message = MachineValidMessage.FACTORYNO_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.FACTORYNO_NOT_BLANK) private String createId; @Excel(name = "固件版本", width = 15) - @NotBlank(message = MachineValidMessage.FIRMWARE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.FIRMWARE_NOT_BLANK) private String hardwareVersion; @Excel(name = "软件版本", width = 15) - @NotBlank(message = MachineValidMessage.SOFTWARE_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.SOFTWARE_NOT_BLANK) private String softwareVersion; @Excel(name = "通讯协议", width = 15) - @NotBlank(message = MachineValidMessage.PROTOCOL_NOT_BLANK) + @NotBlank(message = DeviceValidMessage.PROTOCOL_NOT_BLANK) private String protocol; @Excel(name = "IP地址", width = 20) - @NotBlank(message = MachineValidMessage.IP_NOT_BLANK) - @Pattern(regexp = PatternRegex.IP_REGEX, message = MachineValidMessage.IP_FORMAT_ERROR) + @NotBlank(message = DeviceValidMessage.IP_NOT_BLANK) + @Pattern(regexp = PatternRegex.IP_REGEX, message = DeviceValidMessage.IP_FORMAT_ERROR) private String ip; @Excel(name = "端口号") - @NotNull(message = MachineValidMessage.PORT_NOT_NULL) + @NotNull(message = DeviceValidMessage.PORT_NOT_NULL) private Integer port; @Excel(name = "是否为加密版本(1:是/0:否)", width = 20) - @NotNull(message = MachineValidMessage.ENCRYPTION_NOT_NULL) + @NotNull(message = DeviceValidMessage.ENCRYPTION_NOT_NULL) private Integer encryption; @Excel(name = "识别码(未加密)", width = 30) @@ -93,7 +93,7 @@ public class PqDevExcel implements Serializable { private String sampleId; @Excel(name = "送样日期(yyyy-MM-dd)", width = 25, format = "yyyy-MM-dd") - //@DateTimeStrValid(format = "yyyy-MM-dd", message = MachineValidMessage.ARRIVEDATETIME_FORMAT_ERROR) + //@DateTimeStrValid(format = "yyyy-MM-dd", message = DeviceValidMessage.ARRIVEDATETIME_FORMAT_ERROR) private LocalDate arrivedDate; @Excel(name = "所属地市名称", width = 20) @@ -124,6 +124,6 @@ public class PqDevExcel implements Serializable { private String qrCode; @Excel(name = "复检次数", width = 15) - @NotNull(message = MachineValidMessage.RECHECK_NUM_NOT_NULL) + @NotNull(message = DeviceValidMessage.RECHECK_NUM_NOT_NULL) private Integer reCheckNum; } diff --git a/device/src/main/java/com/njcn/gather/device/device/service/IPqDevService.java b/device/src/main/java/com/njcn/gather/device/device/service/IPqDevService.java index ac3be5d2..3dbec517 100644 --- a/device/src/main/java/com/njcn/gather/device/device/service/IPqDevService.java +++ b/device/src/main/java/com/njcn/gather/device/device/service/IPqDevService.java @@ -1,10 +1,10 @@ -package com.njcn.gather.machine.device.service; +package com.njcn.gather.device.device.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; -import com.njcn.gather.machine.device.pojo.param.PqDevParam; -import com.njcn.gather.machine.device.pojo.po.PqDev; -import com.njcn.gather.machine.device.pojo.vo.PqDevExcel; +import com.njcn.gather.device.device.pojo.param.PqDevParam; +import com.njcn.gather.device.device.pojo.po.PqDev; +import com.njcn.gather.device.device.pojo.vo.PqDevExcel; import java.util.List; @@ -66,4 +66,27 @@ public interface IPqDevService extends IService { void exportPqDevData(PqDevParam.PqDevQueryParam queryParam); + /** + * 获取所有未绑定的设备 + * + * @return 未绑定的设备列表 + */ + List listUnbound(); + + /** + * 根据计划id获取绑定的设备 + * + * @param planId 计划id + * @return 绑定的设备列表 + */ + List listBoundByPlanId(String planId); + + /** + * 绑定计划 + * + * @param planId 计划id + * @param pqDevIds 被检设备id列表 + * @return 绑定成功返回true,否则返回false + */ + boolean bindPlan(String planId, List pqDevIds); } diff --git a/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java b/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java index 3cd7ce78..01cea035 100644 --- a/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java +++ b/device/src/main/java/com/njcn/gather/device/device/service/impl/PqDevServiceImpl.java @@ -1,29 +1,32 @@ -package com.njcn.gather.machine.device.service.impl; +package com.njcn.gather.device.device.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.db.mybatisplus.constant.DbConstant; -import com.njcn.gather.machine.device.mapper.PqDevMapper; -import com.njcn.gather.machine.device.pojo.param.PqDevParam; -import com.njcn.gather.machine.device.pojo.po.PqDev; -import com.njcn.gather.machine.device.pojo.vo.PqDevExcel; -import com.njcn.gather.machine.device.service.IPqDevService; -import com.njcn.gather.machine.device.util.DeviceUtil; +import com.njcn.gather.device.device.pojo.param.PqDevParam; +import com.njcn.gather.device.device.pojo.vo.PqDevExcel; +import com.njcn.gather.device.device.service.IPqDevService; +import com.njcn.gather.device.device.mapper.PqDevMapper; +import com.njcn.gather.device.device.pojo.po.PqDev; +import com.njcn.gather.device.device.util.DeviceUtil; import com.njcn.web.factory.PageFactory; import com.njcn.web.utils.ExcelUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * @author caozehui @@ -130,4 +133,43 @@ public class PqDevServiceImpl extends ServiceImpl implements List pqDevExcels = BeanUtil.copyToList(pqDevs, PqDevExcel.class); ExcelUtil.exportExcel("被检设备导出数据.xlsx", "被检设备", PqDevExcel.class, pqDevExcels); } + + @Override + public List listUnbound() { + return this.lambdaQuery() + .eq(PqDev::getState, DataStateEnum.ENABLE.getCode()) + .isNull(PqDev::getPlanId) + .list(); + } + + @Override + public List listBoundByPlanId(String planId) { + return this.lambdaQuery() + .eq(PqDev::getState, DataStateEnum.ENABLE.getCode()) + .eq(PqDev::getPlanId, planId) + .list(); + } + + @Override + public boolean bindPlan(String planId, List pqDevIds) { + List existedBoundPqDevIds = this.listBoundByPlanId(planId) + .stream().map(PqDev::getId).collect(Collectors.toList()); + + //共有的(交集) + List intersection = existedBoundPqDevIds.stream().filter(pqDevIds::contains).collect(Collectors.toList()); + + //移除 已有的历史绑定而此次不绑定的 + existedBoundPqDevIds.removeAll(intersection); + boolean result1 = this.lambdaUpdate().set(PqDev::getPlanId, null) + .in(PqDev::getId, existedBoundPqDevIds) + .update(); + + //绑定 没有的历史绑定而此次绑定的 + pqDevIds.removeAll(existedBoundPqDevIds); + boolean result2 = this.lambdaUpdate().set(PqDev::getPlanId, planId) + .in(PqDev::getId, pqDevIds) + .update(); + + return result1 && result2; + } } diff --git a/device/src/main/java/com/njcn/gather/device/device/util/DeviceUtil.java b/device/src/main/java/com/njcn/gather/device/device/util/DeviceUtil.java index e7401a8e..bd438fe0 100644 --- a/device/src/main/java/com/njcn/gather/device/device/util/DeviceUtil.java +++ b/device/src/main/java/com/njcn/gather/device/device/util/DeviceUtil.java @@ -1,4 +1,4 @@ -package com.njcn.gather.machine.device.util; +package com.njcn.gather.device.device.util; import com.njcn.common.utils.sm.ThreeDesUtil; import org.apache.commons.codec.binary.Base64; diff --git a/device/src/main/java/com/njcn/gather/device/pojo/constant/MachineValidMessage.java b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java similarity index 88% rename from device/src/main/java/com/njcn/gather/device/pojo/constant/MachineValidMessage.java rename to device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java index 412ba257..344d3fae 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/constant/MachineValidMessage.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java @@ -1,10 +1,10 @@ -package com.njcn.gather.machine.pojo.constant; +package com.njcn.gather.device.pojo.constant; /** * @author caozehui * @date 2024/11/06 */ -public interface MachineValidMessage { +public interface DeviceValidMessage { String ID_NOT_BLANK = "id不能为空,请检查id参数"; @@ -48,5 +48,9 @@ public interface MachineValidMessage { String RECHECK_NUM_NOT_NULL = "复检次数不能为空,请检查reCheckNum参数"; + String PLAN_ID_NOT_NULL="检测计划ID不能为空,请检查planId参数"; + + String PQ_DEV_IDS_NOT_NULL="设备ID集合不能为null,请检查pqDevIds参数"; + String ARRIVE_DATE_TIME_FORMAT_ERROR = "送样日期格式错误,请检查arrivedDateTime参数"; } diff --git a/device/src/main/java/com/njcn/gather/device/pojo/enums/MachineResponseEnum.java b/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java similarity index 66% rename from device/src/main/java/com/njcn/gather/device/pojo/enums/MachineResponseEnum.java rename to device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java index be07e6ff..524387c1 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/enums/MachineResponseEnum.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/enums/DeviceResponseEnum.java @@ -1,9 +1,9 @@ -package com.njcn.gather.machine.pojo.enums; +package com.njcn.gather.device.pojo.enums; import lombok.Getter; @Getter -public enum MachineResponseEnum { +public enum DeviceResponseEnum { //NAME_REPEAT("A001001", "名称重复"), IMPORT_DATA_FAIL("A001002", "导入数据失败"); @@ -12,7 +12,7 @@ public enum MachineResponseEnum { private final String message; - MachineResponseEnum(String code, String message) { + DeviceResponseEnum(String code, String message) { this.code = code; this.message = message; }