Commit 714a5e70 by wangweidong

土工平台修改

parent bf8820eb
...@@ -121,6 +121,8 @@ dependencies { ...@@ -121,6 +121,8 @@ dependencies {
compile("com.google.zxing:javase:3.3.3") compile("com.google.zxing:javase:3.3.3")
compile("org.springframework.boot:spring-boot-starter-mail:2.4.3") compile("org.springframework.boot:spring-boot-starter-mail:2.4.3")
compile ("org.rxtx:rxtx:2.1.7") compile ("org.rxtx:rxtx:2.1.7")
compile ("io.netty:netty-all:4.1.18.Final")
compile ("net.jodah:expiringmap:0.5.9")
compile("com.qcloud:cos_api:5.2.4") { compile("com.qcloud:cos_api:5.2.4") {
exclude module: 'slf4j-log4j12' exclude module: 'slf4j-log4j12'
} }
......
...@@ -43,6 +43,7 @@ public class ExcelController extends ServiceController { ...@@ -43,6 +43,7 @@ public class ExcelController extends ServiceController {
ExcelController.TPL.put("MeterSendSampleImport", "出检样品导入模板"); ExcelController.TPL.put("MeterSendSampleImport", "出检样品导入模板");
ExcelController.TPL.put("SoilEntrustImport", "试验委托单导入模板"); ExcelController.TPL.put("SoilEntrustImport", "试验委托单导入模板");
ExcelController.TPL.put("SoilAptExpImport", "试样项目导入模板"); ExcelController.TPL.put("SoilAptExpImport", "试样项目导入模板");
ExcelController.TPL.put("SamplingList", "样品抽样单模板导出");
ExcelController.TPL.put("TenderContractSupplement.docx", "标书合同(协议)补充单.docx"); ExcelController.TPL.put("TenderContractSupplement.docx", "标书合同(协议)补充单.docx");
...@@ -58,6 +59,7 @@ public class ExcelController extends ServiceController { ...@@ -58,6 +59,7 @@ public class ExcelController extends ServiceController {
ExcelController.TPL.put("QuYang.docx", "取(采)样记录.docx"); ExcelController.TPL.put("QuYang.docx", "取(采)样记录.docx");
ExcelController.TPL.put("YangPinBiaoShiKa.docx", "样品标识卡.docx"); ExcelController.TPL.put("YangPinBiaoShiKa.docx", "样品标识卡.docx");
ExcelController.TPL.put("YangPinChouYangDan.docx", "样品抽样单.docx"); ExcelController.TPL.put("YangPinChouYangDan.docx", "样品抽样单.docx");
ExcelController.TPL.put("SamplingList.xlsx", "抽样单导出模板.xlsx");
} }
@ApiOperation(value = "根据模板名称下载模板", notes = "根据模板名称下载导入模板") @ApiOperation(value = "根据模板名称下载模板", notes = "根据模板名称下载导入模板")
......
package com.patzn.cloud.service.lims.rcp;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import java.sql.Connection;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Component
public class InitBalanceMap implements InitializingBean {
public static ExpiringMap<String,String> mapBalanceId = null;
public static ExpiringMap<String,String> mapBalanceValue = null;
public ExpiringMap<String,String> getMapId(){
return mapBalanceId;
}
public ExpiringMap<String,String> getMapValue(){
return mapBalanceValue;
}
@Override
public void afterPropertiesSet() throws Exception {
mapBalanceId = ExpiringMap.builder()
//设置每个key有效时间60s,如果key不设置过期时间,key永久有效
.expiration(60, TimeUnit.SECONDS)
//允许更新过期时间值,如果不设置variableExpiration,不允许后面更改过期时间,一旦执行更改过期时间操作会抛异常UnsupportedOperationException
.variableExpiration()
//CREATED:只在put和replace方法清零过期时间
//ACCESSED:在CREATED策略基础上增加 在还没过期时get方法清零过期时间。
//清零过期时间也就是重置过期时间,重新计算过期时间
.expirationPolicy(ExpirationPolicy.CREATED)
.build();
mapBalanceValue = ExpiringMap.builder()
//设置每个key有效时间60s,如果key不设置过期时间,key永久有效
.expiration(60, TimeUnit.SECONDS)
//允许更新过期时间值,如果不设置variableExpiration,不允许后面更改过期时间,一旦执行更改过期时间操作会抛异常UnsupportedOperationException
.variableExpiration()
//CREATED:只在put和replace方法清零过期时间
//ACCESSED:在CREATED策略基础上增加 在还没过期时get方法清零过期时间。
//清零过期时间也就是重置过期时间,重新计算过期时间
.expirationPolicy(ExpirationPolicy.CREATED)
.build();
}
}
package com.patzn.cloud.service.lims.rcp;
/*
* @author uv
* @date 2018/10/12 18:25
* 服务端
*/
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public class NettyServer {
public void bind(int port) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(); //bossGroup就是parentGroup,是负责处理TCP/IP连接的
EventLoopGroup workerGroup = new NioEventLoopGroup(); //workerGroup就是childGroup,是负责处理Channel(通道)的I/O事件
ServerBootstrap sb = new ServerBootstrap();
sb.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 128) //初始化服务端可连接队列,指定了队列的大小128
.childOption(ChannelOption.SO_KEEPALIVE, true) //保持长连接
.childHandler(new ChannelInitializer<SocketChannel>() { // 绑定客户端连接时候触发操作
@Override
protected void initChannel(SocketChannel sh) throws Exception {
sh.pipeline()
.addLast(new RpcDecoder(RpcRequest.class)) //解码request
.addLast(new RpcEncoder(RpcResponse.class)) //编码response
.addLast(new ServerHandler()); //使用ServerHandler类来处理接收到的消息
}
});
//绑定监听端口,调用sync同步阻塞方法等待绑定操作完
ChannelFuture future = sb.bind(port).sync();
if (future.isSuccess()) {
System.out.println("服务端启动成功");
} else {
System.out.println("服务端启动失败");
future.cause().printStackTrace();
bossGroup.shutdownGracefully(); //关闭线程组
workerGroup.shutdownGracefully();
}
//成功绑定到端口之后,给channel增加一个 管道关闭的监听器并同步阻塞,直到channel关闭,线程才会往下执行,结束进程。
future.channel().closeFuture().sync();
}
}
package com.patzn.cloud.service.lims.rcp;
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import java.util.List;
public class RpcDecoder extends ByteToMessageDecoder {
//目标对象类型进行解码
private Class<?> target;
public RpcDecoder(Class target) {
this.target = target;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 4) { //不够长度丢弃
return;
}
in.markReaderIndex(); //标记一下当前的readIndex的位置
int dataLength = in.readInt(); // 读取传送过来的消息的长度。ByteBuf 的readInt()方法会让他的readIndex增加4
if (in.readableBytes() < dataLength) { //读到的消息体长度如果小于我们传送过来的消息长度,则resetReaderIndex. 这个配合markReaderIndex使用的。把readIndex重置到mark的地方
in.resetReaderIndex();
return;
}
byte[] data = new byte[dataLength];
in.readBytes(data);
Object obj = JSON.parseObject(data, target); //将byte数据转化为我们需要的对象
out.add(obj);
}
}
package com.patzn.cloud.service.lims.rcp;
/*
* @author uv
* @date 2018/10/13 18:09
* 编码器(将实体类转换成可传输的数据)
*/
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
public class RpcEncoder extends MessageToByteEncoder {
//目标对象类型进行编码
private Class<?> target;
public RpcEncoder(Class target) {
this.target = target;
}
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
if (target.isInstance(msg)) {
byte[] data = JSON.toJSONBytes(msg); //使用fastJson将对象转换为byte
out.writeInt(data.length); //先将消息长度写入,也就是消息头
out.writeBytes(data); //消息体中包含我们要发送的数据
}
}
}
\ No newline at end of file
package com.patzn.cloud.service.lims.rcp;
/*
* @author uv
* @date 2018/10/13 18:10
* 传输请求对象
*/
public class RpcRequest {
private String id;
private Object data;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
@Override
public String toString() {
return "RpcRequest{" + "id='" + id + '\'' + ", data=" + data + '}';
}
}
package com.patzn.cloud.service.lims.rcp;
/*
* @author uv
* @date 2018/10/13 18:10
* 传输响应对象
*/
public class RpcResponse {
private String id;
private Object data;
// 0=success -1=fail
private int status;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Override
public String toString() {
return "RpcResponse{" + "id='" + id + '\'' + ", data=" + data + ", status=" + status + '}';
}
}
package com.patzn.cloud.service.lims.socket; package com.patzn.cloud.service.lims.rcp;
import com.patzn.cloud.service.lims.socket.ServerConfig;
import com.patzn.cloud.service.lims.socket.SocketProperties;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -11,29 +13,24 @@ import java.util.concurrent.ThreadPoolExecutor; ...@@ -11,29 +13,24 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Component @Component
public class TestRunner implements CommandLineRunner { public class Runner implements CommandLineRunner {
@Autowired @Autowired
private SocketProperties properties; private SocketProperties properties;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
ServerSocket server = null;
Socket socket = null;
server = new ServerSocket(properties.getPort());
System.out.println("设备服务器已经开启, 监听端口:" + properties.getPort()); System.out.println("设备服务器已经开启, 监听端口:" + properties.getPort());
ThreadPoolExecutor pool = new ThreadPoolExecutor( new NettyServer().bind(6800);
properties.getPoolCore(), // ThreadPoolExecutor pool = new ThreadPoolExecutor(
properties.getPoolMax(), // properties.getPoolCore(),
properties.getPoolKeep(), // properties.getPoolMax(),
TimeUnit.SECONDS, // properties.getPoolKeep(),
new ArrayBlockingQueue<>(properties.getPoolQueueInit()), // TimeUnit.SECONDS,
new ThreadPoolExecutor.DiscardOldestPolicy() // new ArrayBlockingQueue<>(properties.getPoolQueueInit()),
); // new ThreadPoolExecutor.DiscardOldestPolicy()
while (true) { // );
socket = server.accept();
pool.execute(new ServerConfig(socket));
}
} }
} }
package com.patzn.cloud.service.lims.rcp;
import com.patzn.cloud.service.lims.socket.SpringUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import io.netty.channel.ChannelInboundHandlerAdapter;
import net.jodah.expiringmap.ExpiringMap;
import java.util.UUID;
public class ServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
String oid = ctx.channel().id().asLongText();
RpcRequest request = (RpcRequest) msg;
InitBalanceMap mapInit = (InitBalanceMap)SpringUtil.getBean("initBalanceMap");
ExpiringMap<String,String> mapId = mapInit.getMapId();
ExpiringMap<String,String> mapValue = mapInit.getMapValue();
if (mapId.get(oid)==null){
mapId.put(oid,request.getData().toString());
}else{
mapValue.put(mapId.get(oid),request.getData().toString());
}
System.out.println();
System.out.println("接收到客户端信息:" + request.toString());
//返回的数据结构
RpcResponse response = new RpcResponse();
response.setId(UUID.randomUUID().toString());
response.setData("server响应结果");
response.setStatus(1);
ctx.writeAndFlush(response);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ChannelId channelId = ctx.channel().id();
String text = channelId.asLongText();
ChannelHandlerContext handlerContext = ctx.read();
String content = handlerContext.toString();
System.out.println("服务端接收数据完毕..");
ctx.flush();
}
//读操作时捕获到异常时调用
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.close();
}
//客户端去和服务端连接成功时触发
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
// ctx.writeAndFlush("hello client");
}
}
...@@ -16,11 +16,13 @@ import com.patzn.cloud.oss.starter.OssFileResult; ...@@ -16,11 +16,13 @@ import com.patzn.cloud.oss.starter.OssFileResult;
import com.patzn.cloud.service.eln.entity.ElnForm; import com.patzn.cloud.service.eln.entity.ElnForm;
import com.patzn.cloud.service.eln.entity.ElnTemplate; import com.patzn.cloud.service.eln.entity.ElnTemplate;
import com.patzn.cloud.service.lims.common.SerialTool; import com.patzn.cloud.service.lims.common.SerialTool;
import com.patzn.cloud.service.lims.rcp.InitBalanceMap;
import com.patzn.cloud.service.lims.soil.mapper.SoilOriginalRecordMapper; import com.patzn.cloud.service.lims.soil.mapper.SoilOriginalRecordMapper;
import com.patzn.cloud.service.lims.soil.service.*; import com.patzn.cloud.service.lims.soil.service.*;
import com.patzn.cloud.commons.service.impl.BaseServiceImpl; import com.patzn.cloud.commons.service.impl.BaseServiceImpl;
import com.patzn.cloud.service.soil.entity.*; import com.patzn.cloud.service.soil.entity.*;
import com.patzn.cloud.service.soil.vo.SoilOriginalRecordVO; import com.patzn.cloud.service.soil.vo.SoilOriginalRecordVO;
import net.jodah.expiringmap.ExpiringMap;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -41,6 +43,9 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -41,6 +43,9 @@ import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class SoilOriginalRecordServiceImpl extends BaseServiceImpl<SoilOriginalRecordMapper, SoilOriginalRecord> implements ISoilOriginalRecordService { public class SoilOriginalRecordServiceImpl extends BaseServiceImpl<SoilOriginalRecordMapper, SoilOriginalRecord> implements ISoilOriginalRecordService {
@Autowired
private InitBalanceMap initBalanceMap;
@Autowired @Autowired
private ElnFormClient elnFormClient; private ElnFormClient elnFormClient;
@Autowired @Autowired
...@@ -321,7 +326,8 @@ public class SoilOriginalRecordServiceImpl extends BaseServiceImpl<SoilOriginalR ...@@ -321,7 +326,8 @@ public class SoilOriginalRecordServiceImpl extends BaseServiceImpl<SoilOriginalR
List<SoilOriginalTemplateBalance> balanceList = soilOriginalTemplateBalanceService.list(Condition.create().eq("template_id",templateId).orderBy("itemed",false)); List<SoilOriginalTemplateBalance> balanceList = soilOriginalTemplateBalanceService.list(Condition.create().eq("template_id",templateId).orderBy("itemed",false));
for (SoilOriginalTemplateBalance balance : balanceList) { for (SoilOriginalTemplateBalance balance : balanceList) {
String value = SerialTool.getBalanceValue(balance.getComName(),balance.getBaudRate(),balance.getCommand()); ExpiringMap<String,String> valueMap= initBalanceMap.getMapValue();
String value = valueMap.get(balance.getComName());
if (StringUtils.isNotBlank(value)){ if (StringUtils.isNotBlank(value)){
return value; return value;
} }
......
...@@ -105,6 +105,11 @@ ...@@ -105,6 +105,11 @@
<if test="vo.status!=null"> <if test="vo.status!=null">
AND t.status = #{vo.status} AND t.status = #{vo.status}
</if> </if>
<if test="vo.name!=null">
AND t.name LIKE CONCAT('%',#{vo.name},'%')
</if>
<if test="vo.entrustId!=null"> <if test="vo.entrustId!=null">
AND s.entrust_id = #{vo.entrustId} AND s.entrust_id = #{vo.entrustId}
</if> </if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment