CameraController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.gzlh.device.camera.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.util.XmlUtil;
  4. import com.gzlh.bus.EventDataManager;
  5. import com.gzlh.config.SystemObject;
  6. import com.gzlh.device.camera.factory.CameraFactory;
  7. import com.gzlh.device.camera.properties.CameraPropertiesConfig;
  8. import com.gzlh.entity.ReqBO;
  9. import com.gzlh.utils.FileUtils;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.boot.autoconfigure.web.ServerProperties;
  12. import org.springframework.util.StringUtils;
  13. import org.springframework.web.bind.annotation.PostMapping;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import org.w3c.dom.Document;
  18. import org.w3c.dom.Element;
  19. import javax.annotation.Resource;
  20. import java.io.IOException;
  21. import java.net.InetAddress;
  22. import java.util.*;
  23. @RestController
  24. @RequestMapping("/camera")
  25. public class CameraController {
  26. @Resource
  27. private CameraFactory cameraFactory;
  28. @Resource
  29. private CameraPropertiesConfig cameraPropertiesConfig;
  30. @Resource
  31. private ServerProperties serverProperties;
  32. @PostMapping("/recv")
  33. public void recv(
  34. @RequestBody String xmlStr
  35. // HttpServletRequest request
  36. ) throws IOException {
  37. // String xmlStr = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
  38. String path=SystemObject.filePropertiesConfig.getRootPath();
  39. String channelCode=SystemObject.applicationConfig.getChannelCode();
  40. Map<String, Object> StringObjectMap = new HashMap<>();
  41. Document document = XmlUtil.parseXml(xmlStr);
  42. Element rootElement = XmlUtil.getRootElement(document);
  43. // String i_e_type = rootElement.getAttribute("I_E_TYPE");
  44. XmlUtil.xmlToMap(xmlStr, StringObjectMap);
  45. Map<String, Object> ic = BeanUtil.beanToMap(StringObjectMap.get("IC"));
  46. Map<String, Object> weight =BeanUtil.beanToMap(StringObjectMap.get("WEIGHT"));
  47. Map<String, Object> car = BeanUtil.beanToMap(StringObjectMap.get("CAR"));
  48. Map<String, Object> conta =BeanUtil.beanToMap(StringObjectMap.get("CONTA"));
  49. Map<String, Object> seal = BeanUtil.beanToMap(StringObjectMap.get("SEAL"));
  50. Map<String, String> boxNoMap = new HashMap<>();
  51. ReqBO.Box box = new ReqBO.Box();
  52. if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_F"))) {
  53. box.setBoxF((String) conta.get("CONTA_ID_F"));
  54. }
  55. if (!StringUtils.isEmpty((String) conta.get("CONTA_ID_B"))) {
  56. box.setBoxB((String) conta.get("CONTA_ID_B"));
  57. }
  58. if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_F"))) {
  59. box.setModelF((String) conta.get("CONTA_MODEL_F"));
  60. }
  61. if (!StringUtils.isEmpty((String) conta.get("CONTA_MODEL_B"))) {
  62. box.setModelB((String) conta.get("CONTA_MODEL_B"));
  63. }
  64. Calendar calendar = Calendar.getInstance();
  65. String ipAddr =InetAddress.getLocalHost().getHostAddress()+":"+String.valueOf(serverProperties.getPort());
  66. String savePath=path+"/"+channelCode+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
  67. String fBoxImg = "";
  68. String bBoxImg = "";
  69. for (Map.Entry<String, Object> entry : conta.entrySet()) {
  70. if(entry.getKey().contains("PIC")&& !StringUtils.isEmpty((String) entry.getValue())){
  71. String filePath = FileUtils.downLoad((String) entry.getValue(),savePath);
  72. filePath=filePath.replace(path,ipAddr+"/files");
  73. // String base64 = FileUtils.getBase64FromImg(filePath);
  74. if (entry.getKey().contains("CONTA_F")){
  75. fBoxImg=fBoxImg.concat(filePath).concat(",");
  76. }else if (entry.getKey().contains("CONTA_B")){
  77. bBoxImg=bBoxImg.concat(filePath).concat(",");
  78. }
  79. }
  80. }
  81. box.setBoxFImg(fBoxImg);
  82. box.setBoxBImg(bBoxImg);
  83. EventDataManager.cacheData("box",box);
  84. }
  85. }