HrQianbaoController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. package com.jeecg.qianbao.controller;
  2. import java.io.IOException;
  3. import java.net.URI;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Set;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.validation.ConstraintViolation;
  11. import javax.validation.Validator;
  12. import org.apache.log4j.Logger;
  13. import org.jeecgframework.core.beanvalidator.BeanValidators;
  14. import org.jeecgframework.core.common.controller.BaseController;
  15. import org.jeecgframework.core.common.exception.BusinessException;
  16. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  17. import org.jeecgframework.core.common.model.json.AjaxJson;
  18. import org.jeecgframework.core.common.model.json.DataGrid;
  19. import org.jeecgframework.core.constant.Globals;
  20. import org.jeecgframework.core.util.ExceptionUtil;
  21. import org.jeecgframework.core.util.MyBeanUtils;
  22. import org.jeecgframework.core.util.ResourceUtil;
  23. import org.jeecgframework.core.util.StringUtil;
  24. import org.jeecgframework.core.util.oConvertUtils;
  25. import org.jeecgframework.poi.excel.ExcelImportUtil;
  26. import org.jeecgframework.poi.excel.entity.ExportParams;
  27. import org.jeecgframework.poi.excel.entity.ImportParams;
  28. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  29. import org.jeecgframework.tag.core.easyui.TagUtil;
  30. import org.jeecgframework.web.system.service.SystemService;
  31. import org.jeecgframework.workflow.pojo.activiti.ActRuTask;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.http.HttpHeaders;
  34. import org.springframework.http.HttpStatus;
  35. import org.springframework.http.MediaType;
  36. import org.springframework.http.ResponseEntity;
  37. import org.springframework.stereotype.Controller;
  38. import org.springframework.ui.ModelMap;
  39. import org.springframework.web.bind.annotation.PathVariable;
  40. import org.springframework.web.bind.annotation.RequestBody;
  41. import org.springframework.web.bind.annotation.RequestMapping;
  42. import org.springframework.web.bind.annotation.RequestMethod;
  43. import org.springframework.web.bind.annotation.ResponseBody;
  44. import org.springframework.web.bind.annotation.ResponseStatus;
  45. import org.springframework.web.multipart.MultipartFile;
  46. import org.springframework.web.multipart.MultipartHttpServletRequest;
  47. import org.springframework.web.servlet.ModelAndView;
  48. import org.springframework.web.util.UriComponentsBuilder;
  49. import com.jeecg.qianbao.entity.HrQianbaoEntity;
  50. import com.jeecg.qianbao.service.HrQianbaoServiceI;
  51. import com.jeecg.qianbao.util.FormProcUtil;
  52. /**
  53. * @Title: Controller
  54. * @Description: hr_qianbao
  55. * @author onlineGenerator
  56. * @date 2016-11-22 16:00:46
  57. * @version V1.0
  58. *
  59. */
  60. @Controller
  61. @RequestMapping("/hrQianbaoController")
  62. public class HrQianbaoController extends BaseController {
  63. /**
  64. * Logger for this class
  65. */
  66. private static final Logger logger = Logger.getLogger(HrQianbaoController.class);
  67. @Autowired
  68. private HrQianbaoServiceI hrQianbaoService;
  69. @Autowired
  70. private SystemService systemService;
  71. @Autowired
  72. private Validator validator;
  73. private String message;
  74. public String getMessage() {
  75. return message;
  76. }
  77. public void setMessage(String message) {
  78. this.message = message;
  79. }
  80. /**
  81. * hr_qianbao列表 页面跳转
  82. *
  83. * @return
  84. */
  85. @RequestMapping(params = "list")
  86. public ModelAndView list(HttpServletRequest request) {
  87. return new ModelAndView("com/jeecg/qianbao/hrQianbaoList");
  88. }
  89. /**
  90. * easyui AJAX请求数据
  91. *
  92. * @param request
  93. * @param response
  94. * @param dataGrid
  95. * @param user
  96. */
  97. @RequestMapping(params = "datagrid")
  98. public void datagrid(HrQianbaoEntity hrQianbao,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  99. CriteriaQuery cq = new CriteriaQuery(HrQianbaoEntity.class, dataGrid);
  100. //查询条件组装器
  101. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, hrQianbao, request.getParameterMap());
  102. try{
  103. //自定义追加查询条件
  104. }catch (Exception e) {
  105. throw new BusinessException(e.getMessage());
  106. }
  107. cq.add();
  108. this.hrQianbaoService.getDataGridReturn(cq, true);
  109. TagUtil.datagrid(response, dataGrid);
  110. }
  111. /**
  112. * 删除hr_qianbao
  113. *
  114. * @return
  115. */
  116. @RequestMapping(params = "doDel")
  117. @ResponseBody
  118. public AjaxJson doDel(HrQianbaoEntity hrQianbao, HttpServletRequest request) {
  119. AjaxJson j = new AjaxJson();
  120. hrQianbao = systemService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  121. message = "hr_qianbao删除成功";
  122. try{
  123. hrQianbaoService.delete(hrQianbao);
  124. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  125. }catch(Exception e){
  126. e.printStackTrace();
  127. message = "hr_qianbao删除失败";
  128. throw new BusinessException(e.getMessage());
  129. }
  130. j.setMsg(message);
  131. return j;
  132. }
  133. /**
  134. * 批量删除hr_qianbao
  135. *
  136. * @return
  137. */
  138. @RequestMapping(params = "doBatchDel")
  139. @ResponseBody
  140. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  141. AjaxJson j = new AjaxJson();
  142. message = "hr_qianbao删除成功";
  143. try{
  144. for(String id:ids.split(",")){
  145. HrQianbaoEntity hrQianbao = systemService.getEntity(HrQianbaoEntity.class,
  146. id
  147. );
  148. hrQianbaoService.delete(hrQianbao);
  149. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  150. }
  151. }catch(Exception e){
  152. e.printStackTrace();
  153. message = "hr_qianbao删除失败";
  154. throw new BusinessException(e.getMessage());
  155. }
  156. j.setMsg(message);
  157. return j;
  158. }
  159. /**
  160. * 添加hr_qianbao
  161. *
  162. * @param ids
  163. * @return
  164. */
  165. @RequestMapping(params = "doAdd")
  166. @ResponseBody
  167. public AjaxJson doAdd(HrQianbaoEntity hrQianbao, HttpServletRequest request) {
  168. AjaxJson j = new AjaxJson();
  169. message = "hr_qianbao添加成功";
  170. try{
  171. hrQianbaoService.save(hrQianbao);
  172. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  173. }catch(Exception e){
  174. e.printStackTrace();
  175. message = "hr_qianbao添加失败";
  176. throw new BusinessException(e.getMessage());
  177. }
  178. j.setMsg(message);
  179. return j;
  180. }
  181. /**
  182. * 更新hr_qianbao
  183. *
  184. * @param ids
  185. * @return
  186. */
  187. @RequestMapping(params = "doUpdate")
  188. @ResponseBody
  189. public AjaxJson doUpdate(HrQianbaoEntity hrQianbao, HttpServletRequest request) {
  190. AjaxJson j = new AjaxJson();
  191. message = "hr_qianbao更新成功";
  192. HrQianbaoEntity t = hrQianbaoService.get(HrQianbaoEntity.class, hrQianbao.getId());
  193. try {
  194. MyBeanUtils.copyBeanNotNull2Bean(hrQianbao, t);
  195. hrQianbaoService.saveOrUpdate(t);
  196. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  197. } catch (Exception e) {
  198. e.printStackTrace();
  199. message = "hr_qianbao更新失败";
  200. throw new BusinessException(e.getMessage());
  201. }
  202. j.setMsg(message);
  203. return j;
  204. }
  205. /**
  206. * hr_qianbao新增页面跳转
  207. *
  208. * @return
  209. */
  210. @RequestMapping(params = "goAdd")
  211. public ModelAndView goAdd(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  212. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  213. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  214. req.setAttribute("hrQianbaoPage", hrQianbao);
  215. }
  216. return new ModelAndView("com/jeecg/qianbao/hrQianbao-add");
  217. }
  218. /**
  219. * hr_qianbao编辑页面跳转
  220. *
  221. * @return
  222. */
  223. @RequestMapping(params = "goUpdate")
  224. public ModelAndView goUpdate(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  225. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  226. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  227. req.setAttribute("hrQianbaoPage", hrQianbao);
  228. }
  229. return new ModelAndView("com/jeecg/qianbao/hrQianbao-update");
  230. }
  231. /**
  232. * 1.1.1 拟稿
  233. *
  234. * @return
  235. */
  236. @RequestMapping(params = "goForm_1_1_1")
  237. public ModelAndView goForm_1_1_1(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  238. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  239. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  240. req.setAttribute("hrQianbaoPage", hrQianbao);
  241. }
  242. //初始化表单参数
  243. FormProcUtil.initFormParam(req);
  244. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-1");
  245. }
  246. /**
  247. * 1.1.1.1 内部核稿
  248. *
  249. * @return
  250. */
  251. @RequestMapping(params = "goForm_1_1_1_1")
  252. public ModelAndView goForm_1_1_1_1(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  253. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  254. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  255. req.setAttribute("hrQianbaoPage", hrQianbao);
  256. }
  257. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  258. req.setAttribute("taskId", taskId);
  259. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-1-1");
  260. }
  261. /**
  262. * 1.1.2 部门领导审核
  263. *
  264. * @return
  265. */
  266. @RequestMapping(params = "goForm_1_1_2")
  267. public ModelAndView goForm_1_1_2(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  268. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  269. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  270. req.setAttribute("hrQianbaoPage", hrQianbao);
  271. }
  272. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  273. req.setAttribute("taskId", taskId);
  274. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-2");
  275. }
  276. /**
  277. * 1.1.3 拟稿人传递
  278. *
  279. * @return
  280. */
  281. @RequestMapping(params = "goForm_1_1_3")
  282. public ModelAndView goForm_1_1_3(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  283. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  284. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  285. req.setAttribute("hrQianbaoPage", hrQianbao);
  286. }
  287. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  288. req.setAttribute("taskId", taskId);
  289. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-3");
  290. }
  291. /**
  292. * 1.1.4 会签 (1)
  293. *
  294. * @return
  295. */
  296. @RequestMapping(params = "goForm_1_1_4_1")
  297. public ModelAndView goForm_1_1_4_1(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  298. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  299. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  300. req.setAttribute("hrQianbaoPage", hrQianbao);
  301. }
  302. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  303. req.setAttribute("taskId", taskId);
  304. if (StringUtil.isNotEmpty(taskId)) {
  305. ActRuTask ruTask = this.systemService.get(ActRuTask.class, taskId);
  306. String assignee = ruTask.getAssignee();
  307. req.setAttribute("assignee", assignee);
  308. if("admin".equals(assignee)){
  309. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-4-2");
  310. }
  311. }
  312. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-4-1");
  313. }
  314. /**
  315. * 1.1.4 会签 (2)
  316. *
  317. * @return
  318. */
  319. @RequestMapping(params = "goForm_1_1_4_2")
  320. public ModelAndView goForm_1_1_4_2(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  321. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  322. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  323. req.setAttribute("hrQianbaoPage", hrQianbao);
  324. }
  325. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  326. req.setAttribute("taskId", taskId);
  327. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-4-2");
  328. }
  329. /**
  330. * 1.1.5 拟稿人处理
  331. *
  332. * @return
  333. */
  334. @RequestMapping(params = "goForm_1_1_5")
  335. public ModelAndView goForm_1_1_5(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  336. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  337. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  338. req.setAttribute("hrQianbaoPage", hrQianbao);
  339. }
  340. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  341. req.setAttribute("taskId", taskId);
  342. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-5");
  343. }
  344. /**
  345. * 1.1.6 ISO9000审核
  346. *
  347. * @return
  348. */
  349. @RequestMapping(params = "goForm_1_1_6")
  350. public ModelAndView goForm_1_1_6(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  351. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  352. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  353. req.setAttribute("hrQianbaoPage", hrQianbao);
  354. }
  355. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  356. req.setAttribute("taskId", taskId);
  357. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-6");
  358. }
  359. /**
  360. * 1.1.7 ISO9000部门领导审核
  361. *
  362. * @return
  363. */
  364. @RequestMapping(params = "goForm_1_1_7")
  365. public ModelAndView goForm_1_1_7(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  366. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  367. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  368. req.setAttribute("hrQianbaoPage", hrQianbao);
  369. }
  370. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  371. req.setAttribute("taskId", taskId);
  372. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-7");
  373. }
  374. /**
  375. * 1.1.8 机要秘书组登记
  376. *
  377. * @return
  378. */
  379. @RequestMapping(params = "goForm_1_1_8")
  380. public ModelAndView goForm_1_1_8(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  381. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  382. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  383. req.setAttribute("hrQianbaoPage", hrQianbao);
  384. }
  385. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  386. req.setAttribute("taskId", taskId);
  387. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-8");
  388. }
  389. /**
  390. * 1.1.9 领导签批
  391. *
  392. * @return
  393. */
  394. @RequestMapping(params = "goForm_1_1_9")
  395. public ModelAndView goForm_1_1_9(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  396. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  397. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  398. req.setAttribute("hrQianbaoPage", hrQianbao);
  399. }
  400. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  401. req.setAttribute("taskId", taskId);
  402. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-9");
  403. }
  404. /**
  405. * 1.1.10 机要秘书组传递
  406. *
  407. * @return
  408. */
  409. @RequestMapping(params = "goForm_1_1_10")
  410. public ModelAndView goForm_1_1_10(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  411. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  412. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  413. req.setAttribute("hrQianbaoPage", hrQianbao);
  414. }
  415. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  416. req.setAttribute("taskId", taskId);
  417. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-10");
  418. }
  419. /**
  420. * 1.1.11 拟稿人办理
  421. *
  422. * @return
  423. */
  424. @RequestMapping(params = "goForm_1_1_11")
  425. public ModelAndView goForm_1_1_11(HrQianbaoEntity hrQianbao, HttpServletRequest req) {
  426. if (StringUtil.isNotEmpty(hrQianbao.getId())) {
  427. hrQianbao = hrQianbaoService.getEntity(HrQianbaoEntity.class, hrQianbao.getId());
  428. req.setAttribute("hrQianbaoPage", hrQianbao);
  429. }
  430. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  431. req.setAttribute("taskId", taskId);
  432. return new ModelAndView("com/jeecg/qianbao/hrQianbao-form-1-1-11");
  433. }
  434. /**
  435. * 导入功能跳转
  436. *
  437. * @return
  438. */
  439. @RequestMapping(params = "upload")
  440. public ModelAndView upload(HttpServletRequest req) {
  441. req.setAttribute("controller_name","hrQianbaoController");
  442. return new ModelAndView("common/upload/pub_excel_upload");
  443. }
  444. /**
  445. * 导出excel
  446. *
  447. * @param request
  448. * @param response
  449. */
  450. @RequestMapping(params = "exportXls")
  451. public String exportXls(HrQianbaoEntity hrQianbao,HttpServletRequest request,HttpServletResponse response
  452. , DataGrid dataGrid,ModelMap modelMap) {
  453. CriteriaQuery cq = new CriteriaQuery(HrQianbaoEntity.class, dataGrid);
  454. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, hrQianbao, request.getParameterMap());
  455. List<HrQianbaoEntity> hrQianbaos = this.hrQianbaoService.getListByCriteriaQuery(cq,false);
  456. modelMap.put(NormalExcelConstants.FILE_NAME,"hr_qianbao");
  457. modelMap.put(NormalExcelConstants.CLASS,HrQianbaoEntity.class);
  458. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("hr_qianbao列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  459. "导出信息"));
  460. modelMap.put(NormalExcelConstants.DATA_LIST,hrQianbaos);
  461. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  462. }
  463. /**
  464. * 导出excel 使模板
  465. *
  466. * @param request
  467. * @param response
  468. */
  469. @RequestMapping(params = "exportXlsByT")
  470. public String exportXlsByT(HrQianbaoEntity hrQianbao,HttpServletRequest request,HttpServletResponse response
  471. , DataGrid dataGrid,ModelMap modelMap) {
  472. modelMap.put(NormalExcelConstants.FILE_NAME,"hr_qianbao");
  473. modelMap.put(NormalExcelConstants.CLASS,HrQianbaoEntity.class);
  474. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("hr_qianbao列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  475. "导出信息"));
  476. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  477. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  478. }
  479. @SuppressWarnings("unchecked")
  480. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  481. @ResponseBody
  482. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  483. AjaxJson j = new AjaxJson();
  484. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  485. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  486. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  487. MultipartFile file = entity.getValue();// 获取上传文件对象
  488. ImportParams params = new ImportParams();
  489. params.setTitleRows(2);
  490. params.setHeadRows(1);
  491. params.setNeedSave(true);
  492. try {
  493. List<HrQianbaoEntity> listHrQianbaoEntitys = ExcelImportUtil.importExcel(file.getInputStream(),HrQianbaoEntity.class,params);
  494. for (HrQianbaoEntity hrQianbao : listHrQianbaoEntitys) {
  495. hrQianbaoService.save(hrQianbao);
  496. }
  497. j.setMsg("文件导入成功!");
  498. } catch (Exception e) {
  499. j.setMsg("文件导入失败!");
  500. logger.error(ExceptionUtil.getExceptionMessage(e));
  501. }finally{
  502. try {
  503. file.getInputStream().close();
  504. } catch (IOException e) {
  505. e.printStackTrace();
  506. }
  507. }
  508. }
  509. return j;
  510. }
  511. @RequestMapping(method = RequestMethod.GET)
  512. @ResponseBody
  513. public List<HrQianbaoEntity> list() {
  514. List<HrQianbaoEntity> listHrQianbaos=hrQianbaoService.getList(HrQianbaoEntity.class);
  515. return listHrQianbaos;
  516. }
  517. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  518. @ResponseBody
  519. public ResponseEntity<?> get(@PathVariable("id") String id) {
  520. HrQianbaoEntity task = hrQianbaoService.get(HrQianbaoEntity.class, id);
  521. if (task == null) {
  522. return new ResponseEntity(HttpStatus.NOT_FOUND);
  523. }
  524. return new ResponseEntity(task, HttpStatus.OK);
  525. }
  526. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  527. @ResponseBody
  528. public ResponseEntity<?> create(@RequestBody HrQianbaoEntity hrQianbao, UriComponentsBuilder uriBuilder) {
  529. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  530. Set<ConstraintViolation<HrQianbaoEntity>> failures = validator.validate(hrQianbao);
  531. if (!failures.isEmpty()) {
  532. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  533. }
  534. //保存
  535. hrQianbaoService.save(hrQianbao);
  536. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  537. String id = hrQianbao.getId();
  538. URI uri = uriBuilder.path("/rest/hrQianbaoController/" + id).build().toUri();
  539. HttpHeaders headers = new HttpHeaders();
  540. headers.setLocation(uri);
  541. return new ResponseEntity(headers, HttpStatus.CREATED);
  542. }
  543. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  544. public ResponseEntity<?> update(@RequestBody HrQianbaoEntity hrQianbao) {
  545. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  546. Set<ConstraintViolation<HrQianbaoEntity>> failures = validator.validate(hrQianbao);
  547. if (!failures.isEmpty()) {
  548. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  549. }
  550. //保存
  551. hrQianbaoService.saveOrUpdate(hrQianbao);
  552. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  553. return new ResponseEntity(HttpStatus.NO_CONTENT);
  554. }
  555. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  556. @ResponseStatus(HttpStatus.NO_CONTENT)
  557. public void delete(@PathVariable("id") String id) {
  558. hrQianbaoService.deleteEntityById(HrQianbaoEntity.class, id);
  559. }
  560. }