MaintainPlanController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. package cn.com.lzt.maintainplan.controller;
  2. import cn.com.lzt.common.util.DictUtil;
  3. import cn.com.lzt.common.util.LztUtil;
  4. import cn.com.lzt.common.view.JsonDataModelAndView;
  5. import cn.com.lzt.maintainplan.entity.MaintainPlanEntity;
  6. import cn.com.lzt.maintainplan.page.MaintainPlanPage;
  7. import cn.com.lzt.maintainplan.service.MaintainPlanServiceI;
  8. import cn.com.lzt.maintainplanprojserv.entity.MaintainPlanProjservEntity;
  9. import cn.com.lzt.maintainplantimes.entity.MaintainPlanTimesEntity;
  10. import com.jeecg.qianbao.util.FormProcUtil;
  11. import com.xcgl.weixin.entity.WXAjaxJson;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.apache.log4j.Logger;
  14. import org.codehaus.jackson.map.ObjectMapper;
  15. import org.hibernate.criterion.Restrictions;
  16. import org.jeecgframework.core.beanvalidator.BeanValidators;
  17. import org.jeecgframework.core.common.controller.BaseController;
  18. import org.jeecgframework.core.common.exception.BusinessException;
  19. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  20. import org.jeecgframework.core.common.model.json.AjaxJson;
  21. import org.jeecgframework.core.common.model.json.DataGrid;
  22. import org.jeecgframework.core.constant.Globals;
  23. import org.jeecgframework.core.util.*;
  24. import org.jeecgframework.poi.excel.ExcelImportUtil;
  25. import org.jeecgframework.poi.excel.entity.ExportParams;
  26. import org.jeecgframework.poi.excel.entity.ImportParams;
  27. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  28. import org.jeecgframework.tag.core.easyui.TagUtil;
  29. import org.jeecgframework.web.system.pojo.base.TSUser;
  30. import org.jeecgframework.web.system.service.SystemService;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.http.HttpHeaders;
  33. import org.springframework.http.HttpStatus;
  34. import org.springframework.http.MediaType;
  35. import org.springframework.http.ResponseEntity;
  36. import org.springframework.stereotype.Controller;
  37. import org.springframework.ui.ModelMap;
  38. import org.springframework.web.bind.annotation.*;
  39. import org.springframework.web.multipart.MultipartFile;
  40. import org.springframework.web.multipart.MultipartHttpServletRequest;
  41. import org.springframework.web.servlet.ModelAndView;
  42. import org.springframework.web.util.UriComponentsBuilder;
  43. import javax.servlet.http.HttpServletRequest;
  44. import javax.servlet.http.HttpServletResponse;
  45. import javax.validation.ConstraintViolation;
  46. import javax.validation.Validator;
  47. import java.io.IOException;
  48. import java.net.URI;
  49. import java.util.*;
  50. /**
  51. * @Title: Controller
  52. * @Description: 供方服务计划
  53. * @author onlineGenerator
  54. * @date 2019-05-23 11:34:33
  55. * @version V1.0
  56. *
  57. */
  58. @Controller
  59. @RequestMapping("/maintainPlanController")
  60. public class MaintainPlanController extends BaseController {
  61. /**
  62. * Logger for this class
  63. */
  64. private static final Logger logger = Logger.getLogger(MaintainPlanController.class);
  65. @Autowired
  66. private MaintainPlanServiceI maintainPlanService;
  67. @Autowired
  68. private SystemService systemService;
  69. @Autowired
  70. private Validator validator;
  71. /**
  72. * 供方服务计划列表 页面跳转
  73. *
  74. * @return
  75. */
  76. @RequestMapping(params = "list")
  77. public ModelAndView list(HttpServletRequest request) {
  78. return new ModelAndView("cn/com/lzt/maintainplan/maintainPlanList");
  79. }
  80. @RequestMapping(params = "shortcutsetting")
  81. public ModelAndView shortcutsetting(HttpServletRequest request) {
  82. request.setAttribute("firsttime", request.getParameter("firsttime"));
  83. request.setAttribute("lasttime", request.getParameter("lasttime"));
  84. return new ModelAndView("cn/com/lzt/maintainplan/maintainPlan-shortcut");
  85. }
  86. /**
  87. * easyui AJAX请求数据
  88. *
  89. * @param request
  90. * @param response
  91. * @param dataGrid
  92. */
  93. @RequestMapping(params = "datagrid")
  94. public void datagrid(MaintainPlanEntity maintainPlan,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  95. CriteriaQuery cq = new CriteriaQuery(MaintainPlanEntity.class, dataGrid);
  96. if(StringUtils.isNotBlank(maintainPlan.getDepName())){
  97. cq.like("depName","%"+maintainPlan.getDepName()+"%");
  98. maintainPlan.setDepName(null);
  99. }
  100. if(StringUtils.isNotBlank(maintainPlan.getName())){
  101. cq.like("name","%"+maintainPlan.getName()+"%");
  102. maintainPlan.setName(null);
  103. }
  104. String hasContract = request.getParameter("hasContract");
  105. if(StringUtils.isNotBlank(hasContract)){
  106. if(hasContract.equals("0")) cq.isNull("contractId");
  107. if(hasContract.equals("1")) cq.isNotNull("contractId");
  108. }
  109. if(StringUtils.isNotBlank(maintainPlan.getMaintainMonth())){
  110. cq.like("maintainMonth","%"+maintainPlan.getMaintainMonth()+"%");
  111. maintainPlan.setMaintainMonth(null);
  112. }
  113. if(StringUtils.isNotBlank(maintainPlan.getMaintainYear())){
  114. cq.like("maintainYear","%"+maintainPlan.getMaintainYear()+"%");
  115. maintainPlan.setMaintainYear(null);
  116. }
  117. //查询条件组装器
  118. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, maintainPlan);
  119. try{
  120. TSUser user = ResourceUtil.getSessionUser();
  121. cq.add(Restrictions.eq("createBy",user.getUserName()));
  122. //自定义追加查询条件
  123. }catch (Exception e) {
  124. throw new BusinessException(e.getMessage());
  125. }
  126. cq.add();
  127. this.maintainPlanService.getDataGridReturn(cq, true);
  128. TagUtil.datagrid(response, dataGrid);
  129. }
  130. /**
  131. * 删除供方服务计划
  132. *
  133. * @return
  134. */
  135. @RequestMapping(params = "doDel")
  136. @ResponseBody
  137. public AjaxJson doDel(MaintainPlanEntity maintainPlan, HttpServletRequest request) {
  138. AjaxJson j = new AjaxJson();
  139. maintainPlan = systemService.getEntity(MaintainPlanEntity.class, maintainPlan.getId());
  140. String message = "供方服务计划删除成功";
  141. try{
  142. maintainPlanService.delMain(maintainPlan);
  143. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  144. }catch(Exception e){
  145. e.printStackTrace();
  146. message = "供方服务计划删除失败";
  147. throw new BusinessException(e.getMessage());
  148. }
  149. j.setMsg(message);
  150. return j;
  151. }
  152. /**
  153. * 批量删除供方服务计划
  154. *
  155. * @return
  156. */
  157. @RequestMapping(params = "doBatchDel")
  158. @ResponseBody
  159. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  160. AjaxJson j = new AjaxJson();
  161. String message = "供方服务计划删除成功";
  162. try{
  163. for(String id:ids.split(",")){
  164. MaintainPlanEntity maintainPlan = systemService.getEntity(MaintainPlanEntity.class,
  165. id
  166. );
  167. maintainPlanService.delMain(maintainPlan);
  168. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  169. }
  170. }catch(Exception e){
  171. e.printStackTrace();
  172. message = "供方服务计划删除失败";
  173. throw new BusinessException(e.getMessage());
  174. }
  175. j.setMsg(message);
  176. return j;
  177. }
  178. /**
  179. * 添加供方服务计划
  180. *
  181. * @return
  182. */
  183. @RequestMapping(params = "doAdd")
  184. @ResponseBody
  185. public AjaxJson doAdd(MaintainPlanEntity maintainPlan,MaintainPlanPage maintainPlanPage, HttpServletRequest request) {
  186. if(StringUtils.isNotBlank(maintainPlan.getId())){
  187. return doUpdate(maintainPlan,maintainPlanPage,request);
  188. }
  189. List<MaintainPlanProjservEntity> maintainPlanProjservList = maintainPlanPage.getMaintainPlanProjservList();
  190. List<MaintainPlanTimesEntity> maintainPlanTimesList = maintainPlanPage.getMaintainPlanTimesList();
  191. AjaxJson j = new AjaxJson();
  192. String message = "添加成功";
  193. try{
  194. maintainPlanService.addMain(maintainPlan, maintainPlanProjservList,maintainPlanTimesList);
  195. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  196. }catch(Exception e){
  197. e.printStackTrace();
  198. message = "供方服务计划添加失败";
  199. throw new BusinessException(e.getMessage());
  200. }
  201. j.setMsg(message);
  202. return j;
  203. }
  204. /**
  205. * 更新供方服务计划
  206. *
  207. * @return
  208. */
  209. @RequestMapping(params = "doUpdate")
  210. @ResponseBody
  211. public AjaxJson doUpdate(MaintainPlanEntity maintainPlan,MaintainPlanPage maintainPlanPage, HttpServletRequest request) {
  212. List<MaintainPlanProjservEntity> maintainPlanProjservList = maintainPlanPage.getMaintainPlanProjservList();
  213. List<MaintainPlanTimesEntity> maintainPlanTimesList = maintainPlanPage.getMaintainPlanTimesList();
  214. AjaxJson j = new AjaxJson();
  215. String message = "更新成功";
  216. try{
  217. maintainPlanService.updateMain(maintainPlan, maintainPlanProjservList,maintainPlanTimesList);
  218. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  219. }catch(Exception e){
  220. e.printStackTrace();
  221. message = "更新供方服务计划失败";
  222. throw new BusinessException(e.getMessage());
  223. }
  224. j.setMsg(message);
  225. return j;
  226. }
  227. /**
  228. * 供方服务计划新增页面跳转
  229. *
  230. * @return
  231. */
  232. @RequestMapping(params = "goAdd")
  233. public ModelAndView goAdd(MaintainPlanEntity maintainPlan, HttpServletRequest req) {
  234. if (StringUtil.isNotEmpty(maintainPlan.getId())) {
  235. maintainPlan = maintainPlanService.getEntity(MaintainPlanEntity.class, maintainPlan.getId());
  236. req.setAttribute("maintainPlanPage", maintainPlan);
  237. }
  238. return new ModelAndView("cn/com/lzt/maintainplan/maintainPlan-add");
  239. }
  240. /**
  241. * 供方服务计划编辑页面跳转
  242. *
  243. * @return
  244. */
  245. @RequestMapping(params = "goUpdate")
  246. public ModelAndView goUpdate(MaintainPlanEntity maintainPlan, HttpServletRequest req) {
  247. if (StringUtil.isNotEmpty(maintainPlan.getId())) {
  248. maintainPlan = maintainPlanService.getEntity(MaintainPlanEntity.class, maintainPlan.getId());
  249. req.setAttribute("entity", maintainPlan);
  250. }
  251. return new ModelAndView("cn/com/lzt/maintainplan/maintainPlan-add");
  252. }
  253. /**
  254. * 加载明细列表[供方服务计划服务明细]
  255. *
  256. * @return
  257. */
  258. @RequestMapping(params = "maintainPlanProjservList")
  259. public ModelAndView maintainPlanProjservList(MaintainPlanEntity maintainPlan, HttpServletRequest req) {
  260. //===================================================================================
  261. //获取参数
  262. Object id0 = maintainPlan.getId();
  263. //===================================================================================
  264. //查询-供方服务计划服务明细
  265. String hql0 = "from MaintainPlanProjservEntity where 1 = 1 AND mAINTAINID =? ";
  266. try{
  267. List<MaintainPlanProjservEntity> maintainPlanProjservEntityList = systemService.findHql(hql0,id0);
  268. req.setAttribute("maintainPlanProjservList", maintainPlanProjservEntityList);
  269. }catch(Exception e){
  270. logger.info(e.getMessage());
  271. }
  272. return new ModelAndView("cn/com/lzt/maintainplanprojserv/maintainPlanProjservList");
  273. }
  274. /**
  275. * 加载明细列表[供方服务计划时间明细]
  276. *
  277. * @return
  278. */
  279. @RequestMapping(params = "maintainPlanTimesList")
  280. public ModelAndView maintainPlanTimesList(MaintainPlanEntity maintainPlan, HttpServletRequest req) {
  281. //===================================================================================
  282. //获取参数
  283. Object id1 = maintainPlan.getId();
  284. //===================================================================================
  285. //查询-供方服务计划时间明细
  286. String hql1 = "from MaintainPlanTimesEntity where 1 = 1 AND mAINTAINPLANID =? ";
  287. try{
  288. List<MaintainPlanTimesEntity> maintainPlanTimesEntityList = systemService.findHql(hql1,id1);
  289. req.setAttribute("maintainPlanTimesList", maintainPlanTimesEntityList);
  290. }catch(Exception e){
  291. logger.info(e.getMessage());
  292. }
  293. return new ModelAndView("cn/com/lzt/maintainplantimes/maintainPlanTimesList");
  294. }
  295. /**
  296. * 导出excel
  297. *
  298. * @param request
  299. * @param response
  300. */
  301. @RequestMapping(params = "exportXls")
  302. public String exportXls(MaintainPlanEntity maintainPlan,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
  303. CriteriaQuery cq = new CriteriaQuery(MaintainPlanEntity.class, dataGrid);
  304. //查询条件组装器
  305. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, maintainPlan);
  306. try{
  307. //自定义追加查询条件
  308. }catch (Exception e) {
  309. throw new BusinessException(e.getMessage());
  310. }
  311. cq.add();
  312. List<MaintainPlanEntity> list=this.maintainPlanService.getListByCriteriaQuery(cq, false);
  313. List<MaintainPlanPage> pageList=new ArrayList<MaintainPlanPage>();
  314. if(list!=null&&list.size()>0){
  315. for(MaintainPlanEntity entity:list){
  316. try{
  317. MaintainPlanPage page=new MaintainPlanPage();
  318. MyBeanUtils.copyBeanNotNull2Bean(entity,page);
  319. Object id0 = entity.getId();
  320. String hql0 = "from MaintainPlanProjservEntity where 1 = 1 AND mAINTAINID =? ";
  321. List<MaintainPlanProjservEntity> maintainPlanProjservEntityList = systemService.findHql(hql0,id0);
  322. page.setMaintainPlanProjservList(maintainPlanProjservEntityList);
  323. Object id1 = entity.getId();
  324. String hql1 = "from MaintainPlanTimesEntity where 1 = 1 AND mAINTAINPLANID =? ";
  325. List<MaintainPlanTimesEntity> maintainPlanTimesEntityList = systemService.findHql(hql1,id1);
  326. page.setMaintainPlanTimesList(maintainPlanTimesEntityList);
  327. pageList.add(page);
  328. }catch(Exception e){
  329. logger.info(e.getMessage());
  330. }
  331. }
  332. }
  333. map.put(NormalExcelConstants.FILE_NAME,"供方服务计划");
  334. map.put(NormalExcelConstants.CLASS,MaintainPlanPage.class);
  335. map.put(NormalExcelConstants.PARAMS,new ExportParams("供方服务计划列表", "导出人:Jeecg",
  336. "导出信息"));
  337. map.put(NormalExcelConstants.DATA_LIST,pageList);
  338. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  339. }
  340. /**
  341. * 通过excel导入数据
  342. * @param request
  343. * @param
  344. * @return
  345. */
  346. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  347. @ResponseBody
  348. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  349. AjaxJson j = new AjaxJson();
  350. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  351. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  352. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  353. MultipartFile file = entity.getValue();// 获取上传文件对象
  354. ImportParams params = new ImportParams();
  355. params.setTitleRows(2);
  356. params.setHeadRows(2);
  357. params.setNeedSave(true);
  358. try {
  359. List<MaintainPlanPage> list = ExcelImportUtil.importExcel(file.getInputStream(), MaintainPlanPage.class, params);
  360. MaintainPlanEntity entity1=null;
  361. for (MaintainPlanPage page : list) {
  362. entity1=new MaintainPlanEntity();
  363. MyBeanUtils.copyBeanNotNull2Bean(page,entity1);
  364. maintainPlanService.addMain(entity1, page.getMaintainPlanProjservList(),page.getMaintainPlanTimesList());
  365. }
  366. j.setMsg("文件导入成功!");
  367. } catch (Exception e) {
  368. j.setMsg("文件导入失败!");
  369. logger.error(ExceptionUtil.getExceptionMessage(e));
  370. }finally{
  371. try {
  372. file.getInputStream().close();
  373. } catch (IOException e) {
  374. e.printStackTrace();
  375. }
  376. }
  377. }
  378. return j;
  379. }
  380. /**
  381. * 导出excel 使模板
  382. */
  383. @RequestMapping(params = "exportXlsByT")
  384. public String exportXlsByT(ModelMap map) {
  385. map.put(NormalExcelConstants.FILE_NAME,"供方服务计划");
  386. map.put(NormalExcelConstants.CLASS,MaintainPlanPage.class);
  387. map.put(NormalExcelConstants.PARAMS,new ExportParams("供方服务计划列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  388. "导出信息"));
  389. map.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  390. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  391. }
  392. /**
  393. * 导入功能跳转
  394. *
  395. * @return
  396. */
  397. @RequestMapping(params = "upload")
  398. public ModelAndView upload(HttpServletRequest req) {
  399. req.setAttribute("controller_name", "maintainPlanController");
  400. return new ModelAndView("common/upload/pub_excel_upload");
  401. }
  402. @RequestMapping(method = RequestMethod.GET)
  403. @ResponseBody
  404. public List<MaintainPlanEntity> list() {
  405. List<MaintainPlanEntity> listMaintainPlans=maintainPlanService.getList(MaintainPlanEntity.class);
  406. return listMaintainPlans;
  407. }
  408. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  409. @ResponseBody
  410. public ResponseEntity<?> get(@PathVariable("id") String id) {
  411. MaintainPlanEntity task = maintainPlanService.get(MaintainPlanEntity.class, id);
  412. if (task == null) {
  413. return new ResponseEntity(HttpStatus.NOT_FOUND);
  414. }
  415. return new ResponseEntity(task, HttpStatus.OK);
  416. }
  417. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  418. @ResponseBody
  419. public ResponseEntity<?> create(@RequestBody MaintainPlanPage maintainPlanPage, UriComponentsBuilder uriBuilder) {
  420. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  421. Set<ConstraintViolation<MaintainPlanPage>> failures = validator.validate(maintainPlanPage);
  422. if (!failures.isEmpty()) {
  423. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  424. }
  425. //保存
  426. List<MaintainPlanProjservEntity> maintainPlanProjservList = maintainPlanPage.getMaintainPlanProjservList();
  427. List<MaintainPlanTimesEntity> maintainPlanTimesList = maintainPlanPage.getMaintainPlanTimesList();
  428. MaintainPlanEntity maintainPlan = new MaintainPlanEntity();
  429. try{
  430. MyBeanUtils.copyBeanNotNull2Bean(maintainPlan,maintainPlanPage);
  431. }catch(Exception e){
  432. logger.info(e.getMessage());
  433. }
  434. maintainPlanService.addMain(maintainPlan, maintainPlanProjservList,maintainPlanTimesList);
  435. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  436. String id = maintainPlanPage.getId();
  437. URI uri = uriBuilder.path("/rest/maintainPlanController/" + id).build().toUri();
  438. HttpHeaders headers = new HttpHeaders();
  439. headers.setLocation(uri);
  440. return new ResponseEntity(headers, HttpStatus.CREATED);
  441. }
  442. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  443. public ResponseEntity<?> update(@RequestBody MaintainPlanPage maintainPlanPage) {
  444. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  445. Set<ConstraintViolation<MaintainPlanPage>> failures = validator.validate(maintainPlanPage);
  446. if (!failures.isEmpty()) {
  447. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  448. }
  449. //保存
  450. List<MaintainPlanProjservEntity> maintainPlanProjservList = maintainPlanPage.getMaintainPlanProjservList();
  451. List<MaintainPlanTimesEntity> maintainPlanTimesList = maintainPlanPage.getMaintainPlanTimesList();
  452. MaintainPlanEntity maintainPlan = new MaintainPlanEntity();
  453. try{
  454. MyBeanUtils.copyBeanNotNull2Bean(maintainPlan,maintainPlanPage);
  455. }catch(Exception e){
  456. logger.info(e.getMessage());
  457. }
  458. maintainPlanService.updateMain(maintainPlan, maintainPlanProjservList,maintainPlanTimesList);
  459. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  460. return new ResponseEntity(HttpStatus.NO_CONTENT);
  461. }
  462. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  463. @ResponseStatus(HttpStatus.NO_CONTENT)
  464. public void delete(@PathVariable("id") String id) {
  465. MaintainPlanEntity maintainPlan = maintainPlanService.get(MaintainPlanEntity.class, id);
  466. maintainPlanService.delMain(maintainPlan);
  467. }
  468. @RequestMapping(params = "goView")
  469. public ModelAndView goView(MaintainPlanEntity entity, HttpServletRequest req) {
  470. String userid = "";
  471. if (StringUtil.isNotEmpty(entity.getId())) {
  472. entity = systemService.getEntity(MaintainPlanEntity.class, entity.getId());
  473. req.setAttribute("entity", entity);
  474. }
  475. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  476. if(oConvertUtils.isNotEmpty(taskId)){
  477. FormProcUtil.initWorkflowParam(req);
  478. req.setAttribute("taskId",taskId);
  479. }
  480. req.setAttribute("in_process",true);
  481. return new ModelAndView("cn/com/lzt/maintainplan/maintainPlan-add");
  482. }
  483. //手机审批
  484. @RequestMapping(params = "goViewMobile")
  485. public ModelAndView goViewMobile(MaintainPlanEntity entity, HttpServletRequest req) {
  486. goView(entity,req);
  487. if(LztUtil.isApiRequest()) {
  488. Map<String, Object> data = LztUtil.copyReqAttributes(new String[]{"entity", "taskId"});
  489. String flag = req.getParameter("flag");
  490. data.put("flag",flag==null?-1:Integer.valueOf(flag));
  491. entity = (MaintainPlanEntity) req.getAttribute("entity");
  492. String serviceType = DictUtil.formatToTypeName(entity.getServicetype(),"servicetypedetail");
  493. data.put("serviceType",serviceType);
  494. String hql1 = "from MaintainPlanTimesEntity where 1 = 1 AND mAINTAINPLANID =? ";
  495. List<MaintainPlanTimesEntity> maintainPlanTimesEntityList = systemService.findHql(hql1,entity.getId());
  496. String timesString= "";
  497. for(MaintainPlanTimesEntity timesEntity : maintainPlanTimesEntityList){
  498. timesString+= DateUtils.formatDate(timesEntity.getServicetimestart())+" ~ "+DateUtils.formatDate(timesEntity.getServicetimeend())+"<br>";
  499. }
  500. data.put("timesString",timesString);
  501. return new JsonDataModelAndView(WXAjaxJson.success(data));
  502. }
  503. return null;
  504. }
  505. @RequestMapping(params = "planViewMobile")
  506. public ModelAndView planViewMobile(MaintainPlanEntity entity, HttpServletRequest req) {
  507. Map<String,Object> data = new HashMap<>();
  508. entity = systemService.getEntity(MaintainPlanEntity.class,entity.getId());
  509. String serviceType = DictUtil.formatToTypeName(entity.getServicetype(),"servicetypedetail");
  510. data.put("serviceType",serviceType);
  511. String hql1 = "from MaintainPlanTimesEntity where 1 = 1 AND mAINTAINPLANID =? ";
  512. List<MaintainPlanTimesEntity> maintainPlanTimesEntityList = systemService.findHql(hql1,entity.getId());
  513. String timesString= "";
  514. for(MaintainPlanTimesEntity timesEntity : maintainPlanTimesEntityList){
  515. timesString+= DateUtils.formatDate(timesEntity.getServicetimestart())+" ~ "+DateUtils.formatDate(timesEntity.getServicetimeend())+"<br>";
  516. }
  517. data.put("timesString",timesString);
  518. data.put("entity",entity);
  519. ObjectMapper mapper = new ObjectMapper();
  520. try {
  521. req.setAttribute("data",mapper.writeValueAsString(data));
  522. } catch (IOException e) {
  523. e.printStackTrace();
  524. }
  525. return new ModelAndView("cn/com/lzt/maintainplan/plan_view_mobile");
  526. }
  527. }