package cn.com.lzt.car.cardoc.controller; import cn.afterturn.easypoi.entity.vo.NormalExcelConstants; import cn.afterturn.easypoi.excel.ExcelImportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.com.lzt.car.api.service.CarOnlineClientServiceI; import cn.com.lzt.car.cardoc.entity.CarEntity; import cn.com.lzt.car.cardoc.entity.NonAutomotiveVechicleEntity; import cn.com.lzt.car.cardoc.service.CarService; import java.util.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cn.com.lzt.car.carfleet.service.impl.CarFleetServiceImpl; import cn.com.lzt.common.util.HttpClientUtils; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.daju.mix.dao.entity.TBCar; import com.daju.mix.dao.entity.TBCarFleet; import com.daju.mix.dao.entity.TSBaseUser; import com.daju.mix.dao.entity.TSUser; import com.daju.mix.dao.service.impl.TBCarServiceImpl; import com.daju.mix.vendor.dao.entity.ECarPlay; import com.daju.mix.vendor.dao.entity.ECarResult; import com.daju.mix.vendor.service.ECarVehicleService; import com.google.common.collect.Sets; import com.google.gson.Gson; import org.apache.commons.lang.xwork.StringUtils; import org.apache.log4j.Logger; import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.Restrictions; import org.jeecgframework.core.util.*; import org.jeecgframework.web.system.pojo.base.TSDepart; import org.jeecgframework.web.system.pojo.base.TSType; import org.jeecgframework.web.system.pojo.base.TSTypegroup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import org.jeecgframework.core.common.controller.BaseController; import org.jeecgframework.core.common.exception.BusinessException; import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery; import org.jeecgframework.core.common.model.json.AjaxJson; import org.jeecgframework.core.common.model.json.DataGrid; import org.jeecgframework.core.constant.Globals; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.service.SystemService; import java.io.IOException; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.http.ResponseEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.jeecgframework.core.beanvalidator.BeanValidators; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.net.URI; import java.util.stream.Collectors; import org.springframework.http.MediaType; import org.springframework.web.util.UriComponentsBuilder; /** * @author onlineGenerator * @version V1.0 * @Title: Controller * @Description: 车辆档案 * @date 2019-10-12 14:09:46 */ @Controller @RequestMapping("/carController") public class CarController extends BaseController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(CarController.class); @Resource private CarService carService; @Resource private CarFleetServiceImpl carFleetService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Resource ECarVehicleService eCarVehicleService; @Autowired private CarOnlineClientServiceI onlineClient; @Autowired private TBCarServiceImpl tbCarService; /** * 车辆档案列表 页面跳转 * * @return */ @RequestMapping(params = "nlist") public ModelAndView nlist(HttpServletRequest request) { String viewFlag = request.getParameter("viewFlag"); if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){ request.setAttribute("materialDaptId", request.getParameter("materialDaptId")); } if(StringUtil.isNotEmpty(request.getParameter("carType"))){ request.setAttribute("carType", request.getParameter("carType")); } List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } if (request.getParameterMap().containsKey("flg")) { request.setAttribute("flg", false); } else { // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用) if("1".equals(viewFlag)){ request.setAttribute("flg", false); }else{ request.setAttribute("flg", true); } } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); return new ModelAndView("cn/com/lzt/car/cardoc/carNlist"); } /** * 机动车车辆档案列表 页面跳转 * * @return */ @RequestMapping(params = "nlist1") public ModelAndView nlist1(HttpServletRequest request) { String viewFlag = request.getParameter("viewFlag"); if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){ request.setAttribute("materialDaptId", request.getParameter("materialDaptId")); } List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } if (request.getParameterMap().containsKey("flg")) { request.setAttribute("flg", false); } else { // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用) if("1".equals(viewFlag)){ request.setAttribute("flg", false); }else{ request.setAttribute("flg", true); } } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); return new ModelAndView("cn/com/lzt/car/cardoc/carNlist1"); } /** * 非机动车车辆档案列表 页面跳转 * * @return */ @RequestMapping(params = "nlist2") public ModelAndView nlist2(HttpServletRequest request) { String viewFlag = request.getParameter("viewFlag"); if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){ request.setAttribute("materialDaptId", request.getParameter("materialDaptId")); } List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } if (request.getParameterMap().containsKey("flg")) { request.setAttribute("flg", false); } else { // add-刘梦祥-2021年11月24日10:14:09(添加页面类型判断,方便物料到货页面的编辑领料车引用) if("1".equals(viewFlag)){ request.setAttribute("flg", false); }else{ request.setAttribute("flg", true); } } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); return new ModelAndView("cn/com/lzt/car/cardoc/carNlist2"); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "ndatagrid") public void ndatagrid(CarEntity car, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid); if(StringUtil.isNotEmpty(request.getParameter("materialDaptId"))){ // 根据科室id到科室表中查询对应的code TSDepart tsDepart = this.systemService.getEntity(TSDepart.class,request.getParameter("materialDaptId")); List departStr = new ArrayList<>(); departStr.add(tsDepart.getOrgCode()); departStr.add(tsDepart.getDepartname()); if(tsDepart != null && StringUtil.isNotEmpty(tsDepart.getOrgCode())){ cq.in("sysOrgCode",departStr.toArray()); car.setSysOrgCode(null); } } if(StringUtil.isNotEmpty(request.getParameter("carType"))){ cq.eq("carType",request.getParameter("carType")); car.setCarType(null); } if(StringUtil.isNotEmpty(request.getParameter("areaRegion"))){ cq.eq("areaRegion",request.getParameter("areaRegion")); car.setAreaRegion(null); } if(StringUtil.isNotEmpty(request.getParameter("carType2"))){ cq.eq("carType",request.getParameter("carType2")); car.setCarType(null); } String plate = request.getParameter("plate"); // 查询条件组装器 if (StringUtils.isNotBlank(plate)) { // 模糊查询 cq.like("plate", "%" + plate + "%"); car.setPlate(null); } String type = request.getParameter("type"); // 查询条件组装器 if (StringUtils.isNotBlank(type)) { // 模糊查询 cq.eq("type", type); car.setType(null); } String framenumber = request.getParameter("framenumber"); // 查询条件组装器 if (StringUtils.isNotBlank(framenumber)) { // 模糊查询 cq.like("framenumber", "%" + framenumber + "%"); car.setFramenumber(null); } String brand = request.getParameter("brand"); // 查询条件组装器 if (StringUtils.isNotBlank(brand)) { // 模糊查询 cq.eq("brand", brand); car.setBrand(null); } String energyType = request.getParameter("energyType"); // 查询条件组装器 if (StringUtils.isNotBlank(energyType)) { // 模糊查询 cq.eq("energyType", energyType); car.setBrand(null); } String freetid = request.getParameter("freetid"); // 查询条件组装器 if (StringUtils.isNotBlank(freetid)) { // 模糊查询 cq.eq("freetid", freetid); car.setFleetid(null); } String deviceNo = request.getParameter("deviceNo1"); // 查询条件组装器 if (StringUtils.isNotBlank(deviceNo)) { // 模糊查询 cq.add(Restrictions.ilike("deviceNo1", deviceNo, MatchMode.ANYWHERE)); car.setDeviceNo1(null); } String deviceNo2 = request.getParameter("deviceNo2"); // 查询条件组装器 if (StringUtils.isNotBlank(deviceNo2)) { // 模糊查询 cq.add(Restrictions.ilike("deviceNo2", deviceNo2, MatchMode.ANYWHERE)); car.setDeviceNo2(null); } String deviceNo3 = request.getParameter("deviceNo3"); // 查询条件组装器 if (StringUtils.isNotBlank(deviceNo3)) { // 模糊查询 cq.add(Restrictions.ilike("deviceNo3", deviceNo3, MatchMode.ANYWHERE)); car.setDeviceNo3(null); } // 权限控制 List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); if (!ListUtils.isNullOrEmpty(fleetIds)) { cq.in("fleetid", fleetIds.toArray()); } } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap()); cq.add(); this.carService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 刘梦祥 2022年6月29日10:19:16 (提供录像与回放管理页面查询所有车辆信息接口) * @return List 车辆信息集合 */ @GetMapping(params = "getAllCarsInfo") @ResponseBody public List> getAllCarsInfo(){ String getAllCarsInfoSql = "SELECT\n" + "\ttbc.id,\n" + "\ttbc.plate,\n" + "\ttbc.type,\n" + "\ttsy.typename,\n" + "\ttbc.image,\n" + "\ttbc.gpssn,\n" + "\ttbc.gps_type,\n" + "\ttbc.video_provider,\n" + "\ttbcn.lng,\n" + "\ttbcn.lat,\n" + "\ttbcn.gps_time\n" + "FROM\n" + "\tt_b_car tbc\n" + "LEFT JOIN t_b_car_now tbcn ON tbcn.carid = tbc.id\n" + "LEFT JOIN t_s_type tsy ON tsy.typecode = tbc.type\n" + "LEFT JOIN t_s_typegroup tsyg ON tsyg.id = tsy.typegroupid\n" + "WHERE tbc.car_type = \"motorVehicle\" and\n" + "\ttsyg.typegroupcode = \"cartype\";"; List> carEntities = this.systemService.findForJdbc(getAllCarsInfoSql); // 根据车辆id得到车辆状态 List carIds = new ArrayList<>(); for (Map sqlData : carEntities){ if(sqlData.containsKey("tbc.id")){ carIds.add("\""+sqlData.get("tbc.id")+"\""); }else if(sqlData.containsKey("id")){ carIds.add("\""+sqlData.get("id")+"\""); } } Map result = HttpClientUtils.sendHttpPostCarInfo(carIds); Map dataIdLine = new HashMap<>(); if(result.containsKey("code") && Integer.parseInt(String.valueOf(result.get("code"))) == 0){ List> datas = (List>) result.get("data"); for (Map item : datas){ if(item.containsKey("id")&&item.containsKey("isOffline")){ dataIdLine.put(String.valueOf(item.get("id")),Boolean.valueOf(String.valueOf(item.get("isOffline")))); } } } for (Map sqlData : carEntities){ if(sqlData.containsKey("tbc.id")){ sqlData.put("line", !dataIdLine.getOrDefault(String.valueOf(sqlData.get("tbc.id")), true)); }else if(sqlData.containsKey("id")){ sqlData.put("line", !dataIdLine.getOrDefault(String.valueOf(sqlData.get("id")), true)); } } // 请求硬件接口 return carEntities; } /** * 刘梦祥2022年7月6日20:14:39(根据车辆id和时间范围获取点播时间) * @param id 车辆id * @return */ @GetMapping(params = "getPlayTimes") @ResponseBody public JSONObject getPlayTimes(String id, String beginTime, String endTime, String channelNo){ HashMap params = new HashMap<>(); params.put("id",id); params.put("channelNo", channelNo); params.put("storageType","0"); params.put("beginTime",beginTime); params.put("endTime",endTime); params.put("streamType","2"); params.put("mediaType","2"); params.put("alarmFlag","0"); return eCarVehicleService.requestXML(ECarVehicleService.GET_PLAY_TIMES_URL,params); } /** * 刘梦祥2022年6月30日15:39:18(车载设备点播\停止点播接口) * @param type play 点播操作,stop 停止点播操作 * @param id 车辆id * @param channelNo 1号 驾驶室;2号 前方摄像头;3号 作业区域; 4号 车辆后方 * @param streamType 流类型。0:主码流或子码流;1:主码流;2:子码流;只传音频时值为0 * @param beginTime 点播开始时间 * @param endTime 点播结束时间 * @param playbackWay 回放方式。0:正常 1:快进 2:关键帧快退回放 3:关键帧播放 4:单帧上传 * @param playSpeed 回放速度。回放方式为1和2时有效。0:无效;1:1倍;2:2倍;3:4倍;4:8倍;5:16倍 * @param storageType 存储器类型。0:主存储器或灾备存储器;1:主存储器;2:灾备存储器 * @return */ @GetMapping(params = "playCar") @ResponseBody public JSONObject playCar(String type, String id, String channelNo, String streamType, String beginTime, String endTime, String playbackWay, String playSpeed, String storageType){ HashMap params = new HashMap<>(); params.put("id",id); params.put("channelNo",channelNo); if("play".equals(type)){ params.put("streamType",streamType); params.put("beginTime",beginTime); params.put("endTime",endTime); params.put("playbackWay",playbackWay); params.put("playSpeed",playSpeed); params.put("storageType",storageType); return eCarVehicleService.requestXML(ECarVehicleService.PLAY_CAR_URL,params); }else{ return eCarVehicleService.requestXML(ECarVehicleService.STOP_CAR_URL,params); } } /** * 车辆档案列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); return new ModelAndView("cn/com/lzt/car/cardoc/carList"); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "datagrid") public void datagrid(CarEntity car, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid); //自定义追加查询条件 String name = request.getParameter("name"); // 查询条件组装器 if (StringUtils.isNotBlank(name)) { // 模糊查询 cq.like("name", "%" + name + "%"); car.setName(null); } String plate = request.getParameter("plate"); // 查询条件组装器 if (StringUtils.isNotBlank(plate)) { // 模糊查询 cq.like("plate", "%" + plate + "%"); car.setPlate(null); } String framenumber = request.getParameter("framenumber"); // 查询条件组装器 if (StringUtils.isNotBlank(framenumber)) { // 模糊查询 cq.like("framenumber", "%" + framenumber + "%"); car.setFramenumber(null); } String drivername = request.getParameter("drivername"); // 查询条件组装器 if (StringUtils.isNotBlank(drivername)) { // 模糊查询 cq.like("drivername", "%" + drivername + "%"); car.setDrivername(null); } String gpssn = request.getParameter("gpssn"); // 查询条件组装器 if (StringUtils.isNotBlank(gpssn)) { // 模糊查询 cq.like("gpssn", "%" + gpssn + "%"); car.setGpssn(null); } // 权限控制 List fleetIds = null; if (!ResourceUtil.isLoginUserAdmin()) { fleetIds = carFleetService.getFleetIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); if (!ListUtils.isNullOrEmpty(fleetIds)) { cq.in("fleetid", fleetIds.toArray()); } } else { fleetIds = carFleetService.getAllFleetIds(); } if (ListUtils.isNullOrEmpty(fleetIds)) { fleetIds = new ArrayList<>(); fleetIds.add("0"); } String fleetIdsCond = "('" + org.apache.commons.lang.StringUtil.join(fleetIds, "','") + "')"; logger.info("fleetIdsCond=" + fleetIdsCond); request.setAttribute("fleetIds", fleetIdsCond); //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap()); cq.add(); this.carService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 删除车辆档案 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(CarEntity car, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); car = systemService.getEntity(CarEntity.class, car.getId()); message = "车辆档案删除成功"; try { carService.delete(car); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "车辆档案删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 批量删除车辆档案 * * @return */ @RequestMapping(params = "doBatchDel") @ResponseBody public AjaxJson doBatchDel(String ids, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆档案删除成功"; try { for (String id : ids.split(",")) { CarEntity car = systemService.getEntity(CarEntity.class, id ); carService.delete(car); systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO); } } catch (Exception e) { e.printStackTrace(); message = "车辆档案删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 添加车辆档案 * * @param * @return */ @RequestMapping(params = "doAdd") @ResponseBody public AjaxJson doAdd(TBCar car, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆档案添加成功"; try { tbCarService.add(car); //carService.save(car); systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "车辆档案添加失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 更新车辆档案 * * @param * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(CarEntity car, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆档案更新成功"; CarEntity t = carService.get(CarEntity.class, car.getId()); try { MyBeanUtils.copyBeanNotNull2Bean(car, t); carService.saveOrUpdate(t); systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO); } catch (Exception e) { e.printStackTrace(); message = "车辆档案更新失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } /** * 车辆档案新增页面跳转 * * @return */ @RequestMapping(params = "goAdd") public ModelAndView goAdd(CarEntity car, HttpServletRequest req) { if (StringUtil.isNotEmpty(car.getId())) { car = carService.getEntity(CarEntity.class, car.getId()); req.setAttribute("carPage", car); } return new ModelAndView("cn/com/lzt/car/cardoc/car-add"); } @RequestMapping(params = "goNadd") public ModelAndView goNadd(CarEntity car, HttpServletRequest req) { if (StringUtil.isNotEmpty(car.getId())) { car = carService.getEntity(CarEntity.class, car.getId()); String ou = new StringBuilder().append(car.getOilMin()).append("~").append(car.getOilMax()).toString(); car.setOilUsed(ou); req.setAttribute("carPage", car); } if(StringUtil.isNotEmpty(car.getCarType())){ req.setAttribute("carType", car.getCarType()); } return new ModelAndView("cn/com/lzt/car/cardoc/car-nadd"); } /** * 车辆档案编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(CarEntity car, HttpServletRequest req) { if (StringUtil.isNotEmpty(car.getId())) { car = carService.getEntity(CarEntity.class, car.getId()); req.setAttribute("carPage", car); } return new ModelAndView("cn/com/lzt/car/cardoc/car-update"); } @RequestMapping(params = "goNupdate") public ModelAndView goNupdate(CarEntity car, HttpServletRequest req) { if (StringUtil.isNotEmpty(car.getId())) { car = carService.getEntity(CarEntity.class, car.getId()); String ou = new StringBuilder().append(car.getOilMin()).append("~").append(car.getOilMax()).toString(); car.setOilUsed(ou); req.setAttribute("carPage", car); } return new ModelAndView("cn/com/lzt/car/cardoc/car-nupdate"); } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name", "carController"); return new ModelAndView("common/upload/pub_excel_upload"); } @RequestMapping(params = "nupload") public ModelAndView nupload(HttpServletRequest req) { req.setAttribute("controller_name", "carController"); if(req.getParameter("carType") != null){ req.setAttribute("carType",req.getParameter("carType")); } return new ModelAndView("common/upload/common_excel_upload"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(CarEntity car, HttpServletRequest request, HttpServletResponse response , DataGrid dataGrid, ModelMap modelMap) { Map> errorInfoMap = new HashMap<>(); if(car.getCarType() != null){ request.setAttribute("carType",car.getCarType()); if("motorVehicle".equals(car.getCarType())){ CriteriaQuery cq = new CriteriaQuery(CarEntity.class, dataGrid); cq.eq("carType",car.getCarType()); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap()); cq.add(); List cars = this.carService.getListByCriteriaQuery(cq, false); List returnCars = new ArrayList<>(); // 转义 TSTypegroup typegroup1 = systemService.getTypeGroup("energyType","用油类型"); TSTypegroup typegroup2 = systemService.getTypeGroup("tonnageType","车身重量类型"); TSTypegroup typegroup3 = systemService.getTypeGroup("carState", "车辆状态"); TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商"); TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域"); TSTypegroup typegroup6 = systemService.getTypeGroup("videoProvider", "视频提供商"); TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置"); TSTypegroup typegroup8 = systemService.getTypeGroup("brand", "车系品牌"); List typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType"); List typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType"); List typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState"); List typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType"); List typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion"); List typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider"); List typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype"); List typeList8 = typegroupTotypeList(typegroup8,errorInfoMap,"brand"); if(cars != null && cars.size() > 0){ Gson gson = new Gson(); for (CarEntity carEntity : cars){ CarEntity copyEntity = gson.fromJson(gson.toJson(carEntity),CarEntity.class); try { String getTBCarFleetByIdSqlStr = "select name from t_b_car_fleet where id = " + carEntity.getFleetid(); Map TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByIdSqlStr); if(!Objects.requireNonNull(TBCarFleetData).containsKey("name")){ errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); }else{ copyEntity.setFleetid(String.valueOf(TBCarFleetData.get("name"))); } } catch (Exception e) { errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); log.error("车队查询失败!"+carEntity.getFleetid()); } copyEntity.setEnergyType(getTypeNames(typeList1,carEntity.getEnergyType(),errorInfoMap,"用油类型")); copyEntity.setTonnageType(getTypeNames(typeList2,carEntity.getTonnageType(),errorInfoMap,"车身重量类型")); copyEntity.setCarState(getTypeNames(typeList3,carEntity.getCarState(),errorInfoMap,"车辆状态")); copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商")); copyEntity.setAreaRegion(getTypeNames(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域")); copyEntity.setVideoProvider(getTypeNames(typeList6,carEntity.getVideoProvider(),errorInfoMap,"视频提供商")); copyEntity.setType(getTypeNames(typeList7,carEntity.getType(),errorInfoMap,"车身装置")); copyEntity.setBrand(getTypeNames(typeList8,carEntity.getBrand(),errorInfoMap,"车系品牌")); returnCars.add(copyEntity); } } modelMap.put(NormalExcelConstants.FILE_NAME, "机动车车辆档案"); modelMap.put(NormalExcelConstants.CLASS, CarEntity.class); modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST, returnCars); }else{ CriteriaQuery cq = new CriteriaQuery(NonAutomotiveVechicleEntity.class, dataGrid); cq.eq("carType",car.getCarType()); cq.add(); NonAutomotiveVechicleEntity nonAutomotiveVechicleEntity = new NonAutomotiveVechicleEntity(); nonAutomotiveVechicleEntity.setCarType(car.getCarType()); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, nonAutomotiveVechicleEntity, request.getParameterMap()); List cars = this.carService.getListByCriteriaQuery(cq, false); List returnCars = new ArrayList<>(); // 转义 TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商"); TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域"); TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置"); List typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType"); List typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion"); List typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype"); if(cars != null && cars.size() > 0){ Gson gson = new Gson(); for (NonAutomotiveVechicleEntity carEntity : cars){ NonAutomotiveVechicleEntity copyEntity = gson.fromJson(gson.toJson(carEntity),NonAutomotiveVechicleEntity.class); try { String getTBCarFleetByIdSqlStr = "select name from t_b_car_fleet where id = " + carEntity.getFleetid(); Map TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByIdSqlStr); if(!Objects.requireNonNull(TBCarFleetData).containsKey("name")){ errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); }else{ copyEntity.setFleetid(String.valueOf(TBCarFleetData.get("name"))); } } catch (Exception e) { errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); log.error("车队查询失败!"+carEntity.getFleetid()); } copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商")); copyEntity.setGpsType(getTypeNames(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商")); copyEntity.setAreaRegion(getTypeNames(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域")); copyEntity.setType(getTypeNames(typeList7,carEntity.getType(),errorInfoMap,"车身装置")); returnCars.add(copyEntity); } } modelMap.put(NormalExcelConstants.FILE_NAME, "非机动车车辆档案"); modelMap.put(NormalExcelConstants.CLASS, NonAutomotiveVechicleEntity.class); modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST, returnCars); } } return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } /** * 导出excel 使模板 * * @param request */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(HttpServletRequest request, ModelMap modelMap) { String carType = request.getParameter("carType"); if(StringUtils.isNotEmpty(carType)){ if(carType.equals("motorVehicle")){ // 机动车 modelMap.put(NormalExcelConstants.FILE_NAME, "机动车车辆档案"); modelMap.put(NormalExcelConstants.CLASS, CarEntity.class); }else{ // 非机动车 modelMap.put(NormalExcelConstants.FILE_NAME, "非机动车车辆档案"); modelMap.put(NormalExcelConstants.CLASS, NonAutomotiveVechicleEntity.class); } } modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆档案列表", "导出人:" + ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST, new ArrayList()); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } private void errorInfo(Map> errorMap,String MKey,String EValue){ if(errorMap.containsKey(MKey)){ errorMap.get(MKey).add(EValue); }else{ List errorInfoList = new ArrayList<>(); errorInfoList.add(EValue); errorMap.put(MKey,errorInfoList); } } private List typegroupTotypeList(TSTypegroup typegroup,Map> errorInfoMap,String code){ if(typegroup != null){ return typegroup.getTSTypes(); }else{ errorInfo(errorInfoMap,"字典表查询失败",code); return null; } } private String getTypeValues(List typeList,String code,Map> errorInfoMap,String typeName){ if(StringUtil.isNotEmpty(code) && typeList.size() > 0){ for (TSType tsType:typeList){ if(tsType.getTypename().equals(code)){ return tsType.getTypecode(); } } errorInfo(errorInfoMap,typeName+"未找到",code); } return null; } private String getTypeNames(List typeList,String code,Map> errorInfoMap,String typeName){ if(StringUtil.isNotEmpty(code) && typeList.size() > 0){ for (TSType tsType:typeList){ if(tsType.getTypecode().equals(code)){ return tsType.getTypename(); } } errorInfo(errorInfoMap,typeName+"未找到",code); } return null; } /** * 2022年6月9日16:15:06-add(车辆导入) * @param request * @return */ @SuppressWarnings("unchecked") @Transactional @RequestMapping(params = "importExcel", method = RequestMethod.POST) @ResponseBody public AjaxJson importExcel(HttpServletRequest request) { AjaxJson j = new AjaxJson(); Map> errorInfoMap = new HashMap<>(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map fileMap = multipartRequest.getFileMap(); for (Map.Entry entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 ImportParams params = new ImportParams(); params.setTitleRows(2); params.setHeadRows(1); params.setNeedSave(true); try { String carType = ""; if(request.getParameter("carType") != null){ carType = request.getParameter("carType"); if(carType.equals("motorVehicle")){ TSTypegroup typegroup1 = systemService.getTypeGroup("energyType","用油类型"); TSTypegroup typegroup2 = systemService.getTypeGroup("tonnageType","车身重量类型"); TSTypegroup typegroup3 = systemService.getTypeGroup("carState", "车辆状态"); TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商"); TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域"); TSTypegroup typegroup6 = systemService.getTypeGroup("videoProvider", "视频提供商"); TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置"); TSTypegroup typegroup8 = systemService.getTypeGroup("brand", "车系品牌"); List typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType"); List typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType"); List typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState"); List typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType"); List typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion"); List typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider"); List typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype"); List typeList8 = typegroupTotypeList(typegroup8,errorInfoMap,"brand"); List listCarEntities = ExcelImportUtil.importExcel(file.getInputStream(), CarEntity.class, params); String finalCarType = carType; listCarEntities.forEach(carEntity -> { carEntity.setCarType(finalCarType); carEntity.setEnable(1); try { String getTBCarFleetByNameSqlStr = "select id from t_b_car_fleet where name = '"+ carEntity.getFleetid()+"';"; Map TBCarFleetData = this.systemService.findOneForJdbc(getTBCarFleetByNameSqlStr); if(!Objects.requireNonNull(TBCarFleetData).containsKey("id")){ errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); }else{ carEntity.setFleetid(String.valueOf(TBCarFleetData.get("id"))); } } catch (Exception e) { errorInfo(errorInfoMap,"车队查询失败",carEntity.getFleetid()); log.error("车队查询失败!"+carEntity.getFleetid()); } carEntity.setEnergyType(getTypeValues(typeList1,carEntity.getEnergyType(),errorInfoMap,"用油类型")); carEntity.setTonnageType(getTypeValues(typeList2,carEntity.getTonnageType(),errorInfoMap,"车身重量类型")); carEntity.setCarState(getTypeValues(typeList3,carEntity.getCarState(),errorInfoMap,"车辆状态")); carEntity.setGpsType(getTypeValues(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商")); carEntity.setAreaRegion(getTypeValues(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域")); carEntity.setVideoProvider(getTypeValues(typeList6,carEntity.getVideoProvider(),errorInfoMap,"视频提供商")); carEntity.setType(getTypeValues(typeList7,carEntity.getType(),errorInfoMap,"车身装置")); carEntity.setBrand(getTypeValues(typeList8,carEntity.getBrand(),errorInfoMap,"车系品牌")); if (StringUtil.isEmpty(carEntity.getPlate())) { throw new RuntimeException("车牌号不能为空!!"); } if (StringUtil.isEmpty(carEntity.getPlate().replaceAll("\\s*", ""))) { throw new RuntimeException("车牌号不能为空格!!"); } }); Set collect = listCarEntities.stream().map(CarEntity::getPlate).collect(Collectors.toSet()); List carServiceList = carService.getList(CarEntity.class); Set collect1 = carServiceList.stream().map(CarEntity::getPlate).collect(Collectors.toSet()); Sets.SetView intersection = Sets.intersection(collect, collect1); if (intersection.size() > 0) { throw new Exception("车牌号重复出现: " .concat(String.join(",", intersection))); } for (CarEntity car : listCarEntities) { try { carService.save(car); } catch (Exception e) { logger.error(ExceptionUtil.getExceptionMessage(e)); throw new Exception("文件导入失败"); } } j.setMsg("文件导入成功!"); }else{ TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商"); TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域"); TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置"); List typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType"); List typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion"); List typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype"); List listCarEntities = ExcelImportUtil.importExcel(file.getInputStream(), NonAutomotiveVechicleEntity.class, params); String finalCarType = carType; listCarEntities.forEach(carEntity -> { carEntity.setCarType(finalCarType); carEntity.setEnable(1); carEntity.setGpsType(getTypeValues(typeList4,carEntity.getGpsType(),errorInfoMap,"智能设备厂商")); carEntity.setAreaRegion(getTypeValues(typeList5,carEntity.getAreaRegion(),errorInfoMap,"网格化区域")); carEntity.setType(getTypeValues(typeList7,carEntity.getType(),errorInfoMap,"车身装置")); if (StringUtil.isEmpty(carEntity.getPlate())) { throw new RuntimeException("车牌号不能为空!!"); } if (StringUtil.isEmpty(carEntity.getPlate().replaceAll("\\s*", ""))) { throw new RuntimeException("车牌号不能为空格!!"); } }); Set collect = listCarEntities.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet()); List carServiceList = carService.getList(NonAutomotiveVechicleEntity.class); Set collect1 = carServiceList.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet()); Sets.SetView intersection = Sets.intersection(collect, collect1); if (intersection.size() > 0) { throw new Exception("车牌号重复出现: " .concat(String.join(",", intersection))); } for (NonAutomotiveVechicleEntity car : listCarEntities) { try { carService.save(car); } catch (Exception e) { logger.error(ExceptionUtil.getExceptionMessage(e)); throw new Exception("文件导入失败"); } } if(errorInfoMap.size() > 0){ j.setMsg("文件导入成功!部分数据对照失败:"+errorInfoMap+",请手动修改!"); }else{ j.setMsg("文件导入成功!"); } } } } catch (Exception e) { j.setMsg(e.getMessage()); logger.error(ExceptionUtil.getExceptionMessage(e)); } finally { try { file.getInputStream().close(); } catch (IOException e) { e.printStackTrace(); } } } return j; } @RequestMapping(method = RequestMethod.GET) @ResponseBody public List list() { List listCars = carService.getList(CarEntity.class); return listCars; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { CarEntity task = carService.get(CarEntity.class, id); if (task == null) { return new ResponseEntity(HttpStatus.NOT_FOUND); } return new ResponseEntity(task, HttpStatus.OK); } @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity create(@RequestBody CarEntity car, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(car); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try { carService.save(car); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = car.getId(); URI uri = uriBuilder.path("/rest/carController/" + id).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity(headers, HttpStatus.CREATED); } @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity update(@RequestBody CarEntity car) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(car); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try { carService.saveOrUpdate(car); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码. return new ResponseEntity(HttpStatus.NO_CONTENT); } @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) public void delete(@PathVariable("id") String id) { carService.deleteEntityById(CarEntity.class, id); } }