CarController.java 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. package cn.com.lzt.car.cardoc.controller;
  2. import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
  3. import cn.afterturn.easypoi.excel.ExcelImportUtil;
  4. import cn.afterturn.easypoi.excel.entity.ExportParams;
  5. import cn.afterturn.easypoi.excel.entity.ImportParams;
  6. import cn.com.lzt.car.api.service.CarOnlineClientServiceI;
  7. import cn.com.lzt.car.cardoc.entity.CarEntity;
  8. import cn.com.lzt.car.cardoc.entity.NonAutomotiveVechicleEntity;
  9. import cn.com.lzt.car.cardoc.service.CarService;
  10. import java.util.*;
  11. import javax.annotation.Resource;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import cn.com.lzt.car.carfleet.service.impl.CarFleetServiceImpl;
  15. import cn.com.lzt.common.util.HttpClientUtils;
  16. import com.alibaba.fastjson.JSONObject;
  17. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  18. import com.daju.mix.dao.entity.TBCar;
  19. import com.daju.mix.dao.entity.TBCarFleet;
  20. import com.daju.mix.dao.entity.TSBaseUser;
  21. import com.daju.mix.dao.entity.TSUser;
  22. import com.daju.mix.dao.service.impl.TBCarServiceImpl;
  23. import com.daju.mix.vendor.dao.entity.ECarPlay;
  24. import com.daju.mix.vendor.dao.entity.ECarResult;
  25. import com.daju.mix.vendor.service.ECarVehicleService;
  26. import com.google.common.collect.Sets;
  27. import com.google.gson.Gson;
  28. import org.apache.commons.lang.xwork.StringUtils;
  29. import org.apache.log4j.Logger;
  30. import org.hibernate.criterion.Disjunction;
  31. import org.hibernate.criterion.MatchMode;
  32. import org.hibernate.criterion.Restrictions;
  33. import org.jeecgframework.core.util.*;
  34. import org.jeecgframework.web.system.pojo.base.TSDepart;
  35. import org.jeecgframework.web.system.pojo.base.TSType;
  36. import org.jeecgframework.web.system.pojo.base.TSTypegroup;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.stereotype.Controller;
  39. import org.springframework.transaction.annotation.Transactional;
  40. import org.springframework.ui.ModelMap;
  41. import org.springframework.web.bind.annotation.*;
  42. import org.springframework.web.servlet.ModelAndView;
  43. import org.jeecgframework.core.common.controller.BaseController;
  44. import org.jeecgframework.core.common.exception.BusinessException;
  45. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  46. import org.jeecgframework.core.common.model.json.AjaxJson;
  47. import org.jeecgframework.core.common.model.json.DataGrid;
  48. import org.jeecgframework.core.constant.Globals;
  49. import org.jeecgframework.tag.core.easyui.TagUtil;
  50. import org.jeecgframework.web.system.service.SystemService;
  51. import java.io.IOException;
  52. import org.springframework.web.multipart.MultipartFile;
  53. import org.springframework.web.multipart.MultipartHttpServletRequest;
  54. import org.springframework.http.ResponseEntity;
  55. import org.springframework.http.HttpHeaders;
  56. import org.springframework.http.HttpStatus;
  57. import org.jeecgframework.core.beanvalidator.BeanValidators;
  58. import javax.validation.ConstraintViolation;
  59. import javax.validation.Validator;
  60. import java.net.URI;
  61. import java.util.stream.Collectors;
  62. import org.springframework.http.MediaType;
  63. import org.springframework.web.util.UriComponentsBuilder;
  64. /**
  65. * @author onlineGenerator
  66. * @version V1.0
  67. * @Title: Controller
  68. * @Description: 车辆档案
  69. * @date 2019-10-12 14:09:46
  70. */
  71. @Controller
  72. @RequestMapping("/carController")
  73. public class CarController extends BaseController {
  74. /**
  75. * Logger for this class
  76. */
  77. private static final Logger logger = Logger.getLogger(CarController.class);
  78. @Resource
  79. private CarService carService;
  80. @Resource
  81. private CarFleetServiceImpl carFleetService;
  82. @Autowired
  83. private SystemService systemService;
  84. @Autowired
  85. private Validator validator;
  86. @Resource
  87. ECarVehicleService eCarVehicleService;
  88. @Autowired
  89. private CarOnlineClientServiceI onlineClient;
  90. @Autowired
  91. private TBCarServiceImpl tbCarService;
  92. /**
  93. * 车辆档案列表 页面跳转
  94. *
  95. * @return
  96. */
  97. @RequestMapping(params = "nlist")
  98. public ModelAndView nlist(HttpServletRequest request) {
  99. String viewFlag = request.getParameter("viewFlag");
  100. if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){
  101. request.setAttribute("materialDaptId", request.getParameter("materialDaptId"));
  102. }
  103. if(StringUtil.isNotEmpty(request.getParameter("carType"))){
  104. request.setAttribute("carType", request.getParameter("carType"));
  105. }
  106. List<String> fleetIds = null;
  107. if (!ResourceUtil.isLoginUserAdmin()) {
  108. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  109. } else {
  110. fleetIds = carFleetService.getAllFleetIds();
  111. }
  112. if (ListUtils.isNullOrEmpty(fleetIds)) {
  113. fleetIds = new ArrayList<>();
  114. fleetIds.add("0");
  115. }
  116. if (request.getParameterMap().containsKey("flg")) {
  117. request.setAttribute("flg", false);
  118. } else {
  119. // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用)
  120. if("1".equals(viewFlag)){
  121. request.setAttribute("flg", false);
  122. }else{
  123. request.setAttribute("flg", true);
  124. }
  125. }
  126. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  127. logger.info("fleetIdsCond=" + fleetIdsCond);
  128. request.setAttribute("fleetIds", fleetIdsCond);
  129. return new ModelAndView("cn/com/lzt/car/cardoc/carNlist");
  130. }
  131. /**
  132. * 机动车车辆档案列表 页面跳转
  133. *
  134. * @return
  135. */
  136. @RequestMapping(params = "nlist1")
  137. public ModelAndView nlist1(HttpServletRequest request) {
  138. String viewFlag = request.getParameter("viewFlag");
  139. if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){
  140. request.setAttribute("materialDaptId", request.getParameter("materialDaptId"));
  141. }
  142. List<String> fleetIds = null;
  143. if (!ResourceUtil.isLoginUserAdmin()) {
  144. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  145. } else {
  146. fleetIds = carFleetService.getAllFleetIds();
  147. }
  148. if (ListUtils.isNullOrEmpty(fleetIds)) {
  149. fleetIds = new ArrayList<>();
  150. fleetIds.add("0");
  151. }
  152. if (request.getParameterMap().containsKey("flg")) {
  153. request.setAttribute("flg", false);
  154. } else {
  155. // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用)
  156. if("1".equals(viewFlag)){
  157. request.setAttribute("flg", false);
  158. }else{
  159. request.setAttribute("flg", true);
  160. }
  161. }
  162. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  163. logger.info("fleetIdsCond=" + fleetIdsCond);
  164. request.setAttribute("fleetIds", fleetIdsCond);
  165. return new ModelAndView("cn/com/lzt/car/cardoc/carNlist1");
  166. }
  167. /**
  168. * 非机动车车辆档案列表 页面跳转
  169. *
  170. * @return
  171. */
  172. @RequestMapping(params = "nlist2")
  173. public ModelAndView nlist2(HttpServletRequest request) {
  174. String viewFlag = request.getParameter("viewFlag");
  175. if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){
  176. request.setAttribute("materialDaptId", request.getParameter("materialDaptId"));
  177. }
  178. List<String> fleetIds = null;
  179. if (!ResourceUtil.isLoginUserAdmin()) {
  180. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  181. } else {
  182. fleetIds = carFleetService.getAllFleetIds();
  183. }
  184. if (ListUtils.isNullOrEmpty(fleetIds)) {
  185. fleetIds = new ArrayList<>();
  186. fleetIds.add("0");
  187. }
  188. if (request.getParameterMap().containsKey("flg")) {
  189. request.setAttribute("flg", false);
  190. } else {
  191. // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用)
  192. if("1".equals(viewFlag)){
  193. request.setAttribute("flg", false);
  194. }else{
  195. request.setAttribute("flg", true);
  196. }
  197. }
  198. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  199. logger.info("fleetIdsCond=" + fleetIdsCond);
  200. request.setAttribute("fleetIds", fleetIdsCond);
  201. return new ModelAndView("cn/com/lzt/car/cardoc/carNlist2");
  202. }
  203. /**
  204. * easyui AJAX请求数据
  205. *
  206. * @param request
  207. * @param response
  208. * @param dataGrid
  209. */
  210. @RequestMapping(params = "ndatagrid")
  211. public void ndatagrid(CarEntity car, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  212. CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid);
  213. if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){
  214. // 根据科室id到科室表中查询对应的code
  215. TSDepart tsDepart = this.systemService.getEntity(TSDepart.class,request.getParameter("materialDaptId"));
  216. List<String> departStr = new ArrayList<>();
  217. departStr.add(tsDepart.getOrgCode());
  218. departStr.add(tsDepart.getDepartname());
  219. if(tsDepart != null && StringUtil.isNotEmpty(tsDepart.getOrgCode())){
  220. cq.in("sysOrgCode",departStr.toArray());
  221. car.setSysOrgCode(null);
  222. }
  223. }
  224. if(StringUtil.isNotEmpty(request.getParameter("carType"))){
  225. cq.eq("carType",request.getParameter("carType"));
  226. car.setCarType(null);
  227. }
  228. if(StringUtil.isNotEmpty(request.getParameter("areaRegion"))){
  229. cq.eq("areaRegion",request.getParameter("areaRegion"));
  230. car.setAreaRegion(null);
  231. }
  232. if(StringUtil.isNotEmpty(request.getParameter("carType2"))){
  233. cq.eq("carType",request.getParameter("carType2"));
  234. car.setCarType(null);
  235. }
  236. String plate = request.getParameter("plate");
  237. // 查询条件组装器
  238. if (StringUtils.isNotBlank(plate)) {
  239. // 模糊查询
  240. cq.like("plate", "%" + plate + "%");
  241. car.setPlate(null);
  242. }
  243. String type = request.getParameter("type");
  244. // 查询条件组装器
  245. if (StringUtils.isNotBlank(type)) {
  246. // 模糊查询
  247. cq.eq("type", type);
  248. car.setType(null);
  249. }
  250. String framenumber = request.getParameter("framenumber");
  251. // 查询条件组装器
  252. if (StringUtils.isNotBlank(framenumber)) {
  253. // 模糊查询
  254. cq.like("framenumber", "%" + framenumber + "%");
  255. car.setFramenumber(null);
  256. }
  257. String brand = request.getParameter("brand");
  258. // 查询条件组装器
  259. if (StringUtils.isNotBlank(brand)) {
  260. // 模糊查询
  261. cq.eq("brand", brand);
  262. car.setBrand(null);
  263. }
  264. String energyType = request.getParameter("energyType");
  265. // 查询条件组装器
  266. if (StringUtils.isNotBlank(energyType)) {
  267. // 模糊查询
  268. cq.eq("energyType", energyType);
  269. car.setBrand(null);
  270. }
  271. String freetid = request.getParameter("freetid");
  272. // 查询条件组装器
  273. if (StringUtils.isNotBlank(freetid)) {
  274. // 模糊查询
  275. cq.eq("freetid", freetid);
  276. car.setFleetid(null);
  277. }
  278. String deviceNo = request.getParameter("deviceNo1");
  279. // 查询条件组装器
  280. if (StringUtils.isNotBlank(deviceNo)) {
  281. // 模糊查询
  282. cq.add(Restrictions.ilike("deviceNo1", deviceNo, MatchMode.ANYWHERE));
  283. car.setDeviceNo1(null);
  284. }
  285. String deviceNo2 = request.getParameter("deviceNo2");
  286. // 查询条件组装器
  287. if (StringUtils.isNotBlank(deviceNo2)) {
  288. // 模糊查询
  289. cq.add(Restrictions.ilike("deviceNo2", deviceNo2, MatchMode.ANYWHERE));
  290. car.setDeviceNo2(null);
  291. }
  292. String deviceNo3 = request.getParameter("deviceNo3");
  293. // 查询条件组装器
  294. if (StringUtils.isNotBlank(deviceNo3)) {
  295. // 模糊查询
  296. cq.add(Restrictions.ilike("deviceNo3", deviceNo3, MatchMode.ANYWHERE));
  297. car.setDeviceNo3(null);
  298. }
  299. // 权限控制
  300. List<String> fleetIds = null;
  301. if (!ResourceUtil.isLoginUserAdmin()) {
  302. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  303. if (!ListUtils.isNullOrEmpty(fleetIds)) {
  304. cq.in("fleetid", fleetIds.toArray());
  305. }
  306. } else {
  307. fleetIds = carFleetService.getAllFleetIds();
  308. }
  309. if (ListUtils.isNullOrEmpty(fleetIds)) {
  310. fleetIds = new ArrayList<>();
  311. fleetIds.add("0");
  312. }
  313. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  314. logger.info("fleetIdsCond=" + fleetIdsCond);
  315. request.setAttribute("fleetIds", fleetIdsCond);
  316. //查询条件组装器
  317. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap());
  318. cq.add();
  319. this.carService.getDataGridReturn(cq, true);
  320. TagUtil.datagrid(response, dataGrid);
  321. }
  322. /**
  323. * 刘梦祥 2022年6月29日10:19:16 (提供录像与回放管理页面查询所有车辆信息接口)
  324. * @return List<CarEntity> 车辆信息集合
  325. */
  326. @GetMapping(params = "getAllCarsInfo")
  327. @ResponseBody
  328. public List<Map<String,Object>> getAllCarsInfo(){
  329. String getAllCarsInfoSql = "SELECT\n" +
  330. "\ttbc.id,\n" +
  331. "\ttbc.plate,\n" +
  332. "\ttbc.type,\n" +
  333. "\ttsy.typename,\n" +
  334. "\ttbc.image,\n" +
  335. "\ttbc.gpssn,\n" +
  336. "\ttbc.gps_type,\n" +
  337. "\ttbc.video_provider,\n" +
  338. "\ttbcn.lng,\n" +
  339. "\ttbcn.lat,\n" +
  340. "\ttbcn.gps_time\n" +
  341. "FROM\n" +
  342. "\tt_b_car tbc\n" +
  343. "LEFT JOIN t_b_car_now tbcn ON tbcn.carid = tbc.id\n" +
  344. "LEFT JOIN t_s_type tsy ON tsy.typecode = tbc.type\n" +
  345. "LEFT JOIN t_s_typegroup tsyg ON tsyg.id = tsy.typegroupid\n" +
  346. "WHERE tbc.car_type = \"motorVehicle\" and\n" +
  347. "\ttsyg.typegroupcode = \"cartype\";";
  348. List<Map<String,Object>> carEntities = this.systemService.findForJdbc(getAllCarsInfoSql);
  349. // 根据车辆id得到车辆状态
  350. List<String> carIds = new ArrayList<>();
  351. for (Map<String,Object> sqlData : carEntities){
  352. if(sqlData.containsKey("tbc.id")){
  353. carIds.add("\""+sqlData.get("tbc.id")+"\"");
  354. }else if(sqlData.containsKey("id")){
  355. carIds.add("\""+sqlData.get("id")+"\"");
  356. }
  357. }
  358. Map<String,Object> result = HttpClientUtils.sendHttpPostCarInfo(carIds);
  359. Map<String,Boolean> dataIdLine = new HashMap<>();
  360. if(result.containsKey("code") && Integer.parseInt(String.valueOf(result.get("code"))) == 0){
  361. List<Map<String,Object>> datas = (List<Map<String,Object>>) result.get("data");
  362. for (Map<String,Object> item : datas){
  363. if(item.containsKey("id")&&item.containsKey("isOffline")){
  364. dataIdLine.put(String.valueOf(item.get("id")),Boolean.valueOf(String.valueOf(item.get("isOffline"))));
  365. }
  366. }
  367. }
  368. for (Map<String,Object> sqlData : carEntities){
  369. if(sqlData.containsKey("tbc.id")){
  370. sqlData.put("line", !dataIdLine.getOrDefault(String.valueOf(sqlData.get("tbc.id")), true));
  371. }else if(sqlData.containsKey("id")){
  372. sqlData.put("line", !dataIdLine.getOrDefault(String.valueOf(sqlData.get("id")), true));
  373. }
  374. }
  375. // 请求硬件接口
  376. return carEntities;
  377. }
  378. /**
  379. * 刘梦祥2022年7月6日20:14:39(根据车辆id和时间范围获取点播时间)
  380. * @param id 车辆id
  381. * @return
  382. */
  383. @GetMapping(params = "getPlayTimes")
  384. @ResponseBody
  385. public JSONObject getPlayTimes(String id, String beginTime, String endTime, String channelNo){
  386. HashMap<String, String> params = new HashMap<>();
  387. params.put("id",id);
  388. params.put("channelNo", channelNo);
  389. params.put("storageType","0");
  390. params.put("beginTime",beginTime);
  391. params.put("endTime",endTime);
  392. params.put("streamType","2");
  393. params.put("mediaType","2");
  394. params.put("alarmFlag","0");
  395. return eCarVehicleService.requestXML(ECarVehicleService.GET_PLAY_TIMES_URL,params);
  396. }
  397. /**
  398. * 刘梦祥2022年6月30日15:39:18(车载设备点播\停止点播接口)
  399. * @param type play 点播操作,stop 停止点播操作
  400. * @param id 车辆id
  401. * @param channelNo 1号 驾驶室;2号 前方摄像头;3号 作业区域; 4号 车辆后方
  402. * @param streamType 流类型。0:主码流或子码流;1:主码流;2:子码流;只传音频时值为0
  403. * @param beginTime 点播开始时间
  404. * @param endTime 点播结束时间
  405. * @param playbackWay 回放方式。0:正常 1:快进 2:关键帧快退回放 3:关键帧播放 4:单帧上传
  406. * @param playSpeed 回放速度。回放方式为1和2时有效。0:无效;1:1倍;2:2倍;3:4倍;4:8倍;5:16倍
  407. * @param storageType 存储器类型。0:主存储器或灾备存储器;1:主存储器;2:灾备存储器
  408. * @return
  409. */
  410. @GetMapping(params = "playCar")
  411. @ResponseBody
  412. public JSONObject playCar(String type, String id, String channelNo, String streamType, String beginTime, String endTime, String playbackWay, String playSpeed, String storageType){
  413. HashMap<String, String> params = new HashMap<>();
  414. params.put("id",id);
  415. params.put("channelNo",channelNo);
  416. if("play".equals(type)){
  417. params.put("streamType",streamType);
  418. params.put("beginTime",beginTime);
  419. params.put("endTime",endTime);
  420. params.put("playbackWay",playbackWay);
  421. params.put("playSpeed",playSpeed);
  422. params.put("storageType",storageType);
  423. return eCarVehicleService.requestXML(ECarVehicleService.PLAY_CAR_URL,params);
  424. }else{
  425. return eCarVehicleService.requestXML(ECarVehicleService.STOP_CAR_URL,params);
  426. }
  427. }
  428. /**
  429. * 车辆档案列表 页面跳转
  430. *
  431. * @return
  432. */
  433. @RequestMapping(params = "list")
  434. public ModelAndView list(HttpServletRequest request) {
  435. List<String> fleetIds = null;
  436. if (!ResourceUtil.isLoginUserAdmin()) {
  437. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  438. } else {
  439. fleetIds = carFleetService.getAllFleetIds();
  440. }
  441. if (ListUtils.isNullOrEmpty(fleetIds)) {
  442. fleetIds = new ArrayList<>();
  443. fleetIds.add("0");
  444. }
  445. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  446. logger.info("fleetIdsCond=" + fleetIdsCond);
  447. request.setAttribute("fleetIds", fleetIdsCond);
  448. return new ModelAndView("cn/com/lzt/car/cardoc/carList");
  449. }
  450. /**
  451. * easyui AJAX请求数据
  452. *
  453. * @param request
  454. * @param response
  455. * @param dataGrid
  456. */
  457. @RequestMapping(params = "datagrid")
  458. public void datagrid(CarEntity car, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  459. CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid);
  460. //自定义追加查询条件
  461. String name = request.getParameter("name");
  462. // 查询条件组装器
  463. if (StringUtils.isNotBlank(name)) {
  464. // 模糊查询
  465. cq.like("name", "%" + name + "%");
  466. car.setName(null);
  467. }
  468. String plate = request.getParameter("plate");
  469. // 查询条件组装器
  470. if (StringUtils.isNotBlank(plate)) {
  471. // 模糊查询
  472. cq.like("plate", "%" + plate + "%");
  473. car.setPlate(null);
  474. }
  475. String framenumber = request.getParameter("framenumber");
  476. // 查询条件组装器
  477. if (StringUtils.isNotBlank(framenumber)) {
  478. // 模糊查询
  479. cq.like("framenumber", "%" + framenumber + "%");
  480. car.setFramenumber(null);
  481. }
  482. String drivername = request.getParameter("drivername");
  483. // 查询条件组装器
  484. if (StringUtils.isNotBlank(drivername)) {
  485. // 模糊查询
  486. cq.like("drivername", "%" + drivername + "%");
  487. car.setDrivername(null);
  488. }
  489. String gpssn = request.getParameter("gpssn");
  490. // 查询条件组装器
  491. if (StringUtils.isNotBlank(gpssn)) {
  492. // 模糊查询
  493. cq.like("gpssn", "%" + gpssn + "%");
  494. car.setGpssn(null);
  495. }
  496. // 权限控制
  497. List<String> fleetIds = null;
  498. if (!ResourceUtil.isLoginUserAdmin()) {
  499. fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone());
  500. if (!ListUtils.isNullOrEmpty(fleetIds)) {
  501. cq.in("fleetid", fleetIds.toArray());
  502. }
  503. } else {
  504. fleetIds = carFleetService.getAllFleetIds();
  505. }
  506. if (ListUtils.isNullOrEmpty(fleetIds)) {
  507. fleetIds = new ArrayList<>();
  508. fleetIds.add("0");
  509. }
  510. String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')";
  511. logger.info("fleetIdsCond=" + fleetIdsCond);
  512. request.setAttribute("fleetIds", fleetIdsCond);
  513. //查询条件组装器
  514. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap());
  515. cq.add();
  516. this.carService.getDataGridReturn(cq, true);
  517. TagUtil.datagrid(response, dataGrid);
  518. }
  519. /**
  520. * 删除车辆档案
  521. *
  522. * @return
  523. */
  524. @RequestMapping(params = "doDel")
  525. @ResponseBody
  526. public AjaxJson doDel(CarEntity car, HttpServletRequest request) {
  527. String message = null;
  528. AjaxJson j = new AjaxJson();
  529. car = systemService.getEntity(CarEntity.class, car.getId());
  530. message = "车辆档案删除成功";
  531. try {
  532. carService.delete(car);
  533. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  534. } catch (Exception e) {
  535. e.printStackTrace();
  536. message = "车辆档案删除失败";
  537. throw new BusinessException(e.getMessage());
  538. }
  539. j.setMsg(message);
  540. return j;
  541. }
  542. /**
  543. * 批量删除车辆档案
  544. *
  545. * @return
  546. */
  547. @RequestMapping(params = "doBatchDel")
  548. @ResponseBody
  549. public AjaxJson doBatchDel(String ids, HttpServletRequest request) {
  550. String message = null;
  551. AjaxJson j = new AjaxJson();
  552. message = "车辆档案删除成功";
  553. try {
  554. for (String id : ids.split(",")) {
  555. CarEntity car = systemService.getEntity(CarEntity.class,
  556. id
  557. );
  558. carService.delete(car);
  559. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  560. }
  561. } catch (Exception e) {
  562. e.printStackTrace();
  563. message = "车辆档案删除失败";
  564. throw new BusinessException(e.getMessage());
  565. }
  566. j.setMsg(message);
  567. return j;
  568. }
  569. /**
  570. * 添加车辆档案
  571. *
  572. * @param
  573. * @return
  574. */
  575. @RequestMapping(params = "doAdd")
  576. @ResponseBody
  577. public AjaxJson doAdd(TBCar car, HttpServletRequest request) {
  578. String message = null;
  579. AjaxJson j = new AjaxJson();
  580. message = "车辆档案添加成功";
  581. try {
  582. tbCarService.add(car);
  583. //carService.save(car);
  584. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  585. } catch (Exception e) {
  586. e.printStackTrace();
  587. message = "车辆档案添加失败";
  588. throw new BusinessException(e.getMessage());
  589. }
  590. j.setMsg(message);
  591. return j;
  592. }
  593. /**
  594. * 更新车辆档案
  595. *
  596. * @param
  597. * @return
  598. */
  599. @RequestMapping(params = "doUpdate")
  600. @ResponseBody
  601. public AjaxJson doUpdate(CarEntity car, HttpServletRequest request) {
  602. String message = null;
  603. AjaxJson j = new AjaxJson();
  604. message = "车辆档案更新成功";
  605. CarEntity t = carService.get(CarEntity.class, car.getId());
  606. try {
  607. MyBeanUtils.copyBeanNotNull2Bean(car, t);
  608. carService.saveOrUpdate(t);
  609. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  610. } catch (Exception e) {
  611. e.printStackTrace();
  612. message = "车辆档案更新失败";
  613. throw new BusinessException(e.getMessage());
  614. }
  615. j.setMsg(message);
  616. return j;
  617. }
  618. /**
  619. * 车辆档案新增页面跳转
  620. *
  621. * @return
  622. */
  623. @RequestMapping(params = "goAdd")
  624. public ModelAndView goAdd(CarEntity car, HttpServletRequest req) {
  625. if (StringUtil.isNotEmpty(car.getId())) {
  626. car = carService.getEntity(CarEntity.class, car.getId());
  627. req.setAttribute("carPage", car);
  628. }
  629. return new ModelAndView("cn/com/lzt/car/cardoc/car-add");
  630. }
  631. @RequestMapping(params = "goNadd")
  632. public ModelAndView goNadd(CarEntity car, HttpServletRequest req) {
  633. if (StringUtil.isNotEmpty(car.getId())) {
  634. car = carService.getEntity(CarEntity.class, car.getId());
  635. String ou = new StringBuilder().append(car.getOilMin()).append("~").append(car.getOilMax()).toString();
  636. car.setOilUsed(ou);
  637. req.setAttribute("carPage", car);
  638. }
  639. if(StringUtil.isNotEmpty(car.getCarType())){
  640. req.setAttribute("carType", car.getCarType());
  641. }
  642. return new ModelAndView("cn/com/lzt/car/cardoc/car-nadd");
  643. }
  644. /**
  645. * 车辆档案编辑页面跳转
  646. *
  647. * @return
  648. */
  649. @RequestMapping(params = "goUpdate")
  650. public ModelAndView goUpdate(CarEntity car, HttpServletRequest req) {
  651. if (StringUtil.isNotEmpty(car.getId())) {
  652. car = carService.getEntity(CarEntity.class, car.getId());
  653. req.setAttribute("carPage", car);
  654. }
  655. return new ModelAndView("cn/com/lzt/car/cardoc/car-update");
  656. }
  657. @RequestMapping(params = "goNupdate")
  658. public ModelAndView goNupdate(CarEntity car, HttpServletRequest req) {
  659. if (StringUtil.isNotEmpty(car.getId())) {
  660. car = carService.getEntity(CarEntity.class, car.getId());
  661. String ou = new StringBuilder().append(car.getOilMin()).append("~").append(car.getOilMax()).toString();
  662. car.setOilUsed(ou);
  663. req.setAttribute("carPage", car);
  664. }
  665. return new ModelAndView("cn/com/lzt/car/cardoc/car-nupdate");
  666. }
  667. /**
  668. * 导入功能跳转
  669. *
  670. * @return
  671. */
  672. @RequestMapping(params = "upload")
  673. public ModelAndView upload(HttpServletRequest req) {
  674. req.setAttribute("controller_name", "carController");
  675. return new ModelAndView("common/upload/pub_excel_upload");
  676. }
  677. @RequestMapping(params = "nupload")
  678. public ModelAndView nupload(HttpServletRequest req) {
  679. req.setAttribute("controller_name", "carController");
  680. if(req.getParameter("carType") != null){
  681. req.setAttribute("carType",req.getParameter("carType"));
  682. }
  683. return new ModelAndView("common/upload/common_excel_upload");
  684. }
  685. /**
  686. * 导出excel
  687. *
  688. * @param request
  689. * @param response
  690. */
  691. @RequestMapping(params = "exportXls")
  692. public String exportXls(CarEntity car, HttpServletRequest request, HttpServletResponse response
  693. , DataGrid dataGrid, ModelMap modelMap) {
  694. Map<String,List<String>> errorInfoMap = new HashMap<>();
  695. if(car.getCarType() != null){
  696. request.setAttribute("carType",car.getCarType());
  697. if("motorVehicle".equals(car.getCarType())){
  698. CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid);
  699. cq.eq("carType",car.getCarType());
  700. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap());
  701. cq.add();
  702. List<CarEntity> cars = this.carService.getListByCriteriaQuery(cq, false);
  703. List<CarEntity> returnCars = new ArrayList<>();
  704. // 转义
  705. TSTypegroup typegroup1 = systemService.getTypeGroup("energyType","用油类型");
  706. TSTypegroup typegroup2 = systemService.getTypeGroup("tonnageType","车身重量类型");
  707. TSTypegroup typegroup3 = systemService.getTypeGroup("carState", "车辆状态");
  708. TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商");
  709. TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域");
  710. TSTypegroup typegroup6 = systemService.getTypeGroup("videoProvider", "视频提供商");
  711. TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置");
  712. TSTypegroup typegroup8 = systemService.getTypeGroup("brand", "车系品牌");
  713. List<TSType> typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType");
  714. List<TSType> typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType");
  715. List<TSType> typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState");
  716. List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
  717. List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
  718. List<TSType> typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider");
  719. List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
  720. List<TSType> typeList8 = typegroupTotypeList(typegroup8,errorInfoMap,"brand");
  721. if(cars != null && cars.size() > 0){
  722. Gson gson = new Gson();
  723. for (CarEntity carEntity : cars){
  724. CarEntity copyEntity = gson.fromJson(gson.toJson(carEntity),CarEntity.class);
  725. try {
  726. String getTBCarFleetByIdSqlStr = "select name from t_b_car_fleet where id = " + carEntity.getFleetid();
  727. Map<String,Object> TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByIdSqlStr);
  728. if(!Objects.requireNonNull(TBCarFleetData).containsKey("name")){
  729. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  730. }else{
  731. copyEntity.setFleetid(String.valueOf(TBCarFleetData.get("name")));
  732. }
  733. } catch (Exception e) {
  734. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  735. log.error("车队查询失败!"+carEntity.getFleetid());
  736. }
  737. copyEntity.setEnergyType(getTypeNames(typeList1,carEntity.getEnergyType(),errorInfoMap,"用油类型"));
  738. copyEntity.setTonnageType(getTypeNames(typeList2,carEntity.getTonnageType(),errorInfoMap,"车身重量类型"));
  739. copyEntity.setCarState(getTypeNames(typeList3,carEntity.getCarState(),errorInfoMap,"车辆状态"));
  740. copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商"));
  741. copyEntity.setAreaRegion(getTypeNames(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域"));
  742. copyEntity.setVideoProvider(getTypeNames(typeList6,carEntity.getVideoProvider(),errorInfoMap,"视频提供商"));
  743. copyEntity.setType(getTypeNames(typeList7,carEntity.getType(),errorInfoMap,"车身装置"));
  744. copyEntity.setBrand(getTypeNames(typeList8,carEntity.getBrand(),errorInfoMap,"车系品牌"));
  745. returnCars.add(copyEntity);
  746. }
  747. }
  748. modelMap.put(NormalExcelConstants.FILE_NAME, "机动车车辆档案");
  749. modelMap.put(NormalExcelConstants.CLASS, CarEntity.class);
  750. modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(),
  751. "导出信息"));
  752. modelMap.put(NormalExcelConstants.DATA_LIST, returnCars);
  753. }else{
  754. CriteriaQuery cq = new CriteriaQuery(NonAutomotiveVechicleEntity.class, dataGrid);
  755. cq.eq("carType",car.getCarType());
  756. cq.add();
  757. NonAutomotiveVechicleEntity nonAutomotiveVechicleEntity = new NonAutomotiveVechicleEntity();
  758. nonAutomotiveVechicleEntity.setCarType(car.getCarType());
  759. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, nonAutomotiveVechicleEntity, request.getParameterMap());
  760. List<NonAutomotiveVechicleEntity> cars = this.carService.getListByCriteriaQuery(cq, false);
  761. List<NonAutomotiveVechicleEntity> returnCars = new ArrayList<>();
  762. // 转义
  763. TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商");
  764. TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域");
  765. TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置");
  766. List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
  767. List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
  768. List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
  769. if(cars != null && cars.size() > 0){
  770. Gson gson = new Gson();
  771. for (NonAutomotiveVechicleEntity carEntity : cars){
  772. NonAutomotiveVechicleEntity copyEntity = gson.fromJson(gson.toJson(carEntity),NonAutomotiveVechicleEntity.class);
  773. try {
  774. String getTBCarFleetByIdSqlStr = "select name from t_b_car_fleet where id = " + carEntity.getFleetid();
  775. Map<String,Object> TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByIdSqlStr);
  776. if(!Objects.requireNonNull(TBCarFleetData).containsKey("name")){
  777. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  778. }else{
  779. copyEntity.setFleetid(String.valueOf(TBCarFleetData.get("name")));
  780. }
  781. } catch (Exception e) {
  782. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  783. log.error("车队查询失败!"+carEntity.getFleetid());
  784. }
  785. copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商"));
  786. copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商"));
  787. copyEntity.setAreaRegion(getTypeNames(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域"));
  788. copyEntity.setType(getTypeNames(typeList7,carEntity.getType(),errorInfoMap,"车身装置"));
  789. returnCars.add(copyEntity);
  790. }
  791. }
  792. modelMap.put(NormalExcelConstants.FILE_NAME, "非机动车车辆档案");
  793. modelMap.put(NormalExcelConstants.CLASS, NonAutomotiveVechicleEntity.class);
  794. modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(),
  795. "导出信息"));
  796. modelMap.put(NormalExcelConstants.DATA_LIST, returnCars);
  797. }
  798. }
  799. return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
  800. }
  801. /**
  802. * 导出excel 使模板
  803. *
  804. * @param request
  805. */
  806. @RequestMapping(params = "exportXlsByT")
  807. public String exportXlsByT(HttpServletRequest request, ModelMap modelMap) {
  808. String carType = request.getParameter("carType");
  809. if(StringUtils.isNotEmpty(carType)){
  810. if(carType.equals("motorVehicle")){
  811. // 机动车
  812. modelMap.put(NormalExcelConstants.FILE_NAME, "机动车车辆档案");
  813. modelMap.put(NormalExcelConstants.CLASS, CarEntity.class);
  814. }else{
  815. // 非机动车
  816. modelMap.put(NormalExcelConstants.FILE_NAME, "非机动车车辆档案");
  817. modelMap.put(NormalExcelConstants.CLASS, NonAutomotiveVechicleEntity.class);
  818. }
  819. }
  820. modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(),
  821. "导出信息"));
  822. modelMap.put(NormalExcelConstants.DATA_LIST, new ArrayList());
  823. return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
  824. }
  825. private void errorInfo(Map<String,List<String>> errorMap,String MKey,String EValue){
  826. if(errorMap.containsKey(MKey)){
  827. errorMap.get(MKey).add(EValue);
  828. }else{
  829. List<String> errorInfoList = new ArrayList<>();
  830. errorInfoList.add(EValue);
  831. errorMap.put(MKey,errorInfoList);
  832. }
  833. }
  834. private List<TSType> typegroupTotypeList(TSTypegroup typegroup,Map<String,List<String>> errorInfoMap,String code){
  835. if(typegroup != null){
  836. return typegroup.getTSTypes();
  837. }else{
  838. errorInfo(errorInfoMap,"字典表查询失败",code);
  839. return null;
  840. }
  841. }
  842. private String getTypeValues(List<TSType> typeList,String code,Map<String,List<String>> errorInfoMap,String typeName){
  843. if(StringUtil.isNotEmpty(code) && typeList.size() > 0){
  844. for (TSType tsType:typeList){
  845. if(tsType.getTypename().equals(code)){
  846. return tsType.getTypecode();
  847. }
  848. }
  849. errorInfo(errorInfoMap,typeName+"未找到",code);
  850. }
  851. return null;
  852. }
  853. private String getTypeNames(List<TSType> typeList,String code,Map<String,List<String>> errorInfoMap,String typeName){
  854. if(StringUtil.isNotEmpty(code) && typeList.size() > 0){
  855. for (TSType tsType:typeList){
  856. if(tsType.getTypecode().equals(code)){
  857. return tsType.getTypename();
  858. }
  859. }
  860. errorInfo(errorInfoMap,typeName+"未找到",code);
  861. }
  862. return null;
  863. }
  864. /**
  865. * 2022年6月9日16:15:06-add(车辆导入)
  866. * @param request
  867. * @return
  868. */
  869. @SuppressWarnings("unchecked")
  870. @Transactional
  871. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  872. @ResponseBody
  873. public AjaxJson importExcel(HttpServletRequest request) {
  874. AjaxJson j = new AjaxJson();
  875. Map<String,List<String>> errorInfoMap = new HashMap<>();
  876. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  877. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  878. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  879. MultipartFile file = entity.getValue();// 获取上传文件对象
  880. ImportParams params = new ImportParams();
  881. params.setTitleRows(2);
  882. params.setHeadRows(1);
  883. params.setNeedSave(true);
  884. try {
  885. String carType = "";
  886. if(request.getParameter("carType") != null){
  887. carType = request.getParameter("carType");
  888. if(carType.equals("motorVehicle")){
  889. TSTypegroup typegroup1 = systemService.getTypeGroup("energyType","用油类型");
  890. TSTypegroup typegroup2 = systemService.getTypeGroup("tonnageType","车身重量类型");
  891. TSTypegroup typegroup3 = systemService.getTypeGroup("carState", "车辆状态");
  892. TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商");
  893. TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域");
  894. TSTypegroup typegroup6 = systemService.getTypeGroup("videoProvider", "视频提供商");
  895. TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置");
  896. TSTypegroup typegroup8 = systemService.getTypeGroup("brand", "车系品牌");
  897. List<TSType> typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType");
  898. List<TSType> typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType");
  899. List<TSType> typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState");
  900. List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
  901. List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
  902. List<TSType> typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider");
  903. List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
  904. List<TSType> typeList8 = typegroupTotypeList(typegroup8,errorInfoMap,"brand");
  905. List<CarEntity> listCarEntities = ExcelImportUtil.importExcel(file.getInputStream(), CarEntity.class, params);
  906. String finalCarType = carType;
  907. listCarEntities.forEach(carEntity -> {
  908. carEntity.setCarType(finalCarType);
  909. carEntity.setEnable(1);
  910. try {
  911. String getTBCarFleetByNameSqlStr = "select id from t_b_car_fleet where name = '"+ carEntity.getFleetid()+"';";
  912. Map<String,Object> TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByNameSqlStr);
  913. if(!Objects.requireNonNull(TBCarFleetData).containsKey("id")){
  914. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  915. }else{
  916. carEntity.setFleetid(String.valueOf(TBCarFleetData.get("id")));
  917. }
  918. } catch (Exception e) {
  919. errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid());
  920. log.error("车队查询失败!"+carEntity.getFleetid());
  921. }
  922. carEntity.setEnergyType(getTypeValues(typeList1,carEntity.getEnergyType(),errorInfoMap,"用油类型"));
  923. carEntity.setTonnageType(getTypeValues(typeList2,carEntity.getTonnageType(),errorInfoMap,"车身重量类型"));
  924. carEntity.setCarState(getTypeValues(typeList3,carEntity.getCarState(),errorInfoMap,"车辆状态"));
  925. carEntity.setGpsType(getTypeValues(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商"));
  926. carEntity.setAreaRegion(getTypeValues(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域"));
  927. carEntity.setVideoProvider(getTypeValues(typeList6,carEntity.getVideoProvider(),errorInfoMap,"视频提供商"));
  928. carEntity.setType(getTypeValues(typeList7,carEntity.getType(),errorInfoMap,"车身装置"));
  929. carEntity.setBrand(getTypeValues(typeList8,carEntity.getBrand(),errorInfoMap,"车系品牌"));
  930. if (StringUtil.isEmpty(carEntity.getPlate())) {
  931. throw new RuntimeException("车牌号不能为空!!");
  932. }
  933. if (StringUtil.isEmpty(carEntity.getPlate().replaceAll("\\s*", ""))) {
  934. throw new RuntimeException("车牌号不能为空格!!");
  935. }
  936. });
  937. Set<String> collect = listCarEntities.stream().map(CarEntity::getPlate).collect(Collectors.toSet());
  938. List<CarEntity> carServiceList = carService.getList(CarEntity.class);
  939. Set<String> collect1 = carServiceList.stream().map(CarEntity::getPlate).collect(Collectors.toSet());
  940. Sets.SetView<String> intersection = Sets.intersection(collect, collect1);
  941. if (intersection.size() > 0) {
  942. throw new Exception("车牌号重复出现: " .concat(String.join(",", intersection)));
  943. }
  944. for (CarEntity car : listCarEntities) {
  945. try {
  946. carService.save(car);
  947. } catch (Exception e) {
  948. logger.error(ExceptionUtil.getExceptionMessage(e));
  949. throw new Exception("文件导入失败");
  950. }
  951. }
  952. j.setMsg("文件导入成功!");
  953. }else{
  954. TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商");
  955. TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域");
  956. TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置");
  957. List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
  958. List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
  959. List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
  960. List<NonAutomotiveVechicleEntity> listCarEntities = ExcelImportUtil.importExcel(file.getInputStream(), NonAutomotiveVechicleEntity.class, params);
  961. String finalCarType = carType;
  962. listCarEntities.forEach(carEntity -> {
  963. carEntity.setCarType(finalCarType);
  964. carEntity.setEnable(1);
  965. carEntity.setGpsType(getTypeValues(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商"));
  966. carEntity.setAreaRegion(getTypeValues(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域"));
  967. carEntity.setType(getTypeValues(typeList7,carEntity.getType(),errorInfoMap,"车身装置"));
  968. if (StringUtil.isEmpty(carEntity.getPlate())) {
  969. throw new RuntimeException("车牌号不能为空!!");
  970. }
  971. if (StringUtil.isEmpty(carEntity.getPlate().replaceAll("\\s*", ""))) {
  972. throw new RuntimeException("车牌号不能为空格!!");
  973. }
  974. });
  975. Set<String> collect = listCarEntities.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet());
  976. List<NonAutomotiveVechicleEntity> carServiceList = carService.getList(NonAutomotiveVechicleEntity.class);
  977. Set<String> collect1 = carServiceList.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet());
  978. Sets.SetView<String> intersection = Sets.intersection(collect, collect1);
  979. if (intersection.size() > 0) {
  980. throw new Exception("车牌号重复出现: " .concat(String.join(",", intersection)));
  981. }
  982. for (NonAutomotiveVechicleEntity car : listCarEntities) {
  983. try {
  984. carService.save(car);
  985. } catch (Exception e) {
  986. logger.error(ExceptionUtil.getExceptionMessage(e));
  987. throw new Exception("文件导入失败");
  988. }
  989. }
  990. if(errorInfoMap.size() > 0){
  991. j.setMsg("文件导入成功!部分数据对照失败:"+errorInfoMap+",请手动修改!");
  992. }else{
  993. j.setMsg("文件导入成功!");
  994. }
  995. }
  996. }
  997. } catch (Exception e) {
  998. j.setMsg(e.getMessage());
  999. logger.error(ExceptionUtil.getExceptionMessage(e));
  1000. } finally {
  1001. try {
  1002. file.getInputStream().close();
  1003. } catch (IOException e) {
  1004. e.printStackTrace();
  1005. }
  1006. }
  1007. }
  1008. return j;
  1009. }
  1010. @RequestMapping(method = RequestMethod.GET)
  1011. @ResponseBody
  1012. public List<CarEntity> list() {
  1013. List<CarEntity> listCars = carService.getList(CarEntity.class);
  1014. return listCars;
  1015. }
  1016. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  1017. @ResponseBody
  1018. public ResponseEntity<?> get(@PathVariable("id") String id) {
  1019. CarEntity task = carService.get(CarEntity.class, id);
  1020. if (task == null) {
  1021. return new ResponseEntity(HttpStatus.NOT_FOUND);
  1022. }
  1023. return new ResponseEntity(task, HttpStatus.OK);
  1024. }
  1025. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  1026. @ResponseBody
  1027. public ResponseEntity<?> create(@RequestBody CarEntity car, UriComponentsBuilder uriBuilder) {
  1028. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  1029. Set<ConstraintViolation<CarEntity>> failures = validator.validate(car);
  1030. if (!failures.isEmpty()) {
  1031. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  1032. }
  1033. //保存
  1034. try {
  1035. carService.save(car);
  1036. } catch (Exception e) {
  1037. e.printStackTrace();
  1038. return new ResponseEntity(HttpStatus.NO_CONTENT);
  1039. }
  1040. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  1041. String id = car.getId();
  1042. URI uri = uriBuilder.path("/rest/carController/" + id).build().toUri();
  1043. HttpHeaders headers = new HttpHeaders();
  1044. headers.setLocation(uri);
  1045. return new ResponseEntity(headers, HttpStatus.CREATED);
  1046. }
  1047. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  1048. public ResponseEntity<?> update(@RequestBody CarEntity car) {
  1049. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  1050. Set<ConstraintViolation<CarEntity>> failures = validator.validate(car);
  1051. if (!failures.isEmpty()) {
  1052. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  1053. }
  1054. //保存
  1055. try {
  1056. carService.saveOrUpdate(car);
  1057. } catch (Exception e) {
  1058. e.printStackTrace();
  1059. return new ResponseEntity(HttpStatus.NO_CONTENT);
  1060. }
  1061. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  1062. return new ResponseEntity(HttpStatus.NO_CONTENT);
  1063. }
  1064. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  1065. @ResponseStatus(HttpStatus.NO_CONTENT)
  1066. public void delete(@PathVariable("id") String id) {
  1067. carService.deleteEntityById(CarEntity.class, id);
  1068. }
  1069. }