提交 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;
}
}
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论