AutomaticCaptureManagementController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. package cn.com.lzt.car.automaticCaptureManagement.controller;
  2. import cn.com.lzt.car.automaticCaptureManagement.entity.TBCarAutomaticCaptureManagement;
  3. import cn.com.lzt.car.automaticCaptureManagement.entity.TBCarShootReglas;
  4. import cn.com.lzt.car.automaticCaptureManagement.service.automaticCaptureManagementService;
  5. import com.xcgl.utils.UUID;
  6. import org.apache.commons.lang.xwork.StringUtils;
  7. import org.apache.log4j.Logger;
  8. import org.jeecgframework.core.common.controller.BaseController;
  9. import org.jeecgframework.core.common.exception.BusinessException;
  10. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  11. import org.jeecgframework.core.common.model.json.AjaxJson;
  12. import org.jeecgframework.core.common.model.json.DataGrid;
  13. import org.jeecgframework.core.constant.Globals;
  14. import org.jeecgframework.core.util.JeecgDataAutorUtils;
  15. import org.jeecgframework.core.util.ResourceUtil;
  16. import org.jeecgframework.tag.core.easyui.TagUtil;
  17. import org.jeecgframework.web.system.service.SystemService;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Controller;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import org.springframework.web.bind.annotation.ResponseBody;
  23. import org.springframework.web.servlet.ModelAndView;
  24. import javax.annotation.Resource;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Date;
  30. import java.util.List;
  31. import java.util.Map;
  32. /**
  33. * @author LiuMengxiang
  34. * @version V1.0
  35. * @Title: Controller
  36. * @Description: 自动抓拍、录像条件管理
  37. * @date 2021年11月16日10:03:04
  38. */
  39. @Controller
  40. @RequestMapping("/automaticCaptureManagementController")
  41. public class AutomaticCaptureManagementController extends BaseController {
  42. /**
  43. * Logger for this class
  44. */
  45. private static final Logger logger = Logger.getLogger(AutomaticCaptureManagementController.class);
  46. @Resource
  47. private automaticCaptureManagementService automaticCaptureManagementService;
  48. @Autowired
  49. private SystemService systemService;
  50. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  51. /***
  52. * 页面跳转到自动抓拍管理index页面
  53. * @author 刘梦祥
  54. * @date 2021年11月16日10:08:25
  55. * @param request
  56. * @return ModelAndView
  57. */
  58. @RequestMapping(params = "autoSnapIndex")
  59. public ModelAndView autoSnapIndex(HttpServletRequest request) {
  60. return new ModelAndView("cn/com/lzt/jobimage/automaticCapture/autoSnapList");
  61. }
  62. /**
  63. * 车辆类型同步
  64. *
  65. * @author 刘梦祥
  66. * @Date 2021年12月30日13:44:10
  67. */
  68. public void carType() {
  69. // 添加操作
  70. String carTypeStr = "SELECT\n" +
  71. "\t\t\t*\n" +
  72. "\t\tFROM\n" +
  73. "\t\t\tt_s_type tsy\n" +
  74. "\t\tLEFT JOIN t_s_typegroup tsyg ON tsyg.id = tsy.typegroupid\n" +
  75. "\t\tWHERE\n" +
  76. "\t\t\ttsyg.typegroupcode = \"cartype\"\n" +
  77. "\t\tAND tsy.typename NOT IN (\n" +
  78. "\t\t\t\"皮卡\",\n" +
  79. "\t\t\t\"行政车\",\n" +
  80. "\t\t\t\"其他\",\n" +
  81. "\t\t\t\"铲车\",\n" +
  82. "\t\t\t\"洗桶车\"\n" +
  83. ") and tsy.typecode not in (select car_type_code from t_b_car_automatic_capture_management)";
  84. List<Map<String, Object>> carTypeData = systemService.findForJdbc(carTypeStr);
  85. if (carTypeData != null && carTypeData.size() > 0) {
  86. for (Map<String, Object> carTypeItem : carTypeData) {
  87. TBCarAutomaticCaptureManagement tbCarAutomaticCaptureManagement = new TBCarAutomaticCaptureManagement();
  88. // TBCarAutomaticCaptureManagement tbCarAutomaticCaptureManagement2 = new TBCarAutomaticCaptureManagement();
  89. tbCarAutomaticCaptureManagement.setCarTypeCode(carTypeItem.get("typecode").toString());
  90. tbCarAutomaticCaptureManagement.setCarTypeName(carTypeItem.get("typename").toString());
  91. tbCarAutomaticCaptureManagement.setSnapNum(0);
  92. tbCarAutomaticCaptureManagement.setCameraPosition(0);
  93. tbCarAutomaticCaptureManagement.setTimingSettings(new Date());
  94. tbCarAutomaticCaptureManagement.setTimingSettingsStatus("F");
  95. tbCarAutomaticCaptureManagement.setFixedAreaSetting("");
  96. tbCarAutomaticCaptureManagement.setFixedAreaSettingStatus("F");
  97. tbCarAutomaticCaptureManagement.setVehicleEnableSetting("");
  98. tbCarAutomaticCaptureManagement.setVehicleEnableSettingStatus("F");
  99. tbCarAutomaticCaptureManagement.setManagementType("snap");
  100. tbCarAutomaticCaptureManagement.setCreateUser("系统自动检查");
  101. tbCarAutomaticCaptureManagement.setCreateTime(new Date());
  102. tbCarAutomaticCaptureManagement.setId(UUID.randomUUID().toString());
  103. // del-刘梦祥-2022年7月4日13:25:13(录像回放页面重构、删除录像条件)
  104. /*tbCarAutomaticCaptureManagement2.setCarTypeCode(tbCarAutomaticCaptureManagement.getCarTypeCode());
  105. tbCarAutomaticCaptureManagement2.setCarTypeName(tbCarAutomaticCaptureManagement.getCarTypeName());
  106. tbCarAutomaticCaptureManagement2.setSnapNum(tbCarAutomaticCaptureManagement.getSnapNum());
  107. tbCarAutomaticCaptureManagement2.setCameraPosition(tbCarAutomaticCaptureManagement.getCameraPosition());
  108. tbCarAutomaticCaptureManagement2.setTimingSettings(new Date());
  109. tbCarAutomaticCaptureManagement2.setTimingSettingsStatus(tbCarAutomaticCaptureManagement.getTimingSettingsStatus());
  110. tbCarAutomaticCaptureManagement2.setFixedAreaSetting(tbCarAutomaticCaptureManagement.getFixedAreaSetting());
  111. tbCarAutomaticCaptureManagement2.setFixedAreaSettingStatus(tbCarAutomaticCaptureManagement.getFixedAreaSettingStatus());
  112. tbCarAutomaticCaptureManagement2.setVehicleEnableSetting(tbCarAutomaticCaptureManagement.getVehicleEnableSetting());
  113. tbCarAutomaticCaptureManagement2.setVehicleEnableSettingStatus(tbCarAutomaticCaptureManagement.getVehicleEnableSettingStatus());
  114. tbCarAutomaticCaptureManagement2.setManagementType("video");
  115. tbCarAutomaticCaptureManagement2.setCreateUser(tbCarAutomaticCaptureManagement.getCreateUser());
  116. tbCarAutomaticCaptureManagement2.setCreateTime(new Date());
  117. tbCarAutomaticCaptureManagement2.setId(UUID.randomUUID().toString());*/
  118. systemService.save(tbCarAutomaticCaptureManagement);
  119. // systemService.save(tbCarAutomaticCaptureManagement2);
  120. }
  121. }
  122. // 删除操作
  123. String carTypeDelSql = "SELECT\n" +
  124. "\t*\n" +
  125. "FROM\n" +
  126. "\tt_b_car_automatic_capture_management\n" +
  127. "WHERE\n" +
  128. "\tcar_type_code NOT IN (\n" +
  129. "\t\tSELECT\n" +
  130. "\t\t\ttsy.typecode\n" +
  131. "\t\tFROM\n" +
  132. "\t\t\tt_s_type tsy\n" +
  133. "\t\tLEFT JOIN t_s_typegroup tsyg ON tsyg.id = tsy.typegroupid\n" +
  134. "\t\tWHERE\n" +
  135. "\t\t\ttsyg.typegroupcode = \"cartype\"\n" +
  136. "\t\tAND tsy.typename NOT IN (\n" +
  137. "\t\t\t\"皮卡\",\n" +
  138. "\t\t\t\"行政车\",\n" +
  139. "\t\t\t\"其他\",\n" +
  140. "\t\t\t\"铲车\",\n" +
  141. "\t\t\t\"洗桶车\"\n" +
  142. "\t\t)\n" +
  143. "\t);";
  144. List<Map<String, Object>> carTypeData2 = systemService.findForJdbc(carTypeDelSql);
  145. if (carTypeData2 != null && carTypeData2.size() > 0) {
  146. for (Map<String, Object> carTypeItem : carTypeData) {
  147. systemService.deleteEntityById(TBCarAutomaticCaptureManagement.class, carTypeItem.get("id").toString());
  148. }
  149. }
  150. }
  151. /**
  152. * 摄像头转义
  153. * @author 刘梦祥
  154. * @Date 2021年12月30日16:59:52
  155. * @param cameraPosition
  156. * @param tbCarShootReglas
  157. */
  158. public void getCamaraNo1ByCameraPosition(int cameraPosition, TBCarShootReglas tbCarShootReglas) {
  159. if (cameraPosition - 4 >= 0) {
  160. // 前置摄像头
  161. tbCarShootReglas.setCamaraNo1(1);
  162. cameraPosition -= 4;
  163. } else {
  164. tbCarShootReglas.setCamaraNo1(0);
  165. }
  166. if (cameraPosition - 2 >= 0) {
  167. // 后置摄像头
  168. tbCarShootReglas.setCamaraNo3(1);
  169. cameraPosition -= 2;
  170. } else {
  171. tbCarShootReglas.setCamaraNo3(0);
  172. }
  173. if (cameraPosition - 1 >= 0) {
  174. // 驾驶室摄像头
  175. tbCarShootReglas.setCamaraNo2(1);
  176. } else {
  177. tbCarShootReglas.setCamaraNo2(0);
  178. }
  179. }
  180. /**
  181. * 每次查询时,都检查一下管理表和定时任务同步管理表的数据。(如果多的话,执行添加操作,如果少的话就执行删除操作)
  182. *
  183. * @author 刘梦祥
  184. * @Date 2021年12月30日16:27:32
  185. */
  186. public void carType2() {
  187. try {
  188. // 添加操作
  189. String carTypeStr = "select * from t_b_car_automatic_capture_management where CONCAT(car_type_code,IF(management_type = \"snap\",1,2)) not in (select CONCAT(car_type,`type`) from t_b_car_shoot_reglas)";
  190. List<Map<String, Object>> carTypeData = systemService.findForJdbc(carTypeStr);
  191. if (carTypeData != null && carTypeData.size() > 0) {
  192. for (Map<String, Object> carTypeItem : carTypeData) {
  193. TBCarShootReglas tbCarShootReglas = new TBCarShootReglas();
  194. tbCarShootReglas.setId(UUID.randomUUID().toString());
  195. tbCarShootReglas.setCarType(carTypeItem.get("car_type_code").toString());
  196. tbCarShootReglas.setNum(Integer.parseInt(carTypeItem.get("snap_num").toString()));
  197. tbCarShootReglas.setType("snap".equals(carTypeItem.get("management_type")) ? 1 : 2);
  198. int cameraPosition = Integer.parseInt(carTypeItem.get("camera_position").toString());
  199. getCamaraNo1ByCameraPosition(cameraPosition, tbCarShootReglas);
  200. if (carTypeItem.get("timing_settings") != null && StringUtils.isNotEmpty(carTypeItem.get("timing_settings").toString())) {
  201. tbCarShootReglas.setBeginTime(sdf.parse(carTypeItem.get("timing_settings").toString()));
  202. }
  203. tbCarShootReglas.setByTime("T".equals(carTypeItem.get("timing_settings_status").toString()) ? 1 : 0);
  204. tbCarShootReglas.setByArea("T".equals(carTypeItem.get("fixed_area_setting_status").toString()) ? 1 : 0);
  205. tbCarShootReglas.setByState("T".equals(carTypeItem.get("vehicle_enable_setting_status").toString()) ? 1 : 0);
  206. tbCarShootReglas.setCreateTime(new Date());
  207. systemService.save(tbCarShootReglas);
  208. }
  209. }
  210. // 删除操作
  211. String carTypeDelSql = "select * from t_b_car_shoot_reglas where CONCAT(car_type,`type`) not in (select CONCAT(car_type_code,IF(management_type = \"snap\",1,2)) from t_b_car_automatic_capture_management);";
  212. List<Map<String, Object>> carTypeData2 = systemService.findForJdbc(carTypeDelSql);
  213. if (carTypeData2 != null && carTypeData2.size() > 0) {
  214. for (Map<String, Object> carTypeItem : carTypeData) {
  215. systemService.deleteEntityById(TBCarShootReglas.class, carTypeItem.get("id").toString());
  216. }
  217. }
  218. } catch (Exception e) {
  219. e.printStackTrace();
  220. throw new BusinessException(e.getMessage());
  221. }
  222. }
  223. /***
  224. * 页面跳转到自动录像管理index页面
  225. * @author 刘梦祥
  226. * @date 2021年11月16日10:11:04
  227. * @param request
  228. * @return ModelAndView
  229. */
  230. @RequestMapping(params = "autoVideoIndex")
  231. public ModelAndView autoVideoIndex(HttpServletRequest request) {
  232. return new ModelAndView("cn/com/lzt/jobimage/automaticCapture/autoVideoList");
  233. }
  234. /**
  235. * 初始化请求接口
  236. *
  237. * @param tbCarAutomaticCaptureManagement
  238. * @param request
  239. * @param response
  240. * @param dataGrid
  241. * @author 刘梦祥
  242. * @date 2021年11月16日10:29:39
  243. */
  244. @RequestMapping(params = "datagrid")
  245. @Transactional(rollbackFor = Exception.class)
  246. public void datagrid(TBCarAutomaticCaptureManagement tbCarAutomaticCaptureManagement, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  247. // add-刘梦祥-2021年12月30日11:40:293-每次查询时,都检查一下字典表中的数据。(如果多的话,执行添加操作,如果少的话就执行删除操作)
  248. carType();
  249. // add-刘梦祥-2021年12月30日16:26:38-每次查询时,都检查一下管理表和定时任务同步管理表的数据。(如果多的话,执行添加操作,如果少的话就执行删除操作)
  250. carType2();
  251. CriteriaQuery cq = new CriteriaQuery(TBCarAutomaticCaptureManagement.class, dataGrid);
  252. String carTypeName = request.getParameter("carTypeName");
  253. // 查询条件组装器-车辆类型
  254. if (StringUtils.isNotBlank(carTypeName)) {
  255. cq.like("carTypeName", "%" + carTypeName + "%");
  256. tbCarAutomaticCaptureManagement.setCarTypeName(null);
  257. }
  258. //查询条件组装器
  259. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tbCarAutomaticCaptureManagement, request.getParameterMap());
  260. cq.add();
  261. automaticCaptureManagementService.getDataGridReturn(cq, true);
  262. TagUtil.datagrid(response, dataGrid);
  263. }
  264. /**
  265. * 车辆自动抓拍、录像条件管理更新
  266. *
  267. * @param
  268. * @return AjaxJson
  269. * @author 刘梦祥
  270. * @date 2021年11月16日10:29:47
  271. */
  272. @RequestMapping(params = "update")
  273. @Transactional(rollbackFor = Exception.class)
  274. @ResponseBody
  275. public AjaxJson update(TBCarAutomaticCaptureManagement tbCarAutomaticCaptureManagement) {
  276. String message = null;
  277. AjaxJson j = new AjaxJson();
  278. try {
  279. TBCarAutomaticCaptureManagement t = automaticCaptureManagementService.get(TBCarAutomaticCaptureManagement.class, tbCarAutomaticCaptureManagement.getId());
  280. // add-刘梦祥-2021年12月30日15:03:12-(经过确认添加关联字段)
  281. TBCarShootReglas tbCarShootReglas = new TBCarShootReglas();
  282. if (t != null && t.getCarTypeCode() != null && t.getManagementType() != null) {
  283. CriteriaQuery criteriaQuery = new CriteriaQuery(TBCarShootReglas.class, new DataGrid());
  284. // snap:1,video:2
  285. criteriaQuery.eq("type", "snap".equals(t.getManagementType()) ? 1 : 2);
  286. criteriaQuery.eq("carType", t.getCarTypeCode());
  287. criteriaQuery.add();
  288. List<TBCarShootReglas> tbCarShootReglasList = systemService.getListByCriteriaQuery(criteriaQuery, true);
  289. if (tbCarShootReglasList != null && tbCarShootReglasList.size() == 1) {
  290. // 存在记录,执行更新操作
  291. tbCarShootReglas = tbCarShootReglasList.get(0);
  292. tbCarShootReglas.setUpdateTime(new Date());
  293. } else {
  294. // 不存在记录,执行新增操作
  295. tbCarShootReglas.setId(UUID.randomUUID().toString());
  296. tbCarShootReglas.setNum(t.getSnapNum());
  297. tbCarShootReglas.setType("snap".equals(t.getManagementType()) ? 1 : 2);
  298. tbCarShootReglas.setCarType(t.getCarTypeCode());
  299. int cameraPosition = t.getCameraPosition();
  300. getCamaraNo1ByCameraPosition(cameraPosition, tbCarShootReglas);
  301. tbCarShootReglas.setBeginTime(t.getTimingSettings());
  302. tbCarShootReglas.setByTime("T".equals(t.getTimingSettingsStatus()) ? 1 : 0);
  303. tbCarShootReglas.setByArea("T".equals(t.getFixedAreaSettingStatus()) ? 1 : 0);
  304. tbCarShootReglas.setByState("T".equals(t.getVehicleEnableSettingStatus()) ? 1 : 0);
  305. tbCarShootReglas.setCreateTime(new Date());
  306. }
  307. }
  308. // 抓拍数量设置接收
  309. if (tbCarAutomaticCaptureManagement.getSnapNum() != null) {
  310. t.setSnapNum(tbCarAutomaticCaptureManagement.getSnapNum());
  311. tbCarShootReglas.setNum(tbCarAutomaticCaptureManagement.getSnapNum());
  312. }
  313. // 摄像头设置接收
  314. if (tbCarAutomaticCaptureManagement.getCameraPosition() != null) {
  315. t.setCameraPosition(tbCarAutomaticCaptureManagement.getCameraPosition());
  316. int cameraPosition = tbCarAutomaticCaptureManagement.getCameraPosition();
  317. getCamaraNo1ByCameraPosition(cameraPosition, tbCarShootReglas);
  318. }
  319. // 定时设置
  320. if (tbCarAutomaticCaptureManagement.getTimingSettings() != null) {
  321. tbCarShootReglas.setBeginTime(tbCarAutomaticCaptureManagement.getTimingSettings());
  322. t.setTimingSettings(tbCarAutomaticCaptureManagement.getTimingSettings());
  323. }
  324. // 定时器设置状态
  325. if (tbCarAutomaticCaptureManagement.getTimingSettingsStatus() != null) {
  326. tbCarShootReglas.setByTime("T".equals(tbCarAutomaticCaptureManagement.getTimingSettingsStatus()) ? 1 : 0);
  327. t.setTimingSettingsStatus(tbCarAutomaticCaptureManagement.getTimingSettingsStatus());
  328. }
  329. // 固定区域设置
  330. if (tbCarAutomaticCaptureManagement.getFixedAreaSetting() != null) {
  331. t.setFixedAreaSetting(tbCarAutomaticCaptureManagement.getFixedAreaSetting());
  332. }
  333. // 固定区域设置状态
  334. if (tbCarAutomaticCaptureManagement.getFixedAreaSettingStatus() != null) {
  335. tbCarShootReglas.setByArea("T".equals(tbCarAutomaticCaptureManagement.getFixedAreaSettingStatus()) ? 1 : 0);
  336. t.setFixedAreaSettingStatus(tbCarAutomaticCaptureManagement.getFixedAreaSettingStatus());
  337. }
  338. // 车辆启动设置
  339. if (tbCarAutomaticCaptureManagement.getVehicleEnableSetting() != null) {
  340. t.setVehicleEnableSetting(tbCarAutomaticCaptureManagement.getVehicleEnableSetting());
  341. }
  342. // 车辆启动设置状态
  343. if (tbCarAutomaticCaptureManagement.getVehicleEnableSettingStatus() != null) {
  344. tbCarShootReglas.setByState("T".equals(tbCarAutomaticCaptureManagement.getVehicleEnableSettingStatus()) ? 1 : 0);
  345. t.setVehicleEnableSettingStatus(tbCarAutomaticCaptureManagement.getVehicleEnableSettingStatus());
  346. }
  347. // 添加更新用户信息
  348. t.setUpdateUser(ResourceUtil.getSessionUser().getRealName());
  349. systemService.saveOrUpdate(tbCarShootReglas);
  350. automaticCaptureManagementService.saveOrUpdate(t);
  351. message = "车辆自动抓拍、录像条件管理更新成功";
  352. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  353. } catch (Exception e) {
  354. e.printStackTrace();
  355. throw new BusinessException(e.getMessage());
  356. }
  357. j.setMsg(message);
  358. return j;
  359. }
  360. }