| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- package cn.com.lzt.car.schedule.controller;
- import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
- import cn.afterturn.easypoi.excel.entity.ExportParams;
- import com.daju.common.util.DataPage;
- import com.daju.mix.dao.entity.TBCarSchedule;
- import com.daju.mix.dao.entity.TBCarScheduleType;
- import com.daju.mix.dao.service.impl.TBCarScheduleServiceImpl;
- import com.daju.mix.dao.service.impl.TBCarScheduleTypeServiceImpl;
- import org.apache.commons.lang.StringUtils;
- import org.apache.log4j.Logger;
- import org.jeecgframework.core.common.exception.BusinessException;
- 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.ResourceUtil;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.web.system.pojo.base.DictEntity;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.time.LocalDateTime;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 作业
- * @author :sahib.kio.m
- * @date :Created in 2021/7/9 下午2:02
- */
- @Controller
- @RequestMapping("/scheduleController")
- public class ScheduleController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(ScheduleController.class);
- @Resource
- private TBCarScheduleTypeServiceImpl tbCarScheduleTypeService;
- @Resource
- private TBCarScheduleServiceImpl tbCarScheduleService;
- @Resource
- private SystemService systemService;
- /**
- * 作业类型
- * @param request
- * @return
- */
- @RequestMapping(params = "typeList")
- public ModelAndView typeList(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList");
- }
- @RequestMapping(params = "goTypeAdd")
- public ModelAndView goTypeAdd(HttpServletRequest req) {
- return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList-add");
- }
- @RequestMapping(params = "goTypeUpdate")
- public ModelAndView goTypeUpdate(TBCarScheduleType tbCarScheduleType, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(tbCarScheduleType.getId())) {
- tbCarScheduleType = tbCarScheduleTypeService.getById(tbCarScheduleType.getId());
- req.setAttribute("tbCarScheduleType", tbCarScheduleType);
- }
- return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList-update");
- }
- @RequestMapping(params = "typeListDatagrid")
- public void datagrid(TBCarScheduleType tbCarScheduleType, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- DataPage<TBCarScheduleType> page = tbCarScheduleTypeService.queryPageList(tbCarScheduleType, dataGrid);
- TagUtil.datagrid(response, dataGrid, page);
- }
- @RequestMapping(params = "doTypeUpdate")
- @ResponseBody
- public AjaxJson doTypeUpdate(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "作业类型更新成功";
- try {
- HashMap<String, Object> map = tbCarScheduleTypeService.updataById(tbCarScheduleType);
- j.setAttributes(map);
- } catch (Exception e) {
- e.printStackTrace();
- message = "作业类型更新失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "doTypeAdd")
- @ResponseBody
- public AjaxJson doTypeAdd(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "作业类型添加成功";
- try{
- HashMap<String, Object> hashMap = tbCarScheduleTypeService.insert(tbCarScheduleType);
- j.setAttributes(hashMap);
- }catch(Exception e){
- e.printStackTrace();
- message = "作业类型添加失败";
- throw new BusinessException(message+e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "doTypeDel")
- @ResponseBody
- public AjaxJson doTypeDel(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "作业类型删除成功";
- try{
- tbCarScheduleTypeService.removeById(tbCarScheduleType.getId());
- }catch(Exception e){
- e.printStackTrace();
- message = "作业类型删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 作业班次
- * @param request
- * @return
- */
- @RequestMapping(params = "workArrangeList")
- public ModelAndView workArrangeList(HttpServletRequest request) {
- if(request.getParameterMap().containsKey("flg")){
- request.setAttribute("flg", false);
- }else{
- request.setAttribute("flg", true);
- }
- return new ModelAndView("cn/com/lzt/car/work/workArrangeList");
- }
- @RequestMapping(params = "goWorkArrangeListAdd")
- public ModelAndView goWorkArrangeListAdd(HttpServletRequest req) {
- return new ModelAndView("cn/com/lzt/car/work/workArrangeList-add");
- }
- @RequestMapping(params = "goWorkArrangeListUpdate")
- public ModelAndView goArrangeListUpdate(TBCarSchedule tbCarSchedule, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(tbCarSchedule.getId())) {
- tbCarSchedule = tbCarScheduleService.getById(tbCarSchedule.getId());
- req.setAttribute("tbCarSchedule", tbCarSchedule);
- }
- return new ModelAndView("cn/com/lzt/car/work/workArrangeList-update");
- }
- @RequestMapping(params = "workArrangeListDatagrid")
- public void workArrangeListDatagrid(TBCarSchedule tbCarSchedule, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- DataPage<TBCarSchedule> page = tbCarScheduleService.queryWorkArrangePageList(tbCarSchedule, dataGrid);
- TagUtil.datagrid(response, dataGrid, page);
- }
- @RequestMapping(params = "doWorkArrangeUpdate")
- @ResponseBody
- public AjaxJson doWorkArrangeUpdate(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- // 1129 去除常规排版需改限制
- /*TBCarSchedule db = tbCarScheduleService.getById(tbCarSchedule.getId());
- if("1".equals(db.getWorkArrangeType())){
- j.setMsg("不能修改常规作业班次");
- return j;
- }*/
- message = "作业班次更新成功";
- try {
- tbCarSchedule.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
- tbCarSchedule.setUpdateDate(LocalDateTime.now());
- tbCarSchedule.setUpdateName(ResourceUtil.getSessionUser().getUserName());
- // 解决作业班次code 会更新问题
- tbCarSchedule.setArrangeCode(null);
- // add-刘梦祥-2022年10月21日08:40:36(添加逻辑:当用户修改作业班次的作业时间时,作业排班表也同步修改。)
- if(StringUtils.isNotEmpty(tbCarSchedule.getId())){
- this.systemService.updateBySqlString("update t_b_car_schedule_task set `start` = '"+tbCarSchedule.getStart()+"',`end` = '"+tbCarSchedule.getEnd()+"',`work_time` = '"+tbCarSchedule.getStart() + " - " + tbCarSchedule.getEnd()+"' where schedule_id = '"+tbCarSchedule.getId()+"';");
- }
- HashMap<String, Object> map = tbCarScheduleService.updataById(tbCarSchedule);
- j.setAttributes(map);
- } catch (Exception e) {
- e.printStackTrace();
- message = "作业班次更新失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "changeWorkStatus")
- @ResponseBody
- public AjaxJson changeWorkStatus(TBCarSchedule tbCarSchedule, HttpServletRequest request){
- String message = null;
- AjaxJson j = new AjaxJson();
- TBCarSchedule db = tbCarScheduleService.getById(tbCarSchedule.getId());
- message = "作业班次更新成功";
- /*if("1".equals(db.getWorkArrangeType())){
- j.setMsg("不能修改常规作业班次");
- return j;
- }*/ try {
- db.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
- db.setUpdateDate(LocalDateTime.now());
- db.setUpdateName(ResourceUtil.getSessionUser().getUserName());
- db.setWorkStatus(tbCarSchedule.getWorkStatus());
- // add-刘梦祥-2022年10月21日08:40:36(添加逻辑:当用户修改作业班次的作业时间时,作业排班表也同步修改。)
- if(StringUtils.isNotEmpty(tbCarSchedule.getId())){
- this.systemService.updateBySqlString("update t_b_car_schedule_task set `start` = '"+tbCarSchedule.getStart()+"',`end` = '"+tbCarSchedule.getEnd()+"',`work_time` = '"+tbCarSchedule.getStart() + " - " + tbCarSchedule.getEnd()+"' where schedule_id = '"+tbCarSchedule.getId()+"';");
- }
- HashMap<String, Object> map = tbCarScheduleService.updataById(db);
- j.setAttributes(map);
- } catch (Exception e) {
- e.printStackTrace();
- message = "作业班次更新失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "doWorkArrangeAdd")
- @ResponseBody
- public AjaxJson doWorkArrangeAdd(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- message = "作业类型添加成功";
- try{
- tbCarSchedule.setArrangeCode(tbCarScheduleService.getCode());
- tbCarSchedule.setCreateBy(ResourceUtil.getSessionUser().getRealName());
- tbCarSchedule.setCreateDate(LocalDateTime.now());
- tbCarSchedule.setCreateName(ResourceUtil.getSessionUser().getUserName());
- tbCarSchedule.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
- tbCarSchedule.setUpdateDate(LocalDateTime.now());
- tbCarSchedule.setUpdateName(ResourceUtil.getSessionUser().getUserName());
- //默认启用
- tbCarSchedule.setWorkStatus("1");
- //默认为临时班次
- tbCarSchedule.setWorkArrangeType("2");
- HashMap<String, Object> hashMap = tbCarScheduleService.insert(tbCarSchedule);
- j.setAttributes(hashMap);
- }catch(Exception e){
- e.printStackTrace();
- message = "作业类型添加失败";
- throw new BusinessException(message+e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params = "doWorkArrangeListDel")
- @ResponseBody
- public AjaxJson doWorkArrangeListDel(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
- String message = null;
- AjaxJson j = new AjaxJson();
- //如果当前作业班次有作业排班正在执行,不允许删除并给出提示。
- if(tbCarScheduleService.getScheduleCountById(tbCarSchedule.getId()) > 0){
- j.setMsg("不能删除正在执行的作业班次");
- return j;
- }
- message = "作业班次删除成功";
- try{
- // add-刘梦祥-2022年7月22日14:51:51(添加判断是否存在排班班次或作业排班)
- String sqlStr = "select `code` as taskCode from T_b_car_schedule_task where schedule_id = '"+tbCarSchedule.getId()+"'";
- List<Map<String,Object>> taskList = systemService.findForJdbc(sqlStr);
- if(taskList != null && taskList.size() > 0){
- StringBuilder scheduleNames = new StringBuilder();
- for (Map<String,Object> item : taskList){
- if(item.containsKey("taskCode")){
- if(scheduleNames.length() > 1){
- scheduleNames.append("/").append(item.get("taskCode"));
- }else{
- scheduleNames.append(item.get("taskCode"));
- }
- }
- }
- message = "存在绑定排班信息,请先删除排班:" + scheduleNames;
- }else{
- tbCarScheduleService.removeById(tbCarSchedule.getId());
- 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;
- }
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "workArrangeExportXls")
- public String workArrangeExportXls(TBCarSchedule tbCarSchedule, HttpServletRequest request, HttpServletResponse response
- , DataGrid dataGrid, ModelMap modelMap) {
- List<TBCarSchedule> carSchedules = this.tbCarScheduleService.queryWorkArrangePageList(tbCarSchedule, dataGrid).getList();
- // 作业类型 assignmentStyle
- List<DictEntity> assignmentStyle = systemService.queryDict("", "businessType", "");
- Map<String, String> assignmentStyleMap = assignmentStyle.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
- // 作业班次类型 workArrangeType
- List<DictEntity> workArrangeType = systemService.queryDict("", "workArrangeType", "");
- Map<String, String> workArrangeTypeMap = workArrangeType.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
- // 作业状态 workStatus
- List<DictEntity> workStatus = systemService.queryDict("", "workStatus", "");
- Map<String, String> workStatusMap = workStatus.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
- // 作业类型 type
- List<DictEntity> workType = systemService.queryDict("","assignmentStyle","");
- Map<String, String> workTypeMap = workType.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
- carSchedules.forEach(tbCarSchedule1 -> {
- tbCarSchedule1.setAssignmentStyle(assignmentStyleMap.getOrDefault(tbCarSchedule1.getAssignmentStyle(),"未知业务类型"));
- tbCarSchedule1.setWorkArrangeType(workArrangeTypeMap.getOrDefault(tbCarSchedule1.getWorkArrangeType(),"未知作业班次类型"));
- tbCarSchedule1.setWorkStatus(workStatusMap.getOrDefault(tbCarSchedule1.getWorkStatus(),"未知工作状态"));
- tbCarSchedule1.setType(workTypeMap.getOrDefault(tbCarSchedule1.getType(),"未知作业类型"));
- });
- modelMap.put(NormalExcelConstants.FILE_NAME,"作业班次");
- modelMap.put(NormalExcelConstants.CLASS,TBCarSchedule.class);
- modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("作业班次列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- modelMap.put(NormalExcelConstants.DATA_LIST, carSchedules);
- return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
- }
- /**
- * 作业记录
- * @param request
- * @return
- */
- @RequestMapping(params = "workRecord")
- public ModelAndView workRecord(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/car/work/workRecord");
- }
- @RequestMapping(params = "workRecordDatagrid")
- @ResponseBody
- public Object workRecordDatagrid(HttpServletRequest request) {
- Map<String, String> param = new HashMap<>();
- for (String key : request.getParameterMap().keySet()){
- param.put(key, request.getParameter(key));
- }
- DataPage page = tbCarScheduleService.queryWorkRecordList(param);
- return page;
- }
- }
|