TaskResultController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. package com.xcgl.taskresult.controller;
  2. import java.io.BufferedInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.net.URI;
  7. import java.net.URLEncoder;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. import javax.validation.ConstraintViolation;
  16. import javax.validation.Validator;
  17. import org.apache.commons.lang.StringUtils;
  18. import org.apache.log4j.Logger;
  19. import org.jeecgframework.core.beanvalidator.BeanValidators;
  20. import org.jeecgframework.core.common.controller.BaseController;
  21. import org.jeecgframework.core.common.exception.BusinessException;
  22. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  23. import org.jeecgframework.core.common.model.json.AjaxJson;
  24. import org.jeecgframework.core.common.model.json.DataGrid;
  25. import org.jeecgframework.core.constant.Globals;
  26. import org.jeecgframework.core.util.BrowserUtils;
  27. import org.jeecgframework.core.util.ExceptionUtil;
  28. import org.jeecgframework.core.util.MyBeanUtils;
  29. import org.jeecgframework.core.util.ResourceUtil;
  30. import org.jeecgframework.core.util.StringUtil;
  31. import org.jeecgframework.core.util.oConvertUtils;
  32. import org.jeecgframework.poi.excel.ExcelImportUtil;
  33. import org.jeecgframework.poi.excel.entity.ExportParams;
  34. import org.jeecgframework.poi.excel.entity.ImportParams;
  35. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  36. import org.jeecgframework.tag.core.easyui.TagUtil;
  37. import org.jeecgframework.web.system.pojo.base.TSUser;
  38. import org.jeecgframework.web.system.service.SystemService;
  39. import org.springframework.beans.BeanWrapper;
  40. import org.springframework.beans.BeanWrapperImpl;
  41. import org.springframework.beans.factory.annotation.Autowired;
  42. import org.springframework.http.HttpHeaders;
  43. import org.springframework.http.HttpStatus;
  44. import org.springframework.http.MediaType;
  45. import org.springframework.http.ResponseEntity;
  46. import org.springframework.stereotype.Controller;
  47. import org.springframework.ui.ModelMap;
  48. import org.springframework.web.bind.annotation.PathVariable;
  49. import org.springframework.web.bind.annotation.RequestBody;
  50. import org.springframework.web.bind.annotation.RequestMapping;
  51. import org.springframework.web.bind.annotation.RequestMethod;
  52. import org.springframework.web.bind.annotation.ResponseBody;
  53. import org.springframework.web.bind.annotation.ResponseStatus;
  54. import org.springframework.web.multipart.MultipartFile;
  55. import org.springframework.web.multipart.MultipartHttpServletRequest;
  56. import org.springframework.web.servlet.ModelAndView;
  57. import org.springframework.web.util.UriComponentsBuilder;
  58. import com.aliyun.oss.OSSClient;
  59. import com.aliyun.oss.model.OSSObject;
  60. import com.xcgl.projecttask.entity.ProjecttaskEntity;
  61. import com.xcgl.projecttask.service.ProjecttaskServiceI;
  62. import com.xcgl.taskresult.entity.TaskResultEntity;
  63. import com.xcgl.taskresult.entity.TaskResultPageDto;
  64. import com.xcgl.taskresult.service.TaskResultServiceI;
  65. import com.xcgl.utils.XcglConstant;
  66. import cn.com.lzt.common.service.TSysFileServiceI;
  67. import cn.com.lzt.common.util.CustomerConstant;
  68. /**
  69. * @Title: Controller
  70. * @Description: 工作执行结果
  71. * @author onlineGenerator
  72. * @date 2018-09-07 18:09:38
  73. * @version V1.0
  74. *
  75. */
  76. @Controller
  77. @RequestMapping("/taskResultController")
  78. public class TaskResultController extends BaseController {
  79. /**
  80. * Logger for this class
  81. */
  82. private static final Logger logger = Logger.getLogger(TaskResultController.class);
  83. @Autowired
  84. private TaskResultServiceI taskResultService;
  85. @Autowired
  86. private SystemService systemService;
  87. @Autowired
  88. private Validator validator;
  89. @Autowired
  90. private ProjecttaskServiceI taskService;
  91. @Autowired
  92. private TSysFileServiceI tSysFileService;
  93. /**
  94. * 工作执行结果列表 页面跳转
  95. *
  96. * @return
  97. */
  98. @RequestMapping(params = "list")
  99. public ModelAndView list(HttpServletRequest request) {
  100. ModelAndView mv = new ModelAndView("com/xcgl/taskresult/taskResultList");
  101. String taskid = request.getParameter("taskid");
  102. if(StringUtils.isNotEmpty(taskid)) {
  103. mv = new ModelAndView("com/xcgl/taskresult/taskResultListByTaskID");
  104. ProjecttaskEntity task = systemService.get(ProjecttaskEntity.class, taskid);
  105. if(task.getTasktype().equals("pmdept")) {
  106. mv = new ModelAndView("com/xcgl/taskresult/taskResultListByTaskID-attachment-noscore");
  107. }
  108. List<TaskResultEntity> ls = systemService.findByProperty(TaskResultEntity.class, "taskid", taskid);
  109. if(ls.size() > 0) {
  110. request.setAttribute("memo",ls.get(0).getMemo());
  111. request.setAttribute("taskresult",ls.get(0));
  112. }
  113. request.setAttribute("taskid",taskid);
  114. request.setAttribute("name",task.getName());
  115. }
  116. return mv;
  117. }
  118. public String suffix(String file){
  119. String suffix = file.substring(file.indexOf(".") + 1, file.length());
  120. suffix = suffix.toLowerCase();
  121. if (!"png".equals(suffix) && !"jpg".equals(suffix) && !"gif".equals(suffix) && !"jpeg".equals(suffix)) {
  122. return "1";
  123. }else{
  124. return "2";
  125. }
  126. }
  127. /**
  128. * easyui AJAX请求数据
  129. *
  130. * @param request
  131. * @param response
  132. * @param dataGrid
  133. */
  134. @RequestMapping(params = "datagrid")
  135. public void datagrid(TaskResultEntity taskResult,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  136. CriteriaQuery cq = new CriteriaQuery(TaskResultEntity.class, dataGrid);
  137. String taskid = request.getParameter("taskid");
  138. String entrance = request.getParameter("entrance");
  139. String hideDelete = "1";//显示
  140. if("weeklyMeeting".equals(entrance)){
  141. TSUser sessionUser = ResourceUtil.getSessionUser();
  142. ProjecttaskEntity projecttaskEntity = taskResultService.get(ProjecttaskEntity.class, taskid);
  143. if(!sessionUser.getId().equals(projecttaskEntity.getOwner())){
  144. hideDelete = "2";//隐藏
  145. }
  146. }
  147. if(StringUtils.isNotEmpty(taskid)) {
  148. //TODO
  149. cq.eq("taskid", taskid);
  150. }
  151. cq.add();
  152. List<TaskResultEntity> lsResults = this.taskResultService.getListByCriteriaQuery(cq, false);
  153. List<TaskResultPageDto> pageData = new ArrayList<TaskResultPageDto>();
  154. if(lsResults.size() > 0) {
  155. TaskResultEntity taskret = lsResults.get(0);
  156. TaskResultPageDto pagedto =null;
  157. int i = 1;
  158. if(StringUtils.isNotEmpty(taskret.getPicture1())) {
  159. pagedto = new TaskResultPageDto();
  160. pagedto.setTaskid(taskid);
  161. pagedto.setPicture("工作执行结果"+i);
  162. pagedto.setId(taskret.getPicture1());
  163. pagedto.setSuffix(suffix(taskret.getPicture1()));
  164. pagedto.setHideDelete(hideDelete);
  165. pagedto.setTaskResultId(taskret.getId());
  166. pagedto.setImgIndex(i);
  167. i++;
  168. pageData.add(pagedto);
  169. }
  170. if(StringUtils.isNotEmpty(taskret.getPicture2())) {
  171. pagedto = new TaskResultPageDto();
  172. pagedto.setTaskid(taskid);
  173. pagedto.setPicture("工作执行结果"+i);
  174. pagedto.setId(taskret.getPicture2());
  175. pagedto.setSuffix(suffix(taskret.getPicture2()));
  176. pagedto.setHideDelete(hideDelete);
  177. pagedto.setTaskResultId(taskret.getId());
  178. pagedto.setImgIndex(i);
  179. i++;
  180. pageData.add(pagedto);
  181. }
  182. if(StringUtils.isNotEmpty(taskret.getPicture3())) {
  183. pagedto = new TaskResultPageDto();
  184. pagedto.setTaskid(taskid);
  185. pagedto.setPicture("工作执行结果"+i);
  186. pagedto.setId(taskret.getPicture3());
  187. pagedto.setSuffix(suffix(taskret.getPicture3()));
  188. pagedto.setHideDelete(hideDelete);
  189. pagedto.setTaskResultId(taskret.getId());
  190. pagedto.setImgIndex(i);
  191. i++;
  192. pageData.add(pagedto);
  193. }
  194. if(StringUtils.isNotEmpty(taskret.getPicture4())) {
  195. pagedto = new TaskResultPageDto();
  196. pagedto.setTaskid(taskid);
  197. pagedto.setPicture("工作执行结果"+i);
  198. pagedto.setId(taskret.getPicture4());
  199. pagedto.setSuffix(suffix(taskret.getPicture4()));
  200. pagedto.setHideDelete(hideDelete);
  201. pagedto.setTaskResultId(taskret.getId());
  202. pagedto.setImgIndex(i);
  203. i++;
  204. pageData.add(pagedto);
  205. }
  206. if(StringUtils.isNotEmpty(taskret.getPicture5())) {
  207. pagedto = new TaskResultPageDto();
  208. pagedto.setTaskid(taskid);
  209. pagedto.setPicture("工作执行结果"+i);
  210. pagedto.setId(taskret.getPicture5());
  211. pagedto.setSuffix(suffix(taskret.getPicture5()));
  212. pagedto.setHideDelete(hideDelete);
  213. pagedto.setTaskResultId(taskret.getId());
  214. pagedto.setImgIndex(i);
  215. i++;
  216. pageData.add(pagedto);
  217. }
  218. if(StringUtils.isNotEmpty(taskret.getPicture6())) {
  219. pagedto = new TaskResultPageDto();
  220. pagedto.setTaskid(taskid);
  221. pagedto.setPicture("工作执行结果"+i);
  222. pagedto.setId(taskret.getPicture6());
  223. pagedto.setSuffix(suffix(taskret.getPicture6()));
  224. pagedto.setHideDelete(hideDelete);
  225. pagedto.setTaskResultId(taskret.getId());
  226. pagedto.setImgIndex(i);
  227. i++;
  228. pageData.add(pagedto);
  229. }
  230. if(StringUtils.isNotEmpty(taskret.getPicture7())) {
  231. pagedto = new TaskResultPageDto();
  232. pagedto.setTaskid(taskid);
  233. pagedto.setPicture("工作执行结果"+i);
  234. pagedto.setId(taskret.getPicture7());
  235. pagedto.setSuffix(suffix(taskret.getPicture7()));
  236. pagedto.setHideDelete(hideDelete);
  237. pagedto.setTaskResultId(taskret.getId());
  238. pagedto.setImgIndex(i);
  239. i++;
  240. pageData.add(pagedto);
  241. }
  242. if(StringUtils.isNotEmpty(taskret.getPicture8())) {
  243. pagedto = new TaskResultPageDto();
  244. pagedto.setTaskid(taskid);
  245. pagedto.setPicture("工作执行结果"+i);
  246. pagedto.setId(taskret.getPicture8());
  247. pagedto.setSuffix(suffix(taskret.getPicture8()));
  248. pagedto.setHideDelete(hideDelete);
  249. pagedto.setTaskResultId(taskret.getId());
  250. pagedto.setImgIndex(i);
  251. i++;
  252. pageData.add(pagedto);
  253. }
  254. if(StringUtils.isNotEmpty(taskret.getPicture9())) {
  255. pagedto = new TaskResultPageDto();
  256. pagedto.setTaskid(taskid);
  257. pagedto.setPicture("工作执行结果"+i);
  258. pagedto.setId(taskret.getPicture9());
  259. pagedto.setSuffix(suffix(taskret.getPicture9()));
  260. pagedto.setHideDelete(hideDelete);
  261. pagedto.setTaskResultId(taskret.getId());
  262. pagedto.setImgIndex(i);
  263. i++;
  264. pageData.add(pagedto);
  265. }
  266. if(StringUtils.isNotEmpty(taskret.getPicture10())) {
  267. pagedto = new TaskResultPageDto();
  268. pagedto.setTaskid(taskid);
  269. pagedto.setPicture("工作执行结果"+i);
  270. pagedto.setId(taskret.getPicture10());
  271. pagedto.setSuffix(suffix(taskret.getPicture10()));
  272. pagedto.setHideDelete(hideDelete);
  273. pagedto.setTaskResultId(taskret.getId());
  274. pagedto.setImgIndex(i);
  275. i++;
  276. pageData.add(pagedto);
  277. }
  278. }
  279. dataGrid.setResults(pageData);
  280. TagUtil.datagrid(response, dataGrid);
  281. }
  282. /**
  283. * 跳转至图片预览页面
  284. * @param fileUrl 文件的访问路径
  285. * @param req
  286. * @return
  287. */
  288. @RequestMapping(params = "showPictureview")
  289. public ModelAndView showPictureview(String fileUrl, String aliyunflg, HttpServletRequest req) {
  290. if (StringUtils.isNotEmpty(fileUrl)) {
  291. String dbpath = "";
  292. if ("0".equals(aliyunflg)) {
  293. dbpath = "showOrDownByurl.do?dbPath=" + fileUrl;
  294. } else {
  295. dbpath = "taskResultController.do?aliyunshowOrDownByurl&dbPath=" + fileUrl;
  296. }
  297. req.setAttribute("dbpath", dbpath);
  298. }
  299. return new ModelAndView("com/xcgl/taskresult/pictureview");
  300. }
  301. /**
  302. * 阿里云文件下载及查看
  303. * @author yulong.zhao
  304. * @date 2017年12月28日下午5:58:01
  305. * @param response
  306. * @param request
  307. * @throws Exception
  308. */
  309. @RequestMapping(params="aliyunshowOrDownByurl")
  310. public void getAliyunImgByurl(HttpServletResponse response, HttpServletRequest request) throws Exception{
  311. String flag = request.getParameter("down");//是否下载否则展示图片
  312. String dbpath = oConvertUtils.getString(request.getParameter("dbPath"));
  313. String fileName = "执行结果图片";
  314. if("1".equals(flag)){
  315. response.setContentType("application/x-msdownload;charset=utf-8");
  316. if (BrowserUtils.isIE(request)) {
  317. // IE
  318. fileName = URLEncoder.encode(fileName, "UTF-8");
  319. } else {
  320. // 非IE
  321. fileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
  322. }
  323. response.setHeader("Content-disposition", "attachment; filename="+fileName);
  324. }else{
  325. response.setContentType("image/jpeg;charset=utf-8");
  326. }
  327. String key = "";
  328. if(!"".equals(dbpath)){
  329. key = dbpath;
  330. }
  331. InputStream inputStream = null;
  332. OutputStream outputStream = null;
  333. try {
  334. // 创建OSSClient实例
  335. OSSClient ossClient = new OSSClient(XcglConstant.ENDPOINT_INTERNET, CustomerConstant.ACCESSKEY_ID, CustomerConstant.ACCESSKEY_SECRET);
  336. OSSObject ossObject = ossClient.getObject(CustomerConstant.BUCKETNAME, key);
  337. inputStream = new BufferedInputStream(ossObject.getObjectContent());
  338. outputStream = response.getOutputStream();
  339. byte[] buf = new byte[1024];
  340. int len;
  341. while ((len = inputStream.read(buf)) > 0) {
  342. outputStream.write(buf, 0, len);
  343. }
  344. // 关闭client
  345. ossClient.shutdown();
  346. response.flushBuffer();
  347. } catch (Exception e) {
  348. logger.info("--通过流的方式获取文件异常--" + e.getMessage());
  349. }finally{
  350. if(inputStream != null){
  351. inputStream.close();
  352. }
  353. if(outputStream != null){
  354. outputStream.close();
  355. }
  356. }
  357. }
  358. /**
  359. * 删除工作执行结果
  360. *
  361. * @return
  362. */
  363. @RequestMapping(params = "doDel")
  364. @ResponseBody
  365. public AjaxJson doDel(TaskResultEntity taskResult, HttpServletRequest request) {
  366. String message = null;
  367. AjaxJson j = new AjaxJson();
  368. taskResult = systemService.getEntity(TaskResultEntity.class, taskResult.getId());
  369. message = "工作执行结果删除成功";
  370. try{
  371. taskResultService.delete(taskResult);
  372. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  373. }catch(Exception e){
  374. e.printStackTrace();
  375. message = "工作执行结果删除失败";
  376. throw new BusinessException(e.getMessage());
  377. }
  378. j.setMsg(message);
  379. return j;
  380. }
  381. @RequestMapping(params = "savePicture")
  382. @ResponseBody
  383. public AjaxJson savePicture(TaskResultEntity taskResult, HttpServletRequest request) {
  384. String message = "上传图片成功,执行结果图片保存完成";
  385. AjaxJson j = new AjaxJson();
  386. TaskResultEntity t = systemService.getEntity(TaskResultEntity.class, taskResult.getId());
  387. try {
  388. MyBeanUtils.copyBeanNotNull2Bean(taskResult, t);
  389. taskResultService.saveOrUpdate(t);
  390. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  391. } catch (Exception e) {
  392. e.printStackTrace();
  393. message = "上传图片失败,回写执行结果";
  394. throw new BusinessException(e.getMessage());
  395. }
  396. j.setMsg(message);
  397. return j;
  398. }
  399. @RequestMapping(params = "removePicture")
  400. @ResponseBody
  401. public AjaxJson removePicture(TaskResultEntity taskResult, HttpServletRequest request) {
  402. String message = "删除成功";
  403. AjaxJson j = new AjaxJson();
  404. TaskResultEntity t = systemService.getEntity(TaskResultEntity.class, taskResult.getId());
  405. try {
  406. Integer index = oConvertUtils.getInt(request.getParameter("index"));
  407. if(index>0){
  408. BeanWrapper bean = new BeanWrapperImpl(t);
  409. for(int i=index;i<=10;i++){
  410. if(i!=10) {
  411. bean.setPropertyValue("picture" + i, bean.getPropertyValue("picture" + (i + 1)));
  412. }else {
  413. bean.setPropertyValue("picture" + i,null);
  414. }
  415. }
  416. }
  417. MyBeanUtils.copyBeanNotNull2Bean(taskResult, t);
  418. taskResultService.saveOrUpdate(t);
  419. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  420. } catch (Exception e) {
  421. e.printStackTrace();
  422. message = "删除失败";
  423. throw new BusinessException(e.getMessage());
  424. }
  425. j.setMsg(message);
  426. return j;
  427. }
  428. /**
  429. * 批量删除工作执行结果
  430. *
  431. * @return
  432. */
  433. @RequestMapping(params = "doBatchDel")
  434. @ResponseBody
  435. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  436. String message = null;
  437. AjaxJson j = new AjaxJson();
  438. message = "工作执行结果删除成功";
  439. try{
  440. for(String id:ids.split(",")){
  441. TaskResultEntity taskResult = systemService.getEntity(TaskResultEntity.class,
  442. id
  443. );
  444. taskResultService.delete(taskResult);
  445. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  446. }
  447. }catch(Exception e){
  448. e.printStackTrace();
  449. message = "工作执行结果删除失败";
  450. throw new BusinessException(e.getMessage());
  451. }
  452. j.setMsg(message);
  453. return j;
  454. }
  455. /**
  456. * 添加工作执行结果
  457. *
  458. * @return
  459. */
  460. @RequestMapping(params = "doAdd")
  461. @ResponseBody
  462. public AjaxJson doAdd(TaskResultEntity taskResult, HttpServletRequest request) {
  463. String message = null;
  464. AjaxJson j = new AjaxJson();
  465. message = "工作执行结果添加成功";
  466. try{
  467. taskResultService.save(taskResult);
  468. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  469. }catch(Exception e){
  470. e.printStackTrace();
  471. message = "工作执行结果添加失败";
  472. throw new BusinessException(e.getMessage());
  473. }
  474. j.setMsg(message);
  475. return j;
  476. }
  477. /**
  478. * 更新工作执行结果
  479. * 完成工作ß
  480. * @return
  481. */
  482. @RequestMapping(params = "doUpdate")
  483. @ResponseBody
  484. public AjaxJson doUpdate(TaskResultEntity taskResult, HttpServletRequest request) {
  485. String message = null;
  486. AjaxJson j = new AjaxJson();
  487. message = "工作执行结果更新成功";
  488. TaskResultEntity t = taskResultService.get(TaskResultEntity.class, taskResult.getId());
  489. try {
  490. MyBeanUtils.copyBeanNotNull2Bean(taskResult, t);
  491. taskResultService.saveOrUpdate(t);
  492. tSysFileService.updateBusiId(t.getAttachment(), t.getId());
  493. String temp = request.getParameter("temp");
  494. ProjecttaskEntity task = systemService.getEntity(ProjecttaskEntity.class, t.getTaskid());
  495. String per =request.getParameter("completePer");
  496. task.setCompletePer(per);
  497. t.setProgress(Integer.valueOf(per));
  498. if(!StringUtils.equals(temp,"1" ) && StringUtils.equals(per,"100")) {
  499. task.setExeendtime(new Date());
  500. task.setTaskstatus(XcglConstant.TASKSTATUS_DONE);
  501. taskService.afterDone(task,taskResult);
  502. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  503. }
  504. if(!StringUtils.equals(temp, "1")){
  505. task.setTemp(0);
  506. }
  507. taskService.saveOrUpdate(task);
  508. systemService.updateEntitie(t);
  509. } catch (Exception e) {
  510. e.printStackTrace();
  511. message = "工作执行结果更新失败";
  512. throw new BusinessException(e.getMessage());
  513. }
  514. j.setMsg(message);
  515. return j;
  516. }
  517. /**
  518. * 工作执行结果新增页面跳转
  519. *
  520. * @return
  521. */
  522. @RequestMapping(params = "goAdd")
  523. public ModelAndView goAdd(TaskResultEntity taskResult, HttpServletRequest req) {
  524. if (StringUtil.isNotEmpty(taskResult.getId())) {
  525. taskResult = taskResultService.getEntity(TaskResultEntity.class, taskResult.getId());
  526. req.setAttribute("taskResultPage", taskResult);
  527. }
  528. return new ModelAndView("com/xcgl/taskresult/taskResult-add");
  529. }
  530. /**
  531. * 工作执行结果编辑页面跳转
  532. *
  533. * @return
  534. */
  535. @RequestMapping(params = "goUpdate")
  536. public ModelAndView goUpdate(TaskResultEntity taskResult, HttpServletRequest req) {
  537. if (StringUtil.isNotEmpty(taskResult.getId())) {
  538. taskResult = taskResultService.getEntity(TaskResultEntity.class, taskResult.getId());
  539. req.setAttribute("taskResultPage", taskResult);
  540. }
  541. return new ModelAndView("com/xcgl/taskresult/taskResult-update");
  542. }
  543. /**
  544. * 导入功能跳转
  545. *
  546. * @return
  547. */
  548. @RequestMapping(params = "upload")
  549. public ModelAndView upload(HttpServletRequest req) {
  550. req.setAttribute("controller_name","taskResultController");
  551. return new ModelAndView("common/upload/pub_excel_upload");
  552. }
  553. /**
  554. * 导出excel
  555. *
  556. * @param request
  557. * @param response
  558. */
  559. @RequestMapping(params = "exportXls")
  560. public String exportXls(TaskResultEntity taskResult,HttpServletRequest request,HttpServletResponse response
  561. , DataGrid dataGrid,ModelMap modelMap) {
  562. CriteriaQuery cq = new CriteriaQuery(TaskResultEntity.class, dataGrid);
  563. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, taskResult, request.getParameterMap());
  564. List<TaskResultEntity> taskResults = this.taskResultService.getListByCriteriaQuery(cq,false);
  565. modelMap.put(NormalExcelConstants.FILE_NAME,"工作执行结果");
  566. modelMap.put(NormalExcelConstants.CLASS,TaskResultEntity.class);
  567. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("工作执行结果列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  568. "导出信息"));
  569. modelMap.put(NormalExcelConstants.DATA_LIST,taskResults);
  570. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  571. }
  572. /**
  573. * 导出excel 使模板
  574. *
  575. * @param request
  576. * @param response
  577. */
  578. @RequestMapping(params = "exportXlsByT")
  579. public String exportXlsByT(TaskResultEntity taskResult,HttpServletRequest request,HttpServletResponse response
  580. , DataGrid dataGrid,ModelMap modelMap) {
  581. modelMap.put(NormalExcelConstants.FILE_NAME,"工作执行结果");
  582. modelMap.put(NormalExcelConstants.CLASS,TaskResultEntity.class);
  583. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("工作执行结果列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  584. "导出信息"));
  585. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  586. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  587. }
  588. @SuppressWarnings("unchecked")
  589. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  590. @ResponseBody
  591. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  592. AjaxJson j = new AjaxJson();
  593. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  594. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  595. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  596. MultipartFile file = entity.getValue();// 获取上传文件对象
  597. ImportParams params = new ImportParams();
  598. params.setTitleRows(2);
  599. params.setHeadRows(1);
  600. params.setNeedSave(true);
  601. try {
  602. List<TaskResultEntity> listTaskResultEntitys = ExcelImportUtil.importExcel(file.getInputStream(),TaskResultEntity.class,params);
  603. for (TaskResultEntity taskResult : listTaskResultEntitys) {
  604. taskResultService.save(taskResult);
  605. }
  606. j.setMsg("文件导入成功!");
  607. } catch (Exception e) {
  608. j.setMsg("文件导入失败!");
  609. logger.error(ExceptionUtil.getExceptionMessage(e));
  610. }finally{
  611. try {
  612. file.getInputStream().close();
  613. } catch (IOException e) {
  614. e.printStackTrace();
  615. }
  616. }
  617. }
  618. return j;
  619. }
  620. @RequestMapping(method = RequestMethod.GET)
  621. @ResponseBody
  622. public List<TaskResultEntity> list() {
  623. List<TaskResultEntity> listTaskResults=taskResultService.getList(TaskResultEntity.class);
  624. return listTaskResults;
  625. }
  626. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  627. @ResponseBody
  628. public ResponseEntity<?> get(@PathVariable("id") String id) {
  629. TaskResultEntity task = taskResultService.get(TaskResultEntity.class, id);
  630. if (task == null) {
  631. return new ResponseEntity(HttpStatus.NOT_FOUND);
  632. }
  633. return new ResponseEntity(task, HttpStatus.OK);
  634. }
  635. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  636. @ResponseBody
  637. public ResponseEntity<?> create(@RequestBody TaskResultEntity taskResult, UriComponentsBuilder uriBuilder) {
  638. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  639. Set<ConstraintViolation<TaskResultEntity>> failures = validator.validate(taskResult);
  640. if (!failures.isEmpty()) {
  641. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  642. }
  643. //保存
  644. try{
  645. taskResultService.save(taskResult);
  646. } catch (Exception e) {
  647. e.printStackTrace();
  648. return new ResponseEntity(HttpStatus.NO_CONTENT);
  649. }
  650. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  651. String id = taskResult.getId();
  652. URI uri = uriBuilder.path("/rest/taskResultController/" + id).build().toUri();
  653. HttpHeaders headers = new HttpHeaders();
  654. headers.setLocation(uri);
  655. return new ResponseEntity(headers, HttpStatus.CREATED);
  656. }
  657. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  658. public ResponseEntity<?> update(@RequestBody TaskResultEntity taskResult) {
  659. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  660. Set<ConstraintViolation<TaskResultEntity>> failures = validator.validate(taskResult);
  661. if (!failures.isEmpty()) {
  662. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  663. }
  664. //保存
  665. try{
  666. taskResultService.saveOrUpdate(taskResult);
  667. } catch (Exception e) {
  668. e.printStackTrace();
  669. return new ResponseEntity(HttpStatus.NO_CONTENT);
  670. }
  671. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  672. return new ResponseEntity(HttpStatus.NO_CONTENT);
  673. }
  674. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  675. @ResponseStatus(HttpStatus.NO_CONTENT)
  676. public void delete(@PathVariable("id") String id) {
  677. taskResultService.deleteEntityById(TaskResultEntity.class, id);
  678. }
  679. }