提交 c3a1e9da authored 作者: zjm's avatar zjm

Merge branch 'read-dev' of git.yfzx.zjtys.com.cn:matrix/device-back into dev

...@@ -931,8 +931,6 @@ public class AllotBillController { ...@@ -931,8 +931,6 @@ public class AllotBillController {
} }
//父任务未被完成 可以被撤回 //父任务未被完成 可以被撤回
Integer billId = taskBto.getBillId(); Integer billId = taskBto.getBillId();
String title = taskBto.getTitle();
AllotBill allotBill = allotBillService.getOne(billId); AllotBill allotBill = allotBillService.getOne(billId);
Integer currentUserId = userUtils.getCurrentUserId(); Integer currentUserId = userUtils.getCurrentUserId();
List<Integer> idList = userPublicService.findOtherUser(currentUserId); List<Integer> idList = userPublicService.findOtherUser(currentUserId);
...@@ -946,18 +944,6 @@ public class AllotBillController { ...@@ -946,18 +944,6 @@ public class AllotBillController {
.map(User::getUserId) .map(User::getUserId)
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
//给同单位专管员和收件单位专管员推阅知
// messageBto1.setContent(title.substring(0,4)+"撤回"+title.substring(4));
// messageBto1.setContent("撤回对" + allotBill.getReceiveUnit()+"的型号为"+"的任务");
// MessageBto messageBto = new MessageBto(-1, parentTask.getBusinessType(), messageBto1.getContent(), idList, 1);
// BeanUtils.copyProperties(messageBto1,messageBto);
// messageBto.setTaskId(-1);
// messageService.add(messageBto);
// myWebSocket.sendMessage1();
// //将任务都完结
// taskService.moveToRevoke(taskBto);
// taskService.moveToRevoke(parentTask);
List<DeviceLibrary> deviceLibraryList = null; List<DeviceLibrary> deviceLibraryList = null;
if (allotBill.getAllotCheckDetail() != null) { if (allotBill.getAllotCheckDetail() != null) {
List<Integer> ids = StringSplitUtil.split(allotBill.getAllotCheckDetail()); List<Integer> ids = StringSplitUtil.split(allotBill.getAllotCheckDetail());
...@@ -972,21 +958,20 @@ public class AllotBillController { ...@@ -972,21 +958,20 @@ public class AllotBillController {
DeviceLogDto deviceLogDto = new DeviceLogDto(id, "对" + deviceLibrary.getName() + "配发撤回", null, null, null); DeviceLogDto deviceLogDto = new DeviceLogDto(id, "对" + deviceLibrary.getName() + "配发撤回", null, null, null);
deviceLogDtos.add(deviceLogDto); deviceLogDtos.add(deviceLogDto);
}); });
//设置装备为在库 //设置装备为在库
deviceLibraryService.updateLifeStatus2(2,ids); deviceLibraryService.updateLifeStatus2(2,ids);
deviceLibraryList = deviceLibraryService.findByIds(ids); deviceLibraryList = deviceLibraryService.findByIds(ids);
//添加日志 //添加日志
deviceLogService.addAllLog(deviceLogDtos); deviceLogService.addAllLog(deviceLogDtos);
allotBill.setDeviceLibraries(deviceLibraryList); allotBill.setDeviceLibraries(deviceLibraryList);
allotBillService.delete(allotBill.getId()); allotBillService.delete(allotBill.getId());
} }
// 配发撤回:操作人 撤回 配发:【发送单位】至【发往单位】【型号数量】
messageBto1.setContent("撤回对" + allotBill.getReceiveUnit()+"的型号为"+deviceLibraryList.stream().map(DeviceLibrary::getModel) // 例:市A 撤回 配发:【杭州市机要局】至【萧山机要局】【型号:A001,A002共3件】
.collect(Collectors.toList())+"的任务"); messageBto1.setContent("撤回 配发:"+MessageFormatUtil.spellTwoWicket(allotBill.getSendUnit(),allotBill.getReceiveUnit())+
MessageFormatUtil.spellModelSetAndCount(deviceLibraryList.stream().map(DeviceLibrary::getModel)
.collect(Collectors.toSet()),allotBill.getAllotCount()));
MessageBto messageBto = new MessageBto(-1, taskBto.getBusinessType(), messageBto1.getContent(), idList, 1); MessageBto messageBto = new MessageBto(-1, taskBto.getBusinessType(), messageBto1.getContent(), idList, 1);
BeanUtils.copyProperties(messageBto1,messageBto); BeanUtils.copyProperties(messageBto1,messageBto);
messageBto.setTaskId(-1); messageBto.setTaskId(-1);
...@@ -994,7 +979,6 @@ public class AllotBillController { ...@@ -994,7 +979,6 @@ public class AllotBillController {
myWebSocket.sendMessage1(); myWebSocket.sendMessage1();
//将任务都完结 //将任务都完结
taskService.moveToRevoke(taskBto); taskService.moveToRevoke(taskBto);
return ResponseEntity.ok(messageBto); return ResponseEntity.ok(messageBto);
} }
......
...@@ -798,7 +798,15 @@ public class DeviceApplyController { ...@@ -798,7 +798,15 @@ public class DeviceApplyController {
@PostMapping("/removeSameSeq") @PostMapping("/removeSameSeq")
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResponseEntity removeSameSeq(@RequestBody RemoveSameSeqVo removeSameSeqVo) { public ResponseEntity removeSameSeq(@RequestBody RemoveSameSeqVo removeSameSeqVo) {
ApplyRemoveSeqVo applyRemoveSeqVo = deviceApplyBillService.removeSameSeq(removeSameSeqVo); ApplyRemoveSeqVo applyRemoveSeqVo = new ApplyRemoveSeqVo();
if (removeSameSeqVo.getRemoveSameSeq() != null){
applyRemoveSeqVo = deviceApplyBillService.removeSameSeq(removeSameSeqVo);
}else {
//没有重复的
List<String> list = DeviceSeqUtil.selectDeviceSeqs(removeSameSeqVo.getSeqNumberList());
applyRemoveSeqVo.setSeqList(list);
applyRemoveSeqVo.setCount(list.size());
}
return ResponseEntity.ok(applyRemoveSeqVo); return ResponseEntity.ok(applyRemoveSeqVo);
} }
......
package com.tykj.dev.device.apply.subject.vo; package com.tykj.dev.device.apply.subject.vo;
import com.tykj.dev.device.apply.subject.domin.DeviceApplyBill;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.packing.subject.domin.PackingLibrary;
import com.tykj.dev.device.task.subject.vo.TaskLogUserVo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -23,5 +19,4 @@ public class ApplyRemoveSeqVo { ...@@ -23,5 +19,4 @@ public class ApplyRemoveSeqVo {
@ApiModelProperty(name = "区间数量") @ApiModelProperty(name = "区间数量")
private Integer count; private Integer count;
} }
//package com.tykj.dev.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//
///**
// * @author zsp
// * @create 2021/12/13 14:20
// */
//@Configuration
//public class ReadMachineLoader {
//
// @PostConstruct
// private void getLoader(){
// if (System.getProperty("myapplibrary") == null){
// System.setProperty("myapplibrary","libModuleAPIJni.so");
// System.loadLibrary("libModuleAPIJni");
// }
// }
//}
package com.tykj.dev.device.library.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.library.service.DeviceLibraryCacheService;
import com.tykj.dev.device.library.service.DeviceLibraryPositionService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.library.subject.domin.DeviceLibraryPosition;
import com.tykj.dev.device.library.subject.vo.DeviceLibraryPositionMessageVo;
import com.tykj.dev.device.library.subject.vo.RotationVo;
import com.tykj.dev.device.library.subject.vo.ScriptSaveVo;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* DATE:2021-8-11
* Author:zsp
*/
@RestController
@RequestMapping(value = "/deviceLibraryPosition")
@AutoDocument
@Api(tags = "装备3D模块", description = "装备3D模块")
@Slf4j
public class DeviceLibraryPositionController {
@Resource
private DeviceLibraryPositionService deviceLibraryPositionService;
@GetMapping("/findByStorageLocationId")
@ApiOperation(value = "根据库房位置查询装备")
public ResponseEntity<List<DeviceLibraryPosition>> findByStorageLocationId(Integer StorageLocationId){
List<DeviceLibraryPosition> deviceLibraryPositions = new ArrayList<>();
for (DeviceLibraryPosition deviceLibraryPosition : deviceLibraryPositionService.findByStorageLocationId(StorageLocationId)) {
deviceLibraryPosition.setDeviceLibraryPositionMessageVo(
JacksonUtil.readValue(deviceLibraryPosition.getDeviceLibraryPositionMessage(), new TypeReference<DeviceLibraryPositionMessageVo>() {}));
deviceLibraryPosition.setRotationVo(
JacksonUtil.readValue(deviceLibraryPosition.getRotation(), new TypeReference<RotationVo>() {}));
deviceLibraryPositions.add(deviceLibraryPosition);
}
return ResponseEntity.ok(deviceLibraryPositions);
}
@PostMapping("/updateDeviceLibraryPosition")
@ApiOperation(value = "修改3D")
public ResponseEntity<String> updateDeviceLibraryPosition(@RequestBody DeviceLibraryPosition deviceLibraryPosition){
String messageVo = deviceLibraryPosition.getDeviceLibraryPositionMessageVo().toJson();
String rotationVo = deviceLibraryPosition.getRotationVo().toJson();
deviceLibraryPosition.setDeviceLibraryPositionMessage(messageVo);
deviceLibraryPosition.setRotation(rotationVo);
deviceLibraryPositionService.updateDeviceLibraryPosition(deviceLibraryPosition);
return ResponseEntity.ok("修改成功");
}
@GetMapping("/findById")
@ApiOperation(value = "根据id查询")
public ResponseEntity<DeviceLibraryPosition> findById(Integer id){
DeviceLibraryPosition deviceLibraryPosition = deviceLibraryPositionService.findById(id);
return ResponseEntity.ok(deviceLibraryPosition);
}
@GetMapping("/delete")
@ApiOperation(value = "根据id删除")
public ResponseEntity<String> deleteByPosition(Integer id){
deviceLibraryPositionService.deleteByPosition(id);
return ResponseEntity.ok("删除成功");
}
}
package com.tykj.dev.device.library.repository;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.library.subject.domin.DeviceLibraryPosition;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author zsp
*/
@SuppressWarnings("SqlResolve")
public interface DeviceLibraryPositionDao extends JpaRepository<DeviceLibraryPosition, Integer>, JpaSpecificationExecutor<DeviceLibraryPosition> {
List<DeviceLibraryPosition> findAllByStorageLocationId(Integer StorageLocationId);
}
package com.tykj.dev.device.library.service;
import com.tykj.dev.device.library.subject.domin.DeviceLibraryPosition;
import java.util.List;
/**
* @author zsp
* @create 2021/12/13 16:23
*/
public interface DeviceLibraryPositionService {
void addDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition);
void updateDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition);
void batchDeviceLibraryPositions(List<DeviceLibraryPosition> deviceLibraryPositions);
List<DeviceLibraryPosition> findByStorageLocationId(Integer StorageLocationId);
DeviceLibraryPosition findById(Integer id);
void deleteByPosition(Integer id);
}
...@@ -527,4 +527,7 @@ public interface DeviceLibraryService { ...@@ -527,4 +527,7 @@ public interface DeviceLibraryService {
List<DeviceLibrary> findAllByRfids(List<String> rfids); List<DeviceLibrary> findAllByRfids(List<String> rfids);
List<DeviceLibrary> batchDevices(List<DeviceLibrary> deviceLibraryEntity);
} }
//package com.tykj.dev.device.library.service.impl;
//
//import com.tykj.dev.device.library.repository.DeviceLibraryPositionDao;
//import com.tykj.dev.device.library.service.DeviceLibraryPositionService;
//import com.tykj.dev.device.library.service.DeviceLibraryService;
//import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
//import com.tykj.dev.device.library.subject.domin.DeviceLibraryPosition;
//import com.tykj.dev.device.user.util.UserUtils;
//import lombok.val;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//import java.util.Optional;
//
///**
// * @author zsp
// * @create 2021/12/13 16:23
// */
//@Service
//public class DeviceLibraryPositionServiceImpl implements DeviceLibraryPositionService {
//
// @Autowired
// private UserUtils userUtils;
//
// @Autowired
// private DeviceLibraryService deviceLibraryService;
//
// @Autowired
// private DeviceLibraryPositionDao deviceLibraryPositionDao;
//
// @Override
// public void addDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition) {
// deviceLibraryPositionDao.save(deviceLibraryPosition);
// }
//
// @Override
// public void updateDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition) {
// deviceLibraryPositionDao.save(deviceLibraryPosition);
// }
//
// @Override
// public void batchDeviceLibraryPositions(List<DeviceLibraryPosition> deviceLibraryPositions) {
// deviceLibraryPositionDao.saveAll(deviceLibraryPositions);
// }
//
// @Override
// public List<DeviceLibraryPosition> findByStorageLocationId(Integer StorageLocationId) {
// return deviceLibraryPositionDao.findAllByStorageLocationId(StorageLocationId);
//
// }
//
// @Override
// public DeviceLibraryPosition findById(Integer id) {
// DeviceLibraryPosition deviceLibraryPosition = new DeviceLibraryPosition();
// Optional<DeviceLibraryPosition> positionDaoById = deviceLibraryPositionDao.findById(id);
// if(positionDaoById.isPresent()){
// deviceLibraryPosition = positionDaoById.get();
// }
// return deviceLibraryPosition;
// }
//
// @Override
// public void deleteByPosition(Integer id) {
// DeviceLibraryPosition deviceLibraryPosition= findById(id);
// DeviceLibrary deviceLibrary = deviceLibraryService.getOne(deviceLibraryPosition.getDeviceId());
// deviceLibrary.setStorageLocation(null);
// deviceLibrary.setStorageLocationId(null);
// deviceLibraryPositionDao.delete(deviceLibraryPosition);
// deviceLibraryService.update(deviceLibrary);
// }
//}
...@@ -1239,6 +1239,12 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService { ...@@ -1239,6 +1239,12 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
return deviceLibraryDao.findAllByRfidCardIdIn(rfids); return deviceLibraryDao.findAllByRfidCardIdIn(rfids);
} }
@Override
@UpdateCache
public List<DeviceLibrary> batchDevices(List<DeviceLibrary> deviceLibraryEntity) {
return deviceLibraryDao.saveAll(deviceLibraryEntity);
}
// @Override // @Override
// @UpdateCache // @UpdateCache
// public int updatePartParentId(List<Integer> deviceIds) { // public int updatePartParentId(List<Integer> deviceIds) {
...@@ -1395,6 +1401,8 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService { ...@@ -1395,6 +1401,8 @@ public class DeviceLibraryServiceImpl implements DeviceLibraryService {
if (deviceLibrarySelectVo.getSeqInterval()!=null&&DeviceSeqUtil.selectDeviceSeqs(deviceLibrarySelectVo.getSeqInterval()).size()>0){ if (deviceLibrarySelectVo.getSeqInterval()!=null&&DeviceSeqUtil.selectDeviceSeqs(deviceLibrarySelectVo.getSeqInterval()).size()>0){
predicateBuilder.in("seqNumber", DeviceSeqUtil.selectDeviceSeqs(deviceLibrarySelectVo.getSeqInterval())); predicateBuilder.in("seqNumber", DeviceSeqUtil.selectDeviceSeqs(deviceLibrarySelectVo.getSeqInterval()));
} }
predicateBuilder.like(deviceLibrarySelectVo.getRfidCardId() != null,"rfidCardId",
"%"+deviceLibrarySelectVo.getRfidCardId()+"%");
//新增库房位置 //新增库房位置
predicateBuilder.eq(deviceLibrarySelectVo.getStorageLocationId() != null,"storageLocationId",deviceLibrarySelectVo.getStorageLocationId()); predicateBuilder.eq(deviceLibrarySelectVo.getStorageLocationId() != null,"storageLocationId",deviceLibrarySelectVo.getStorageLocationId());
//新增装备的形态 //新增装备的形态
......
package com.tykj.dev.device.library.subject.domin;
import com.tykj.dev.device.library.subject.vo.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author zsp
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update device_library_position set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("装备3D位置存储库")
public class DeviceLibraryPosition implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue
@ApiModelProperty(name = "主键id")
@Column(columnDefinition = "integer NOT NULL AUTO_INCREMENT")
private Integer id;
/**
* 型号
*/
@ApiModelProperty(value = "型号")
private String model;
/**
* 型号
*/
@ApiModelProperty(value = "装备的id")
private Integer deviceId;
/**
* 密级
*/
@ApiModelProperty(value = "密级")
private Integer secretLevel;
/**
* 装备名称
*/
@ApiModelProperty(value = "装备名称")
private String name;
/**
* 装备序列号
*/
@ApiModelProperty(value = "装备序列号")
private String seqNumber;
/**
* 生产序列号
*/
@ApiModelProperty(value = "生产序列号")
private String prodNumber;
/**
* rfid表面号
*/
@ApiModelProperty(value = "rfid表面号")
private String rfidSurfaceId;
/**
* rfid卡号
*/
@ApiModelProperty(value = "rfid卡号")
private String rfidCardId;
/**
* 所在单位
*/
@ApiModelProperty(value = "所在单位")
private String locationUnit;
/**
* 所属单位
*/
@ApiModelProperty(value = "所属单位")
private String ownUnit;
/**
* 创建用户id
*/
@CreatedBy
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
/**
* 创建时间
*/
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新用户id
*/
@LastModifiedBy
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
/**
* 更新时间
*/
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
/**
* 删除标记(0:未删除,1:已删除)
*/
@ApiModelProperty(value = "删除标记(0:未删除,1:已删除)")
private Integer deleteTag = 0;
@ApiModelProperty(value = "库房位置",notes = "默认是库房")
private String storageLocation;
@ApiModelProperty(value = "装备存放位置Id",notes = "默认是库房")
private Integer storageLocationId;
@ApiModelProperty(value = "DeviceLibraryPosition名称",notes = "")
private String deviceLibraryPositionName;
@ApiModelProperty(value = "位置信息",notes = "{x, y, z}")
@Column(name = "Device_Library_Position_Message",columnDefinition = "TEXT")
private String deviceLibraryPositionMessage;
@ApiModelProperty(value = "旋转信息",notes = "{x, y, z}")
@Column(name = "Rotation",columnDefinition = "TEXT")
private String rotation;
@ApiModelProperty(value = "是否在机柜中 ",notes = "0 不在 1 在")
private Integer ifCabinet = 0;
@ApiModelProperty(value = "在几号机柜里",notes = "1")
private Integer cabinetPosition;
@ApiModelProperty(value = "u位",notes = "1-1")
private String uNum;
@ApiModelProperty("旋转信息vo")
@Transient
private DeviceLibraryPositionMessageVo deviceLibraryPositionMessageVo;
@ApiModelProperty("位置信息vo")
@Transient
private RotationVo rotationVo;
}
package com.tykj.dev.device.library.subject.vo;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.stereotype.Repository;
/**
* @author zsp
* @create 2021/12/13 16:46
*/
@Data
@ApiModel("位置信息")
@Repository
public class DeviceLibraryPositionMessageVo {
@ApiModelProperty("位置信息")
private String x;
private String y;
private String z;
public String toJson(){
return JacksonUtil.toJSon(this);
}
}
package com.tykj.dev.device.library.subject.vo;
import com.tykj.dev.misc.utils.JacksonUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.stereotype.Repository;
/**
* @author zsp
*/
@Data
@ApiModel("旋转信息")
@Repository
public class RotationVo {
@ApiModelProperty("位置信息")
private String x;
private String y;
private String z;
public String toJson(){
return JacksonUtil.toJSon(this);
}
}
...@@ -395,6 +395,8 @@ public class MatchingDeviceLibraryServiceImpl implements MatchingDeviceLibrarySe ...@@ -395,6 +395,8 @@ public class MatchingDeviceLibraryServiceImpl implements MatchingDeviceLibrarySe
predicateBuilder.in("rfidCardId", ""); predicateBuilder.in("rfidCardId", "");
} }
} }
predicateBuilder.like(matchingDeviceSelectVo.getRfidCardId() != null,"rfidCardId",
"%"+matchingDeviceSelectVo.getRfidCardId()+"%");
predicateBuilder.eq(matchingDeviceSelectVo.getMatchingDeviceStorageLocationId() != null, predicateBuilder.eq(matchingDeviceSelectVo.getMatchingDeviceStorageLocationId() != null,
"matchingDeviceStorageLocationId",matchingDeviceSelectVo.getMatchingDeviceStorageLocationId()); "matchingDeviceStorageLocationId",matchingDeviceSelectVo.getMatchingDeviceStorageLocationId());
return predicateBuilder; return predicateBuilder;
......
...@@ -36,6 +36,9 @@ public class MatchingDeviceSelectVo extends CustomPage { ...@@ -36,6 +36,9 @@ public class MatchingDeviceSelectVo extends CustomPage {
@ApiModelProperty(value = "存放位置id") @ApiModelProperty(value = "存放位置id")
private Integer matchingDeviceStorageLocationId; private Integer matchingDeviceStorageLocationId;
@ApiModelProperty(value = "rfidCardId")
private Integer rfidCardId;
private String typeDim; private String typeDim;
private String modelDim; private String modelDim;
......
...@@ -121,6 +121,7 @@ public enum BusinessEnum { ...@@ -121,6 +121,7 @@ public enum BusinessEnum {
SUSPENSION(29,"中止业务"), SUSPENSION(29,"中止业务"),
READMACHINE(30,"盘存"),
; ;
public Integer id; public Integer id;
......
...@@ -317,7 +317,15 @@ public enum StatusEnum { ...@@ -317,7 +317,15 @@ public enum StatusEnum {
SCRAP_2222(2222, "等待上传报废签收单"), SCRAP_2222(2222, "等待上传报废签收单"),
SCRAP_2223(2223, "报废草稿"), SCRAP_2223(2223, "报废草稿"),
SCRAP_2224(2224, "报废出库签章审核"), SCRAP_2224(2224, "报废出库签章审核"),
SCRAP_2225(2225, "报废出库等待盖电子签章"); SCRAP_2225(2225, "报废出库等待盖电子签章"),
/**
* 盘存状态draft
*/
READ_DEAFT(3000, "保存盘存草稿"),
READ_End(3001, "结束盘存任务"),
;
public Integer id; public Integer id;
......
...@@ -493,14 +493,27 @@ public class PackingController { ...@@ -493,14 +493,27 @@ public class PackingController {
@ApiOperation(value = "判断序列号区间是否存在") @ApiOperation(value = "判断序列号区间是否存在")
@PostMapping("/seqsExist/{id}/{num}/{seq}") @PostMapping("/seqsExist/{id}/{num}/{seq}")
public ResponseEntity seqsExist(@PathVariable("id") int id,@PathVariable("num") int num,@PathVariable("seq") String seq){ public ResponseEntity seqsExist(@PathVariable("id") int id,@PathVariable("num") int num,@PathVariable("seq") String seq){
// List<DeviceLibrary> deviceLibraries = packingLibraryService.getAllDevSeqs(id); List<DeviceLibrary> deviceLibraries = packingLibraryService.getAllDevSeqs(id);
List<DeviceLibrary> deviceLibraries = deviceLibraryCacheService.getAllDeviceLibraryList(); // List<DeviceLibrary> deviceLibraries = deviceLibraryCacheService.getAllDeviceLibraryList();
List<String> existSeqs = deviceLibraries.stream().map(DeviceLibrary::getSeqNumber).collect(Collectors.toList()); List<String> existSeqs = deviceLibraries.stream().map(DeviceLibrary::getSeqNumber).collect(Collectors.toList());
//输入的区间序列号
List<String> inputSeqs = DeviceSeqUtil.selectDeviceSeqs(seq); List<String> inputSeqs = DeviceSeqUtil.selectDeviceSeqs(seq);
List<String> hasApplySeqs = deviceLibraries.stream() List<String> hasApplySeqs = deviceLibraries.stream()
.filter(deviceLibrary -> deviceLibrary.getApplyTaskId()!=null) .filter(deviceLibrary -> deviceLibrary.getApplyTaskId()!=null)
.map(DeviceLibrary::getSeqNumber) .map(DeviceLibrary::getSeqNumber)
.collect(Collectors.toList()); .collect(Collectors.toList());
//新增判断
if (!inputSeqs.isEmpty()){
for (String inputSeq : inputSeqs) {
if (!existSeqs.contains(inputSeq)){
return ResponseEntity.ok("序列号为"+inputSeq+"与型号不匹配");
}
if (deviceLibraryService.findBySeqNumber(inputSeq).getPackingId() != id){
return ResponseEntity.ok("序列号为"+inputSeq+"与型号不匹配");
}
}
}
if (inputSeqs.size()!=num){ if (inputSeqs.size()!=num){
return ResponseEntity.ok("序列号区间总数为"+inputSeqs.size()+",与装备数量不匹配"); return ResponseEntity.ok("序列号区间总数为"+inputSeqs.size()+",与装备数量不匹配");
} }
...@@ -1008,7 +1021,7 @@ public class PackingController { ...@@ -1008,7 +1021,7 @@ public class PackingController {
packingLogService.add(packingLog); packingLogService.add(packingLog);
packingLibrary.setFileDb(FilesUtil.stringFileToList(packingLibraryUpdateVo.getFileList())); packingLibrary.setFileDb(FilesUtil.stringFileToList(packingLibraryUpdateVo.getFileList()));
} }
packingLibraryService.update(packingLibrary); PackingLibrary library = packingLibraryService.update(packingLibrary);
//发送阅知信息 //发送阅知信息
List<Integer> userIds = userPublicService.findOtherUser(userUtils.getCurrentUserId()); List<Integer> userIds = userPublicService.findOtherUser(userUtils.getCurrentUserId());
// originalMap.entrySet().forEach( // originalMap.entrySet().forEach(
...@@ -1022,7 +1035,7 @@ public class PackingController { ...@@ -1022,7 +1035,7 @@ public class PackingController {
MessageBto messageBto = new MessageBto(0, 1, "修改" + packingLibraryUpdateVo.getModel() + "列装信息:原" + mapToString(originalMap) + "-->现" + mapToString(nowMap), userIds, 0); MessageBto messageBto = new MessageBto(0, 1, "修改" + packingLibraryUpdateVo.getModel() + "列装信息:原" + mapToString(originalMap) + "-->现" + mapToString(nowMap), userIds, 0);
messageService.add(messageBto); messageService.add(messageBto);
} }
return ResponseEntity.ok("编辑成功"); return ResponseEntity.ok(library);
} }
......
...@@ -61,6 +61,7 @@ public class PackingLibraryController { ...@@ -61,6 +61,7 @@ public class PackingLibraryController {
@ApiOperation(value = "申请后入库获取父子结构列装(去除已入库序列号)", notes = "获取父子结构列装") @ApiOperation(value = "申请后入库获取父子结构列装(去除已入库序列号)", notes = "获取父子结构列装")
@PostMapping("/merge") @PostMapping("/merge")
public ResponseEntity merge(@RequestBody List<PackingLibrary> packingLibraries){ public ResponseEntity merge(@RequestBody List<PackingLibrary> packingLibraries){
List<MergeVo> mergeVos = new ArrayList<>();
Map<String,DeviceLibrary> map = deviceLibraryService.getAllDeviceSeqMap(); Map<String,DeviceLibrary> map = deviceLibraryService.getAllDeviceSeqMap();
packingLibraries.forEach(packingLibrary -> { packingLibraries.forEach(packingLibrary -> {
List<String> inputSeqs = DeviceSeqUtil.selectDeviceSeqs(packingLibrary.getSeq()); List<String> inputSeqs = DeviceSeqUtil.selectDeviceSeqs(packingLibrary.getSeq());
...@@ -72,8 +73,14 @@ public class PackingLibraryController { ...@@ -72,8 +73,14 @@ public class PackingLibraryController {
// }); // });
// packingLibrary.setSeq(StringSplitUtil.stringListToString(DeviceSeqUtil.getContinuousSeqs(outputSeqs))); // packingLibrary.setSeq(StringSplitUtil.stringListToString(DeviceSeqUtil.getContinuousSeqs(outputSeqs)));
packingLibrary.setSeq(StringSplitUtil.stringListToString(DeviceSeqUtil.getContinuousSeqs(inputSeqs))); packingLibrary.setSeq(StringSplitUtil.stringListToString(DeviceSeqUtil.getContinuousSeqs(inputSeqs)));
MergeVo mergeVo = new MergeVo();
mergeVo.setStorageCount(packingLibrary.getWaitNum());
// mergeVo.setPackingLibrary(packingLibrary);
mergeVo.setSeqInterval(packingLibrary.getSeq());
mergeVo.setSeqList(inputSeqs);
packingLibrary.setMergeVo(mergeVo);
}); });
//返回父子结构 //返回父子结构
Map<Integer, PackingLibrary> nodeCollect = Map<Integer, PackingLibrary> nodeCollect =
packingLibraries.stream().collect(Collectors.toMap(PackingLibrary::getId, packingLibrary -> packingLibrary)); packingLibraries.stream().collect(Collectors.toMap(PackingLibrary::getId, packingLibrary -> packingLibrary));
......
...@@ -3,6 +3,7 @@ package com.tykj.dev.device.packing.subject.domin; ...@@ -3,6 +3,7 @@ package com.tykj.dev.device.packing.subject.domin;
import com.tykj.dev.config.cache.ConfigCache; import com.tykj.dev.config.cache.ConfigCache;
import com.tykj.dev.device.file.entity.FileRet; import com.tykj.dev.device.file.entity.FileRet;
import com.tykj.dev.device.file.service.FilesUtil; import com.tykj.dev.device.file.service.FilesUtil;
import com.tykj.dev.device.packing.subject.vo.MergeVo;
import com.tykj.dev.misc.utils.SpringUtils; import com.tykj.dev.misc.utils.SpringUtils;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -304,6 +305,10 @@ public class PackingLibrary { ...@@ -304,6 +305,10 @@ public class PackingLibrary {
@ApiModelProperty(value = "等级") @ApiModelProperty(value = "等级")
private Integer level; private Integer level;
@Transient
@ApiModelProperty(value = "merge")
private MergeVo mergeVo;
public void addChildNode(PackingLibrary packingLibraryEntity) { public void addChildNode(PackingLibrary packingLibraryEntity) {
childs.add(packingLibraryEntity); childs.add(packingLibraryEntity);
......
package com.tykj.dev.device.packing.subject.vo;
import com.tykj.dev.device.packing.subject.domin.PackingLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author dengdiyi
*/
@Data
@ApiModel("合并vo")
@Repository
public class MergeVo {
@ApiModelProperty(name = "列装对象")
private PackingLibrary packingLibrary;
@ApiModelProperty(name = "入库数量",example = "1")
private Integer storageCount;
@ApiModelProperty(name = "生成的序列号区间",example = "1")
private String seqInterval;
@ApiModelProperty(name = "生成的序列号集合")
private List<String> seqList;
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>equip</artifactId>
<groupId>com.tykj</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.tykj.dev</groupId>
<artifactId>dev-readmachine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dev-readmachine</name>
<description>dev-readmachine</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tykj</groupId>
<artifactId>dev-library</artifactId>
</dependency>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>rfid</artifactId>
</dependency>
<dependency>
<groupId>com.tykj.dev</groupId>
<artifactId>socket</artifactId>
</dependency>
<dependency>
<groupId>com.zebra</groupId>
<artifactId>sdk1</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/ModuleAPI_J.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.tykj.dev.readmachine.devreadmachine;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {
"com.tykj.dev.*",
})
public class DevReadmachineApplication {
public static void main(String[] args) {
SpringApplication.run(DevReadmachineApplication.class, args);
}
}
package com.tykj.dev.readmachine.devreadmachine.Entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.*;
import java.util.Date;
/**
* @author zsp
* @create 2021/12/3 10:24
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update read_machine_bill set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("盘存账单")
public class ReadMachineBill {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ApiModelProperty(value = "盘存标题")
@Column(name = "title",columnDefinition = "TEXT")
private String title;
@CreatedBy
@ApiModelProperty(value = "创建用户id")
private Integer createUserId;
@ApiModelProperty(value = "操作单位的id")
private Integer createUnitId;
@ApiModelProperty(value = "删除标志位")
private Integer deleteTag = 0;
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
@LastModifiedBy
@ApiModelProperty(value = "更新用户id")
private Integer updateUserId;
@ApiModelProperty(value = "入库的数量")
private Integer readNum;
@ApiModelProperty(value = "账单的状态",notes = "0 是草稿 1 是已完成")
private Integer status;
/**
* 更新时间
*/
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "任务id")
@Transient
private Integer taskId;
@ApiModelProperty(value = "操作人的名称")
@Transient
private String createUserName;
}
package com.tykj.dev.readmachine.devreadmachine.Entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
* @author zsp
* @create 2021/12/3 10:24
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update read_machine_ip set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("读写机ip表")
public class ReadMachineIp {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ApiModelProperty(value = "ip")
private String ip;
@ApiModelProperty(value = "子网掩码")
private String mask;
@ApiModelProperty(value = "网关")
private String gateway;
@ApiModelProperty(value = "读写机名称")
private String readMachineName;
@ApiModelProperty(value = "删除标志位")
private Integer deleteTag = 0;
@ApiModelProperty(value = "老的ip")
private String oldIp;
}
package com.tykj.dev.readmachine.devreadmachine.Entity;
import com.tykj.dev.config.cache.ConfigCache;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.misc.utils.SpringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
* @author zsp
* @create 2021/12/3 10:24
*/
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@SQLDelete(sql = "update read_machine_library set delete_tag = 1 where id = ?")
@Where(clause = "delete_tag = 0")
@ApiModel("盘存账单")
public class ReadMachineLibrary {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ApiModelProperty(value = "型号")
private String model;
@ApiModelProperty(value = "删除标志位")
private Integer deleteTag = 0;
/**
* 密级
*/
@ApiModelProperty(value = "密级")
private Integer secretLevel;
/**
* 装备名称
*/
@ApiModelProperty(value = "装备名称")
private String name;
/**
* 装备序列号
*/
@ApiModelProperty(value = "装备序列号")
private String seqNumber;
/**
* rfid卡号
*/
@ApiModelProperty(value = "rfid卡号")
private String rfidCardId;
@ApiModelProperty(value = "readMachineId",example = "111")
private Integer readMachineId;
@ApiModelProperty(value = "存放位置id")
private Integer storageLocationId;
@ApiModelProperty(value = "存放位置名称")
private String storageLocation;
@ApiModelProperty(value = "状态",notes = "0 是草稿或者未入库 1是入库")
private Integer status;
@ApiModelProperty(value = "所在单位")
private String locationUnit;
/**
* 所属单位
*/
@ApiModelProperty(value = "所属单位")
private String ownUnit;
@ApiModelProperty(value = "生命状态")
private Integer lifeStatus;
@CreatedDate
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
* 更新时间
*/
@LastModifiedDate
@ApiModelProperty(value = "更新时间")
private Date updateTime;
@ApiModelProperty(value = "生命状态")
@Transient
private String lifeStatusName;
public ReadMachineLibrary setConfigName(){
ConfigCache configCache = SpringUtils.getBean("initConfigCache");
if (configCache != null) {
setLifeStatusName(configCache.getLifeStatusMap().get(this.lifeStatus)==null?"-":configCache.getLifeStatusMap().get(this.lifeStatus));
}
return this;
}
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 12:31
*/
@Data
@ApiModel("读取装备信息的vo")
public class ReadDeviceVo {
@ApiModelProperty(value = "装备RFID集合")
private List<String> rfids;
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 12:31
*/
@Data
@ApiModel("保存草稿返回前端的vo")
public class SaveDefatVos {
@ApiModelProperty(value = "保存盘存库的vo的集合")
private List<ReadMachineLibrary> readMachineLibraries;
@ApiModelProperty(value = "任务id")
private Integer taskId;
@ApiModelProperty(value = "账单的id")
private Integer readMachineBillId;
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.util.Date;
/**
* @author zsp
* @create 2021/12/3 12:31
*/
@Data
@ApiModel("保存盘存库的vo")
public class SaveReadMachineVo {
@ApiModelProperty(value = "装备的id")
private Integer deviceId;
@ApiModelProperty(value = "装备的型号")
private String model;
@ApiModelProperty(value = "装备的名称")
private String name;
@ApiModelProperty(value = "装备的序列号")
private String seqNumber;
@ApiModelProperty(value = "rfid表面号")
private String rfidCardId;
@ApiModelProperty(value = "存放位置")
private Integer storageLocationId;
@ApiModelProperty(value = "存放位置名称")
private String storageLocation;
@ApiModelProperty(value = "状态",notes = "0 是草稿或者未入库 1是入库")
private Integer status = 0;
@ApiModelProperty(value = "所在单位")
private String locationUnit;
@ApiModelProperty(value = "生命状态")
private Integer lifeStatus;
/**
* 所属单位
*/
@ApiModelProperty(value = "所属单位")
private String ownUnit;
public ReadMachineLibrary toEntity(){
ReadMachineLibrary readMachineLibrary = new ReadMachineLibrary();
BeanUtils.copyProperties(this,readMachineLibrary);
return readMachineLibrary;
}
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 12:31
*/
@Data
@ApiModel("保存盘存库的vos")
public class SaveReadMachineVos {
@ApiModelProperty(value = "保存盘存库的vo的集合")
private List<SaveReadMachineVo> saveReadMachineVo;
@ApiModelProperty(value = "任务id")
private Integer taskId;
@ApiModelProperty(value = "标题")
private String title;
@ApiModelProperty(value = "入库的数量")
private Integer readNum;
}
package com.tykj.dev.readmachine.devreadmachine.Vo;
import com.tykj.dev.misc.base.CustomPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author zsp
* @create 2021/12/3 11:22
*/
@Data
@ApiModel("查询账单vo")
public class SelectBillVo extends CustomPage {
@ApiModelProperty(value = "开始时间")
private Date startTime;
@ApiModelProperty(value = "结束时间")
private Date endTime;
// @ApiModelProperty(value = "当前登录的单位id")
// private Integer unitId;
}
package com.tykj.dev.readmachine.devreadmachine.controller;
import cn.hutool.core.util.ObjectUtil;
import com.tykj.dev.config.swagger.AutoDocument;
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.user.cache.UserCache;
import com.tykj.dev.misc.base.BusinessEnum;
import com.tykj.dev.misc.utils.*;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineBill;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import com.tykj.dev.readmachine.devreadmachine.Vo.*;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineBillService;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineIpService;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineLibraryService;
import com.tykj.dev.readmachine.devreadmachine.socket.ReadWebSocket;
import com.tykj.dev.readmachine.devreadmachine.toBack.BackReadDetailVo;
import com.tykj.dev.readmachine.devreadmachine.util.ReadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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.*;
import java.util.stream.Collectors;
/**
* @author zsp
* @create 2021/12/3 10:59
*/
@RestController
@RequestMapping(value = "/readMachine")
@AutoDocument
@Api(tags = "盘存模块", description = "盘存接口")
@Validated
@Slf4j
public class ReadMachineBillController {
@Autowired
private ReadMachineBillService readMachineBillService;
@Resource
private DeviceLibraryService deviceLibraryService;
@Resource
private ReadWebSocket readWebSocket;
@Resource
private UserCache userCache;
@Autowired
private ReadMachineIpService readMachineIpService;
@Autowired
private ReadMachineLibraryService readMachineLibraryService;
private List<String> RFIDS = new ArrayList<>();
private List<String> existRFIDS = new ArrayList<>();
private List<String> notExistRFIDS = new ArrayList<>();
public static Boolean localFlag = false;
private List<DeviceLibrary> deviceLibraries = new ArrayList<>();
@Autowired
private TaskService taskService;
// static{
// //增加一个全局变量,只要加载过这个so就不再执行,除非进程重启才会清掉该变量。
// if(System.getProperty("myapplibrary")==null){
// log.info("myapplibrary:{}",System.getProperty("myapplibrary"));
// System.setProperty("myapplibrary", "libModuleAPIJni.so");
//// System.loadLibrary("libModuleAPIJni");
// System.load("/usr/lib/libModuleAPIJni.so");
// }
// }
@ApiOperation(value = "保存盘存接口", notes = "保存盘存接口")
@PostMapping(value = "/addReadMachineBill")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> addReadMachineBill(@RequestBody SaveReadMachineVos saveReadMachineVos) {
readMachineBillService.saveReadMachineBill(saveReadMachineVos);
return ResponseEntity.ok("保存成功");
}
@ApiOperation(value = "保存盘存草稿接口", notes = "保存盘存草稿接口")
@PostMapping(value = "/saveReadMachineBillForDraft")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> saveReadMachineBillForDraft(@RequestBody SaveReadMachineVos saveReadMachineVos) {
readMachineBillService.saveReadMachineBillForDraft(saveReadMachineVos);
return ResponseEntity.ok("保存草稿成功");
}
@ApiOperation(value = "查询账单的接口", notes = "查询账单的接口")
@PostMapping(value = "/findAllBySpec")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<Page<ReadMachineBill>> findAllBySpec(@RequestBody SelectBillVo selectBillVo) {
List<ReadMachineBill> spec = readMachineBillService.findAllBySpec(selectBillVo);
spec.forEach(readMachineBill -> {
readMachineBill.setCreateUserName(
userCache.findById(readMachineBill.getCreateUserId()).getName());
readMachineBill.setTaskId(taskService.get(readMachineBill.getId(), BusinessEnum.READMACHINE.id).getId());
});
Page<ReadMachineBill> perPage = PageUtil.getPerPage(selectBillVo.getPage(), selectBillVo.getSize(),spec, selectBillVo.getPageable());
return ResponseEntity.ok(perPage);
}
@ApiOperation(value = "读取装备信息对比的接口", notes = "读取装备信息对比的接口")
@GetMapping(value = "/compareDeviceDetail")
@Transactional(rollbackFor = Exception.class)
public void readDeviceDetail(Boolean flag) {
if (flag) {
if (!localFlag) {
localFlag = true;
startDeviceDetail();
}
} else {
localFlag = false;
}
}
@ApiOperation(value = "查询详情接口", notes = "查询详情接口")
@GetMapping(value = "/readDetail")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<BackReadDetailVo> readDetail(Integer billId) {
BackReadDetailVo backReadDetailVo = new BackReadDetailVo();
ReadMachineBill readMachineBill = readMachineBillService.findById(billId);
List<ReadMachineLibrary> readMachineLibraryList =
readMachineLibraryService.findByReadMachineBillId(readMachineBill.getId());
readMachineLibraryList.forEach(ReadMachineLibrary::setConfigName);
backReadDetailVo.setReadNum(readMachineBill.getReadNum());
backReadDetailVo.setReadMachineLibraries(readMachineLibraryList);
backReadDetailVo.setCreateUserName(userCache.findById(readMachineBill.getCreateUserId()).getName());
return ResponseEntity.ok(backReadDetailVo);
}
@ApiOperation(value = "读取ISO放置的位置", notes = "读取ISO放置的位置")
@GetMapping(value = "/receiveString")
public ResponseEntity<String> receiveString() {
return ResponseEntity.ok(System.getProperty("java.library.path"));
}
@ApiOperation(value = "任务不保存", notes = "任务不保存")
@PostMapping(value = "/notSaveTask")
public ResponseEntity<String> notSaveTask(@RequestBody SaveDefatVos saveDefatVos) {
readMachineBillService.deleteReadMachineBillForDraft(saveDefatVos);
return ResponseEntity.ok("任务已取消");
}
/**
* 读取装备信息
*/
public List<DeviceLibrary> startDeviceDetail(){
ReadUtils readUtils = new ReadUtils();
//先获取ip1
//TODO 后续考虑做成ip的选择,目前先写死
String ip = readMachineIpService.findById(1).getIp();
//先开启
readUtils.testinitreader(ip);
while (localFlag){
//开始盘存
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());
if (!deviceLibraries.isEmpty()){
deviceLibraries.forEach(deviceLibrary -> {
if (ObjectUtil.isNotNull(deviceLibrary)){
deviceLibrary.setConfigName();
readWebSocket.sendMessageForReadMachine(deviceLibrary);
}
});
}
}
return deviceLibraries;
}
}
package com.tykj.dev.readmachine.devreadmachine.controller;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineIp;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineIpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author zsp
* @create 2021/12/3 10:59
*/
@RestController
@RequestMapping(value = "/readIp")
@AutoDocument
@Api(tags = "修改ip", description = "修改ip")
@Slf4j
public class ReadMachineIpController {
@Autowired
private ReadMachineIpService readMachineIpService;
@ApiOperation(value = "修改ip的接口", notes = "修改ip的接口")
@PostMapping(value = "/updateIp")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<ReadMachineIp> updateIp(@RequestBody ReadMachineIp readMachineIp) {
ReadMachineIp readMachineIp1 = readMachineIpService.updateIp(readMachineIp);
return ResponseEntity.ok(readMachineIp1);
}
@ApiOperation(value = "新增ip接口", notes = "新增ip接口")
@PostMapping(value = "/addIp")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<String> addIp(@RequestBody ReadMachineIp readMachineIp) {
//先判断名称是否存在
List<String> names =
readMachineIpService.findAll().stream().map(ReadMachineIp::getReadMachineName).collect(Collectors.toList());
if (!names.isEmpty()){
if (names.contains(readMachineIp.getReadMachineName())){
throw new ApiException("该名称已经存在,请更换名称");
}
}
readMachineIpService.addIp(readMachineIp);
return ResponseEntity.ok("新增ip成功");
}
@ApiOperation(value = "查询ip列表", notes = "查询ip列表")
@PostMapping(value = "/findAllIp")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<List<ReadMachineIp>> findAllIp() {
List<ReadMachineIp> readMachineIpList = readMachineIpService.findAll();
return ResponseEntity.ok(readMachineIpList);
}
@ApiOperation(value = "选中要使用的读写机", notes = "选中要使用的读写机")
@GetMapping(value = "/selectIp")
@Transactional(rollbackFor = Exception.class)
public ResponseEntity<ReadMachineIp> selectIp(Integer id) {
ReadMachineIp readMachineIp = readMachineIpService.findById(id);
return ResponseEntity.ok(readMachineIp);
}
}
package com.tykj.dev.rfid.controller; package com.tykj.dev.readmachine.devreadmachine.controller;
import com.tykj.dev.config.swagger.AutoDocument; import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.rfid.timeTask.ReadUtils; import com.tykj.dev.readmachine.devreadmachine.Vo.SaveReadMachineVos;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineBillService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/** /**
* @author zsp * @author zsp
* @create 2021/12/2 10:39 * @create 2021/12/3 10:59
*/ */
@RestController @RestController
@Api(tags = "读写机模块", description = "读写机模块") @RequestMapping(value = "/readMachineLibrary")
@AutoDocument @AutoDocument
@RequestMapping("/readMachine") @Api(tags = "盘存库模块", description = "盘存库接口")
@Slf4j @Slf4j
public class ReadController { public class ReadMachineLibraryController {
@Resource
private ReadMachineBillService readMachineBillService;
@PostMapping("/startReadMachine")
@ApiOperation(value = "开始扫描读写机")
public ResponseEntity startReadMachine(){
ReadUtils readUtils = new ReadUtils();
//先开启
readUtils.testinitreader();
//开始盘存
readUtils.testinventory1();
//关闭
readUtils.getJreader().CloseReader();
return ResponseEntity.ok("读写成功");
}
} }
package com.tykj.dev.readmachine.devreadmachine.repository;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineBill;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
/**
* @author zsp
* @create 2021/12/3 10:52
*/
public interface ReadMachineBillDao extends JpaRepository<ReadMachineBill,Integer>, JpaSpecificationExecutor<ReadMachineBill> {
}
package com.tykj.dev.readmachine.devreadmachine.repository;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineIp;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 10:52
*/
public interface ReadMachineIpDao extends JpaRepository<ReadMachineIp,Integer>, JpaSpecificationExecutor<ReadMachineIp> {
}
package com.tykj.dev.readmachine.devreadmachine.repository;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineBill;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 10:52
*/
public interface ReadMachineLibraryDao extends JpaRepository<ReadMachineLibrary,Integer>, JpaSpecificationExecutor<ReadMachineLibrary> {
List<ReadMachineLibrary> findAllByReadMachineId(Integer readMachineId);
}
package com.tykj.dev.readmachine.devreadmachine.service;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineBill;
import com.tykj.dev.readmachine.devreadmachine.Vo.SaveDefatVos;
import com.tykj.dev.readmachine.devreadmachine.Vo.SaveReadMachineVo;
import com.tykj.dev.readmachine.devreadmachine.Vo.SaveReadMachineVos;
import com.tykj.dev.readmachine.devreadmachine.Vo.SelectBillVo;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 10:59
*/
public interface ReadMachineBillService {
/**
* 新增读写盘存账单
* @param readMachineBill 账单实体
* @return 账单实体
*/
ReadMachineBill addEntity(ReadMachineBill readMachineBill);
/**
* 根据id查询账单
* @param id 账单id
* @return 账单实体
*/
ReadMachineBill findById(Integer id);
/**
* 更新实体
* @param readMachineBill 需要修改账单的实体
* @return 更新后的实体
*/
ReadMachineBill updateEntity(ReadMachineBill readMachineBill);
void deleteEntity(Integer id);
/**
* 条件查询
* @param selectBillVo 查询条件的vo
* @return 账单实体的集合
*/
List<ReadMachineBill> findAllBySpec(SelectBillVo selectBillVo);
/**
* 开始盘点s
* @param saveReadMachineVos 盘点的vo
* @return 账单实体
*/
ReadMachineBill saveReadMachineBill(SaveReadMachineVos saveReadMachineVos);
/**
* 保存草稿
* @param saveReadMachineVos 盘点的vos
* @return 账单实体
*/
SaveDefatVos saveReadMachineBillForDraft(SaveReadMachineVos saveReadMachineVos);
/**
* 删除草稿
* @param saveDefatVos saveDefatVos
*/
void deleteReadMachineBillForDraft(SaveDefatVos saveDefatVos);
}
package com.tykj.dev.readmachine.devreadmachine.service;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineIp;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 10:59
*/
public interface ReadMachineIpService {
/**
* add
* @param machineIp addIp
*/
void addIp(ReadMachineIp machineIp);
/**
* update
* @param machineIp updateIp
*/
ReadMachineIp updateIp(ReadMachineIp machineIp);
/**
* 根据id查询
*/
ReadMachineIp findById(Integer id);
/**
* 查询全部
*/
List<ReadMachineIp> findAll();
void deleteById(Integer id);
ReadMachineIp findByName(String name);
}
package com.tykj.dev.readmachine.devreadmachine.service;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 10:59
*/
public interface ReadMachineLibraryService {
/**
* 新增盘存库
* @param readMachineLibrary 盘存库实体
* @return 盘存库实体
*/
ReadMachineLibrary addEntity(ReadMachineLibrary readMachineLibrary);
void batchDeleteEntity(List<ReadMachineLibrary> readMachineLibraries);
/**
* 根据账单id查询盘存库
* @param readMachineBillId 账单id
* @return 盘存库的集合
*/
List<ReadMachineLibrary> findByReadMachineBillId(Integer readMachineBillId);
/**
* 保存全部
* @param readMachineLibraries 全部的实体
*/
void saveAll(List<ReadMachineLibrary> readMachineLibraries);
/**
* 批量更新
*/
void batchUpdate(List<ReadMachineLibrary> readMachineLibraries);
}
package com.tykj.dev.readmachine.devreadmachine.service.impl;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.dev.device.library.repository.DeviceLibraryPositionDao;
import com.tykj.dev.device.library.service.DeviceLibraryPositionService;
import com.tykj.dev.device.library.subject.domin.DeviceLibraryPosition;
import com.tykj.dev.device.user.util.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
/**
* @author zsp
* @create 2021/12/13 16:23
*/
@Service
public class DeviceLibraryPositionServiceImpl implements DeviceLibraryPositionService {
@Autowired
private UserUtils userUtils;
@Autowired
private DeviceLibraryPositionDao deviceLibraryPositionDao;
@Override
public void addDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition) {
deviceLibraryPositionDao.save(deviceLibraryPosition);
}
@Override
public void updateDeviceLibraryPosition(DeviceLibraryPosition deviceLibraryPosition) {
deviceLibraryPositionDao.save(deviceLibraryPosition);
}
@Override
public void batchDeviceLibraryPositions(List<DeviceLibraryPosition> deviceLibraryPositions) {
deviceLibraryPositionDao.saveAll(deviceLibraryPositions);
}
@Override
public List<DeviceLibraryPosition> findByStorageLocationId(Integer StorageLocationId) {
return deviceLibraryPositionDao.findAllByStorageLocationId(StorageLocationId);
}
@Override
public DeviceLibraryPosition findById(Integer id) {
DeviceLibraryPosition deviceLibraryPosition = new DeviceLibraryPosition();
Optional<DeviceLibraryPosition> positionDaoById = deviceLibraryPositionDao.findById(id);
if(positionDaoById.isPresent()){
deviceLibraryPosition = positionDaoById.get();
}
return deviceLibraryPosition;
}
@Override
public void deleteByPosition(Integer id) {
deviceLibraryPositionDao.deleteById(id);
}
}
package com.tykj.dev.readmachine.devreadmachine.service.impl;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineIp;
import com.tykj.dev.readmachine.devreadmachine.repository.ReadMachineIpDao;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineIpService;
import com.tykj.dev.readmachine.devreadmachine.util.ReadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Optional;
/**
* @author zsp
* @create 2021/12/14 13:18
*/
@Service
@Slf4j
public class ReadMachineIpServiceImpl implements ReadMachineIpService {
@Autowired
private ReadMachineIpDao readMachineIpDao;
@Override
public void addIp(ReadMachineIp machineIp) {
readMachineIpDao.save(machineIp);
}
@Override
public ReadMachineIp updateIp(ReadMachineIp machineIp) {
ReadUtils readUtils = new ReadUtils();
readUtils.testinitreader(machineIp.getOldIp());
try {
readUtils.testsetip(machineIp.getIp(),machineIp.getMask(), machineIp.getGateway());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("e = " + e);
}
log.info("读写机ip修改成功");
machineIp.setOldIp(machineIp.getIp());
return readMachineIpDao.save(machineIp);
}
@Override
public ReadMachineIp findById(Integer id) {
Optional<ReadMachineIp> re = readMachineIpDao.findById(id);
ReadMachineIp readMachineIp = new ReadMachineIp();
if (re.isPresent()){
readMachineIp = re.get();
}
return readMachineIp;
}
@Override
public List<ReadMachineIp> findAll() {
return readMachineIpDao.findAll();
}
@Override
public void deleteById(Integer id) {
readMachineIpDao.deleteById(id);
}
@Override
public ReadMachineIp findByName(String name) {
return null;
}
}
package com.tykj.dev.readmachine.devreadmachine.service.impl;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import com.tykj.dev.readmachine.devreadmachine.repository.ReadMachineLibraryDao;
import com.tykj.dev.readmachine.devreadmachine.service.ReadMachineLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author zsp
* @create 2021/12/3 11:00
*/
@Service
public class ReadMachineLibraryServiceImpl implements ReadMachineLibraryService {
@Autowired
private ReadMachineLibraryDao readMachineLibraryDao;
/**
* 新增盘存库
*
* @param readMachineLibrary 盘存库实体
* @return 盘存库实体
*/
@Override
public ReadMachineLibrary addEntity(ReadMachineLibrary readMachineLibrary) {
return readMachineLibraryDao.save(readMachineLibrary);
}
@Override
public void batchDeleteEntity(List<ReadMachineLibrary> readMachineLibraries) {
readMachineLibraryDao.deleteAll(readMachineLibraries);
}
/**
* 根据账单id查询盘存库
*
* @param readMachineBillId 账单id
* @return 盘存库的集合
*/
@Override
public List<ReadMachineLibrary> findByReadMachineBillId(Integer readMachineBillId) {
return readMachineLibraryDao.findAllByReadMachineId(readMachineBillId);
}
/**
* 保存全部
*
* @param readMachineLibraries 全部的实体
*/
@Override
public void saveAll(List<ReadMachineLibrary> readMachineLibraries) {
readMachineLibraryDao.saveAll(readMachineLibraries);
}
@Override
public void batchUpdate(List<ReadMachineLibrary> readMachineLibraries) {
readMachineLibraryDao.saveAll(readMachineLibraries);
}
}
package com.tykj.dev.readmachine.devreadmachine.socket;
/**
* @author zjm
* @version 1.0.0
* @ClassName Message.java
* @Description TODO
* @createTime 2020年08月23日 12:30:00
*/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Message {
private Integer isRequest;
}
package com.tykj.dev.readmachine.devreadmachine.socket;
/**
* zsp
*/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MessageError {
private String rfid;
private String message;
}
package com.tykj.dev.readmachine.devreadmachine.socket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tykj.dev.readmachine.devreadmachine.controller.ReadMachineBillController;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author zjm
* @version 1.0.0
* @ClassName MyWebSocket.java
* @Description TODO
* @createTime 2020年08月19日 23:53:00
*/
@Slf4j
@ServerEndpoint(value = "/websocket/{userId}") //接受websocket请求路径
@Component //注册到spring容器中
@Data
public class ReadWebSocket {
/**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
*/
private static ConcurrentHashMap<String, ReadWebSocket> webSocketMap = new ConcurrentHashMap<>();
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
/**
* 接收userId
*/
private String userId;
/**
* 发送自定义消息
*/
public static void sendInfo(String message, String userId) throws IOException {
log.info("发送消息到:" + userId + ",报文:" + message);
if (StringUtils.isNotBlank(userId) && webSocketMap.containsKey(userId)) {
webSocketMap.get(userId).sendMessage(message);
} else {
log.error("用户" + userId + ",不在线!");
}
}
/**
* 连接建立成功调用的方法
*/
@OnOpen
public void onOpen(Session session, @PathParam("userId") String userId) {
this.session = session;
this.userId = userId;
if (webSocketMap.containsKey(userId)) {
webSocketMap.remove(userId);
webSocketMap.put(userId, this);
//加入set中
} else {
webSocketMap.put(userId, this);
//加入set中
//在线数加1
}
log.info("用户连接:" + userId + ",当前在线人数为:" + webSocketMap.size());
sendMessage("连接成功");
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
//从set中删除
webSocketMap.remove(userId);
if (webSocketMap.size() == 0){
ReadMachineBillController.localFlag= false;
}
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
}
public void Close(String userId) {
//从set中删除
webSocketMap.remove(userId);
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
}
public ReadWebSocket getMap(String userId) {
ReadWebSocket myWebSocket = webSocketMap.get(userId);
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
return myWebSocket;
}
/**
* 收到客户端消息后调用的方法
* @param message 客户端发送过来的消息
*/
@OnMessage
public void onMessage(String message, Session session) {
log.info("用户消息:" + userId + ",报文:" + message);
//可以群发消息
//消息保存到数据库、redis
if (StringUtils.isNotBlank(message)) {
try {
//解析发送的报文
JSONObject jsonObject = JSON.parseObject(message);
//追加发送人(防止串改)
jsonObject.put("fromUserId", this.userId);
String toUserId = jsonObject.getString("toUserId");
//传送给对应toUserId用户的websocket
if (StringUtils.isNotBlank(toUserId) && webSocketMap.containsKey(toUserId)) {
webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
} else {
log.error("请求的userId:" + toUserId + "不在该服务器上");
//否则不在这个服务器上,发送到mysql或者redis
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("用户错误:" + this.userId + ",原因:" + error.getMessage());
error.printStackTrace();
}
/**
* 实现服务器主动推送
*/
public void sendMessage(String message) {
try {
this.session.getBasicRemote().sendText(JSONObject.toJSONString(new Message(1)));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 实现服务器主动推送
*/
public void sendMessage2(Object o) {
try {
this.session.getBasicRemote().sendText(JSONObject.toJSONString(o));
} catch (IOException e) {
e.printStackTrace();
}
}
public void sendMessage1() {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage("1");
}
}
public void sendMessageForReadMachine(Object o) {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage2(o);
}
}
public void sendMessageForReadMachine1(Object o,Integer userId) {
webSocketMap.get(String.valueOf(userId)).sendMessage2(o);
}
public void sendMessageForReadMachineError(String rfid) {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage2(new MessageError(rfid,"该RFID为:"+rfid+"设备查询不到"));
}
}
/**
* 判断是否断开连接,断开返回true,没有返回false
* @param socket
* @return
*/
// public Boolean isServerClose(Socket socket){
// try{
// socket.sendUrgentData(0xFF);//发送1个字节的紧急数据,默认情况下,服务器端没有开启紧急数据处理,不影响正常通信
// return false;
// }catch(Exception se){
// return true;
// }
// }
}
package com.tykj.dev.readmachine.devreadmachine.toBack;
import com.tykj.dev.readmachine.devreadmachine.Entity.ReadMachineLibrary;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zsp
* @create 2021/12/7 9:24
*/
@Data
@ApiModel("详情的返回vo")
public class BackReadDetailVo {
@ApiModelProperty(value = "本次盘存的盘存库")
private List<ReadMachineLibrary> readMachineLibraries;
@ApiModelProperty(value = "操作人")
private String createUserName;
@ApiModelProperty(value = "本次盘存的数量")
private Integer readNum;
}
package com.tykj.dev.readmachine.devreadmachine.util;
import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author zsp
* @create 2021/12/7 10:15
*/
public class BeanDtoVoUtils {
/**
* TODO dot ,Do ,entity 相互转换
* 同:BeanUtils.copyProperties(dtoEntity, newInstance);
*
* @param oldClass 原数据--Dto,Vo,entity
* @param newClass 转换为--Dto,Vo,entity
* @return
*/
public static <E> E convert(Object oldClass, Class<E> newClass) {
// 判断oldClass 是否为空!
if (oldClass == null) {
return null;
}
// 判断newClass 是否为空
if (newClass == null) {
return null;
}
try {
// 创建新的对象实例
E newInstance = newClass.newInstance();
// 把原对象数据拷贝到新的对象
BeanUtils.copyProperties(oldClass, newInstance);
// 返回新对象
return newInstance;
} catch (Exception e) {
return null;
}
}
//TODO Page<Entity> 分页对象转 Page<Vo> ( list 循环)
public static <T, V> Page<V> pageVo(Page<T> page, Class<V> v) {
try {
List<T> tList = page.getContent();
List<V> voList = new ArrayList<>();
for (T t : tList) {
V newv = (V) BeanDtoVoUtils.convert(t, v.newInstance().getClass());
voList.add(newv);
}
Page<V> vs = new PageImpl<>(voList, page.getPageable(), page.getTotalElements());
return vs;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//TODO Page<Entity> 分页对象转 Page<Vo> (Stream 方式)
public static <T, V> Page<V> pageVoStream(Page<T> page, Class<V> v) {
List<V> voList = page.getContent().stream().map(item -> {
try {
return (V) BeanDtoVoUtils.convert(item, v.newInstance().getClass());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
Page<V> vs = new PageImpl<>(voList, page.getPageable(), page.getTotalElements());
return vs;
}
//TODO list<Entity> 集合对象转list<Vo> ( list 循环)
public static <T, V> List<V> listVo(List<T> oldList, Class<V> v) {
try {
List<V> voList = new ArrayList<>();
for (T t : oldList) {
V newv = (V) BeanDtoVoUtils.convert(t, v.newInstance().getClass());
voList.add(newv);
}
return voList;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
//TODO list<Entity> 集合对象转list<Vo> (Stream 方式)
public static <T, V> List<V> listVoStream(List<T> oldList, Class<V> v) {
List<V> voList = oldList.stream().map(item -> {
try {
return (V) BeanDtoVoUtils.convert(item, v.newInstance().getClass());
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
return voList;
}
}
package com.tykj.dev.readmachine.devreadmachine;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DevReadmachineApplicationTests {
@Test
void contextLoads() {
}
}
...@@ -37,13 +37,13 @@ ...@@ -37,13 +37,13 @@
<systemPath>${project.basedir}/src/main/resources/lib/ZSDK_API.jar</systemPath> <systemPath>${project.basedir}/src/main/resources/lib/ZSDK_API.jar</systemPath>
</dependency> </dependency>
<dependency> <!--<dependency>
<groupId>com.zebra</groupId> <groupId>com.zebra</groupId>
<artifactId>sdk1</artifactId> <artifactId>sdk1</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/ModuleAPI_Java_2.2.0.0.jar</systemPath> <systemPath>${project.basedir}/src/main/resources/lib/ModuleAPI_Java_2.2.0.0.jar</systemPath>
</dependency> </dependency>-->
<dependency> <dependency>
<groupId>com.rfid</groupId> <groupId>com.rfid</groupId>
......
...@@ -27,6 +27,8 @@ public class InventoryThread extends Thread { ...@@ -27,6 +27,8 @@ public class InventoryThread extends Thread {
private static int CURRENT_READ_POINT = 0; private static int CURRENT_READ_POINT = 0;
private final int ANT_COUNT = 2; private final int ANT_COUNT = 2;
private final String PanIP = "192.168.101.201";
/** /**
* 每次盘存的临时变量 * 每次盘存的临时变量
*/ */
...@@ -137,12 +139,12 @@ public class InventoryThread extends Thread { ...@@ -137,12 +139,12 @@ public class InventoryThread extends Thread {
@Override @Override
public void run() { public void run() {
mReaderHelper = mConnector.connectNet("192.168.0.178", 4001); mReaderHelper = mConnector.connectNet(PanIP, 8080);
if (mReaderHelper != null) { if (mReaderHelper != null) {
try { try {
mReaderHelper.registerObserver(mObserver); mReaderHelper.registerObserver(mObserver);
//默认切换到默认天线 //默认切换到默认天线
changeAnt(currentAnt); // changeAnt(currentAnt);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
...@@ -151,6 +153,7 @@ public class InventoryThread extends Thread { ...@@ -151,6 +153,7 @@ public class InventoryThread extends Thread {
log.error("连接天线失败"); log.error("连接天线失败");
mConnector.disConnect(); mConnector.disConnect();
} }
readTag();
} }
/** /**
......
package com.tykj.dev.socket;
/**
* zsp
*/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MessageError {
private String rfid;
private String message;
}
...@@ -2,14 +2,17 @@ package com.tykj.dev.socket; ...@@ -2,14 +2,17 @@ package com.tykj.dev.socket;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.websocket.*; import javax.websocket.*;
import javax.websocket.server.PathParam; import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpoint;
import java.io.IOException; import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -20,8 +23,9 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -20,8 +23,9 @@ 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 = "/public/websocket/{userId}") //接受websocket请求路径
@Component //注册到spring容器中 @Component //注册到spring容器中
@Data
public class MyWebSocket { public class MyWebSocket {
/** /**
* concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 * concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
...@@ -66,12 +70,13 @@ public class MyWebSocket { ...@@ -66,12 +70,13 @@ public class MyWebSocket {
//加入set中 //加入set中
//在线数加1 //在线数加1
} }
log.info("用户连接:" + userId + ",当前在线人数为:" + webSocketMap.size()); log.info("用户连接:" + userId + ",当前在线人数为:" + webSocketMap.size());
sendMessage("连接成功"); sendMessage("连接成功");
} }
/** /**
* 连接关闭调用的方法 * 连接关闭调用的方法
*/ */
...@@ -89,9 +94,15 @@ public class MyWebSocket { ...@@ -89,9 +94,15 @@ public class MyWebSocket {
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size()); log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
} }
public MyWebSocket getMap(String userId) {
MyWebSocket myWebSocket = webSocketMap.get(userId);
log.info("用户退出:" + userId + ",当前在线人数为:" + webSocketMap.size());
return myWebSocket;
}
/** /**
* 收到客户端消息后调用的方法 * 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息 * @param message 客户端发送过来的消息
*/ */
@OnMessage @OnMessage
...@@ -141,10 +152,55 @@ public class MyWebSocket { ...@@ -141,10 +152,55 @@ public class MyWebSocket {
} }
} }
/**
* 实现服务器主动推送
*/
public void sendMessage2(Object o) {
try {
this.session.getBasicRemote().sendText(JSONObject.toJSONString(o));
} catch (IOException 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");
} }
} }
public void sendMessageForReadMachine(Object o) {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage2(o);
}
}
public void sendMessageForReadMachine1(Object o,Integer userId) {
webSocketMap.get(String.valueOf(userId)).sendMessage2(o);
}
public void sendMessageForReadMachineError(String rfid) {
for (String i : webSocketMap.keySet()) {
webSocketMap.get(i).sendMessage2(new MessageError(rfid,"该RFID为:"+rfid+"设备查询不到"));
}
}
/**
* 判断是否断开连接,断开返回true,没有返回false
* @param socket
* @return
*/
// public Boolean isServerClose(Socket socket){
// try{
// socket.sendUrgentData(0xFF);//发送1个字节的紧急数据,默认情况下,服务器端没有开启紧急数据处理,不影响正常通信
// return false;
// }catch(Exception se){
// return true;
// }
// }
} }
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论