| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126 |
- 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<String> 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<String> 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<String> 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<String> 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<String> 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<CarEntity> 车辆信息集合
- */
- @GetMapping(params = "getAllCarsInfo")
- @ResponseBody
- public List<Map<String,Object>> 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<Map<String,Object>> carEntities = this.systemService.findForJdbc(getAllCarsInfoSql);
- // 根据车辆id得到车辆状态
- List<String> carIds = new ArrayList<>();
- for (Map<String,Object> sqlData : carEntities){
- if(sqlData.containsKey("tbc.id")){
- carIds.add("\""+sqlData.get("tbc.id")+"\"");
- }else if(sqlData.containsKey("id")){
- carIds.add("\""+sqlData.get("id")+"\"");
- }
- }
- Map<String,Object> result = HttpClientUtils.sendHttpPostCarInfo(carIds);
- Map<String,Boolean> dataIdLine = new HashMap<>();
- if(result.containsKey("code") && Integer.parseInt(String.valueOf(result.get("code"))) == 0){
- List<Map<String,Object>> datas = (List<Map<String,Object>>) result.get("data");
- for (Map<String,Object> 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<String,Object> 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<String, String> 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<String, String> 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<String> 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<String> 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<String,List<String>> 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<CarEntity> cars = this.carService.getListByCriteriaQuery(cq, false);
- List<CarEntity> 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<TSType> typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType");
- List<TSType> typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType");
- List<TSType> typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState");
- List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
- List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
- List<TSType> typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider");
- List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
- List<TSType> 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<String,Object> 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<NonAutomotiveVechicleEntity> cars = this.carService.getListByCriteriaQuery(cq, false);
- List<NonAutomotiveVechicleEntity> returnCars = new ArrayList<>();
- // 转义
- TSTypegroup typegroup4 = systemService.getTypeGroup("gpsType", "智能设备厂商");
- TSTypegroup typegroup5 = systemService.getTypeGroup("areaRegion","网格化区域");
- TSTypegroup typegroup7 = systemService.getTypeGroup("cartype", "车身装置");
- List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
- List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
- List<TSType> 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<String,Object> 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<String,List<String>> errorMap,String MKey,String EValue){
- if(errorMap.containsKey(MKey)){
- errorMap.get(MKey).add(EValue);
- }else{
- List<String> errorInfoList = new ArrayList<>();
- errorInfoList.add(EValue);
- errorMap.put(MKey,errorInfoList);
- }
- }
- private List<TSType> typegroupTotypeList(TSTypegroup typegroup,Map<String,List<String>> errorInfoMap,String code){
- if(typegroup != null){
- return typegroup.getTSTypes();
- }else{
- errorInfo(errorInfoMap,"字典表查询失败",code);
- return null;
- }
- }
- private String getTypeValues(List<TSType> typeList,String code,Map<String,List<String>> 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<TSType> typeList,String code,Map<String,List<String>> 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<String,List<String>> errorInfoMap = new HashMap<>();
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- for (Map.Entry<String, MultipartFile> 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<TSType> typeList1 = typegroupTotypeList(typegroup1,errorInfoMap,"energyType");
- List<TSType> typeList2 = typegroupTotypeList(typegroup2,errorInfoMap,"tonnageType");
- List<TSType> typeList3 = typegroupTotypeList(typegroup3,errorInfoMap,"carState");
- List<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
- List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
- List<TSType> typeList6 = typegroupTotypeList(typegroup6,errorInfoMap,"videoProvider");
- List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
- List<TSType> typeList8 = typegroupTotypeList(typegroup8,errorInfoMap,"brand");
- List<CarEntity> 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<String,Object> 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<String> collect = listCarEntities.stream().map(CarEntity::getPlate).collect(Collectors.toSet());
- List<CarEntity> carServiceList = carService.getList(CarEntity.class);
- Set<String> collect1 = carServiceList.stream().map(CarEntity::getPlate).collect(Collectors.toSet());
- Sets.SetView<String> 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<TSType> typeList4 = typegroupTotypeList(typegroup4,errorInfoMap,"gpsType");
- List<TSType> typeList5 = typegroupTotypeList(typegroup5,errorInfoMap,"areaRegion");
- List<TSType> typeList7 = typegroupTotypeList(typegroup7,errorInfoMap,"cartype");
- List<NonAutomotiveVechicleEntity> 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<String> collect = listCarEntities.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet());
- List<NonAutomotiveVechicleEntity> carServiceList = carService.getList(NonAutomotiveVechicleEntity.class);
- Set<String> collect1 = carServiceList.stream().map(NonAutomotiveVechicleEntity::getPlate).collect(Collectors.toSet());
- Sets.SetView<String> 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<CarEntity> list() {
- List<CarEntity> 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<ConstraintViolation<CarEntity>> 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<ConstraintViolation<CarEntity>> 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);
- }
- }
|