Commit c85da2a8 zshaohui

每日出入库和货架使用情况 抛送到中控

1 个父辈 fc7d5d20
package com.neotel.smfcore.custom.lizhen.kafka.config;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Component
public class StorageExportConfig {
//private final static List<String> exportStrArr = Arrays.asList("MU1_1", "MU4_1", "MU2_1", "MU5_1", "MU1_2", "MU4_2", "MU5_2", "MU3_1");
public static Map<String, String> exportMap = new ConcurrentHashMap<>();
@PostConstruct
public void initMap() {
exportMap.put("MU1_1", "SJ202306205006");
exportMap.put("MU1_2", "SJ202306205007");
exportMap.put("MU2_1", "SJ202306205005");
exportMap.put("MU3_1", "SJ202306205008");
exportMap.put("MU4_1", "SJ202306205003");
exportMap.put("MU4_2", "SJ202306205004");
exportMap.put("MU5_1", "SJ202306205001");
exportMap.put("MU5_2", "SJ202306205002");
}
public static String getMachineId(String key) {
return exportMap.get(key);
}
}
package com.neotel.smfcore.custom.lizhen.kafka.bean; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
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;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
@Data @Data
@ApiModel("心跳信息") @ApiModel("心跳信息")
......
package com.neotel.smfcore.custom.lizhen.kafka.bean; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
......
package com.neotel.smfcore.custom.lizhen.kafka.bean; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
......
package com.neotel.smfcore.custom.lizhen.kafka.bean; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
@Data @Data
public class MachineStatus { public class MachineStatus {
......
package com.neotel.smfcore.custom.lizhen.kafka.config; package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.config;
public class KafkaConfig { public class KafkaConfig {
/** /**
......
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.config;
public class StorageNameConfig {
//原材料仓货架
public static final String semiFinishedTower = "semi-finished-tower";
}
package com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.service;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.neotel.smfcore.core.barcode.enums.BARCODE_STATUS;
import com.neotel.smfcore.core.device.enums.OP;
import com.neotel.smfcore.core.device.enums.OP_STATUS;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.system.service.manager.IDataLogManager;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean.MachineParameter;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.bean.MachineParameterData;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.config.KafkaConfig;
import com.neotel.smfcore.custom.luxsan.factory_c.wipstor.kafka.config.StorageNameConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
//@Async
@Service
@Slf4j
public class KafkaService {
@Autowired
private IDataLogManager dataLogManager;
@Autowired
private DataCache dataCache;
@Autowired
private KafkaTemplate kafkaTemplate;
@Autowired
private IStoragePosManager storagePosManager;
@Scheduled(fixedRate = 1000 * 60 * 5)
public void setTowerDataMachineParamter() {
log.info("开始推送原材料仓tower数据");
MachineParameter machineParameter = new MachineParameter();
String dateStr = DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
machineParameter.setOccurrenceTime(dateStr);
machineParameter.setMachineID(StorageNameConfig.semiFinishedTower);
machineParameter.setContentType("F");
machineParameter.setMachineType("半成品货架");
machineParameter.setSupplierID("NEOTEL");
machineParameter.setProgramName("");
machineParameter.setProgramVersion("");
machineParameter.setSerialNumber("");
machineParameter.setResult("");
machineParameter.setEmpNo("");
machineParameter.setClientIP("");
List<String> storageIdList = new ArrayList<>();
for (Storage storage : dataCache.getAllStorage().values()) {
if (!storage.isVirtual()) {
storageIdList.add(storage.getId());
}
}
//获取货架所有库位的使用情况
int totalCount = storagePosManager.countByQuery(new Query(Criteria.where("storageId").in(storageIdList)));
int usedCount = storagePosManager.countByQuery(new Query(Criteria.where("barcode.status").is(BARCODE_STATUS.IN_STORE).and("storageId").in(storageIdList)));
int emptyCount = totalCount - usedCount;
int todayInCount = getTodayInOutCount(storageIdList, OP.PUT_IN);
int todayOutCount = getTodayInOutCount(storageIdList, OP.CHECKOUT);
List<MachineParameterData> dataList = new ArrayList<>();
dataList.add(new MachineParameterData("totalCount", totalCount + ""));
dataList.add(new MachineParameterData("emptyCount", emptyCount + ""));
dataList.add(new MachineParameterData("usedCount", usedCount + ""));
dataList.add(new MachineParameterData("todayInCount", todayInCount + ""));
dataList.add(new MachineParameterData("todayOutCount", todayOutCount + ""));
machineParameter.setData(dataList);
String machineParameterStr = JSON.toJSONString(machineParameter);
log.info("MachineParameter主题为:" + KafkaConfig.MACHINEPARAMETER_TOPIC + "内容为:" + machineParameterStr);
ListenableFuture future = kafkaTemplate.send(KafkaConfig.MACHINEPARAMETER_TOPIC, machineParameterStr);
log.info("MachineParameter返回结果为:" + JSON.toJSONString(future));
log.info("结束推送原材料仓tower数据");
}
public int getTodayInOutCount(List<String> storageIdList, int type) {
Query q = new Query();
Criteria c = new Criteria();
c.and("updateDate").gte(getDate()); //时间大于今天
c.and("status").in(OP_STATUS.END.name(), OP_STATUS.FINISHED.name()); // 任务是完成的
c.and("storageId").in(storageIdList);
c.and("type").is(type);
return dataLogManager.countByQuery(q.addCriteria(c));
}
private Date getDate() {
//1.获取到当前时间
Date currentDate = new Date();
//2.获取到今天的开始时间
String currentDay = DateUtil.format(currentDate, "yyyy-MM-dd");
currentDay += " 00:00:00";
Date startDate = DateUtil.parse(currentDay, "yyyy-MM-dd HH:mm:ss");
log.info("获取到开始时间为:" + startDate);
return startDate;
}
}
...@@ -17,12 +17,12 @@ spring: ...@@ -17,12 +17,12 @@ spring:
database: wipsmf #原材料仓数据库 database: wipsmf #原材料仓数据库
#kafka配置 #kafka配置
# kafka: kafka:
# bootstrap-servers: 10.190.196.135:9092 bootstrap-servers: 10.68.16.18:9092,10.68.16.19:9092,10.68.16.20:9092
# consumer: consumer:
# group-id: neotel group-id: neotel
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# value-deserializer: org.apache.kafka.common.serialization.StringDeserializer value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
#jwt #jwt
jwt: jwt:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!