package cn.com.lzt.car.schedule.controller; import cn.com.lzt.car.cardoc.entity.CarEntity; import cn.com.lzt.car.cardoc.service.impl.CarServiceImpl; import cn.com.lzt.car.carfleet.service.impl.CarFleetServiceImpl; import cn.com.lzt.car.schedule.entity.CarListExcelEntity; import cn.com.lzt.car.schedule.entity.CarScheduleEntity; import cn.com.lzt.car.schedule.entity.ManListExcelEntity; import cn.com.lzt.car.schedule.entity.TBCarDrivingRecord; import cn.com.lzt.car.schedule.service.CarScheduleServiceI; import cn.com.lzt.car.schedule.service.impl.CarScheduleCountServiceImpl; import cn.com.lzt.car.schedule.service.impl.TBCarDrivingRecordServiceImpl; import cn.com.lzt.car.scheduledetail.entity.CarScheduleRouteEntity; import cn.com.lzt.car.scheduledetail.entity.TBCarScheduleCommon; import cn.com.lzt.car.scheduledetail.entity.TBCarScheduleCommonSection; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; import com.daju.common.constants.CarTypeEnum; import com.daju.common.constants.ScheduleAssignmentStyleEnum; import com.daju.common.util.DataPage; import com.daju.mix.dao.entity.PDeviceDetailRecord; import com.daju.mix.dao.entity.TBCarScheduleArrange; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.jeecgframework.core.beanvalidator.BeanValidators; 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.core.util.*; import org.jeecgframework.poi.excel.ExcelImportUtil; import cn.afterturn.easypoi.entity.vo.NormalExcelConstants; import cn.afterturn.easypoi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.tag.core.easyui.TagUtil; import org.jeecgframework.web.system.pojo.base.TSBaseUser; import org.jeecgframework.web.system.service.SystemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.ConstraintViolation; import javax.validation.Validator; import java.io.IOException; import java.net.URI; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.*; /** * @Title: Controller * @Description: 车辆作业计划 * @author onlineGenerator * @date 2019-10-15 09:47:08 * @version V1.0 * */ @Controller @RequestMapping("/carScheduleController") public class CarScheduleController extends BaseController { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(CarScheduleController.class); @Autowired private CarScheduleServiceI carScheduleService; @Resource private CarFleetServiceImpl carFleetService; @Resource private CarServiceImpl carService; @Autowired private SystemService systemService; @Autowired private Validator validator; @Resource private CarScheduleCountServiceImpl TBCarScheduleCountService; @Resource private TBCarDrivingRecordServiceImpl tbCarDrivingRecordService; @RequestMapping(params = "carScheduleDoneStat") public ModelAndView carScheduleDoneStat(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/car/schedule/carScheduleDoneStat"); } @RequestMapping(params = "carList") public ModelAndView carList(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/schedule/carList"); } @RequestMapping(params = "manList") public ModelAndView manList(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/schedule/manList"); } @RequestMapping(params = "drivingRecordList") public ModelAndView drivingRecordList(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/schedule/drivingRecordList"); } @RequestMapping(params = "detail") public ModelAndView goDetail(HttpServletRequest request) { if(request.getParameter("id") != null){ String id = request.getParameter("id"); String sqlStr = "SELECT\n" + "\ttbc.plate,\n" + "\tCONCAT(\n" + "\t\ttbcstd.yearmonth,\n" + "\t\t\"-\",\n" + "\t\ttbcstd.code_day\n" + "\t) scheduleDate,\n" + "\ttbcstd.username,\n" + "\ttbcst.`start` workStartTime,\n" + "\ttbcst.`end` workEndTime,\n" + "\tCONCAT('(',tbcst.`start`,'-',tbcst.`end`,')') workTime,\n" + "\ttbcst.arrange_name arrangeName,\n" + "\tIFNULL(tbcmr.`status`,0) workNumberToDay,\n" + "\ttbwr.place_code,\n" + "\ttbwr.place_name,\n" + "\ttbcsfar.finished_area\n" + "FROM\n" + "\tt_b_car tbc\n" + "LEFT JOIN t_b_car_schedule_task_detail tbcstd ON tbcstd.carid = tbc.id\n" + "LEFT JOIN t_b_car_schedule_task tbcst ON tbcst.id = tbcstd.pid\n" + "LEFT JOIN t_b_work_route_list tbwr ON tbwr.route_id = tbcst.work_route\n" + "LEFT JOIN t_b_archives_area tbaa ON tbaa.`code` = tbwr.place_code\n" + "LEFT JOIN t_b_car_mileage_record tbcmr ON tbcmr.schedule_date = CONCAT(\n" + "\t\ttbcstd.yearmonth,\n" + "\t\t\"-\",\n" + "\t\ttbcstd.code_day\n" + "\t) AND tbcmr.route_area_id = tbaa.id AND tbcmr.route_id = tbwr.route_id AND tbcmr.car_id = tbcstd.carid\n" + "LEFT JOIN t_b_car_schedule_finished_area_record tbcsfar ON tbcsfar.car_id = tbcstd.carid\n" + "AND tbcsfar.schedule_date = CONCAT(\n" + "\ttbcstd.yearmonth,\n" + "\t\"-\",\n" + "\ttbcstd.code_day\n" + ")\n" + "WHERE\n" + "\ttbcstd.id = '"+id+"';"; if(request.getParameter("queryType") != null && "user".equals(request.getParameter("queryType"))){ sqlStr = "SELECT\n" + "\tCONCAT(\n" + "\t\ttbcstd.yearmonth,\n" + "\t\t\"-\",\n" + "\t\ttbcstd.code_day\n" + "\t) scheduleDate,\n" + "\ttbcstd.username,\n" + "\ttbcst.`start` workStartTime,\n" + "\ttbcst.`end` workEndTime,\n" + "\tCONCAT('(',tbcst.`start`,'-',tbcst.`end`,')') workTime,\n" + "\ttbcst.arrange_name arrangeName,\n" + "\tIFNULL(tbcmr.`status`,0) workNumberToDay,\n" + "\ttbwr.place_code,\n" + "\ttbwr.place_name,\n" + "\ttbcsfar.finished_area\n" + "FROM\n" + "\tt_s_base_user tbc\n" + "LEFT JOIN t_b_car_schedule_task_detail tbcstd ON tbcstd.user_id = tbc.id\n" + "LEFT JOIN t_b_car_schedule_task tbcst ON tbcst.id = tbcstd.pid\n" + "LEFT JOIN t_b_work_route_list tbwr ON tbwr.route_id = tbcst.work_route\n" + "LEFT JOIN t_b_archives_area tbaa ON tbaa.`code` = tbwr.place_code\n" + "LEFT JOIN t_b_car_mileage_record tbcmr ON tbcmr.schedule_date = CONCAT(\n" + "\t\ttbcstd.yearmonth,\n" + "\t\t\"-\",\n" + "\t\ttbcstd.code_day\n" + "\t) AND tbcmr.route_area_id = tbaa.id AND tbcmr.route_id = tbwr.route_id AND tbcmr.car_id = tbcstd.user_id\n" + "LEFT JOIN t_b_car_schedule_finished_area_record tbcsfar ON tbcsfar.car_id = tbcstd.user_id\n" + "AND tbcsfar.schedule_date = CONCAT(\n" + "\ttbcstd.yearmonth,\n" + "\t\"-\",\n" + "\ttbcstd.code_day\n" + ")\n" + "WHERE\n" + "\ttbcstd.id = '"+id+"';"; } List> workInfo = systemService.findForJdbc(sqlStr); if(workInfo != null && workInfo.size() >0){ for (Map workItem:workInfo){ if(workItem.containsKey("username") && workItem.get("username") != null){ String username = String.valueOf(workItem.get("username")); if(username.contains(",")){ workItem.put("username",username.substring(0,username.indexOf(","))); workItem.put("usernames",username.substring(username.indexOf(",")+1)); } } if(workItem.containsKey("finished_area") && workItem.get("finished_area") != null){ String workArea = String.valueOf(workItem.get("finished_area")); String scheduleArea = String.valueOf(workItem.get("place_code")); String[] workAreas = workArea.contains("/") ? workArea.split("/") : new String[]{workArea}; int workNumberToDay = 0; for (String workAreaItem:workAreas){ if(workAreaItem.contains(scheduleArea)){ if(workAreaItem.contains(",")){ String[] workDate = workAreaItem.split(","); String[] workTimes = workDate[1].split(";"); List workTimeState = new ArrayList<>(); if(workTimes.length > 0){ // add-刘梦祥-2022年8月15日15:07:31(根据排班作业时间和作业元素完成时间区分状态) if(workItem.containsKey("scheduleDate") && workItem.get("scheduleDate") != null && workItem.containsKey("workStartTime") && workItem.get("workStartTime") != null && workItem.containsKey("workEndTime") && workItem.get("workEndTime") != null){ String scheduleDate = String.valueOf(workItem.get("scheduleDate")); String workStartTime = String.valueOf(workItem.get("workStartTime")); String workEndTime = String.valueOf(workItem.get("workEndTime")); if(workStartTime.contains(":")){ workStartTime.replaceAll(":",":"); } if(workEndTime.contains(":")){ workEndTime.replaceAll(":",":"); } for (String workTime:workTimes){ if(DateUtil.parseDateTime(workTime).after(DateUtil.parseDateTime(scheduleDate + " " + workStartTime + ":00")) && DateUtil.parseDateTime(workTime).before(DateUtil.parseDateTime(scheduleDate + " " + workEndTime + ":00"))) { workTimeState.add(workTime); workNumberToDay += 1; } } } } workItem.put("workTimes",workTimeState); } break; } } workItem.put("workNumberToDay",workNumberToDay); }else{ workItem.put("workNumberToDay",0); } if(workItem.containsKey("workNumberToDay") && workItem.get("workNumberToDay") != null){ String workNumberToDay = String.valueOf(workItem.get("workNumberToDay")); workItem.put("workState","0".equals(workNumberToDay) ? "未完成":"已完成"); } } } request.setAttribute("queryType", request.getParameter("queryType")); request.setAttribute("workInfo", workInfo); } return new ModelAndView("cn/com/lzt/schedule/carList-detail"); } @RequestMapping(params = "carListDatagrid") @ResponseBody public Object carListDatagrid(HttpServletRequest request){ Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()) { param.put(key, request.getParameter(key)); } return TBCarScheduleCountService.queryCarPageByScheduleId(param); } @RequestMapping(params = "manListDatagrid") @ResponseBody public Object manListDatagrid(HttpServletRequest request){ Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()) { param.put(key, request.getParameter(key)); } return TBCarScheduleCountService.queryUserPageByScheduleId(param); } @RequestMapping(params = "drivingRecordListDatagrid") @ResponseBody public Object drivingRecordListDatagrid(HttpServletRequest request){ Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()) { param.put(key, request.getParameter(key)); } List carTypes = new ArrayList<>(); String MENU_DATA_AUTHOR_RULE_SQL = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); if (!cn.com.lzt.common.util.StringUtil.isEmpty(MENU_DATA_AUTHOR_RULE_SQL)){ if(MENU_DATA_AUTHOR_RULE_SQL.contains(",")){ MENU_DATA_AUTHOR_RULE_SQL = MENU_DATA_AUTHOR_RULE_SQL.replaceAll(",","','"); } String[] MENU_DATA_AUTHOR_RULE_SQL_Split = MENU_DATA_AUTHOR_RULE_SQL.split(" "); String getCarType = "select tsy.typename from t_s_type tsy LEFT JOIN t_s_typegroup tsyg on tsyg.id = tsy.typegroupid where tsyg.typegroupcode = \"cartype\" and tsy.typecode "+MENU_DATA_AUTHOR_RULE_SQL_Split[MENU_DATA_AUTHOR_RULE_SQL_Split.length-1]+";"; carTypes = this.systemService.findListbySql(getCarType); } return tbCarDrivingRecordService.recordPage(param,carTypes); } /** * 车辆作业计划列表 页面跳转 * * @return */ @RequestMapping(params = "list") public ModelAndView list(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/car/schedule/carScheduleList"); } @RequestMapping(params = "detailBaidu") public ModelAndView detailBaidu(HttpServletRequest request) { return new ModelAndView("cn/com/lzt/car/schedule/carScheduleDetailListBaidu"); } @RequestMapping(params = "listAndBaidu") public ModelAndView listAndBaidu(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleid"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); request.setAttribute("schedule", carSchedule); if(carSchedule.getType().equals("route")) { return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleDetailSet"); } else if(carSchedule.getType().equals("section")) { return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleSectionSet"); } else if(carSchedule.getType().equals("place")) { return new ModelAndView("cn/com/lzt/car/scheduledetail/carSchedulePlaceSet"); } return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleDetailSet"); } @RequestMapping(params = "archiveSet") public ModelAndView archiveSet(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleid"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); TSBaseUser user = systemService.get(TSBaseUser.class, carSchedule.getUserId()); request.setAttribute("schedule", carSchedule); request.setAttribute("user", user); if(carSchedule.getAssignmentStyle().equals(ScheduleAssignmentStyleEnum.DustBinClean.getCode())){ return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleArchiveSet"); } if(carSchedule.getAssignmentStyle().equals(ScheduleAssignmentStyleEnum.TOILETS.getCode())){ return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleToiletSet"); } return new ModelAndView(""); } @RequestMapping(params = "archiveList") public ModelAndView archiveList(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleid"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); TSBaseUser user = systemService.get(TSBaseUser.class, carSchedule.getUserId()); request.setAttribute("schedule", carSchedule); request.setAttribute("user", user); return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleArchiveList"); } @RequestMapping(params = "doArchiveSectionAdd") @ResponseBody public AjaxJson doArchiveSectionAdd(HttpServletRequest request) throws ParseException { String message = null; TBCarScheduleCommonSection common = new TBCarScheduleCommonSection(); common.setScheduleId(request.getParameter("scheduleId")); String date = request.getParameter("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); common.setDate(sdf.parse(date)); AjaxJson j = new AjaxJson(); message = "排班添加成功"; j.setSuccess(true); if(carScheduleService.hasScheduleSection(common)) { message = "排班添加失败,已经存在相同排班"; j.setMsg(message); j.setSuccess(false); return j; } try{ common.setCreateDate(LocalDateTime.now()); carScheduleService.addScheduleSection(common); }catch(Exception e){ e.printStackTrace(); message = "档案添加失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "archiveAdd") public ModelAndView archiveAdd(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleid"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); request.setAttribute("schedule", carSchedule); return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleArchiveAdd"); } @RequestMapping(params = "scheduleDoneDatagrid") public void scheduleDoneDatagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()){ param.put(key, request.getParameter(key)); } DataPage result = carScheduleService.getDoneList(param); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "toiletSetDatagrid") public void toiletSetDatagrid(TBCarScheduleArrange object, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { DataPage result = carScheduleService.getToiletList(request.getParameter("scheduleId")); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "archiveListDatagrid") public void archiveListDatagrid(TBCarScheduleArrange object, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { DataPage result = carScheduleService.getArchiveList(request.getParameter("scheduleId")); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "archiveSetDatagrid") public void archiveSetDatagrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { DataPage result = carScheduleService.getDustbinByScheduleCommon(request.getParameter("scheduleid")); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "archiveListDetail") public ModelAndView archiveListDetail(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleId"); String date = request.getParameter("date"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); TSBaseUser user = systemService.get(TSBaseUser.class, carSchedule.getUserId()); request.setAttribute("user", user); request.setAttribute("schedule", carSchedule); request.setAttribute("date", date); return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleArchiveListDetail"); } @RequestMapping(params = "archiveListDetailDatagrid") public void archiveListDetail(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { Map param = new HashMap<>(); for (String key : request.getParameterMap().keySet()){ param.put(key, request.getParameter(key)); } DataPage result = carScheduleService.archiveListDetail(param); TagUtil.datagrid(response, dataGrid, result); } @RequestMapping(params = "doArchiveAdd") @ResponseBody public AjaxJson doArchiveAdd(TBCarScheduleCommon common, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "档案添加成功"; j.setSuccess(true); if(carScheduleService.hasSchedule(common)) { message = "档案添加失败,已经存在相同档案"; j.setMsg(message); j.setSuccess(false); return j; } try{ common.setCreateDate(LocalDateTime.now()); carScheduleService.addSchedule(common); }catch(Exception e){ e.printStackTrace(); message = "档案添加失败"; j.setSuccess(false); throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "doArchiveSectionDel") @ResponseBody public AjaxJson doArchiveSectionDel(TBCarScheduleCommonSection common, HttpServletRequest request){ String message = null; AjaxJson j = new AjaxJson(); message = "排班删除成功"; try{ carScheduleService.delScheduleSection(common); }catch(Exception e){ e.printStackTrace(); message = "排班删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "doArchiveDel") @ResponseBody public AjaxJson doArchiveDel(TBCarScheduleCommon common, HttpServletRequest request){ String message = null; AjaxJson j = new AjaxJson(); message = "档案删除成功"; try{ carScheduleService.delSchedule(common); }catch(Exception e){ e.printStackTrace(); message = "档案删除失败"; throw new BusinessException(e.getMessage()); } j.setMsg(message); return j; } @RequestMapping(params = "listArrange") public ModelAndView listArrange(HttpServletRequest request) { String scheduleid = request.getParameter("scheduleid"); CarScheduleEntity carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, scheduleid); request.setAttribute("schedule", carSchedule); TSBaseUser user = systemService.get(TSBaseUser.class, carSchedule.getUserId()); request.setAttribute("user", user); request.setAttribute("scheduleId", carSchedule.getId()); // if(carSchedule.getType().equals("route")) { // return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleDetailSet"); // } else if(carSchedule.getType().equals("section")) { // return new ModelAndView("cn/com/lzt/car/scheduledetail/carScheduleSectionSet"); // } else if(carSchedule.getType().equals("place")) { // return new ModelAndView("cn/com/lzt/car/scheduledetail/carSchedulePlaceSet"); // } return new ModelAndView("cn/com/lzt/car/schedule/scheduleArrangeList"); } /** * easyui AJAX请求数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "datagrid") public void datagrid(CarScheduleEntity carSchedule,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { CriteriaQuery cq = new CriteriaQuery(CarScheduleEntity.class, dataGrid); //查询条件组装器 if(StringUtils.isNotBlank(carSchedule.getCarname())) { //模糊查询 cq.like("carname", "%"+carSchedule.getCarname()+"%"); carSchedule.setCarname(null); } if(!ResourceUtil.isLoginUserAdmin()) { List carIds = carService.getCarIdsCreateBy(ResourceUtil.getSessionUser().getMobilePhone()); if(!ListUtils.isNullOrEmpty(carIds)) cq.in("carid", carIds.toArray()); } //查询条件组装器 org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, carSchedule, request.getParameterMap()); cq.add(); this.carScheduleService.getDataGridReturn(cq, true); TagUtil.datagrid(response, dataGrid); } /** * 删除车辆作业计划 * * @return */ @RequestMapping(params = "doDel") @ResponseBody public AjaxJson doDel(CarScheduleEntity carSchedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); carSchedule = systemService.getEntity(CarScheduleEntity.class, carSchedule.getId()); message = "车辆作业计划删除成功"; try{ systemService.executeSql("delete from t_b_car_schedule_route where scheduleid = ?", carSchedule.getId()); carScheduleService.delete(carSchedule); 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(",")){ CarScheduleEntity carSchedule = systemService.getEntity(CarScheduleEntity.class, id ); carScheduleService.delete(carSchedule); 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 = "doAdd") @ResponseBody public AjaxJson doAdd(CarScheduleEntity carSchedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆作业计划添加成功"; if(hasCarSchedule(carSchedule)) { message = "车辆作业计划添加失败,已经存在同一时间段的作业计划,请检查修改后在保存"; j.setMsg(message); j.setSuccess(false); return j; } try{ String carId = carSchedule.getCarid(); if(StringUtil.isNotEmpty(carId)) { CarEntity carEntity = systemService.get(CarEntity.class, carSchedule.getCarid()); carSchedule.setUserId(carEntity.getDriverid()); } carSchedule.setCarname(systemService.get(CarEntity.class,carSchedule.getCarid()).getName()); carScheduleService.save(carSchedule); 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; } private boolean hasCarSchedule(CarScheduleEntity carSchedule) { boolean hasSchedule = false; String sql = "select id From t_b_Car_Schedule sche where carid =? and ( (sche.start > ? and sche.start < ? ) or ( sche.end > ? and sche.end < ? ) )"; List> scheList = systemService.findForJdbc(sql, carSchedule.getCarid(), carSchedule.getStart(),carSchedule.getEnd(), carSchedule.getStart(),carSchedule.getEnd()); if(scheList.size() > 0) hasSchedule = true; return hasSchedule; } /** * 更新车辆作业计划 * * @return */ @RequestMapping(params = "doUpdate") @ResponseBody public AjaxJson doUpdate(CarScheduleEntity carSchedule, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆作业计划更新成功"; CarScheduleEntity t = carScheduleService.get(CarScheduleEntity.class, carSchedule.getId()); try { MyBeanUtils.copyBeanNotNull2Bean(carSchedule, t); CarEntity carEntity = systemService.get(CarEntity.class, carSchedule.getCarid()); t.setUserId(carEntity.getDriverid()); t.setCarname(carEntity.getName()); carScheduleService.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 = "doClone") @ResponseBody public AjaxJson doClone(String scheduleid, HttpServletRequest request) { String message = null; AjaxJson j = new AjaxJson(); message = "车辆作业计划复制成功"; CarScheduleEntity t = carScheduleService.get(CarScheduleEntity.class, scheduleid); List details = carScheduleService.findByProperty(CarScheduleRouteEntity.class, "scheduleid", scheduleid); try { CarScheduleEntity carSchedule = new CarScheduleEntity(); MyBeanUtils.copyBean2Bean(carSchedule, t); carSchedule.setId(null); carScheduleService.save(carSchedule); for(CarScheduleRouteEntity detail : details) { CarScheduleRouteEntity newDetail = new CarScheduleRouteEntity(); MyBeanUtils.copyBean2Bean(newDetail, detail); newDetail.setScheduleid(carSchedule.getId()); newDetail.setId(null); systemService.save(newDetail); } 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(CarScheduleEntity carSchedule, HttpServletRequest req) { if (StringUtil.isNotEmpty(carSchedule.getId())) { carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, carSchedule.getId()); req.setAttribute("carSchedulePage", carSchedule); } return new ModelAndView("cn/com/lzt/car/schedule/carSchedule-add"); } /** * 车辆作业计划编辑页面跳转 * * @return */ @RequestMapping(params = "goUpdate") public ModelAndView goUpdate(CarScheduleEntity carSchedule, HttpServletRequest req) { if (StringUtil.isNotEmpty(carSchedule.getId())) { carSchedule = carScheduleService.getEntity(CarScheduleEntity.class, carSchedule.getId()); req.setAttribute("carSchedulePage", carSchedule); } return new ModelAndView("cn/com/lzt/car/schedule/carSchedule-update"); } /** * 导入功能跳转 * * @return */ @RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name","carScheduleController"); return new ModelAndView("common/upload/pub_excel_upload"); } /** * 导出excel * * @param request * @param response */ @RequestMapping(params = "exportXls") public String exportXls(CarScheduleEntity carSchedule,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { CriteriaQuery cq = new CriteriaQuery(CarScheduleEntity.class, dataGrid); org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, carSchedule, request.getParameterMap()); List carSchedules = this.carScheduleService.getListByCriteriaQuery(cq,false); modelMap.put(NormalExcelConstants.FILE_NAME,"车辆作业计划"); modelMap.put(NormalExcelConstants.CLASS,CarScheduleEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("车辆作业计划列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,carSchedules); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } /** * 导出excel 使模板 * * @param request * @param response */ @RequestMapping(params = "exportXlsByT") public String exportXlsByT(CarScheduleEntity carSchedule,HttpServletRequest request,HttpServletResponse response , DataGrid dataGrid,ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME,"车辆作业计划"); modelMap.put(NormalExcelConstants.CLASS,CarScheduleEntity.class); modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("车辆作业计划列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(), "导出信息")); modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList()); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } @SuppressWarnings("unchecked") @RequestMapping(params = "importExcel", method = RequestMethod.POST) @ResponseBody public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) { AjaxJson j = new AjaxJson(); 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 { List listCarScheduleEntitys = ExcelImportUtil.importExcel(file.getInputStream(),CarScheduleEntity.class,params); for (CarScheduleEntity carSchedule : listCarScheduleEntitys) { carScheduleService.save(carSchedule); } j.setMsg("文件导入成功!"); } catch (Exception e) { j.setMsg("文件导入失败!"); 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 listCarSchedules=carScheduleService.getList(CarScheduleEntity.class); return listCarSchedules; } @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public ResponseEntity get(@PathVariable("id") String id) { CarScheduleEntity task = carScheduleService.get(CarScheduleEntity.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 CarScheduleEntity carSchedule, UriComponentsBuilder uriBuilder) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(carSchedule); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ carScheduleService.save(carSchedule); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(HttpStatus.NO_CONTENT); } //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象. String id = carSchedule.getId(); URI uri = uriBuilder.path("/rest/carScheduleController/" + 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 CarScheduleEntity carSchedule) { //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息. Set> failures = validator.validate(carSchedule); if (!failures.isEmpty()) { return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST); } //保存 try{ carScheduleService.saveOrUpdate(carSchedule); } 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) { carScheduleService.deleteEntityById(CarScheduleEntity.class, id); } @RequestMapping(params = "carExcelExport") public String carExcelExport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME, "车辆计划完成情况统计"); modelMap.put(NormalExcelConstants.CLASS, CarListExcelEntity.class); modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆计划完成情况统计", "导出人:"+ ResourceUtil.getSessionUser().getRealName(), "导出信息")); Map param = new HashMap(); for(String key : request.getParameterMap().keySet()){ param.put(key, request.getParameter(key)); } IPage> result = TBCarScheduleCountService.queryCarPageByScheduleId(param); List list = new ArrayList<>(); for(Map map : result.getRecords()){ CarListExcelEntity pdr = JSONObject.parseObject(JSONObject.toJSONString(map),CarListExcelEntity.class); list.add(pdr); } modelMap.put(NormalExcelConstants.DATA_LIST, list); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } @RequestMapping(params = "manExcelExport") public String manExcelExport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME, "人员计划完成情况统计"); modelMap.put(NormalExcelConstants.CLASS, ManListExcelEntity.class); modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("人员计划完成情况统计", "导出人:"+ ResourceUtil.getSessionUser().getRealName(), "导出信息")); Map param = new HashMap(); for(String key : request.getParameterMap().keySet()){ param.put(key, request.getParameter(key)); } IPage> result = TBCarScheduleCountService.queryUserPageByScheduleId(param); List list = new ArrayList<>(); for(Map map : result.getRecords()){ ManListExcelEntity pdr = JSONObject.parseObject(JSONObject.toJSONString(map),ManListExcelEntity.class); list.add(pdr); } modelMap.put(NormalExcelConstants.DATA_LIST, list); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } @RequestMapping(params = "drExcelExport") public String drExcelExport(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, ModelMap modelMap) { modelMap.put(NormalExcelConstants.FILE_NAME, "车辆行驶记录统计"); modelMap.put(NormalExcelConstants.CLASS, TBCarDrivingRecord.class); modelMap.put(NormalExcelConstants.PARAMS, new ExportParams("车辆行驶记录统计", "导出人:"+ ResourceUtil.getSessionUser().getRealName(), "导出信息")); Map param = new HashMap(); for(String key : request.getParameterMap().keySet()){ param.put(key, request.getParameter(key)); } List carTypes = new ArrayList<>(); String MENU_DATA_AUTHOR_RULE_SQL = JeecgDataAutorUtils.loadDataSearchConditonSQLString(); if (!cn.com.lzt.common.util.StringUtil.isEmpty(MENU_DATA_AUTHOR_RULE_SQL)){ if(MENU_DATA_AUTHOR_RULE_SQL.contains(",")){ MENU_DATA_AUTHOR_RULE_SQL = MENU_DATA_AUTHOR_RULE_SQL.replaceAll(",","','"); } String[] MENU_DATA_AUTHOR_RULE_SQL_Split = MENU_DATA_AUTHOR_RULE_SQL.split(" "); String getCarType = "select tsy.typename from t_s_type tsy LEFT JOIN t_s_typegroup tsyg on tsyg.id = tsy.typegroupid where tsyg.typegroupcode = \"cartype\" and tsy.typecode "+MENU_DATA_AUTHOR_RULE_SQL_Split[MENU_DATA_AUTHOR_RULE_SQL_Split.length-1]+";"; carTypes = this.systemService.findListbySql(getCarType); } IPage result = tbCarDrivingRecordService.recordPage(param,carTypes); List list = new ArrayList<>(); for(TBCarDrivingRecord map : result.getRecords()){ TBCarDrivingRecord pdr = JSONObject.parseObject(JSONObject.toJSONString(map),TBCarDrivingRecord.class); list.add(pdr); } modelMap.put(NormalExcelConstants.DATA_LIST, list); return NormalExcelConstants.EASYPOI_EXCEL_VIEW; } }