离线提醒

camera_merge
王一鸣 5 years ago
parent 017d3f1377
commit 4e5eb52d00

@ -1,11 +1,13 @@
package com.zhehekeji.web.controller; package com.zhehekeji.web.controller;
import com.github.pagehelper.PageInfo;
import com.zhehekeji.common.util.ValidatorUtil; import com.zhehekeji.common.util.ValidatorUtil;
import com.zhehekeji.core.pojo.Result; import com.zhehekeji.core.pojo.Result;
import com.zhehekeji.core.util.Assert; import com.zhehekeji.core.util.Assert;
import com.zhehekeji.web.entity.Order; import com.zhehekeji.web.entity.Order;
import com.zhehekeji.web.pojo.OrderSaveReq; import com.zhehekeji.web.pojo.OrderSaveReq;
import com.zhehekeji.web.pojo.OrderSearch; import com.zhehekeji.web.pojo.OrderSearch;
import com.zhehekeji.web.pojo.OrderVO;
import com.zhehekeji.web.service.OrderService; import com.zhehekeji.web.service.OrderService;
import com.zhehekeji.web.service.PlcService; import com.zhehekeji.web.service.PlcService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -48,12 +50,12 @@ public class OrderController {
return Result.success(); return Result.success();
} }
@ApiOperation("工单开始信号") // @ApiOperation("工单开始信号")
@GetMapping("/start") // @GetMapping("/start")
public Result orderStart(@ApiParam("工单号") @RequestParam String orderNum, @ApiParam("plc")@RequestParam String plcId){ // public Result orderStart(@ApiParam("工单号") @RequestParam String orderNum, @ApiParam("plc")@RequestParam String plcId){
plcService.orderStart(orderNum,plcId); // plcService.orderStart(orderNum,plcId);
return Result.success(); // return Result.success();
} // }
@ApiOperation("工单结束信号") @ApiOperation("工单结束信号")
@GetMapping("/stop") @GetMapping("/stop")
@ -79,24 +81,11 @@ public class OrderController {
@PostMapping("/list") @PostMapping("/list")
@ApiOperation(value = "查询") @ApiOperation(value = "查询")
//@SessionHandler //@SessionHandler
public Result<List<Order>> orders(@RequestBody OrderSearch orderSearch) { public Result<PageInfo<OrderVO>> orders(@RequestBody OrderSearch orderSearch) {
//validatorUtil.validate(orderSearch); //validatorUtil.validate(orderSearch);
return Result.success(orderService.orders(orderSearch)); return Result.success(orderService.orders(orderSearch));
} }
@GetMapping("/media")
//@ApiOperation(value = "视频测试")
//@SessionHandler(userType = UserType.ACCOUNT)
public void media() {
}
/*@GetMapping("/userCenter") /*@GetMapping("/userCenter")
@ApiOperation("用户中心地址") @ApiOperation("用户中心地址")
public Result<IndexVO> userCenter(){ public Result<IndexVO> userCenter(){

@ -49,11 +49,11 @@ public class PLCController {
@GetMapping("/disPlc") @GetMapping("/disPlc")
@ApiOperation(value = "未连接的PLC") @ApiOperation(value = "未连接的PLC")
public Result<List<StreetConn.PlcStatus>> disConn(){ public Result<List<StreetConn.PlcStatus>> disConn(){
return Result.success(plcService.disStreets()); return Result.success(StreetConn.disConnList());
} }
@GetMapping("/plcStatus") @GetMapping("/plcStatus")
@ApiOperation(value = "是否存在连接异常的PLC 返回 true 表示有存在异常的") @ApiOperation(value = "返回连接异常的PLC数量")
public Result<Integer> plcStatus(){ public Result<Integer> plcStatus(){
return Result.success(plcService.plcStatus()); return Result.success(plcService.plcStatus());
} }

@ -27,12 +27,12 @@ public class RealTimeController {
return Result.success(realTimeService.realTimes()); return Result.success(realTimeService.realTimes());
} }
@GetMapping("/lychee") // @GetMapping("/lychee")
@ApiOperation(value = "获取荔枝的ip") // @ApiOperation(value = "获取荔枝的ip")
//@SessionHandler // //@SessionHandler
public Result<String> lychee() { // public Result<String> lychee() {
return Result.success(realTimeService.lychee()); // return Result.success(realTimeService.lychee());
} // }
} }

@ -8,6 +8,7 @@ import com.zhehekeji.web.entity.Warn;
import com.zhehekeji.web.pojo.OrderSaveReq; import com.zhehekeji.web.pojo.OrderSaveReq;
import com.zhehekeji.web.pojo.OrderSearch; import com.zhehekeji.web.pojo.OrderSearch;
import com.zhehekeji.web.pojo.warn.WarnSearch; import com.zhehekeji.web.pojo.warn.WarnSearch;
import com.zhehekeji.web.pojo.warn.WarnVO;
import com.zhehekeji.web.service.OrderService; import com.zhehekeji.web.service.OrderService;
import com.zhehekeji.web.service.PlcService; import com.zhehekeji.web.service.PlcService;
import com.zhehekeji.web.service.WarnService; import com.zhehekeji.web.service.WarnService;
@ -33,24 +34,10 @@ public class WarnController {
@PostMapping("/list") @PostMapping("/list")
@ApiOperation(value = "查询") @ApiOperation(value = "查询")
//@SessionHandler //@SessionHandler
public Result<PageInfo<Warn>> orders(@RequestBody WarnSearch warnSearch) { public Result<PageInfo<WarnVO>> orders(@RequestBody WarnSearch warnSearch) {
validatorUtil.validate(warnSearch); validatorUtil.validate(warnSearch);
return Result.success(warnService.page(warnSearch)); return Result.success(warnService.page(warnSearch));
} }
@GetMapping("/media")
//@ApiOperation(value = "视频测试")
//@SessionHandler(userType = UserType.ACCOUNT)
public void media() {
}
/*@GetMapping("/userCenter") /*@GetMapping("/userCenter")
@ApiOperation("用户中心地址") @ApiOperation("用户中心地址")
public Result<IndexVO> userCenter(){ public Result<IndexVO> userCenter(){

@ -25,6 +25,46 @@ public class Order {
@ApiModelProperty("0:正常 1告警") @ApiModelProperty("0:正常 1告警")
private Integer status; private Integer status;
/**
* 1 2
*/
private Integer inOut1;
/**
* 1 2
*/
private Integer leftRight1;
/**
*
*/
private Integer column1;
/**
*
*/
private Integer row1;
/**
* 1 2
*/
private Integer inOut2;
/**
* 1 2
*/
private Integer leftRight2;
/**
*
*/
private Integer column2;
/**
*
*/
private Integer row2;
// private String shelveId; // private String shelveId;
// //
// @TableField("`row`") // @TableField("`row`")
@ -61,7 +101,4 @@ public class Order {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime; private LocalDateTime endTime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
} }

