123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.gzlh.device.camera.controller;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.XmlUtil;
- import com.gzlh.bus.EventDataManager;
- import com.gzlh.config.SystemObject;
- import com.gzlh.device.camera.factory.CameraFactory;
- import com.gzlh.device.camera.properties.CameraPropertiesConfig;
- import com.gzlh.entity.ReqBO;
- import com.gzlh.utils.FileUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.autoconfigure.web.ServerProperties;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import javax.annotation.Resource;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.util.*;
- @RestController
- @RequestMapping("/camera")
- public class CameraController {
- @Resource
- private CameraFactory cameraFactory;
- @Resource
- private CameraPropertiesConfig cameraPropertiesConfig;
- @Resource
- private ServerProperties serverProperties;
- @PostMapping("/recv")
- public void recv(
- @RequestBody String xmlStr
- // HttpServletRequest request
- ) throws IOException {
- // String xmlStr = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
- String path=SystemObject.filePropertiesConfig.getRootPath();
- String channelCode=SystemObject.applicationConfig.getChannelCode();
- Map<String, Object> StringObjectMap = new HashMap<>();
- Document document = XmlUtil.parseXml(xmlStr);
- Element rootElement = XmlUtil.getRootElement(document);
- // String i_e_type = rootElement.getAttribute("I_E_TYPE");
- XmlUtil.xmlToMap(xmlStr, StringObjectMap);
- Map<String, Object> ic = BeanUtil.beanToMap(StringObjectMap.get("IC"));
- Map<String, Object> weight =BeanUtil.beanToMap(StringObjectMap.get("WEIGHT"));
- Map<String, Object> car = BeanUtil.beanToMap(StringObjectMap.get("CAR"));
- Map<String, Object> conta =BeanUtil.beanToMap(StringObjectMap.get("CONTA"));
- Map<String, Object> seal = BeanUtil.beanToMap(StringObjectMap.get("SEAL"));
- Map<String, String> boxNoMap = new HashMap<>();
- ReqBO.Box box = new ReqBO.Box();
- if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_F"))) {
- box.setBoxF((String) conta.get("CONTA_ID_F"));
- }
- if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_B"))) {
- box.setBoxB((String) conta.get("CONTA_ID_B"));
- }
- if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_F"))) {
- box.setModelF((String) conta.get("CONTA_MODEL_F"));
- }
- if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_B"))) {
- box.setModelB((String) conta.get("CONTA_MODEL_B"));
- }
- Calendar calendar = Calendar.getInstance();
- String ipAddr =InetAddress.getLocalHost().getHostAddress()+":"+String.valueOf(serverProperties.getPort());
- String savePath=path+"/"+channelCode+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
- String fBoxImg = "";
- String bBoxImg = "";
- for (Map.Entry<String, Object> entry : conta.entrySet()) {
- if(entry.getKey().contains("PIC")&& !StringUtils.isEmpty((String) entry.getValue())){
- String filePath = FileUtils.downLoad((String) entry.getValue(),savePath);
- filePath=filePath.replace(path,ipAddr+"/files");
- // String base64 = FileUtils.getBase64FromImg(filePath);
- if (entry.getKey().contains("CONTA_F")){
- fBoxImg=fBoxImg.concat(filePath).concat(",");
- }else if (entry.getKey().contains("CONTA_B")){
- bBoxImg=bBoxImg.concat(filePath).concat(",");
- }
- }
- }
- box.setBoxFImg(fBoxImg);
- box.setBoxBImg(bBoxImg);
- EventDataManager.cacheData("box",box);
- }
- }
|