| | |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.mina.core.service.IoAcceptor; |
| | | import org.apache.mina.core.service.IoHandler; |
| | | import org.apache.mina.core.session.IoSession; |
| | | import org.jeecg.common.api.CommonAPI; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.config.TenantContext; |
| | | import org.jeecg.common.config.mqtoken.UserTokenContext; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.util.JwtUtil; |
| | | import org.jeecg.common.util.RedisUtil; |
| | | import org.jeecg.common.util.SpringContextUtils; |
| | | import org.jeecg.modules.dry.api.JeecgSystemApi; |
| | | import org.jeecg.modules.dry.common.CacheConstants; |
| | | import org.jeecg.modules.dry.entity.DryEquipment; |
| | | import org.jeecg.modules.dry.entity.DryHerb; |
| | | import org.jeecg.modules.dry.entity.DryOrder; |
| | | import org.jeecg.modules.dry.entity.DryOrderTrend; |
| | | import org.jeecg.modules.dry.entity.*; |
| | | import org.jeecg.modules.dry.service.*; |
| | | import org.jeecg.modules.dry.vo.DryOrderTrendVo; |
| | | import org.jeecg.modules.dry.vo.DryOrderVo; |
| | | import org.jeecg.modules.dry.vo.RealTimeDataVo; |
| | | import org.jeecg.modules.dry.socket.ServerHandler; |
| | | import org.jeecg.modules.dry.socket.SocketServerConfig; |
| | | import org.jeecg.modules.dry.util.DryUtil; |
| | | import org.jeecg.modules.dry.vo.*; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.ObjectOutputStream; |
| | | import java.net.Socket; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class DryRealTimeDataServiceImpl implements IDryRealTimeDataService { |
| | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | @Autowired |
| | | private IDryProdRecordService prodRecordService; |
| | | |
| | | @Autowired |
| | | private CommonAPI commonAPI; |
| | | |
| | | private String token; |
| | | |
| | | |
| | | |
| | | public String getTemporaryToken() { |
| | | if (token == null) { |
| | | RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class); |
| | | // 模拟登录生成Token |
| | | token = JwtUtil.sign("admin", "b668043e3ea4bc2d"); |
| | | // 设置Token缓存有效时间为 5 分钟 |
| | | redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
| | | redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, 5 * 60 * 1000); |
| | | } |
| | | |
| | | return token; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result<?> realTimeDataHandle(RealTimeDataVo realTimeDataVo) { |
| | | TenantContext.setTenant(realTimeDataVo.getTenantid()+""); |
| | | log.info("实时数据:"+realTimeDataVo.toString()); |
| | | |
| | | |
| | | // 1 查询或创建工单 |
| | | // 1.1 从redis取出工单缓存 |
| | |
| | | orderVo.setLowalarm(realTimeDataVo.getLowalarm()); |
| | | orderVo.setWind(realTimeDataVo.getWind()); |
| | | orderVo.setOriginWeight(realTimeDataVo.getWeight2()); |
| | | orderVo.setWatt(realTimeDataVo.getWatt()); |
| | | orderVo.setSteam(realTimeDataVo.getSteam()); |
| | | orderVo.setEnvHum(realTimeDataVo.getEnvhum()); |
| | | orderVo.setEnvTemp(realTimeDataVo.getEnvtemp()); |
| | | orderVo.setRemain(realTimeDataVo.getAi_total_time()); |
| | | orderVo.setCurRemain(realTimeDataVo.getAi_time()); |
| | | orderVo.setState_fan(realTimeDataVo.getState_fan()); |
| | | orderVo.setState_roller(realTimeDataVo.getState_roller()); |
| | | orderVo.setState_auto(realTimeDataVo.getState_auto()); |
| | | orderVo.setState_windbox(realTimeDataVo.getState_windbox()); |
| | | orderVo.setState_valve(realTimeDataVo.getState_valve()); |
| | | orderVo.setOrderStatus(realTimeDataVo.getWorkorder_status()); |
| | | orderVo.setEqp_status(realTimeDataVo.getEqp_status()); |
| | | orderVo.setEqp_state(realTimeDataVo.getEqp_state()); |
| | | orderVo.setWarning(realTimeDataVo.getEqp_warning()); |
| | | orderVo.setFault(realTimeDataVo.getEqp_fault()); |
| | | orderVo.setLevel(realTimeDataVo.getLevel()); |
| | | |
| | | |
| | | DryOrderTrendVo trendVo = new DryOrderTrendVo(realTimeDataVo); |
| | | // 2.2 保存工单含水率变化 或 重量变化 |
| | | |
| | | if(realTimeDataVo.getReport_flag()) { |
| | | DryProdRecord prodRecord = new DryProdRecord(); |
| | | prodRecord.setReportHeadName(realTimeDataVo.getReport_head_name()); |
| | | prodRecord.setReportHeadBatch(realTimeDataVo.getReport_head_batch()); |
| | | prodRecord.setReportHeadNum(realTimeDataVo.getReport_head_num()); |
| | | prodRecord.setReportHeadMachine(realTimeDataVo.getReport_head_machine()); |
| | | prodRecord.setReportHeadAccepter(realTimeDataVo.getReport_head_accepter()); |
| | | prodRecord.setReportHeadDate(realTimeDataVo.getReport_head_date()); |
| | | prodRecord.setReportHeadLeader(realTimeDataVo.getReport_head_leader()); |
| | | prodRecord.setReportHeadTecher(realTimeDataVo.getReport_head_techer()); |
| | | |
| | | prodRecord.setReportCheckField(realTimeDataVo.getReport_check_field()?1:0); |
| | | prodRecord.setReportCheckFile(realTimeDataVo.getReport_check_file()?1:0); |
| | | prodRecord.setReportCheckTag(realTimeDataVo.getReport_check_tag()?1:0); |
| | | prodRecord.setReportCheckTool(realTimeDataVo.getReport_check_tool()?1:0); |
| | | prodRecord.setReportCheckMan(realTimeDataVo.getReport_check_man()); |
| | | prodRecord.setReportCheckStatus(realTimeDataVo.getReport_check_status()?1:0); |
| | | prodRecord.setReportCheckQa(realTimeDataVo.getReport_check_qa()); |
| | | prodRecord.setReportCheckRecord(realTimeDataVo.getReport_check_record()); |
| | | |
| | | prodRecord.setReportProductView(realTimeDataVo.getReport_product_view()?1:0); |
| | | prodRecord.setReportProductWind(realTimeDataVo.getReport_product_wind()?1:0); |
| | | prodRecord.setReportProductSun(realTimeDataVo.getReport_product_sun()?1:0); |
| | | prodRecord.setReportProductLowDry(realTimeDataVo.getReport_product_low_dry()?1:0); |
| | | prodRecord.setReportProductDry(realTimeDataVo.getReport_product_dry()?1:0); |
| | | prodRecord.setReportProductStart(realTimeDataVo.getReport_product_start()); |
| | | prodRecord.setReportProductEnd(realTimeDataVo.getReport_product_end()); |
| | | prodRecord.setReportProductTotal(realTimeDataVo.getReport_product_total()); |
| | | prodRecord.setReportProductCheck(realTimeDataVo.getReport_product_check()?1:0); |
| | | prodRecord.setReportProductMan1(realTimeDataVo.getReport_product_man1()); |
| | | prodRecord.setReportProductMan2(realTimeDataVo.getReport_product_man2()); |
| | | prodRecord.setReportProductWeight(realTimeDataVo.getReport_product_weight()); |
| | | prodRecord.setReportProductWaste(realTimeDataVo.getReport_product_waste()); |
| | | prodRecord.setReportProductUse(realTimeDataVo.getReport_product_use()); |
| | | prodRecord.setReportProductQa(realTimeDataVo.getReport_product_qa()); |
| | | |
| | | prodRecord.setReportCleanMachine(realTimeDataVo.getReport_clean_machine()?1:0); |
| | | prodRecord.setReportCleanWaste(realTimeDataVo.getReport_clean_waste()?1:0); |
| | | prodRecord.setReportCleanTool(realTimeDataVo.getReport_clean_tool()?1:0); |
| | | prodRecord.setReportCleanDoor(realTimeDataVo.getReport_clean_door()?1:0); |
| | | prodRecord.setReportCleanBox(realTimeDataVo.getReport_clean_box()?1:0); |
| | | prodRecord.setReportCleanRecord(realTimeDataVo.getReport_clean_record()?1:0); |
| | | prodRecord.setReportCleanDate(realTimeDataVo.getReport_clean_date()); |
| | | prodRecord.setReportCleanMan(realTimeDataVo.getReport_clean_man()); |
| | | prodRecord.setReportCleanConfirm(realTimeDataVo.getReport_clean_confirm()?1:0); |
| | | prodRecord.setReportCleanQa(realTimeDataVo.getReport_clean_qa()); |
| | | prodRecordService.save(prodRecord); |
| | | } |
| | | saveOrderTrendVo(trendVo, orderVo); |
| | | orderVo.setTrendVo(trendVo); |
| | | orderVo.getBellowsTemp().put(realTimeDataVo.getTime3(), realTimeDataVo.getTemp2()); |
| | |
| | | @Override |
| | | public Result<?> queryMachineRealTImeData(RealTimeDataVo realTimeDataVo) { |
| | | TenantContext.setTenant(realTimeDataVo.getTenantid()+""); |
| | | DryOrderVo orderVo = (DryOrderVo) redisUtil.hget(CacheConstants.RedisKeyEnum.WORK_ORDER.getCode(), realTimeDataVo.getTenantid()+"_"+realTimeDataVo.getMachineid()); |
| | | |
| | | |
| | | LambdaQueryWrapper<DryEquipment> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | queryWrapper.eq(DryEquipment::getTenantId, realTimeDataVo.getTenantid()); |
| | | queryWrapper.eq(DryEquipment::getEnable, "Y"); |
| | | |
| | | List<DryEquipment> dryEquipments = equipmentService.list(queryWrapper); |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | List<Double> dList = new ArrayList<>(); |
| | | DryOrderVo orderVo = (DryOrderVo) redisUtil.hget(CacheConstants.RedisKeyEnum.WORK_ORDER.getCode(), realTimeDataVo.getTenantid() + "_" + realTimeDataVo.getMachineid()); |
| | | try { |
| | | |
| | | |
| | | if (dryEquipments != null && dryEquipments.size() > 0) { |
| | | dryEquipments.stream().forEach(item -> { |
| | | DryOrderVo order = (DryOrderVo) redisUtil.hget(CacheConstants.RedisKeyEnum.WORK_ORDER.getCode(), realTimeDataVo.getTenantid() + "_" + item.getCode()); |
| | | if (order != null) { |
| | | double v = order.getOriginWeight() - order.getYield(); |
| | | list.add(item.getName().substring(0, item.getName().indexOf('#')+1)); |
| | | if (v > 0 && order.getDryTime()>0) { |
| | | DecimalFormat df = new DecimalFormat("#.00"); |
| | | dList.add(Double.valueOf(df.format(v / order.getDryTime() * 60))); |
| | | } else { |
| | | dList.add(50d); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } |
| | | if (orderVo != null) { |
| | | orderVo.setCompEqpNum(list); |
| | | orderVo.setCompEqpEffic(dList); |
| | | } |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return Result.ok(orderVo); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result<?> sendSocketMsg(CommandMessageVo msgVo) { |
| | | |
| | | |
| | | DryEquipment dryEquipment = equipmentService.selectByTenantIdEquipmentId(msgVo.getTenantId() + "", msgVo.getMachineId()); |
| | | log.info("获取设备:" + dryEquipment.toString()); |
| | | |
| | | // managedSessions.keySet().forEach(addr -> { |
| | | // ObjectOutputStream oos = null; |
| | | try { |
| | | // Socket socket = SocketServerConfig.clientMap.get(addr); |
| | | IoSession session = ServerHandler.clientSocket.get(dryEquipment.getIp()); |
| | | if (session == null) { |
| | | return Result.error("未获取到session,请检查客户端配置或设备ip配置是否正常"); |
| | | } |
| | | SocketMsgVo smv = new SocketMsgVo(msgVo); |
| | | session.write(JSONObject.toJSONString(smv)); |
| | | // oos = new ObjectOutputStream(socket.getOutputStream()); |
| | | // String s = JSONObject.toJSONString(new SocketMsgVo(msgVo)); |
| | | // oos.writeUTF(s); |
| | | // oos.flush(); |
| | | |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } finally { |
| | | |
| | | } |
| | | // }); |
| | | return Result.OK(); |
| | | } |
| | | } |