@ -23,18 +23,22 @@ public class OrderLastMedia {
@TableField("`column`") @TableField("`column`")
private Integer column; private Integer column;
private String lastPutOrderNum; private String lastOrderNum;
@ApiModelProperty("入库照片") private String pics;
private String putPath;
// private String lastPutOrderNum;
private String lastOutOrderNum; //
// @ApiModelProperty("入库照片")
@ApiModelProperty("出库照片") // private String putPath;
private String outPutPath; //
// private String lastOutOrderNum;
private String lastGoodsOrderNum; //
// @ApiModelProperty("出库照片")
@ApiModelProperty("货位照片") // private String outPutPath;
private String goodsPath; //
//
//
// @ApiModelProperty("货位照片")
// private String goodsPath;
} }

@ -1,6 +1,5 @@
package com.zhehekeji.web.lib; package com.zhehekeji.web.lib;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;
import com.zhehekeji.common.util.PathUtil; import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.web.entity.Order; import com.zhehekeji.web.entity.Order;
@ -8,6 +7,7 @@ import com.zhehekeji.web.entity.OrderLastMedia;
import com.zhehekeji.web.mapper.OrderLastMediaMapper; import com.zhehekeji.web.mapper.OrderLastMediaMapper;
import com.zhehekeji.web.mapper.OrderMapper; import com.zhehekeji.web.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -53,16 +53,37 @@ public class CaptureRunnable implements Runnable {
if (picPath == null) { if (picPath == null) {
return; return;
} }
log.debug("save pic orderNum:{} path:{}", orderInfo.getOrderNum(), picPath); log.debug("save pic orderNum:{} path:{}", orderInfo.getOrderNum(), path);
//todo 根据orderNum找到货架暂时qqq
String shelveId = orderInfo.getShelveId(); String shelveId = orderInfo.getShelveId();
Integer row = orderInfo.getRow(); Integer row = orderInfo.getRow();
Integer column = orderInfo.getColumn(); Integer column = orderInfo.getColumn();
//同步 防止有照片丢失
synchronized (orderInfo.getOrderNum().intern()){
Order order = orderMapper.getOneByOrderNum(orderInfo.getOrderNum());
if(order != null){
OrderLastMedia orderLastMedia = lastMediaMapper.getOne(shelveId,row,column); OrderLastMedia orderLastMedia = lastMediaMapper.getOne(shelveId,row,column);
if (orderLastMedia == null) { if (orderLastMedia == null) {
orderLastMedia = initLastOrder(shelveId,row,column); orderLastMedia = initLastOrder(shelveId,row,column,orderInfo.getOrderNum());
}
String pics = order.getPicPaths();
if(StringUtils.isEmpty(pics)){
order.setPicPaths(path);
}else {
order.setPicPaths(pics+","+path);
}
orderMapper.updateById(order);
//todo 盘点图片 先不做
// if(StringUtils.isEmpty(orderLastMedia.getPics())){
// orderLastMedia.setPics(picPath);
// }else {
// orderLastMedia.setPics(pics+","+picPath);
// }
// lastMediaMapper.updateById(orderLastMedia);
} }
Order order = new Order();
}
//order.setId(orderInfo.getOrderId()); //order.setId(orderInfo.getOrderId());
// if (OrderInfo.OrderPathType.GOODS.getType().equals(orderInfo.getType())) { // if (OrderInfo.OrderPathType.GOODS.getType().equals(orderInfo.getType())) {
// order.setGoodsPath(path); // order.setGoodsPath(path);
@ -77,19 +98,17 @@ public class CaptureRunnable implements Runnable {
// orderLastMedia.setLastOutOrderNum(orderInfo.getOrderNum()); // orderLastMedia.setLastOutOrderNum(orderInfo.getOrderNum());
// orderLastMedia.setOutPutPath(path); // orderLastMedia.setOutPutPath(path);
// } // }
lastMediaMapper.updateById(orderLastMedia);
orderMapper.update(order, new UpdateWrapper<Order>().eq("order_num",orderInfo.getOrderNum()));
return; return;
} }
log.warn("no order"); log.warn("no order");
} }
private OrderLastMedia initLastOrder(String shelveId,Integer row,Integer column) { private OrderLastMedia initLastOrder(String shelveId,Integer row,Integer column,String orderNum) {
OrderLastMedia orderLastMedia = new OrderLastMedia(); OrderLastMedia orderLastMedia = new OrderLastMedia();
//todo 解析订单号
orderLastMedia.setShelveId(shelveId); orderLastMedia.setShelveId(shelveId);
orderLastMedia.setRow(row); orderLastMedia.setRow(row);
orderLastMedia.setColumn(column); orderLastMedia.setColumn(column);
orderLastMedia.setLastOrderNum(orderNum);
// orderLastMedia.setLastOutOrderId(0L); // orderLastMedia.setLastOutOrderId(0L);
// orderLastMedia.setLastPutOrderId(0L); // orderLastMedia.setLastPutOrderId(0L);
// orderLastMedia.setLastGoodsOrderId(0L); // orderLastMedia.setLastGoodsOrderId(0L);

@ -2,10 +2,17 @@ package com.zhehekeji.web.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhehekeji.web.entity.Order; import com.zhehekeji.web.entity.Order;
import com.zhehekeji.web.pojo.OrderSearch;
import com.zhehekeji.web.pojo.OrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface OrderMapper extends BaseMapper<Order> { public interface OrderMapper extends BaseMapper<Order> {
@Select("select * from `order` where order_num = #{orderNum} limit 1") @Select("select * from `order` where order_num = #{orderNum} limit 1")
Order getOneByOrderNum(String orderNum); Order getOneByOrderNum(String orderNum);
List<OrderVO> list(@Param("req")OrderSearch orderSearch);
} }

@ -2,8 +2,15 @@ package com.zhehekeji.web.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhehekeji.web.entity.Warn; import com.zhehekeji.web.entity.Warn;
import com.zhehekeji.web.pojo.warn.WarnSearch;
import com.zhehekeji.web.pojo.warn.WarnVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface WarnMapper extends BaseMapper<Warn> { public interface WarnMapper extends BaseMapper<Warn> {
List<WarnVO> list(@Param("req") WarnSearch warnSearch);
} }

@ -17,4 +17,8 @@ public class OrderSearch {
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTimestamp; private LocalDateTime endTimestamp;
private Integer pageSize;
private Integer pageNum;
} }

@ -0,0 +1,27 @@
package com.zhehekeji.web.pojo;
import com.zhehekeji.web.entity.Order;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class OrderVO extends Order {
@ApiModelProperty("货架类型 0单伸 1双伸")
private Integer streetType;
@ApiModelProperty("巷道")
private String streetName;
@ApiModelProperty("货位号")
private String goodsLocation;
@ApiModelProperty("时长")
private String timeLength;
private String [] pics;
}

@ -1,5 +1,6 @@
package com.zhehekeji.web.pojo.warn; package com.zhehekeji.web.pojo.warn;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -14,7 +15,9 @@ public class WarnSearch {
@NotNull(message = "pageSize不能为空") @NotNull(message = "pageSize不能为空")
private Integer pageSize; private Integer pageSize;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime; private LocalDateTime startTime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime; private LocalDateTime endTime;
} }

@ -0,0 +1,12 @@
package com.zhehekeji.web.pojo.warn;
import com.zhehekeji.web.entity.Warn;
import lombok.Data;
@Data
public class WarnVO extends Warn {
private String streetName;
private String timeLength;
}

@ -10,7 +10,7 @@ import java.util.concurrent.TimeUnit;
import static java.nio.ByteOrder.BIG_ENDIAN; import static java.nio.ByteOrder.BIG_ENDIAN;
/** /**
* *
* *
* @author Administrator * @author Administrator
* *
@ -32,11 +32,10 @@ public class HeartNettyClientFilter extends ChannelInitializer<SocketChannel> {
@Override @Override
protected void initChannel(SocketChannel ch) throws Exception { protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline(); ChannelPipeline ph = ch.pipeline();
//因为服务端设置的超时时间是5秒所以客户端设置4秒 //4秒发一次心跳
ph.addLast(new IdleStateHandler(0, 4, 0, TimeUnit.SECONDS)); ph.addLast(new IdleStateHandler(0, 4, 0, TimeUnit.SECONDS));
ph.addLast(new MyProtocolDecoder(null,plcService)); ph.addLast(new MyProtocolDecoder(plcService));
ph.addLast(new MyProtocolEncoder()); ph.addLast(new MyProtocolEncoder());
//处理客户端的业务逻辑
ph.addLast(new HeartNettyClientHandler(streetId,sendHeart)); ph.addLast(new HeartNettyClientHandler(streetId,sendHeart));
} }
} }

@ -7,7 +7,7 @@ import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/** /**
* * PLC
* *
* @author Administrator * @author Administrator
* *

@ -13,6 +13,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* IO
*/
@Slf4j @Slf4j
public class IOImportListener extends AnalysisEventListener<IOImport> { public class IOImportListener extends AnalysisEventListener<IOImport> {

@ -28,6 +28,8 @@ public class InitService implements ApplicationRunner {
@Resource @Resource
private NettyClient nettyClient; private NettyClient nettyClient;
public static Integer cameraNum;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
//球机登录 //球机登录
@ -36,7 +38,12 @@ public class InitService implements ApplicationRunner {
loginThread.start(); loginThread.start();
//plc 连接状态初始化 //plc 连接状态初始化
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0)); List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));
streets.forEach(street -> { streets.forEach(street -> {
//随便找一个巷道,只要配置了一个球机,就是单个球机的项目
if((street.getCamera1Id() != null && street.getCamera2Id() == null)||(street.getCamera2Id() != null && street.getCamera1Id() == null)){
cameraNum = 1;
}
StreetConn.init(street.getId(),street.getPlcId()); StreetConn.init(street.getId(),street.getPlcId());
try { try {
nettyClient.createClient(street); nettyClient.createClient(street);

@ -12,17 +12,21 @@ import java.util.concurrent.ThreadPoolExecutor;
@Slf4j @Slf4j
public class MyProtocolDecoder extends FixedLengthFrameDecoder { public class MyProtocolDecoder extends FixedLengthFrameDecoder {
private ThreadPoolExecutor threadPoolExecutor;
private PlcService plcService; private PlcService plcService;
public MyProtocolDecoder(ThreadPoolExecutor threadPoolExecutor, PlcService plcService) { public MyProtocolDecoder(PlcService plcService) {
super(43); super(43);
this.threadPoolExecutor = threadPoolExecutor;
this.plcService = plcService; this.plcService = plcService;
} }
/**
* TCP
*
* @param ctx
* @param in
* @return
* @throws Exception
*/
@Override @Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
in = (ByteBuf) super.decode(ctx, in); in = (ByteBuf) super.decode(ctx, in);
@ -51,13 +55,13 @@ public class MyProtocolDecoder extends FixedLengthFrameDecoder {
short short6 = in.readShort(); short short6 = in.readShort();
short short7 = in.readShort(); short short7 = in.readShort();
short short8 = in.readShort(); short short8 = in.readShort();
PlcOrderInfo plcOrderInfo = new PlcOrderInfo(plcId,taskId,(int)short1,(int)short2,(int)short3,(int)short4,(int)short5,(int)short6,(int)short7,(int)short8); PlcOrderInfo plcOrderInfo = new PlcOrderInfo(plcId, taskId, (int) short1, (int) short2, (int) short3, (int) short4, (int) short5, (int) short6, (int) short7, (int) short8);
byte maohao = in.readByte(); byte maohao = in.readByte();
byte leixing = in.readByte(); byte leixing = in.readByte();
byte w = in.readByte(); byte w = in.readByte();
Character character = new Character((char)leixing); Character character = new Character((char) leixing);
String code = character.toString()+w; String code = character.toString() + w;
byte b1 = in.readByte(); byte b1 = in.readByte();
byte b2 = in.readByte(); byte b2 = in.readByte();
byte b3 = in.readByte(); byte b3 = in.readByte();
@ -66,51 +70,51 @@ public class MyProtocolDecoder extends FixedLengthFrameDecoder {
byte b6 = in.readByte(); byte b6 = in.readByte();
byte b7 = in.readByte(); byte b7 = in.readByte();
byte b8 = in.readByte(); byte b8 = in.readByte();
byte[]bytes=new byte[]{b1,b2,b3,b4,b5,b6,b7,b8}; byte[] bytes = new byte[]{b1, b2, b3, b4, b5, b6, b7, b8};
if (type.equals("0A")) { if (type.equals("0A")) {
//心跳 //心跳
log.debug("receive heart plcId:{}",plcId); log.debug("receive heart plcId:{}", plcId);
} else if (type.equals("0B")) { } else if (type.equals("0B")) {
if ("B1".equals(code)) { if ("B1".equals(code)) {
log.info("order start ,plcId:{},orderInfo:{}",plcId, plcOrderInfo.toString()); log.info("order start ,plcId:{},orderInfo:{}", plcId, plcOrderInfo.toString());
plcService.orderStart(plcOrderInfo.getOrderNum(), plcId); plcService.orderStart(plcOrderInfo, plcId);
} else if ("B2".equals(code)) { } else if ("B2".equals(code)) {
log.info("order end, plcId:{},orderInfo:{}",plcId, plcOrderInfo.toString()); log.info("order end, plcId:{},orderInfo:{}", plcId, plcOrderInfo.toString());
plcService.orderStop(plcId,plcOrderInfo.getOrderNum()); plcService.orderStop(plcId, plcOrderInfo.getOrderNum());
} }
} else if (type.equals("0C")) { } else if (type.equals("0C")) {
log.info("action code,{} plcId:{},orderInfo:{}",code,plcId, plcOrderInfo.toString()); log.info("action code,{} plcId:{},orderInfo:{}", code, plcId, plcOrderInfo.toString());
Integer times = OrderAction.put(plcOrderInfo.getOrderNum()); Integer times = OrderAction.put(plcOrderInfo.getOrderNum());
//执行动作 //执行动作
plcService.action(plcOrderInfo,plcId,times,code); plcService.action(plcOrderInfo, plcId, times, code);
} else if(type.equals("0D")){ } else if (type.equals("0D")) {
log.info(" warn code:{}",code); log.info(" warn code:{}", code);
if("D0".equals(code)){ if ("D0".equals(code)) {
log.info("warn start ,plcId:{},warnInfo:b1:{},b2:{},b3:{},b4:{},b5:{},b6:{},b7:{},b8:{}",plcId,b1, b2, b3, b4, b5, b6, b7, b8); log.info("warn start ,plcId:{},warnInfo:b1:{},b2:{},b3:{},b4:{},b5:{},b6:{},b7:{},b8:{}", plcId, b1, b2, b3, b4, b5, b6, b7, b8);
plcService.warnStart(plcId); plcService.warnStart(plcId);
//动作 //动作
//解析具体的告警 具体规则见文档 //解析具体的告警 具体规则见文档
int n = 1; int n = 1;
int warn = 0; int warn = 0;
for(byte b: bytes){ for (byte b : bytes) {
warn = warn(b,8*n); warn = warn(b, 8 * n);
if(warn > 0){ if (warn > 0) {
break; break;
} }
n++; n++;
} }
if(warn > 0){ if (warn > 0) {
//执行动作 //执行动作
//times = 1 只执行动作 //times = 1 只执行动作
//code 写作"D{warn}" //code 写作"D{warn}"
plcService.action(plcOrderInfo,plcId,1,"D"+warn); plcService.action(plcOrderInfo, plcId, 1, "D" + warn);
} }
}else if("D100".equals(code)){ } else if ("D100".equals(code)) {
log.info("warn end ,plcId:{}",plcId); log.info("warn end ,plcId:{}", plcId);
plcService.warnStop(plcId); plcService.warnStop(plcId);
} }
} }
@ -119,13 +123,19 @@ public class MyProtocolDecoder extends FixedLengthFrameDecoder {
} }
private Integer warn(byte b,Integer num){ /**
*
* @param b
* @param num
* @return
*/
private Integer warn(byte b, Integer num) {
String tString = Integer.toBinaryString((b & 0xFF) + 0x100).substring(1); String tString = Integer.toBinaryString((b & 0xFF) + 0x100).substring(1);
Integer warn = 0; Integer warn = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
char item = tString.charAt(i); char item = tString.charAt(i);
if(String.valueOf(item).equals("1")){ if (String.valueOf(item).equals("1")) {
warn = num-i; warn = num - i;
} }
} }
return warn; return warn;

@ -36,7 +36,7 @@ public class NettyClient {
try { try {
client.connect(street.getPlcIp(), street.getPlcPort()).sync().channel(); client.connect(street.getPlcIp(), street.getPlcPort()).sync().channel();
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("plc连接 被打断或无法连接{}",e); log.error("plc连接异常{}",e);
} }
} }

@ -2,6 +2,8 @@ package com.zhehekeji.web.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhehekeji.common.util.PathUtil; import com.zhehekeji.common.util.PathUtil;
import com.zhehekeji.web.entity.Order; import com.zhehekeji.web.entity.Order;
import com.zhehekeji.web.entity.Street; import com.zhehekeji.web.entity.Street;
@ -10,14 +12,18 @@ import com.zhehekeji.web.mapper.OrderMapper;
import com.zhehekeji.web.mapper.StreetMapper; import com.zhehekeji.web.mapper.StreetMapper;
import com.zhehekeji.web.pojo.OrderSaveReq; import com.zhehekeji.web.pojo.OrderSaveReq;
import com.zhehekeji.web.pojo.OrderSearch; import com.zhehekeji.web.pojo.OrderSearch;
import com.zhehekeji.web.pojo.OrderVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Slf4j @Slf4j
@ -25,7 +31,7 @@ public class OrderService {
@Resource @Resource
private OrderMapper orderMapper; private OrderMapper orderMapper;
// @Resource // @Resource
// private StreetShelveMapper streetShelveMapper; // private StreetShelveMapper streetShelveMapper;
@Resource @Resource
private StreetMapper streetMapper; private StreetMapper streetMapper;
@ -36,16 +42,84 @@ public class OrderService {
@Value("${mp4Path}") @Value("${mp4Path}")
private String mp4Path; private String mp4Path;
public List<Order> orders(OrderSearch orderSearch) { public PageInfo<OrderVO> orders(OrderSearch orderSearch) {
QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>(); // QueryWrapper<Order> queryWrapper = new QueryWrapper<Order>();
if(!StringUtils.isEmpty(orderSearch.getOrderNum())){ // if(!StringUtils.isEmpty(orderSearch.getOrderNum())){
queryWrapper.eq("order_num", orderSearch.getOrderNum()); // queryWrapper.eq("order_num", orderSearch.getOrderNum());
// }
// if(orderSearch.getStartTimestamp() != null && orderSearch.getEndTimestamp() != null){
// queryWrapper.between("create_time",orderSearch.getStartTimestamp(),orderSearch.getEndTimestamp());
// }
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));
Map<Integer, Street> streetMap = new HashMap<>();
streets.forEach(street -> {
streetMap.put(street.getId(), street);
});
PageHelper.startPage(orderSearch.getPageNum(), orderSearch.getPageSize());
List<OrderVO> orders = orderMapper.list(orderSearch);
orders.forEach(orderVO -> {
if (streetMap.get(orderVO.getStreetId()) != null) {
orderVO.setStreetName(streetMap.get(orderVO.getStreetId()).getName());
} }
if(orderSearch.getStartTimestamp() != null && orderSearch.getEndTimestamp() != null){ //from to 模型
queryWrapper.between("create_time",orderSearch.getStartTimestamp(),orderSearch.getEndTimestamp()); if (orderVO.getInOut1() != null && orderVO.getInOut2() != null) {
//左右货架 货位号
//库内转库内 看 to
Integer column = 0;
Integer row = 0;
//左货架 右货架
Integer leftRight = 0;
if (orderVO.getInOut1() == 1 && orderVO.getInOut2() == 1) {
leftRight = orderVO.getLeftRight2();
column = orderVO.getColumn2();
row = orderVO.getRow2();
} else if (orderVO.getInOut1() == 1) {
leftRight = orderVO.getLeftRight1();
//看from
orderVO.setStreetType(orderVO.getLeftRight1());
column = orderVO.getColumn1();
row = orderVO.getRow1();
} else if (orderVO.getInOut2() == 1) {
leftRight = orderVO.getLeftRight2();
//看to
orderVO.setStreetType(orderVO.getLeftRight2());
column = orderVO.getColumn2();
row = orderVO.getRow2();
} }
List<Order> orders = orderMapper.selectList(queryWrapper); if (leftRight > 0) {
return orders; //PLC 1是左 2是由
Street street = streetMap.get(orderVO.getStreetId());
if(street != null){
if(leftRight == 1){
orderVO.setStreetType(street.getLeftType());
}else {
orderVO.setStreetType(street.getRightType());
}
}
String leftRightS = leftRight == 1 ? "左" : "右";
//里外 现在无法判断 这个项目全是 里
String location = "%s-里-%s列%s行";
orderVO.setGoodsLocation(String.format(location, leftRightS, column, row));
}
}
//计算订单的时间
if (orderVO.getEndTime() != null && orderVO.getStartTime() != null) {
Duration duration = Duration.between(orderVO.getStartTime(), orderVO.getEndTime());
Long seconds = duration.getSeconds();
int minutes = seconds.intValue() / 60;
int remainingSeconds = seconds.intValue() % 60;
String timeLength = minutes + ":" + remainingSeconds;
orderVO.setTimeLength(timeLength);
}
if (!StringUtils.isEmpty(orderVO.getPicPaths())) {
String[] pics = orderVO.getPicPaths().split(",");
orderVO.setPics(pics);
}
});
return new PageInfo<>(orders);
} }
public Long add(OrderSaveReq saveReq) { public Long add(OrderSaveReq saveReq) {
@ -53,18 +127,18 @@ public class OrderService {
String orderNum = saveReq.getOrderNum(); String orderNum = saveReq.getOrderNum();
order.setStatus(0); order.setStatus(0);
order.setOrderNum(orderNum); order.setOrderNum(orderNum);
order.setCreateTime(LocalDateTime.now());
orderMapper.insert(order); orderMapper.insert(order);
return order.getId(); return order.getId();
} }
/** /**
* *
*
* @param orderNum * @param orderNum
* @param street * @param street
* @param warn true * @param warn true
*/ */
public void orderStop(String orderNum,Street street,Boolean warn) { public void orderStop(String orderNum, Street street, Boolean warn) {
Order order = orderMapper.getOneByOrderNum(orderNum); Order order = orderMapper.getOneByOrderNum(orderNum);
if (order == null) { if (order == null) {
@ -75,9 +149,9 @@ public class OrderService {
log.error("订单结束信号订单未开始orderNum:{}", orderNum); log.error("订单结束信号订单未开始orderNum:{}", orderNum);
return; return;
} }
if(warn){ if (warn) {
order.setStatus(1); order.setStatus(1);
}else { } else {
order.setStatus(0); order.setStatus(0);
} }
order.setOrderNum(orderNum); order.setOrderNum(orderNum);
@ -98,5 +172,4 @@ public class OrderService {
} }
} }

@ -51,11 +51,6 @@ public class PlcService {
@Resource @Resource
private CameraIOMapper ioMapper; private CameraIOMapper ioMapper;
public List<StreetConn.PlcStatus> disStreets(){
return StreetConn.disConnList();
}
public Integer plcStatus(){ public Integer plcStatus(){
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0)); List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));
List<Integer> connIds = StreetConn.connList(); List<Integer> connIds = StreetConn.connList();
@ -64,18 +59,25 @@ public class PlcService {
/** /**
* *
* @param orderNum * @param plcOrderInfo
* @param plcId * @param plcId
*/ */
public void orderStart(String orderNum,String plcId) { public void orderStart(PlcOrderInfo plcOrderInfo,String plcId) {
Order order = new Order(); Order order = new Order();
order.setOrderNum(orderNum); order.setOrderNum(plcOrderInfo.getOrderNum());
order.setStartTime(LocalDateTime.now()); order.setStartTime(LocalDateTime.now());
order.setCreateTime(LocalDateTime.now());
Street street = streetService.getStreetByPlcId(plcId); Street street = streetService.getStreetByPlcId(plcId);
if(street != null){ if(street != null){
OrderRealtime.startOrder(street.getId(), orderNum); OrderRealtime.startOrder(street.getId(), plcOrderInfo.getOrderNum());
order.setStreetId(street.getId()); order.setStreetId(street.getId());
order.setInOut1(plcOrderInfo.getInOut1());
order.setLeftRight1(plcOrderInfo.getLeftRight1());
order.setColumn1(plcOrderInfo.getColumn1());
order.setRow1(plcOrderInfo.getRow1());
order.setInOut2(plcOrderInfo.getInOut2());
order.setLeftRight2(plcOrderInfo.getLeftRight2());
order.setColumn2(plcOrderInfo.getColumn2());
order.setRow2(plcOrderInfo.getRow2());
orderMapper.insert(order); orderMapper.insert(order);
//orderMapper.update(order, new UpdateWrapper<Order>().eq("order_num", orderNum)); //orderMapper.update(order, new UpdateWrapper<Order>().eq("order_num", orderNum));
} }

@ -27,11 +27,11 @@ public class RealTimeService {
@Resource @Resource
private LycheeMapper lycheeMapper; private LycheeMapper lycheeMapper;
public String lychee(){ // public String lychee(){
Lychee lychee = lycheeMapper.selectById(1); // Lychee lychee = lycheeMapper.selectById(1);
Assert.notNull(lychee,"未配置荔枝转码服务"); // Assert.notNull(lychee,"未配置荔枝转码服务");
return lychee.getIp(); // return lychee.getIp();
} // }
public List<RealTime> realTimes(){ public List<RealTime> realTimes(){
List<Street> streets = streetMapper.selectByMap(new HashMap<>(0)); List<Street> streets = streetMapper.selectByMap(new HashMap<>(0));

@ -52,6 +52,10 @@ public class StreetConn {
return disConnIds; return disConnIds;
} }
/**
* PLC
* @return
*/
public static List<PlcStatus> disConnList(){ public static List<PlcStatus> disConnList(){
List<PlcStatus> plcStatuses = new ArrayList<>(); List<PlcStatus> plcStatuses = new ArrayList<>();
@ -69,6 +73,7 @@ public class StreetConn {
*/ */
public static void init(Integer streetId,String plcId){ public static void init(Integer streetId,String plcId){
PlcStatus plcStatus = new PlcStatus(); PlcStatus plcStatus = new PlcStatus();
plcStatus.streetId = streetId;
plcStatus.status = Boolean.FALSE; plcStatus.status = Boolean.FALSE;
plcStatus.time = LocalDateTime.now(); plcStatus.time = LocalDateTime.now();
plcStatus.plcId = plcId; plcStatus.plcId = plcId;
@ -102,6 +107,8 @@ public class StreetConn {
private LocalDateTime time; private LocalDateTime time;
private String plcId; private String plcId;
private Integer streetId;
} }
} }

@ -6,9 +6,11 @@ import com.github.pagehelper.PageInfo;
import com.zhehekeji.web.entity.Warn; import com.zhehekeji.web.entity.Warn;
import com.zhehekeji.web.mapper.WarnMapper; import com.zhehekeji.web.mapper.WarnMapper;
import com.zhehekeji.web.pojo.warn.WarnSearch; import com.zhehekeji.web.pojo.warn.WarnSearch;
import com.zhehekeji.web.pojo.warn.WarnVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration;
import java.util.List; import java.util.List;
@Service @Service
@ -17,13 +19,21 @@ public class WarnService {
@Resource @Resource
private WarnMapper warnMapper; private WarnMapper warnMapper;
public PageInfo<Warn> page(WarnSearch warnSearch){ public PageInfo<WarnVO> page(WarnSearch warnSearch){
PageHelper.startPage(warnSearch.getPageNum(),warnSearch.getPageSize()); PageHelper.startPage(warnSearch.getPageNum(),warnSearch.getPageSize());
QueryWrapper<Warn> queryWrapper = new QueryWrapper<>();
if(warnSearch.getStartTime() != null && warnSearch.getEndTime() != null){ List<WarnVO> warns = warnMapper.list(warnSearch);
queryWrapper.between("start_time",warnSearch.getStartTime(),warnSearch.getEndTime()); warns.forEach(warnVO -> {
if(warnVO.getStartTime() != null && warnVO.getEndTime() != null){
Duration duration = Duration.between(warnVO.getStartTime(), warnVO.getEndTime());
Long seconds = duration.getSeconds();
int minutes = seconds.intValue() / 60;
int remainingSeconds = seconds.intValue() % 60;
String timeLength = minutes+":"+remainingSeconds;
warnVO.setTimeLength(timeLength);
} }
List<Warn> warns = warnMapper.selectList(queryWrapper);
});
return new PageInfo<>(warns); return new PageInfo<>(warns);
} }
} }

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhehekeji.web.mapper.OrderMapper">
<select id="list" parameterType="com.zhehekeji.web.pojo.OrderSearch" resultType="com.zhehekeji.web.pojo.OrderVO">
select t.*
from `order` t
<where>
<if test="req.orderNum != null and req.orderNum != ''">
and t.order_num = #{req.orderNum}
</if>
<if test="req.startTimestamp != null and req.endTimestamp != null">
and t.start_time >= #{req.startTimestamp} and t.start_time &lt;= #{req.endTimestamp}
</if>
</where>
order by t.id desc
</select>
</mapper>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhehekeji.web.mapper.WarnMapper">
<select id="list" parameterType="com.zhehekeji.web.pojo.warn.WarnSearch" resultType="com.zhehekeji.web.pojo.warn.WarnVO">
select t.*,s.name as streetName
from warn t
left join street s on s.id = t.street_id
<where>
<if test="req.startTime != null and req.endTime != null">
and t.start_time >= #{req.startTime} and t.start_time &lt;= #{req.endTime}
</if>
</where>
order by t.id desc
</select>
</mapper>
Loading…
Cancel
Save