ScheduleController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. package cn.com.lzt.car.schedule.controller;
  2. import cn.afterturn.easypoi.entity.vo.NormalExcelConstants;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import com.daju.common.util.DataPage;
  5. import com.daju.mix.dao.entity.TBCarSchedule;
  6. import com.daju.mix.dao.entity.TBCarScheduleType;
  7. import com.daju.mix.dao.service.impl.TBCarScheduleServiceImpl;
  8. import com.daju.mix.dao.service.impl.TBCarScheduleTypeServiceImpl;
  9. import org.apache.commons.lang.StringUtils;
  10. import org.apache.log4j.Logger;
  11. import org.jeecgframework.core.common.exception.BusinessException;
  12. import org.jeecgframework.core.common.model.json.AjaxJson;
  13. import org.jeecgframework.core.common.model.json.DataGrid;
  14. import org.jeecgframework.core.constant.Globals;
  15. import org.jeecgframework.core.util.ResourceUtil;
  16. import org.jeecgframework.core.util.StringUtil;
  17. import org.jeecgframework.tag.core.easyui.TagUtil;
  18. import org.jeecgframework.web.system.pojo.base.DictEntity;
  19. import org.jeecgframework.web.system.service.SystemService;
  20. import org.springframework.stereotype.Controller;
  21. import org.springframework.ui.ModelMap;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.ResponseBody;
  24. import org.springframework.web.servlet.ModelAndView;
  25. import javax.annotation.Resource;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.time.LocalDateTime;
  29. import java.util.HashMap;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.stream.Collectors;
  33. /**
  34. * 作业
  35. * @author :sahib.kio.m
  36. * @date :Created in 2021/7/9 下午2:02
  37. */
  38. @Controller
  39. @RequestMapping("/scheduleController")
  40. public class ScheduleController {
  41. /**
  42. * Logger for this class
  43. */
  44. private static final Logger logger = Logger.getLogger(ScheduleController.class);
  45. @Resource
  46. private TBCarScheduleTypeServiceImpl tbCarScheduleTypeService;
  47. @Resource
  48. private TBCarScheduleServiceImpl tbCarScheduleService;
  49. @Resource
  50. private SystemService systemService;
  51. /**
  52. * 作业类型
  53. * @param request
  54. * @return
  55. */
  56. @RequestMapping(params = "typeList")
  57. public ModelAndView typeList(HttpServletRequest request) {
  58. return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList");
  59. }
  60. @RequestMapping(params = "goTypeAdd")
  61. public ModelAndView goTypeAdd(HttpServletRequest req) {
  62. return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList-add");
  63. }
  64. @RequestMapping(params = "goTypeUpdate")
  65. public ModelAndView goTypeUpdate(TBCarScheduleType tbCarScheduleType, HttpServletRequest req) {
  66. if (StringUtil.isNotEmpty(tbCarScheduleType.getId())) {
  67. tbCarScheduleType = tbCarScheduleTypeService.getById(tbCarScheduleType.getId());
  68. req.setAttribute("tbCarScheduleType", tbCarScheduleType);
  69. }
  70. return new ModelAndView("cn/com/lzt/car/schedule/scheduleTypeList-update");
  71. }
  72. @RequestMapping(params = "typeListDatagrid")
  73. public void datagrid(TBCarScheduleType tbCarScheduleType, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  74. DataPage<TBCarScheduleType> page = tbCarScheduleTypeService.queryPageList(tbCarScheduleType, dataGrid);
  75. TagUtil.datagrid(response, dataGrid, page);
  76. }
  77. @RequestMapping(params = "doTypeUpdate")
  78. @ResponseBody
  79. public AjaxJson doTypeUpdate(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
  80. String message = null;
  81. AjaxJson j = new AjaxJson();
  82. message = "作业类型更新成功";
  83. try {
  84. HashMap<String, Object> map = tbCarScheduleTypeService.updataById(tbCarScheduleType);
  85. j.setAttributes(map);
  86. } catch (Exception e) {
  87. e.printStackTrace();
  88. message = "作业类型更新失败";
  89. throw new BusinessException(e.getMessage());
  90. }
  91. j.setMsg(message);
  92. return j;
  93. }
  94. @RequestMapping(params = "doTypeAdd")
  95. @ResponseBody
  96. public AjaxJson doTypeAdd(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
  97. String message = null;
  98. AjaxJson j = new AjaxJson();
  99. message = "作业类型添加成功";
  100. try{
  101. HashMap<String, Object> hashMap = tbCarScheduleTypeService.insert(tbCarScheduleType);
  102. j.setAttributes(hashMap);
  103. }catch(Exception e){
  104. e.printStackTrace();
  105. message = "作业类型添加失败";
  106. throw new BusinessException(message+e.getMessage());
  107. }
  108. j.setMsg(message);
  109. return j;
  110. }
  111. @RequestMapping(params = "doTypeDel")
  112. @ResponseBody
  113. public AjaxJson doTypeDel(TBCarScheduleType tbCarScheduleType, HttpServletRequest request) {
  114. String message = null;
  115. AjaxJson j = new AjaxJson();
  116. message = "作业类型删除成功";
  117. try{
  118. tbCarScheduleTypeService.removeById(tbCarScheduleType.getId());
  119. }catch(Exception e){
  120. e.printStackTrace();
  121. message = "作业类型删除失败";
  122. throw new BusinessException(e.getMessage());
  123. }
  124. j.setMsg(message);
  125. return j;
  126. }
  127. /**
  128. * 作业班次
  129. * @param request
  130. * @return
  131. */
  132. @RequestMapping(params = "workArrangeList")
  133. public ModelAndView workArrangeList(HttpServletRequest request) {
  134. if(request.getParameterMap().containsKey("flg")){
  135. request.setAttribute("flg", false);
  136. }else{
  137. request.setAttribute("flg", true);
  138. }
  139. return new ModelAndView("cn/com/lzt/car/work/workArrangeList");
  140. }
  141. @RequestMapping(params = "goWorkArrangeListAdd")
  142. public ModelAndView goWorkArrangeListAdd(HttpServletRequest req) {
  143. return new ModelAndView("cn/com/lzt/car/work/workArrangeList-add");
  144. }
  145. @RequestMapping(params = "goWorkArrangeListUpdate")
  146. public ModelAndView goArrangeListUpdate(TBCarSchedule tbCarSchedule, HttpServletRequest req) {
  147. if (StringUtil.isNotEmpty(tbCarSchedule.getId())) {
  148. tbCarSchedule = tbCarScheduleService.getById(tbCarSchedule.getId());
  149. req.setAttribute("tbCarSchedule", tbCarSchedule);
  150. }
  151. return new ModelAndView("cn/com/lzt/car/work/workArrangeList-update");
  152. }
  153. @RequestMapping(params = "workArrangeListDatagrid")
  154. public void workArrangeListDatagrid(TBCarSchedule tbCarSchedule, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  155. DataPage<TBCarSchedule> page = tbCarScheduleService.queryWorkArrangePageList(tbCarSchedule, dataGrid);
  156. TagUtil.datagrid(response, dataGrid, page);
  157. }
  158. @RequestMapping(params = "doWorkArrangeUpdate")
  159. @ResponseBody
  160. public AjaxJson doWorkArrangeUpdate(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
  161. String message = null;
  162. AjaxJson j = new AjaxJson();
  163. // 1129 去除常规排版需改限制
  164. /*TBCarSchedule db = tbCarScheduleService.getById(tbCarSchedule.getId());
  165. if("1".equals(db.getWorkArrangeType())){
  166. j.setMsg("不能修改常规作业班次");
  167. return j;
  168. }*/
  169. message = "作业班次更新成功";
  170. try {
  171. tbCarSchedule.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
  172. tbCarSchedule.setUpdateDate(LocalDateTime.now());
  173. tbCarSchedule.setUpdateName(ResourceUtil.getSessionUser().getUserName());
  174. // 解决作业班次code 会更新问题
  175. tbCarSchedule.setArrangeCode(null);
  176. // add-刘梦祥-2022年10月21日08:40:36(添加逻辑:当用户修改作业班次的作业时间时,作业排班表也同步修改。)
  177. if(StringUtils.isNotEmpty(tbCarSchedule.getId())){
  178. 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()+"';");
  179. }
  180. HashMap<String, Object> map = tbCarScheduleService.updataById(tbCarSchedule);
  181. j.setAttributes(map);
  182. } catch (Exception e) {
  183. e.printStackTrace();
  184. message = "作业班次更新失败";
  185. throw new BusinessException(e.getMessage());
  186. }
  187. j.setMsg(message);
  188. return j;
  189. }
  190. @RequestMapping(params = "changeWorkStatus")
  191. @ResponseBody
  192. public AjaxJson changeWorkStatus(TBCarSchedule tbCarSchedule, HttpServletRequest request){
  193. String message = null;
  194. AjaxJson j = new AjaxJson();
  195. TBCarSchedule db = tbCarScheduleService.getById(tbCarSchedule.getId());
  196. message = "作业班次更新成功";
  197. /*if("1".equals(db.getWorkArrangeType())){
  198. j.setMsg("不能修改常规作业班次");
  199. return j;
  200. }*/ try {
  201. db.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
  202. db.setUpdateDate(LocalDateTime.now());
  203. db.setUpdateName(ResourceUtil.getSessionUser().getUserName());
  204. db.setWorkStatus(tbCarSchedule.getWorkStatus());
  205. // add-刘梦祥-2022年10月21日08:40:36(添加逻辑:当用户修改作业班次的作业时间时,作业排班表也同步修改。)
  206. if(StringUtils.isNotEmpty(tbCarSchedule.getId())){
  207. 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()+"';");
  208. }
  209. HashMap<String, Object> map = tbCarScheduleService.updataById(db);
  210. j.setAttributes(map);
  211. } catch (Exception e) {
  212. e.printStackTrace();
  213. message = "作业班次更新失败";
  214. throw new BusinessException(e.getMessage());
  215. }
  216. j.setMsg(message);
  217. return j;
  218. }
  219. @RequestMapping(params = "doWorkArrangeAdd")
  220. @ResponseBody
  221. public AjaxJson doWorkArrangeAdd(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
  222. String message = null;
  223. AjaxJson j = new AjaxJson();
  224. message = "作业类型添加成功";
  225. try{
  226. tbCarSchedule.setArrangeCode(tbCarScheduleService.getCode());
  227. tbCarSchedule.setCreateBy(ResourceUtil.getSessionUser().getRealName());
  228. tbCarSchedule.setCreateDate(LocalDateTime.now());
  229. tbCarSchedule.setCreateName(ResourceUtil.getSessionUser().getUserName());
  230. tbCarSchedule.setUpdateBy(ResourceUtil.getSessionUser().getRealName());
  231. tbCarSchedule.setUpdateDate(LocalDateTime.now());
  232. tbCarSchedule.setUpdateName(ResourceUtil.getSessionUser().getUserName());
  233. //默认启用
  234. tbCarSchedule.setWorkStatus("1");
  235. //默认为临时班次
  236. tbCarSchedule.setWorkArrangeType("2");
  237. HashMap<String, Object> hashMap = tbCarScheduleService.insert(tbCarSchedule);
  238. j.setAttributes(hashMap);
  239. }catch(Exception e){
  240. e.printStackTrace();
  241. message = "作业类型添加失败";
  242. throw new BusinessException(message+e.getMessage());
  243. }
  244. j.setMsg(message);
  245. return j;
  246. }
  247. @RequestMapping(params = "doWorkArrangeListDel")
  248. @ResponseBody
  249. public AjaxJson doWorkArrangeListDel(TBCarSchedule tbCarSchedule, HttpServletRequest request) {
  250. String message = null;
  251. AjaxJson j = new AjaxJson();
  252. //如果当前作业班次有作业排班正在执行,不允许删除并给出提示。
  253. if(tbCarScheduleService.getScheduleCountById(tbCarSchedule.getId()) > 0){
  254. j.setMsg("不能删除正在执行的作业班次");
  255. return j;
  256. }
  257. message = "作业班次删除成功";
  258. try{
  259. // add-刘梦祥-2022年7月22日14:51:51(添加判断是否存在排班班次或作业排班)
  260. String sqlStr = "select `code` as taskCode from T_b_car_schedule_task where schedule_id = '"+tbCarSchedule.getId()+"'";
  261. List<Map<String,Object>> taskList = systemService.findForJdbc(sqlStr);
  262. if(taskList != null && taskList.size() > 0){
  263. StringBuilder scheduleNames = new StringBuilder();
  264. for (Map<String,Object> item : taskList){
  265. if(item.containsKey("taskCode")){
  266. if(scheduleNames.length() > 1){
  267. scheduleNames.append("/").append(item.get("taskCode"));
  268. }else{
  269. scheduleNames.append(item.get("taskCode"));
  270. }
  271. }
  272. }
  273. message = "存在绑定排班信息,请先删除排班:" + scheduleNames;
  274. }else{
  275. tbCarScheduleService.removeById(tbCarSchedule.getId());
  276. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  277. }
  278. }catch(Exception e){
  279. e.printStackTrace();
  280. message = "作业班次删除成功";
  281. throw new BusinessException(e.getMessage());
  282. }
  283. j.setMsg(message);
  284. return j;
  285. }
  286. /**
  287. * 导出excel
  288. *
  289. * @param request
  290. * @param response
  291. */
  292. @RequestMapping(params = "workArrangeExportXls")
  293. public String workArrangeExportXls(TBCarSchedule tbCarSchedule, HttpServletRequest request, HttpServletResponse response
  294. , DataGrid dataGrid, ModelMap modelMap) {
  295. List<TBCarSchedule> carSchedules = this.tbCarScheduleService.queryWorkArrangePageList(tbCarSchedule, dataGrid).getList();
  296. // 作业类型 assignmentStyle
  297. List<DictEntity> assignmentStyle = systemService.queryDict("", "businessType", "");
  298. Map<String, String> assignmentStyleMap = assignmentStyle.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
  299. // 作业班次类型 workArrangeType
  300. List<DictEntity> workArrangeType = systemService.queryDict("", "workArrangeType", "");
  301. Map<String, String> workArrangeTypeMap = workArrangeType.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
  302. // 作业状态 workStatus
  303. List<DictEntity> workStatus = systemService.queryDict("", "workStatus", "");
  304. Map<String, String> workStatusMap = workStatus.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
  305. // 作业类型 type
  306. List<DictEntity> workType = systemService.queryDict("","assignmentStyle","");
  307. Map<String, String> workTypeMap = workType.stream().collect(Collectors.toMap(DictEntity::getTypecode, DictEntity::getTypename));
  308. carSchedules.forEach(tbCarSchedule1 -> {
  309. tbCarSchedule1.setAssignmentStyle(assignmentStyleMap.getOrDefault(tbCarSchedule1.getAssignmentStyle(),"未知业务类型"));
  310. tbCarSchedule1.setWorkArrangeType(workArrangeTypeMap.getOrDefault(tbCarSchedule1.getWorkArrangeType(),"未知作业班次类型"));
  311. tbCarSchedule1.setWorkStatus(workStatusMap.getOrDefault(tbCarSchedule1.getWorkStatus(),"未知工作状态"));
  312. tbCarSchedule1.setType(workTypeMap.getOrDefault(tbCarSchedule1.getType(),"未知作业类型"));
  313. });
  314. modelMap.put(NormalExcelConstants.FILE_NAME,"作业班次");
  315. modelMap.put(NormalExcelConstants.CLASS,TBCarSchedule.class);
  316. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("作业班次列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  317. "导出信息"));
  318. modelMap.put(NormalExcelConstants.DATA_LIST, carSchedules);
  319. return NormalExcelConstants.EASYPOI_EXCEL_VIEW;
  320. }
  321. /**
  322. * 作业记录
  323. * @param request
  324. * @return
  325. */
  326. @RequestMapping(params = "workRecord")
  327. public ModelAndView workRecord(HttpServletRequest request) {
  328. return new ModelAndView("cn/com/lzt/car/work/workRecord");
  329. }
  330. @RequestMapping(params = "workRecordDatagrid")
  331. @ResponseBody
  332. public Object workRecordDatagrid(HttpServletRequest request) {
  333. Map<String, String> param = new HashMap<>();
  334. for (String key : request.getParameterMap().keySet()){
  335. param.put(key, request.getParameter(key));
  336. }
  337. DataPage page = tbCarScheduleService.queryWorkRecordList(param);
  338. return page;
  339. }
  340. }