zy-acs-flow/src/map/insight/agv/AgvMain.jsx
@@ -178,7 +178,7 @@ <KeyValuePair label={translate('common.field.status')} value={info?.agvStatus} /> </Grid> <Grid item xs={12}> <KeyValuePair label={translate('table.field.agvDetail.vol')} value={info?.vol} /> <KeyValuePair label={translate('table.field.agvDetail.soc')} value={info?.soc} /> </Grid> {/* <Grid item xs={12}> <KeyValuePair label={translate('table.field.agvDetail.soc')} value={info?.soc} /> zy-acs-gateway/src/main/resources/application.yml
@@ -6,7 +6,7 @@ name: @pom.artifactId@ datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/rcs_ctu_stable?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/rcs_ctu_stable_xgc?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: xltys1995 @@ -24,7 +24,7 @@ max: 30 min: 10 timeout: 5000 index: 8 index: 9 logging: file: zy-acs-manager/pom.xml
@@ -143,7 +143,13 @@ <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.2.6</version> <version>4.0.3</version> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.16.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> zy-acs-manager/src/main/java/com/zy/acs/manager/core/DemoController.java
@@ -155,7 +155,7 @@ agvDetail.setCode(code.getId()); agvDetail.setStatus(AgvStatusType.IDLE.val); agvDetail.setAgvAngle(workDirection); agvDetail.setVol(5000); agvDetail.setSoc(80); agvDetailService.updateById(agvDetail); } zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/MaintainScheduler.java
@@ -54,7 +54,7 @@ for (Agv agv : agvList) { AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); if (null == agvDetail || null == agvDetail.getVol() || null == agvDetail.getAgvStatus()) { if (null == agvDetail || null == agvDetail.getSoc() || null == agvDetail.getAgvStatus()) { continue; } if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/utils/MapDataListener.java
New file @@ -0,0 +1,138 @@ package com.zy.acs.manager.manager.controller.utils; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.fastjson.JSON; import com.google.common.collect.Lists; import com.zy.acs.common.utils.GsonUtils; import com.zy.acs.framework.common.Cools; import com.zy.acs.manager.manager.entity.Code; import com.zy.acs.manager.manager.entity.CodeGap; import com.zy.acs.manager.manager.entity.Route; import com.zy.acs.manager.manager.service.CodeGapService; import com.zy.acs.manager.manager.service.CodeService; import com.zy.acs.manager.manager.service.RouteService; import lombok.extern.slf4j.Slf4j; import java.util.*; @Slf4j public class MapDataListener implements ReadListener<Map<Integer, String>> { /** * 每隔5条存储数据库,实际使用中可以100条,然后清理list ,方便内存回收 */ private static final int BATCH_COUNT = 10000; private List<Map<Integer, String>> cachedDataList = Lists.newArrayListWithExpectedSize(BATCH_COUNT); /** * 假设这个是一个DAO,当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。 */ private RouteService routeService; private CodeService codeService; private CodeGapService codeGapService; private List<Code> codes = new ArrayList<>(); private List<Route> routes = new ArrayList<>(); private List<CodeGap> codeGaps = new ArrayList<>(); /** * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来 * * @param routeService */ public MapDataListener(RouteService routeService, CodeService codeService, CodeGapService codeGapService) { this.routeService = routeService; this.codeService = codeService; this.codeGapService = codeGapService; } /** * 这个每一条数据解析都会来调用 * * @param data one row value. It is same as {@link AnalysisContext#readRowHolder()} * @param context */ @Override public void invoke(Map<Integer, String> data, AnalysisContext context) { log.info("解析到一条数据:{}", JSON.toJSONString(data)); cachedDataList.add(data); // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM if (cachedDataList.size() >= BATCH_COUNT) { saveData(); // 存储完成清理 list cachedDataList = Lists.newArrayListWithExpectedSize(BATCH_COUNT); } } /** * 所有数据解析完成了 都会来调用 * * @param context */ @Override public void doAfterAllAnalysed(AnalysisContext context) { // 这里也要保存数据,确保最后遗留的数据也存储到数据库 Map<Integer, String> xData = cachedDataList.get(78); Map<Integer, String> x = new HashMap<>(); xData.entrySet().forEach(entry -> { x.put(entry.getKey() , entry.getValue()); }); Map<Integer, String> y = new HashMap<>(); for (int i = 0; i < cachedDataList.size(); i++) { Map<Integer, String> integerStringMap = cachedDataList.get(i); y.put(i, integerStringMap.get(1)); } log.info("x轴:{}", JSON.toJSONString(x)); log.info("y轴:{}", JSON.toJSONString(y)); for (int i = 0; i < cachedDataList.size(); i++) { if (i >= 78) { continue; } Map<Integer, String> integerStringMap = cachedDataList.get(i); int finalI = i; integerStringMap.entrySet().forEach(entry -> { if (entry.getValue() != null && entry.getValue().startsWith("00")) { log.info("数据:{}", entry.getValue()); Code code = new Code(); code.setData(entry.getValue()); code.setUuid("code".concat(code.getData())); if (x.get(entry.getKey()) == null) { log.info("x轴数据为空:{}", entry.getKey()); } code.setX(Double.parseDouble(x.get(entry.getKey()))+10000); if (y.get(finalI) == null) { log.info("y轴数据为空:{},{}", finalI, y.get(finalI)); } code.setY(Double.parseDouble(y.get(finalI))+10000); code.setScale(GsonUtils.toJson(Cools.add("x", 1).add("y", 1))); code.setCreateTime(new Date()); code.setUpdateTime(new Date()); codes.add(code); } }); } //log.info("所有数据解析完成!{}", JSON.toJSONString(codes)); log.info("所有数据解析完成!{}", codes.size()); saveData(); } /** * 加上存储数据库 */ private void saveData() { log.info("{}条数据,开始存储数据库!", cachedDataList.size()); for (Code code : codes){ codeService.save(code); } log.info("存储数据库成功!"); } } zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/utils/UtilsController.java
New file @@ -0,0 +1,100 @@ package com.zy.acs.manager.manager.controller.utils; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.common.collect.Lists; import com.zy.acs.common.utils.Utils; import com.zy.acs.manager.common.annotation.OperationLog; import com.zy.acs.manager.manager.entity.Code; import com.zy.acs.manager.manager.entity.Loc; import com.zy.acs.manager.manager.service.CodeGapService; import com.zy.acs.manager.manager.service.CodeService; import com.zy.acs.manager.manager.service.LocService; import com.zy.acs.manager.manager.service.RouteService; import com.zy.acs.manager.system.controller.BaseController; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.List; import java.util.Map; /** * Created by vincent on 2023/6/12 */ @Api(tags = "Utils Api") @RestController @RequestMapping("/api/file") public class UtilsController extends BaseController { @Autowired private RouteService routeService; @Autowired private LocService locService; @Autowired private CodeService codeService; @Autowired private CodeGapService codeGapService; /** * 文件上传 * <p> * 1. 创建excel对应的实体对象 参照{@link Map<Integer, String>} * <p> * 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link MapDataListener} * <p> * 3. 直接读即可 */ @RequestMapping("/excel/map/import") @ResponseBody @OperationLog("import map data") public String upload(MultipartFile file) throws IOException { EasyExcel.read(file.getInputStream(), new MapDataListener(routeService, codeService, codeGapService)).sheet().doRead(); return "success"; } private List<Integer> starts = Lists.newArrayList(7, 62, 126, 182, 237, 292, 347, 436, 525, 614, 793, 882, 970, 1059, 1148, 1324, 1416, 1505); private int d = 10; private int d2 = 5; private List<Integer> starts2 = Lists.newArrayList(389, 478, 567, 745, 835, 923, 1012, 1101, 1190, 1366, 1458, 1547); @RequestMapping("/loc") @ResponseBody @OperationLog("import map data") public String loc() { List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>().orderByAsc(Loc::getRow).orderByAsc(Loc::getBay).orderByAsc(Loc::getLev)); for (Loc loc : list) { // if (loc.getBay() <= 24) { // Integer i = starts.get((loc.getRow() - 1) / 2); // Code cacheByData = codeService.getCacheByData(Utils.zeroFill((loc.getBay()%8 -1+ i + loc.getBay() / 8 * 10) + "", 8)); // loc.setCode(cacheByData.getId()); // locService.updateById(loc); // } // if (loc.getBay() > 24 && loc.getBay() <= 32) { // Integer i = starts.get((loc.getRow() - 1) / 2) + 30; // Code cacheByData = codeService.getCacheByData(Utils.zeroFill(((loc.getBay() - 24)%4-1 + i + (loc.getBay() - 24) / 4 * 6) + "", 8)); // loc.setCode(cacheByData.getId()); // locService.updateById(loc); // } if (loc.getBay() > 32) { Integer i = starts2.get((loc.getRow() - 13) / 2); Code cacheByData = codeService.getCacheByData(Utils.zeroFill((Utils.zeroFill((((loc.getBay()-1) % 8) + i + (((loc.getBay()-1) / 8) - 4) * 10) + "", 8)) + "", 8)); loc.setCode(cacheByData.getId()); locService.updateById(loc); } } return "success"; } } zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/AgvServiceImpl.java
@@ -206,7 +206,7 @@ log.warn("[{}]号Agv未收到状态包......", agvNo); return false; } if (agvDetail.getVol() == 0) { if (null == agvDetail.getSoc() || agvDetail.getSoc() == 0) { return false; } if (!agvDetail.getAgvStatus().equals(AgvStatusType.IDLE) && !agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { @@ -214,7 +214,7 @@ return false; } if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { if (agvDetail.getVol() < agvModel.getQuaBattery()) { if (agvDetail.getSoc() < agvModel.getQuaBattery()) { return false; } } zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/FuncStaServiceImpl.java
@@ -94,7 +94,7 @@ AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); if (agvDetail.getAgvStatus().equals(AgvStatusType.CHARGE)) { if (agvDetail.getVol() < agvModel.getQuaBattery()) { if (agvDetail.getSoc() < agvModel.getQuaBattery()) { return false; } } else { zy-acs-manager/src/main/resources/application.yml
@@ -7,7 +7,7 @@ static-path-pattern: /** datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/rcs_ctu_stable?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/rcs_ctu_stable_xgc?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: xltys1995 type: com.alibaba.druid.pool.DruidDataSource @@ -48,7 +48,7 @@ max: 30 min: 10 timeout: 5000 index: 8 index: 9 floyd: enable: false zy-acs-manager/src/main/resources/mapper/manager/AgvDetailMapper.xml
@@ -27,7 +27,7 @@ </sql> <select id="selectMajorByAgvId" resultType="com.zy.acs.manager.manager.entity.AgvDetail"> SELECT id, agv_id, pos, code, last_code, agv_angle, vol, backpack, status, deleted SELECT id, agv_id, pos, code, last_code, agv_angle, vol,soc, backpack, status, deleted FROM man_agv_detail WHERE agv_id = #{agvId} LIMIT 1