package com.zcloud.controller.operatingvehicles; import cn.hutool.core.bean.BeanUtil; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; import com.zcloud.logs.LogAnno; import com.zcloud.service.assignedManage.AssignedManageService; import com.zcloud.service.operatingvehicles.OperatingVehiclesService; import com.zcloud.service.scrapManage.ScrapManageService; import com.zcloud.service.system.DepartmentService; import com.zcloud.service.system.ImgFilesService; import com.zcloud.util.*; import net.sf.json.JSONArray; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import java.io.File; import java.util.*; import java.util.stream.Collectors; @Controller @RequestMapping("/operatingvehicles") public class OperatingVehiclesController extends BaseController { @Autowired private OperatingVehiclesService operatingVehiclesService; @Autowired private ImgFilesService imgfilesService; @Autowired private ScrapManageService scrapManageService; @Autowired private DepartmentService departmentService; @Autowired private AssignedManageService assignedManageService; /** * 新增 * * @param * @throws Exception */ @RequestMapping(value = "/add") @ResponseBody public Object add() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("OPERATING_ID", this.get32UUID()); //运营车辆主键 pd.put("ISDELETE", "0"); //是否删除(0:有效 1:删除) pd.put("CREATOR", Jurisdiction.getUSER_ID()); //添加人id pd.put("CREATORNAME", Jurisdiction.getName()); //添加人名字 pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); pd.put("NETWORK_STATUS", "未入网"); pd.put("ISSCRAP", "0"); operatingVehiclesService.save(pd); map.put("pd", pd); map.put("result", errInfo); return map; } /** * 删除 * * @param * @throws Exception */ @RequestMapping(value = "/delete") @ResponseBody public Object delete() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); if (Tools.notEmpty(pd.getString("OPERATING_ID"))) { PageData findPageData = operatingVehiclesService.findById(pd); findPageData.remove("REMARK"); PageData scrapAddData = new PageData(); BeanUtil.copyProperties(findPageData,scrapAddData); scrapAddData.put("SCRAP_ID", this.get32UUID()); scrapAddData.put("RECORD_NUMBER", findPageData.get("GOODSSELFNUMBER")); scrapAddData.put("SCRAP_VEHICLEMODEL", "运输车辆"); scrapAddData.put("SCRAP_DATE", DateUtil.date2Str(new Date())); scrapAddData.put("REGISTRANT", Jurisdiction.getName()); scrapAddData.put("CREATTIME", DateUtil.date2Str(new Date())); scrapAddData.put("OPERATTIME", DateUtil.date2Str(new Date())); scrapAddData.put("BRAND", findPageData.get("VEHICLE_BRAND")); scrapAddData.put("TRANSACTION_DATE", DateUtil.date2Str(new Date())); scrapAddData.put("SCRAP_VEHICLE", findPageData.get("PLATE_NUMBER")); scrapAddData.put("ISDELETE", "0"); scrapManageService.save(scrapAddData); } pd.put("DELETOR", Jurisdiction.getUSER_ID()); pd.put("DELETORNAME", Jurisdiction.getName()); pd.put("DELETTIME", DateUtil.date2Str(new Date())); operatingVehiclesService.delete(pd); map.put("result", errInfo); //返回结果 return map; } /** * 修改 * * @param * @throws Exception */ @RequestMapping(value = "/edit") @ResponseBody public Object edit() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("OPERATOR", Jurisdiction.getCORPINFO_ID()); pd.put("OPERATORNAME", Jurisdiction.getName()); pd.put("OPERATTIME", DateUtil.date2Str(new Date())); operatingVehiclesService.edit(pd); PageData pageData = new PageData(); pageData.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); pageData.put("ID", pd.getString("OPERATING_ID")); PageData vehicleAssignedInfo = assignedManageService.findByRawVehicleId(pageData); if (!Tools.isEmpty(vehicleAssignedInfo)) { BeanUtil.copyProperties(pd, vehicleAssignedInfo); vehicleAssignedInfo.put("POWER_TYPE", pd.getString("FUEL_TYPE")); vehicleAssignedInfo.put("RAW_OWNERS", pd.getString("VEHICLEOWNER")); vehicleAssignedInfo.put("RAW_CONTACT_NUMBER", pd.getString("CONTACT_NUMBER")); vehicleAssignedInfo.put("RAW_OPERATION_CERTIFICATE", pd.getString("OPERATING_CERTIFICATE")); assignedManageService.edit(vehicleAssignedInfo); } PageData pd2 = scrapManageService.findByScrapVehicleId(pageData); if(!ObjectUtils.isEmpty(pd2)) { BeanUtil.copyProperties(pd,pd2); pd2.put("VEHICLE_MODEL", pd.getString("VEHICLE_MODEL")); pd2.put("VEHICLEOWNER_NUMBER", pd.getString("CONTACT_NUMBER")); pd2.put("BRAND", pd.getString("VEHICLE_BRAND")); scrapManageService.edit(pd2); } map.put("pd", pd); map.put("result", errInfo); return map; } /** * 去修改页面获取数据 * * @param * @throws Exception */ @RequestMapping(value = "/goEdit") @ResponseBody public Object goEdit() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); pd = operatingVehiclesService.findById(pd); pd.put("FOREIGN_KEY", pd.getString("OPERATING_ID")); pd.put("TYPE", 130); List headstockphoto = imgfilesService.listAll(pd);//车头照片 pd.put("TYPE", 121); List drivingLicenseImgs = imgfilesService.listAll(pd);//行驶证照片 pd.put("TYPE", 122); List operatingcertificatephoto = imgfilesService.listAll(pd);//运营证照片 List zdepartmentPdList = new ArrayList(); PageData dept = new PageData(); dept.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); dept = this.departmentService.findByCorpId(dept); String ZDEPARTMENT_ID = dept.getString("DEPARTMENT_ID"); PageData node = new PageData(); node.put("id", dept.get("DEPARTMENT_ID")); node.put("parentId", dept.get("PARENT_ID")); node.put("name", dept.get("NAME")); node.put("icon", "../../../assets/images/user.gif"); zdepartmentPdList.add(node); JSONArray arr = JSONArray .fromObject(departmentService.listAllDepartmentToSelect(ZDEPARTMENT_ID, zdepartmentPdList)); map.put("zTreeNodes", (null == arr ? "" : "{\"treeNodes\":" + arr.toString() + "}")); map.put("pd", pd); map.put("headstockphoto", headstockphoto); map.put("drivinglicensephoto", drivingLicenseImgs); map.put("operatingcertificatephoto", operatingcertificatephoto); map.put("result", errInfo); return map; } @RequestMapping(value = "/list") @ResponseBody public Object list(Page page) throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业ID page.setPd(pd); List varList = operatingVehiclesService.list(page); //列出Question列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); return map; } @RequestMapping(value = "/operationvehicleList") @ResponseBody public Object operationVehicleList() throws Exception { Map map = new HashMap(); String errInfo = "success"; String corpId = Jurisdiction.getCORPINFO_ID(); List list = operatingVehiclesService.operationVehicleList(corpId); //列出Question列表 map.put("list", list); map.put("result", errInfo); return map; } @RequestMapping(value = "/findById") @ResponseBody public Object findById() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); pd.put("FOREIGN_KEY", pd.getString("OPERATING_ID")); pd.put("TYPE", 130); List headstockphoto = imgfilesService.listAll(pd);//车头照片 pd.put("TYPE", 121); List drivinglicensephoto = imgfilesService.listAll(pd);//行驶证照片 pd.put("TYPE", 132); List operatingcertificatephoto = imgfilesService.listAll(pd);//运营证照片 map.put("pd", pd); map.put("headstockphoto", headstockphoto); map.put("drivinglicensephoto", drivinglicensephoto); map.put("operatingcertificatephoto", operatingcertificatephoto); pd = operatingVehiclesService.findById(pd); map.put("pd", pd); map.put("result", errInfo); return map; } @RequestMapping(value = "/setOperationsScrapStatus") @ResponseBody public Object setOperationsScrapStatus() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); operatingVehiclesService.setScrapStatus(pd); map.put("pd", pd); map.put("result", errInfo); return map; } @RequestMapping(value = "/corpList") @ResponseBody public Object corpList() throws Exception { Map map = new HashMap(); String errInfo = "success"; String corpId = Jurisdiction.getCORPINFO_ID(); List list = operatingVehiclesService.corpList(corpId); //列出Question列表 map.put("list", list); map.put("result", errInfo); return map; } @RequestMapping(value = "/findByPlateNumber") @ResponseBody public Object findByPlateNumber() throws Exception { Map map = new HashMap(); String errInfo = "success"; PageData pd = new PageData(); pd = this.getPageData(); pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); pd.put("PLATE_NUMBER", pd.getString("vehicleNumber")); PageData resData = operatingVehiclesService.findByfindByPlateNumber(pd); map.put("pd", resData); map.put("result", errInfo); return map; } /** * 导出到excel * * @param * @throws Exception */ @RequestMapping(value = "/excel") // // @RequiresPermissions("toExcel") public ModelAndView exportExcel() throws Exception { ModelAndView mv = new ModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); String DATA_IDS = pd.getString("DATA_IDS"); if (Tools.notEmpty(DATA_IDS)) { String[] ArrayDATA_IDS = DATA_IDS.split(","); pd.put("ArrayDATA_IDS", ArrayDATA_IDS); } Map dataMap = new HashMap(); List titles = new ArrayList(); titles.add("车牌号"); //1 titles.add("车架号"); //2 titles.add("车辆类型"); //3 titles.add("运营证号"); //4 titles.add("归属部门"); //5 titles.add("车主"); //6 titles.add("车主电话"); //7 titles.add("初登日期"); //8 titles.add("发证日期"); //9 titles.add("到期日期"); //10 titles.add("车辆品牌"); //11 titles.add("车辆型号"); //12 titles.add("核定总质量"); //13 titles.add("核定载质量"); //14 dataMap.put("titles", titles); List varOList = operatingVehiclesService.listOut(pd); List varList = new ArrayList(); for (int i = 0; i < varOList.size(); i++) { PageData vpd = new PageData(); vpd.put("var1", varOList.get(i).getString("PLATE_NUMBER"));//1 vpd.put("var2", varOList.get(i).getString("FRAMES_NUMBER"));//2 vpd.put("var3", varOList.get(i).getString("VEHICLE_TYPE"));//3 vpd.put("var4", varOList.get(i).getString("OPERATING_CERTIFICATE"));//4 vpd.put("var5", varOList.get(i).getString("BELONGING_DEPARTMENT"));//5 vpd.put("var6", varOList.get(i).getString("VEHICLEOWNER"));//6 vpd.put("var7", varOList.get(i).getString("VEHICLEOWNER_NUMBER"));//7 vpd.put("var8", varOList.get(i).getString("FIRSTSHOW_DATE"));//8 vpd.put("var9", varOList.get(i).getString("CERTIFICATE_DATE"));//9 vpd.put("var10", varOList.get(i).getString("EXPIRE_DATE"));//10 vpd.put("var11", varOList.get(i).getString("VEHICLE_BRAND"));//11 vpd.put("var12", varOList.get(i).getString("VEHICLE_MODEL"));//12 vpd.put("var13", varOList.get(i).getString("VOUCH_TOTALMASS"));//13 vpd.put("var14", varOList.get(i).getString("VOUCH_PAYLOAD"));//14 varList.add(vpd); } dataMap.put("varList", varList); ObjectExcelView erv = new ObjectExcelView(); mv = new ModelAndView(erv, dataMap); return mv; } @RequestMapping(value = "/readExcel") @SuppressWarnings("unchecked") @ResponseBody @Transactional @LogAnno(menuType = "双重预防", menuServer = "风险管控", instructionsOperate = "风险点(单元)", instructionsType = "上传附件") public Object readExcel(@RequestParam(value = "FFILE", required = false) MultipartFile file) throws Exception { Map map = new HashMap(); String errInfo = "success"; StringBuffer errorStr = new StringBuffer(); if (null != file && !file.isEmpty()) { File tempFile = new File(file.getOriginalFilename()); //新建file FileUtils.copyInputStreamToFile(file.getInputStream(), tempFile); //将MultipartFile复制到File List listPd = (List) ObjectExcelRead.readExcel(tempFile, 1, 0, 0); // 执行读EXCEL操作,读出的数据导入List // 2:从第3行开始;0:从第A列开始;0:第0个sheet /** * var0 :风险点(单元) var1 :所属部门 */ try { if (listPd.size() < 1) { map.put("result", "error"); // 返回结果 map.put("resultStr", "Excel数据为空,请检查数据后,重新上传!"); FileUtils.deleteQuietly(tempFile);//删除临时文件 return map; } List riskunitList = new ArrayList<>(); PageData pd = new PageData(); pd.put("ISDELETE", "0"); pd.put("BELONGING_DEPT", Jurisdiction.getCORPINFO_ID()); List riskunitListAll = operatingVehiclesService.listAll(pd); Map riskunitMapAll = new HashMap<>(); for (PageData pageData : riskunitListAll) { // 使用车牌号作为键 String plateNumberKey = Tools.excelHandle(pageData.getString("PLATE_NUMBER")); riskunitMapAll.put(plateNumberKey, pageData); } List header = new ArrayList<>(); header.add("自编号"); header.add("车牌号"); header.add("车架号"); /*header.add("车身编号");*/ header.add("车辆类型"); header.add("运营证号"); header.add("归属部门"); header.add("车主"); header.add("车主电话"); header.add("联系人"); header.add("联系电话"); header.add("初登日期"); header.add("发证日期"); header.add("到期日期"); header.add("车辆品牌"); header.add("车辆型号"); header.add("核定总质量"); header.add("核定载质量"); /*header.add("容积");*/ header.add("备注"); Map hasRiskUnit = new HashMap<>(); int succeeNum = 1; for (PageData lpd : listPd) { succeeNum++; convertExcelDate(lpd, "var10"); // 初登日期 FIRSTSHOW_DATE convertExcelDate(lpd, "var11"); // 发证日期 CERTIFICATE_DATE convertExcelDate(lpd, "var12"); // 到期日期 EXPIRE_DATE System.out.println(lpd.get("var10") + "--" + lpd.get("var11") + "--" + lpd.get("var12")); for (int i = 0; i < header.size(); i++) { if (!lpd.containsKey("var" + i)) { errorStr.append("

第" + succeeNum + "行的\"" + header.get(i) + "\"无数据

"); continue; } if (Tools.isEmpty(lpd.get("var" + i))) { errorStr.append("

第" + succeeNum + "行的\"" + header.get(i) + "\"无数据

"); continue; } } String plateNumberVar = Tools.isEmpty(lpd.get("var1")) ? "" : Tools.excelHandle(lpd.get("var1")); if (riskunitMapAll.containsKey(plateNumberVar)) { errorStr.append("

第" + succeeNum + "行:" + "车牌号为\"" + plateNumberVar + "\"的记录已存在,请检查!" + "

"); continue; } if (hasRiskUnit.containsKey(plateNumberVar)) { errorStr.append("

第" + succeeNum + "行:" + "车牌号重复,请重新检查内容!" + "

"); continue; } hasRiskUnit.put(plateNumberVar, "1"); PageData riskunit = new PageData(); riskunit.put("GOODSSELFNUMBER", lpd.get("var0")); riskunit.put("PLATE_NUMBER", lpd.get("var1")); riskunit.put("FRAMES_NUMBER", lpd.get("var2")); riskunit.put("VEHICLE_TYPE", lpd.get("var3")); riskunit.put("OPERATING_CERTIFICATE", lpd.get("var4")); riskunit.put("BELONGING_DEPARTMENT", lpd.get("var5")); riskunit.put("VEHICLEOWNER", lpd.get("var6")); riskunit.put("VEHICLEOWNER_NUMBER", lpd.get("var7")); riskunit.put("CONTACT", lpd.get("var8")); riskunit.put("CONTACT_NUMBER", lpd.get("var9")); riskunit.put("FIRSTSHOW_DATE", lpd.get("var10")); riskunit.put("CERTIFICATE_DATE", lpd.get("var11")); riskunit.put("EXPIRE_DATE", lpd.get("var12")); riskunit.put("VEHICLE_BRAND", lpd.get("var13")); riskunit.put("VEHICLE_MODEL", lpd.get("var14")); riskunit.put("VOUCH_TOTALMASS", lpd.get("var15")); riskunit.put("VOUCH_PAYLOAD", lpd.get("var16")); riskunit.put("REMARK", lpd.get("var18")); riskunit.put("OPERATING_ID", this.get32UUID()); riskunit.put("ISDELETE", "0"); riskunit.put("CREATOR", Jurisdiction.getName()); riskunit.put("CREATTIME", DateUtil.date2Str(new Date())); riskunit.put("OPERATOR", Jurisdiction.getName()); riskunit.put("OPERATTIME", DateUtil.date2Str(new Date())); riskunit.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); riskunitList.add(riskunit); } if (Tools.isEmpty(errorStr.toString())) { for (PageData riskunit : riskunitList) { operatingVehiclesService.save(riskunit); } errorStr.append("成功导入" + riskunitList.size() + "条数据!"); } else { errInfo = "error"; } FileUtils.deleteQuietly(tempFile);//删除临时文件 } catch (Exception e) { map.put("result", "fail"); // 返回结果 map.put("resultStr", errorStr.toString()); FileUtils.deleteQuietly(tempFile);//删除临时文件 return map; } } map.put("result", "success");//返回结果 map.put("resultType", errInfo);//返回message类型 map.put("isExcel", "1");//返回类型 map.put("resultStr", errorStr.toString()); return map; } private void convertExcelDate(PageData lpd, String field) { Object excelDateObj = lpd.get(field); if (excelDateObj != null) { // 尝试将对象转换为Double,因为Excel中的日期是以Double类型的数字存储的 double excelDate = Double.parseDouble(excelDateObj.toString()); // 使用Apache POI的DateUtil获取Java日期对象 Date javaDate = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(excelDate); // 使用您的DateUtil工具类进行日期格式化 String formattedDate = DateUtil.date2Str(javaDate, "yyyy-MM-dd"); // 更新lpd对象中的日期字段 lpd.put(field, formattedDate); } } }