提交 66917ec9 authored 作者: zhoushaopan's avatar zhoushaopan

fix(盘存自查模块): 新增接口,盘存

新增接口,盘存
上级 69a908b9
...@@ -373,7 +373,9 @@ public enum LogType { ...@@ -373,7 +373,9 @@ public enum LogType {
//[业务操作日志]存储失败:找不到业务类型为+4,旧状态为400,新状态为8888的日志模板 //[业务操作日志]存储失败:找不到业务类型为+4,旧状态为400,新状态为8888的日志模板
SELF_CHECK_8(170,SELF_CHECK.id,WAIT_SELF_CHECK.id,ARCHIVE.id,"核查结束,系统发起的自查自动结束"), SELF_CHECK_8(170,SELF_CHECK.id,WAIT_SELF_CHECK.id,ARCHIVE.id,"核查结束,系统发起的自查自动结束"),
REPAIR_BACK_21(171,REPAIR.id, ORIGIN_STATUS.id, REPAIR_SEND_UNDER_DRAFT.id, "省直属等待出库"), REPAIR_BACK_21(171,REPAIR.id, ORIGIN_STATUS.id, REPAIR_SEND_UNDER_DRAFT.id, "省直属等待出库"),
ALLOT_BACK_21(172,ALLOT_BACK.id,ORIGIN_STATUS.id,BACK_UNDER_DRAFT.id,"省直属等待出库"); ALLOT_BACK_21(172,ALLOT_BACK.id,ORIGIN_STATUS.id,BACK_UNDER_DRAFT.id,"省直属等待出库"),
READ_SELF(173,READMACHINE_SELFCHECK.id,ORIGIN_STATUS.id,READ_SELF_CHECK.id,"开始进行盘点自查"),
READ_SELF_END(174,READMACHINE_SELFCHECK.id,ORIGIN_STATUS.id,READ_SELF_CHECK_END.id,"盘点自查结束");
public Integer id; public Integer id;
......
...@@ -287,6 +287,10 @@ public class DeviceLibrary implements Serializable { ...@@ -287,6 +287,10 @@ public class DeviceLibrary implements Serializable {
@Transient @Transient
private Integer isInLibrary; private Integer isInLibrary;
@Transient
@ApiModelProperty(value = "状态",notes = "1 读取到 0 未读取到")
private Integer status;
// @Transient // @Transient
// private DeviceLibraryPosition deviceLibraryPosition; // private DeviceLibraryPosition deviceLibraryPosition;
......
...@@ -121,7 +121,9 @@ public enum BusinessEnum { ...@@ -121,7 +121,9 @@ public enum BusinessEnum {
SUSPENSION(29,"中止业务"), SUSPENSION(29,"中止业务"),
READMACHINE(30,"盘存"), READMACHINE(30,"盘存盘点"),
READMACHINE_SELFCHECK(31,"盘存自查"),
; ;
public Integer id; public Integer id;
......
...@@ -324,6 +324,12 @@ public enum StatusEnum { ...@@ -324,6 +324,12 @@ public enum StatusEnum {
*/ */
READ_DEAFT(3000, "保存盘存草稿"), READ_DEAFT(3000, "保存盘存草稿"),
READ_End(3001, "结束盘存任务"), READ_End(3001, "结束盘存任务"),
/**
* 盘存自查状态
*/
READ_SELF_CHECK(3002,"开始进行盘点自查"),
READ_SELF_CHECK_END(3003,"盘点自查结束")
; ;
......
package com.tykj.dev.readmachine.devreadmachine.Entity;
import com.fasterxml.jackson.core.type.TypeReference;
import com.tykj.dev.device.user.cache.UserCache;
import com.tykj.dev.misc.utils.JacksonUtil;
import com.tykj.dev.misc.utils.SpringUtils;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackJsonVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.DeviceVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.beans.BeanUtils;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.swing.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author zsp
* @create 2022/1/18 10:16
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@ApiModel("载体自查实体")
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update warehouse_inspection set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
public class WarehouseInspectionBill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(value = "主键id")
private Integer id;
@Column(name = "title",columnDefinition = "TEXT")
@ApiModelProperty(value = "自查名称")
private String title;
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "库房数量")
private Integer checkedCount;
@ApiModelProperty(value = "实查数量")
private Integer checkingCount;
@ApiModelProperty(value = "创建人的id")
private Integer createUserId;
@Column(name = "check_detail",columnDefinition = "TEXT")
@ApiModelProperty(value = "自查详情")
private String checkResult;
@Column(name = "un_check_detail",columnDefinition = "TEXT")
@ApiModelProperty(value = "自查详情")
private String unCheckResult;
@ApiModelProperty(value = "逻辑删除",notes = "0 未删除 1 已删除")
private Integer deleteTag = 0;
@ApiModelProperty(value = "创建人的名称")
@Transient
private String createUserName;
public WarehouseInspectionBill setConfig(){
UserCache initUserCache = SpringUtils.getBean("initUserCache");
assert initUserCache != null;
setCreateUserName(initUserCache.findById(this.createUserId).getName());
return this;
}
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2022/1/14 17:00
*/
@Data
@ApiModel("读写机自查的vo")
public class ReadMachineSelefVo {
@ApiModelProperty(value = "装备的集合")
private List<DeviceLibrary> deviceLibraries;
@ApiModelProperty(value = "数量")
private Integer size;
}
package com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2022/1/19 9:51
*/
@Data
@ApiModel("装备转换vo")
public class BackJsonVo {
@ApiModelProperty(value = "读取到的详情")
private List<DeviceLibrary> inDeviceLibraryList;
@ApiModelProperty(value = "未读取到的详情")
private List<DeviceLibrary> outDeviceLibraryList;
}
package com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2022/1/18 10:58
*/
@Data
@ApiModel("保存盘点自查vo")
public class BackSelfCheckVo {
@ApiModelProperty(value = "盘点自查的对象")
private WarehouseInspectionBill warehouseInspectionBill;
@ApiModelProperty(value = "装备转换的vo")
private BackJsonVo backJsonVo;
}
package com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author zsp
* @create 2022/1/18 13:01
*/
@Data
@ApiModel("查询装备的vo")
public class DeviceVo {
@ApiModelProperty(value = "装备状态为读取到的集合")
private List<Map<Integer,Integer>> inDevices;
@ApiModelProperty(value = "装备状态为未读取到的集合")
private List<Map<Integer,Integer>> outDevices;
}
package com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.misc.utils.JacksonUtil;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.Map;
/**
* @author zsp
* @create 2022/1/18 10:58
*/
@Data
@ApiModel("保存盘点自查vo")
public class SaveSelfCheckVo {
@ApiModelProperty(value = "自查名称")
private String title;
@ApiModelProperty(value = "创建人的id")
private Integer createUserId;
@ApiModelProperty(value = "创建人的名称")
private String createUserName;
@ApiModelProperty(value = "库房数量")
private Integer checkedCount;
@ApiModelProperty(value = "实查数量")
private Integer checkingCount;
@ApiModelProperty(value = "装备的详情")
private DeviceVo deviceVo;
public WarehouseInspectionBill toEntity(){
WarehouseInspectionBill warehouseInspection = new WarehouseInspectionBill();
BeanUtils.copyProperties(this,warehouseInspection);
List<Map<Integer, Integer>> inDevices = deviceVo.getInDevices();
//转换json
if (inDevices.size()>0){
String checkResult = JacksonUtil.toJSon(inDevices);
warehouseInspection.setCheckResult(checkResult);
}
List<Map<Integer, Integer>> outDevices = deviceVo.getOutDevices();
if (outDevices.size() >0){
String unCheckResult = JacksonUtil.toJSon(outDevices);
warehouseInspection.setUnCheckResult(unCheckResult);
}
return warehouseInspection;
}
}
...@@ -28,6 +28,7 @@ import org.springframework.validation.annotation.Validated; ...@@ -28,6 +28,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -61,16 +62,39 @@ public class ReadMachineBillController { ...@@ -61,16 +62,39 @@ public class ReadMachineBillController {
@Autowired @Autowired
private ReadMachineLibraryService readMachineLibraryService; private ReadMachineLibraryService readMachineLibraryService;
/**
* 所有的rfid的集合
*/
private List<String> RFIDS = new ArrayList<>(); private List<String> RFIDS = new ArrayList<>();
/**
* 存在的rfid的集合
*/
private List<String> existRFIDS = new ArrayList<>(); private List<String> existRFIDS = new ArrayList<>();
/**
* 不存在的rfid的集合
*/
private List<String> notExistRFIDS = new ArrayList<>(); private List<String> notExistRFIDS = new ArrayList<>();
public static Boolean localFlag = false; public static Boolean localFlag = false;
/**
* 装备的集合
*/
private List<DeviceLibrary> deviceLibraries = new ArrayList<>(); private List<DeviceLibrary> deviceLibraries = new ArrayList<>();
/**
* 本次自查盘库的所有的装备的集合
*/
public static Set<DeviceLibrary> totalDeviceLibraries = new HashSet<>();
/**
* 上次读取 theRead
*/
public static List<DeviceLibrary> theReadDeviceLibraries = new ArrayList<>();
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
...@@ -172,6 +196,7 @@ public class ReadMachineBillController { ...@@ -172,6 +196,7 @@ public class ReadMachineBillController {
RFIDS.clear(); RFIDS.clear();
RFIDS.addAll(rfids); RFIDS.addAll(rfids);
List<DeviceLibrary> deviceLibraryList = deviceLibraryService.findAllByRfids(RFIDS); List<DeviceLibrary> deviceLibraryList = deviceLibraryService.findAllByRfids(RFIDS);
deviceLibraryList.forEach(DeviceLibrary::setConfigName);
List<String> existRfids = List<String> existRfids =
deviceLibraryList.stream().map(DeviceLibrary::getRfidCardId).collect(Collectors.toList()); deviceLibraryList.stream().map(DeviceLibrary::getRfidCardId).collect(Collectors.toList());
existRFIDS.clear(); existRFIDS.clear();
...@@ -179,6 +204,7 @@ public class ReadMachineBillController { ...@@ -179,6 +204,7 @@ public class ReadMachineBillController {
RFIDS.removeAll(existRFIDS); RFIDS.removeAll(existRFIDS);
notExistRFIDS.clear(); notExistRFIDS.clear();
notExistRFIDS.addAll(RFIDS); notExistRFIDS.addAll(RFIDS);
//处理异常的装备的
if (!notExistRFIDS.isEmpty()){ if (!notExistRFIDS.isEmpty()){
notExistRFIDS.forEach(s -> readWebSocket.sendMessageForReadMachineError(s)); notExistRFIDS.forEach(s -> readWebSocket.sendMessageForReadMachineError(s));
} }
...@@ -197,4 +223,383 @@ public class ReadMachineBillController { ...@@ -197,4 +223,383 @@ public class ReadMachineBillController {
return deviceLibraries; return deviceLibraries;
} }
@ApiOperation(value = "读取装备信息对比的接口(自查)", notes = "读取装备信息对比的接口")
@GetMapping(value = "/compareDeviceDetailForSelfCheck")
@Transactional(rollbackFor = Exception.class)
public void readDeviceDetailForSelfCheck(Boolean flag) {
if (flag) {
if (!localFlag) {
localFlag = true;
startDeviceDetailForSelfCheck1();
totalDeviceLibraries.clear();
theReadDeviceLibraries.clear();
}
} else {
localFlag = false;
}
}
/**
* 读取装备信息为了自查
*/
public List<DeviceLibrary> startDeviceDetailForSelfCheck(){
ReadUtils readUtils = new ReadUtils();
//先获取ip1
//TODO 后续考虑做成ip的选择,目前先写死
String ip = readMachineIpService.findById(1).getIp();
//先开启
readUtils.testinitreader(ip);
while (localFlag){
//开始盘存 开始读取rfids
List<String> rfids = readUtils.testinventory1();
log.info("rfid's:{}",rfids);
RFIDS.clear();
RFIDS.addAll(rfids);
//本次从数据库里面查询
List<DeviceLibrary> deviceLibraryList = deviceLibraryService.findAllByRfids(RFIDS);
List<String> existRfids =
deviceLibraryList.stream().map(DeviceLibrary::getRfidCardId).collect(Collectors.toList());
existRFIDS.clear();
existRFIDS.addAll(existRfids);
RFIDS.removeAll(existRFIDS);
notExistRFIDS.clear();
notExistRFIDS.addAll(RFIDS);
//处理异常的装备的
if (!notExistRFIDS.isEmpty()){
notExistRFIDS.forEach(s -> readWebSocket.sendMessageForReadMachineError(s));
}
deviceLibraries.clear();
deviceLibraries.addAll(deviceLibraryList);
log.info("deviceLibraries:{}",deviceLibraries.size());
// 现在读取的所有装备转成map
Map<Integer, DeviceLibrary> deviceLibraryMap =
totalDeviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
//本次读取的装备转换成map
Map<Integer, DeviceLibrary> thisTimeDeviceLibraryMap =
deviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
ReadMachineSelefVo readMachineSelefVo = new ReadMachineSelefVo();
//总的装备id
Set<Integer> integers = deviceLibraryMap.keySet();
//先判断总的集合是不是空
if (totalDeviceLibraries.size()>0){
log.info("进入total");
//说明不是第一次读取
//判断本次读取的是否已经读取过了
List<Integer> theReadDeviceIds = deviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
//转换成本次读取的map
Map<Integer, DeviceLibrary> theDeviceMap =
deviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
//取交集
theReadDeviceIds.removeAll(integers);
//如果此时读取装备id的集合大于0 则说明有新的放上去了
if (theReadDeviceIds.size()>0){
//先判断上次读取装备集合 是否为空
if (!theReadDeviceLibraries.isEmpty()){
log.info("theReadDeviceLibraries不为空");
//一定要是上一次比下一次的多 减法 10件之内
if (theReadDeviceLibraries.size()> deviceLibraries.size()){
//大于 说明是拿下去了 假如拿下去两件 返回值为 size=10 list为null
readMachineSelefVo.setSize(deviceLibraries.size());
readMachineSelefVo.setDeviceLibraries(null);
//移除
theReadDeviceLibraries.removeAll(deviceLibraries);
//发通知
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
log.info("拿下去了");
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
}
if (theReadDeviceLibraries.size() == deviceLibraries.size()){
//需要判断双方集合完全一致
//上次读取的集合
List<Integer> collect =
theReadDeviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
//本次读取的集合
List<Integer> collect1 =
deviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
Map<Integer, DeviceLibrary> libraryMap =
deviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId,
Function.identity()));
collect1.removeAll(collect);
if (collect1.isEmpty()){
//说明完全一致
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
//发通知
readMachineSelefVo.setDeviceLibraries(null);
readMachineSelefVo.setSize(deviceLibraries.size());
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
log.info("完全一致");
}else {
//拿到新的
List<DeviceLibrary> newReadList = new ArrayList<>();
collect1.forEach(integer -> {
DeviceLibrary deviceLibrary = libraryMap.get(integer);
newReadList.add(deviceLibrary);
});
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
//发通知
log.info("虽然长度一致,但是有新的");
totalDeviceLibraries.addAll(newReadList);
readMachineSelefVo.setSize(deviceLibraries.size());
readMachineSelefVo.setDeviceLibraries(newReadList);
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
}
}
if (theReadDeviceLibraries.size()<deviceLibraries.size()){
//小于 说明是放上去新的 如果为未读的 返回值为 size =10 list为2 如果是已读的 返回值为 size=10 list为null
//做交集
readMachineSelefVo.setSize(deviceLibraries.size());
deviceLibraries.removeAll(theReadDeviceLibraries);
//还需要判断是已经读取过
List<Integer> readIds =
deviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
readIds.removeAll(integers);
if (readIds.size()>0){
//说明没有读过
List<DeviceLibrary> noReadList =
deviceLibraries.stream().filter(deviceLibrary -> readIds.contains(deviceLibrary.getId()))
.collect(Collectors.toList());
//构建返回值的类
readMachineSelefVo.setDeviceLibraries(noReadList);
theReadDeviceLibraries.addAll(noReadList);
log.info("放上去了新的一部分");
//发通知
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
totalDeviceLibraries.addAll(noReadList);
}else {
readMachineSelefVo.setDeviceLibraries(null);
//发通知
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
}
}
}
else {
//此时在放上去一个
//判断是不是已经被读取过了
List<Integer> deviceIds =
deviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
//跟总的取交集
deviceIds.removeAll(integers);
List<DeviceLibrary> noReadList = new ArrayList<>();
if (deviceIds.size()>0){
//说明是新的
//构建vo 发通知
readMachineSelefVo.setSize(deviceLibraries.size());
deviceIds.forEach(integer -> {
DeviceLibrary deviceLibrary = thisTimeDeviceLibraryMap.get(integer);
noReadList.add(deviceLibrary);
});
readMachineSelefVo.setDeviceLibraries(noReadList);
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
//添加到总的集合中
totalDeviceLibraries.addAll(noReadList);
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
}else {
//说明是旧的
readMachineSelefVo.setSize(deviceLibraries.size());
readMachineSelefVo.setDeviceLibraries(null);
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
}
}
}else {
//都是重复的
readMachineSelefVo.setSize(deviceLibraries.size());
readMachineSelefVo.setDeviceLibraries(null);
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
//发通知
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
//将本次读取的放在上一次的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
}
}else {
//第一次读取 直接推送
readMachineSelefVo.setSize(deviceLibraries.size());
readMachineSelefVo.setDeviceLibraries(deviceLibraries);
//发通知
log.info("第一次读取");
//将本次读取的存储起来
theReadDeviceLibraries.addAll(deviceLibraries);
//存放在总的集合中
totalDeviceLibraries.addAll(deviceLibraries);
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
}
}
return deviceLibraries;
}
/**
* 读取装备信息为了自查
*/
public List<DeviceLibrary> startDeviceDetailForSelfCheck1(){
ReadUtils readUtils = new ReadUtils();
//先获取ip1
String ip = readMachineIpService.findById(1).getIp();
//先开启
readUtils.testinitreader(ip);
while (localFlag){
//开始盘存 开始读取rfids
List<String> rfids = readUtils.testinventory1();
log.info("rfid's:{}",rfids);
RFIDS.clear();
RFIDS.addAll(rfids);
//本次从数据库里面查询
List<DeviceLibrary> deviceLibraryList = deviceLibraryService.findAllByRfids(RFIDS);
List<String> existRfids =
deviceLibraryList.stream().map(DeviceLibrary::getRfidCardId).collect(Collectors.toList());
existRFIDS.clear();
existRFIDS.addAll(existRfids);
RFIDS.removeAll(existRFIDS);
notExistRFIDS.clear();
notExistRFIDS.addAll(RFIDS);
//处理异常的装备的
if (!notExistRFIDS.isEmpty()){
notExistRFIDS.forEach(s -> readWebSocket.sendMessageForReadMachineError(s));
}
deviceLibraries.clear();
deviceLibraries.addAll(deviceLibraryList);
log.info("deviceLibraries:{}",deviceLibraries.size());
//总读取的所有装备转成map
Map<Integer, DeviceLibrary> deviceLibraryMap =
totalDeviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
//本次读取的装备转换成map
Map<Integer, DeviceLibrary> thisTimeDeviceLibraryMap =
deviceLibraries.stream().collect(Collectors.toMap(DeviceLibrary::getId, Function.identity()));
//构建返回vo
ReadMachineSelefVo readMachineSelefVo = new ReadMachineSelefVo();
readMachineSelefVo.setSize(deviceLibraries.size());
//本次读取的装备id的集合
List<Integer> theReadDeviceIds = deviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
//上次读取到装备id的集合
List<Integer> theLastDeviceIds =
theReadDeviceLibraries.stream().map(DeviceLibrary::getId).collect(Collectors.toList());
//总的装备id
Set<Integer> totalDeviceIds = deviceLibraryMap.keySet();
//存放每次读取的新的未读的装备的集合
List<DeviceLibrary> newReadList = new ArrayList<>();
//先判断总的集合是不是空
if (totalDeviceLibraries.size()>0){
log.info("进入total");
//说明不是第一次读取
//判断本次读取的是否已经读取过了
//取交集
theReadDeviceIds.removeAll(totalDeviceIds);
//如果此时读取装备id的集合大于0 则说明有新的放上去了
if (theReadDeviceIds.size()>0){
//先判断上次读取装备集合 是否为空
if (!theReadDeviceLibraries.isEmpty()){
log.info("theReadDeviceLibraries不为空");
//一定要是上一次比下一次的多 减法 10件之内
if (theReadDeviceLibraries.size()> deviceLibraries.size()){
//大于 说明是拿下去了 假如拿下去两件 返回值为 size=10 list为null
readMachineSelefVo.setDeviceLibraries(null);
//发通知
log.info("拿下去了");
}
if (theReadDeviceLibraries.size() == deviceLibraries.size()){
theReadDeviceIds.removeAll(theLastDeviceIds);
if (theReadDeviceIds.size()== 0){
//说明完全一致
//发通知
readMachineSelefVo.setDeviceLibraries(null);
log.info("完全一致");
}
else {
theReadDeviceIds.forEach(integer -> {
DeviceLibrary deviceLibrary = thisTimeDeviceLibraryMap.get(integer);
newReadList.add(deviceLibrary);
});
//将本次读取的放在上一次的集合中
//发通知
log.info("虽然长度一致,但是有新的");
totalDeviceLibraries.addAll(newReadList);
readMachineSelefVo.setDeviceLibraries(newReadList);
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
}
}
if (theReadDeviceLibraries.size()<deviceLibraries.size()){
//小于 说明是放上去新的 如果为未读的 返回值为 size =10 list为2 如果是已读的 返回值为 size=10 list为null
//做交集
deviceLibraries.removeAll(theReadDeviceLibraries);
//还需要判断是已经读取过
theReadDeviceIds.removeAll(totalDeviceIds);
if (theReadDeviceIds.size()>0){
List<DeviceLibrary> noReadList =
deviceLibraries.stream().filter(deviceLibrary -> theReadDeviceIds.contains(deviceLibrary.getId()))
.collect(Collectors.toList());
//构建返回值的类
readMachineSelefVo.setDeviceLibraries(noReadList);
//发通知
//将本次读取的放在上一次的集合中
totalDeviceLibraries.addAll(noReadList);
}else {
readMachineSelefVo.setDeviceLibraries(null);
}
}
}
else {
//此时在放上去一个
//判断是不是已经被读取过了
//跟总的取交集
theReadDeviceIds.removeAll(totalDeviceIds);
List<DeviceLibrary> noReadList = new ArrayList<>();
if (theReadDeviceIds.size()>0){
//说明是新的
//构建vo 发通知
theReadDeviceIds.forEach(integer -> {
DeviceLibrary deviceLibrary = thisTimeDeviceLibraryMap.get(integer);
noReadList.add(deviceLibrary);
});
readMachineSelefVo.setDeviceLibraries(noReadList);
//添加到总的集合中
totalDeviceLibraries.addAll(noReadList);
}else {
//说明是旧的
readMachineSelefVo.setDeviceLibraries(null);
}
}
}else {
//都是重复的
readMachineSelefVo.setDeviceLibraries(null);
}
}else {
//第一次读取 直接推送
readMachineSelefVo.setDeviceLibraries(deviceLibraries);
//发通知
log.info("第一次读取");
//将本次读取的存储起来
//存放在总的集合中
totalDeviceLibraries.addAll(deviceLibraries);
}
//无论如何都需要执行的
//1.将本次读取的添加到上一次读取的集合中
theReadDeviceLibraries.clear();
theReadDeviceLibraries.addAll(deviceLibraries);
//2.发通知
readWebSocket.sendMessageForReadMachineForSelfCheck(readMachineSelefVo);
}
return deviceLibraries;
}
} }
package com.tykj.dev.readmachine.devreadmachine.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackJsonVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.SaveSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.service.WarehouseInspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author zsp
* @create 2022/1/18 10:32
*/
@RestController
@RequestMapping(value = "/warehouseInspectionBill")
@AutoDocument
@Api(tags = "盘存自查", description = "盘存自查")
@Validated
@Slf4j
public class WarehouseInspectionBillController {
@Resource
private WarehouseInspectionService warehouseInspectionService;
@PostMapping("/startSelfCheck")
@ApiOperation(value = "开启盘存自查业务")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> startSelfCheck(@RequestBody SaveSelfCheckVo saveSelfCheckVo){
warehouseInspectionService.startSelfCheck(saveSelfCheckVo);
return ResponseEntity.ok("盘点完成");
}
@GetMapping("/findByBillId")
@ApiOperation(value = "查看单个业务")
public ResponseEntity<BackSelfCheckVo> findByBillId(Integer id){
BackSelfCheckVo backSelfCheckVo = warehouseInspectionService.findById(id);
return ResponseEntity.ok(backSelfCheckVo);
}
@GetMapping("/findAllBillList")
@ApiOperation(value = "查看盘点自查业务列表")
public ResponseEntity<List<WarehouseInspectionBill>> findAllBillList(){
List<WarehouseInspectionBill> bills = warehouseInspectionService.findAll();
bills.forEach(WarehouseInspectionBill::setConfig);
return ResponseEntity.ok(bills);
}
@GetMapping("/findByTaskId")
@ApiOperation(value = "通过任务id查询详情")
public ResponseEntity<BackSelfCheckVo> findByTaskId(Integer taskId){
BackSelfCheckVo backSelfCheckVo = warehouseInspectionService.findByTaskId(taskId);
return ResponseEntity.ok(backSelfCheckVo);
}
@GetMapping("/findAllDevices")
@ApiOperation(value = "查询所有的装备")
public ResponseEntity<BackJsonVo> findAllDevices(){
List<DeviceLibrary> allDevices = warehouseInspectionService.findAllDevices();
allDevices.forEach(DeviceLibrary::setConfigName);
BackJsonVo backJsonVo = new BackJsonVo();
backJsonVo.setOutDeviceLibraryList(allDevices);
return ResponseEntity.ok(backJsonVo);
}
}
package com.tykj.dev.readmachine.devreadmachine.repository;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author zsp
* @create 2022/1/18 10:37
*/
public interface WarehouseInspectionDao extends JpaRepository<WarehouseInspectionBill,Integer>, JpaSpecificationExecutor<WarehouseInspectionBill> {
}
package com.tykj.dev.readmachine.devreadmachine.service;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.SaveSelfCheckVo;
import java.util.List;
/**
* @author zsp
* @create 2022/1/18 10:32
*/
public interface WarehouseInspectionService {
/**
* 新增实体
* @param warehouseInspectionBill 盘存自查对象vo
* @return WarehouseInspectionBill 业务对象
*/
WarehouseInspectionBill addEntity(WarehouseInspectionBill warehouseInspectionBill);
/**
* 开始盘存自查任务
* @param selfCheckVo 发起自查对象
*/
void startSelfCheck(SaveSelfCheckVo selfCheckVo);
/**
* 更新实体
* @param warehouseInspection 盘存自查对象
*/
void updateEntity(WarehouseInspectionBill warehouseInspection);
/**
* 查询单个
* @param id 主键id
* WarehouseInspectionBill 业务对象
*/
BackSelfCheckVo findById(Integer id);
/**
* 查询单个
* @param id 主键id
* WarehouseInspectionBill 业务对象
*/
WarehouseInspectionBill findById1(Integer id);
// void findAllByContional();
/**
* 删除单个
* @param id 主键id
*/
void deleteById(Integer id);
/**
* 查询所有装备
* @return 所有的都是未读的装备对象
*/
List<DeviceLibrary> findAllDevices();
/**
* 查询所有的业务对象
* @return List<WarehouseInspectionBill> 业务列表
*/
List<WarehouseInspectionBill> findAll();
/**
* 根据任务id查询业务
* @param taskId 任务id
* @return BackSelfCheckVo
*/
BackSelfCheckVo findByTaskId(Integer taskId);
}
package com.tykj.dev.readmachine.devreadmachine.service;
import com.fasterxml.jackson.core.type.TypeReference;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.dev.device.library.service.DeviceLibraryService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.user.util.UserUtils;
import com.tykj.dev.misc.base.BusinessEnum;
import com.tykj.dev.misc.base.StatusEnum;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.utils.JacksonUtil;
import com.tykj.dev.readmachine.devreadmachine.Entity.WarehouseInspectionBill;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackJsonVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.BackSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.selfCheckVo.SaveSelfCheckVo;
import com.tykj.dev.readmachine.devreadmachine.repository.WarehouseInspectionDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author zsp
* @create 2022/1/18 10:36
*/
@Service
public class WarehouseInspectionServiceImpl implements WarehouseInspectionService {
@Resource
private WarehouseInspectionDao warehouseInspectionDao;
@Autowired
private DeviceLibraryService deviceLibraryService;
@Resource
private TaskService taskService;
@Resource
private UserUtils userUtils;
@Override
public WarehouseInspectionBill addEntity(WarehouseInspectionBill warehouseInspectionBill) {
return warehouseInspectionDao.save(warehouseInspectionBill);
}
@Override
public void startSelfCheck(SaveSelfCheckVo selfCheckVo) {
Integer currentUserId = userUtils.getCurrentUserId();
Integer unitId = userUtils.getCurrentUnitId();
List<Integer> userList = new ArrayList<>();
userList.add(currentUserId);
//先进行对象的赋值
WarehouseInspectionBill warehouseInspectionBill = selfCheckVo.toEntity();
//然后保存
WarehouseInspectionBill warehouseInspectionBill1 = addEntity(warehouseInspectionBill);
TaskBto taskBto = new TaskBto(StatusEnum.READ_SELF_CHECK.id,selfCheckVo.getTitle(),".",
warehouseInspectionBill1.getId(), BusinessEnum.READMACHINE_SELFCHECK.id,unitId,0,userList);
taskService.start(taskBto);
taskService.moveToEnd(taskBto);
}
@Override
public void updateEntity(WarehouseInspectionBill warehouseInspection) {
warehouseInspectionDao.save(warehouseInspection);
}
@Override
public BackSelfCheckVo findById(Integer id) {
Optional<WarehouseInspectionBill> byId = warehouseInspectionDao.findById(id);
if (byId.isPresent()){
WarehouseInspectionBill warehouseInspectionBill = byId.get();
warehouseInspectionBill.setConfig();
return toBackSelfCheckVo(warehouseInspectionBill);
}else {
throw new ApiException(String.format("要查询的数据不存在,查询的billId为 %d,businessType为 %d", id, 30));
}
}
@Override
public WarehouseInspectionBill findById1(Integer id) {
Optional<WarehouseInspectionBill> byId = warehouseInspectionDao.findById(id);
if (byId.isPresent()){
WarehouseInspectionBill warehouseInspectionBill = byId.get();
warehouseInspectionBill.setConfig();
return warehouseInspectionBill;
}else {
throw new ApiException(String.format("要查询的数据不存在,查询的billId为 %d,businessType为 %d", id, 30));
}
}
@Override
public void deleteById(Integer id) {
warehouseInspectionDao.deleteById(id);
}
@Override
public List<DeviceLibrary> findAllDevices() {
String currentUserUnitName = userUtils.getCurrentUserUnitName();
PredicateBuilder<DeviceLibrary> predicateBuilder = Specifications.and();
predicateBuilder.eq("ownUnit",currentUserUnitName);
predicateBuilder.eq("locationUnit",currentUserUnitName);
List<DeviceLibrary> allDevices = deviceLibraryService.findAllDevices().stream()
.filter(deviceLibrary -> deviceLibrary.getOwnUnit().equals(currentUserUnitName)
&& deviceLibrary.getLocationUnit().equals(currentUserUnitName)).collect(Collectors.toList());
allDevices.forEach(deviceLibrary -> deviceLibrary.setStatus(0));
return allDevices;
}
@Override
public List<WarehouseInspectionBill> findAll() {
return warehouseInspectionDao.findAll();
}
@Override
public BackSelfCheckVo findByTaskId(Integer taskId) {
TaskBto byTaskId = taskService.findByTaskId(taskId);
WarehouseInspectionBill inspectionBill = findById1(byTaskId.getBillId());
inspectionBill.setConfig();
BackSelfCheckVo backSelfCheckVo = new BackSelfCheckVo();
backSelfCheckVo.setWarehouseInspectionBill(inspectionBill);
backSelfCheckVo.setBackJsonVo(toBackSelfCheckVo(inspectionBill).getBackJsonVo());
return backSelfCheckVo;
}
private BackSelfCheckVo toBackSelfCheckVo(WarehouseInspectionBill warehouseInspectionBill){
//总的装备的map
List<DeviceLibrary> allDevices = findAllDevices();
BackSelfCheckVo backSelfCheckVo = new BackSelfCheckVo();
backSelfCheckVo.setWarehouseInspectionBill(warehouseInspectionBill);
List<Map<Integer, Integer>> inMaps = JacksonUtil.readValue(warehouseInspectionBill.getCheckResult(), new TypeReference<List<Map<Integer
, Integer>>>() {
});
List<Map<Integer, Integer>> outMaps = JacksonUtil.readValue(warehouseInspectionBill.getUnCheckResult(), new TypeReference<List<Map<Integer
, Integer>>>() {
});
BackJsonVo backJsonVo = new BackJsonVo();
//遍历已读的装备的集合
List<DeviceLibrary> readDeviceList = new ArrayList<>();
List<Integer> readKeyList = new ArrayList<>();
assert inMaps != null;
for (Map<Integer, Integer> inMap : inMaps) {
Set<Integer> integers = inMap.keySet();
readKeyList.addAll(integers);
}
readDeviceList = allDevices.stream().filter(deviceLibrary -> {
if (readKeyList.contains(deviceLibrary.getId())){
deviceLibrary.setStatus(1);
return true;
}else {
return false;
}
}).collect(Collectors.toList());
allDevices.removeAll(readDeviceList);
//遍历未读的装备的集合
List<DeviceLibrary> noReadDeviceList = new ArrayList<>();
List<Integer> noReadKeyList = new ArrayList<>();
assert outMaps != null;
for (Map<Integer, Integer> outMap : outMaps) {
Set<Integer> integers = outMap.keySet();
noReadKeyList.addAll(integers);
}
noReadDeviceList = allDevices.stream().filter(deviceLibrary -> {
if (noReadKeyList.contains(deviceLibrary.getId())){
deviceLibrary.setStatus(0);
return true;
}else {
return false;
}
}).collect(Collectors.toList());
backJsonVo.setInDeviceLibraryList(readDeviceList);
backJsonVo.setOutDeviceLibraryList(noReadDeviceList);
backSelfCheckVo.setBackJsonVo(backJsonVo);
return backSelfCheckVo;
}
}
...@@ -22,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -22,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @createTime 2020年08月19日 23:53:00 * @createTime 2020年08月19日 23:53:00
*/ */
@Slf4j @Slf4j
@ServerEndpoint(value = "/websocket/{userId}") //接受websocket请求路径 @ServerEndpoint(value = "/websocket/{userId}",encoders = {ServerEncoder.class}) //接受websocket请求路径
@Component //注册到spring容器中 @Component //注册到spring容器中
@Data @Data
public class ReadWebSocket { public class ReadWebSocket {
...@@ -85,6 +85,8 @@ public class ReadWebSocket { ...@@ -85,6 +85,8 @@ public class ReadWebSocket {
webSocketMap.remove(userId); webSocketMap.remove(userId);
if (webSocketMap.size() == 0){ if (webSocketMap.size() == 0){
ReadMachineBillController.localFlag= false; ReadMachineBillController.localFlag= false;
ReadMachineBillController.totalDeviceLibraries.clear();
ReadMachineBillController.theReadDeviceLibraries.clear();
} }
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size()); log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
} }
...@@ -165,6 +167,14 @@ public class ReadWebSocket { ...@@ -165,6 +167,14 @@ public class ReadWebSocket {
} }
} }
public void sendMessage3(Object o) {
try {
this.session.getBasicRemote().sendObject(o);
} catch (IOException | EncodeException e) {
e.printStackTrace();
}
}
public void sendMessage1() { public void sendMessage1() {
for (String i : webSocketMap.keySet()) { for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage("1"); webSocketMap.get(i).sendMessage("1");
...@@ -177,6 +187,12 @@ public class ReadWebSocket { ...@@ -177,6 +187,12 @@ public class ReadWebSocket {
} }
} }
public void sendMessageForReadMachineForSelfCheck(Object o) {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage3(o);
}
}
public void sendMessageForReadMachine1(Object o,Integer userId) { public void sendMessageForReadMachine1(Object o,Integer userId) {
webSocketMap.get(String.valueOf(userId)).sendMessage2(o); webSocketMap.get(String.valueOf(userId)).sendMessage2(o);
......
package com.tykj.dev.readmachine.devreadmachine.socket;
import com.alibaba.fastjson.JSONObject;
import com.tykj.dev.readmachine.devreadmachine.Vo.ReadMachineSelefVo;
import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
/**
* @author zsp
* @create 2022/1/17 15:53
*/
public class ServerEncoder implements Encoder.Text<ReadMachineSelefVo> {
@Override
public String encode(ReadMachineSelefVo object) throws EncodeException {
return JSONObject.toJSONString(object);
}
@Override
public void init(EndpointConfig endpointConfig) {
}
@Override
public void destroy() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论