PromotionTransferController.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. package cn.com.lzt.promotiontransfer.controller;
  2. import java.io.IOException;
  3. import java.net.URI;
  4. import java.text.ParsePosition;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.Set;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import javax.servlet.http.HttpSession;
  15. import javax.validation.ConstraintViolation;
  16. import javax.validation.Validator;
  17. import org.apache.commons.lang3.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.ContextHolderUtils;
  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.p3.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.TSDepart;
  38. import org.jeecgframework.web.system.pojo.base.TSUser;
  39. import org.jeecgframework.web.system.service.SystemService;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.http.HttpHeaders;
  42. import org.springframework.http.HttpStatus;
  43. import org.springframework.http.MediaType;
  44. import org.springframework.http.ResponseEntity;
  45. import org.springframework.stereotype.Controller;
  46. import org.springframework.ui.ModelMap;
  47. import org.springframework.web.bind.annotation.PathVariable;
  48. import org.springframework.web.bind.annotation.RequestBody;
  49. import org.springframework.web.bind.annotation.RequestMapping;
  50. import org.springframework.web.bind.annotation.RequestMethod;
  51. import org.springframework.web.bind.annotation.ResponseBody;
  52. import org.springframework.web.bind.annotation.ResponseStatus;
  53. import org.springframework.web.multipart.MultipartFile;
  54. import org.springframework.web.multipart.MultipartHttpServletRequest;
  55. import org.springframework.web.servlet.ModelAndView;
  56. import org.springframework.web.util.UriComponentsBuilder;
  57. import cn.com.lzt.duties.entity.DutiesEntity;
  58. import cn.com.lzt.leave.service.ModifyServiceI;
  59. import cn.com.lzt.post.entity.PostEntity;
  60. import cn.com.lzt.promotiontransfer.entity.PromotionTransferEntity;
  61. import cn.com.lzt.promotiontransfer.service.PromotionTransferServiceI;
  62. import com.jeecg.qianbao.util.FormProcUtil;
  63. /**
  64. * @Title: Controller
  65. * @Description: 人事晋升申请表
  66. * @author onlineGenerator
  67. * @date 2017-10-19 11:23:16
  68. * @version V1.0
  69. *
  70. */
  71. @Controller
  72. @RequestMapping("/promotionTransferController")
  73. public class PromotionTransferController extends BaseController {
  74. /**
  75. * Logger for this class
  76. */
  77. private static final Logger logger = Logger.getLogger(PromotionTransferController.class);
  78. @Autowired
  79. private PromotionTransferServiceI promotionTransferService;
  80. @Autowired
  81. private SystemService systemService;
  82. @Autowired
  83. private Validator validator;
  84. @Autowired
  85. private ModifyServiceI modifyService;
  86. /**
  87. * 人事晋升申请表列表 页面跳转
  88. *
  89. * @return
  90. */
  91. @RequestMapping(params = "list")
  92. public ModelAndView list(HttpServletRequest request) {
  93. return new ModelAndView("cn/com/lzt/promotiontransfer/promotionTransferList");
  94. }
  95. /**
  96. * easyui AJAX请求数据
  97. *
  98. * @param request
  99. * @param response
  100. * @param dataGrid
  101. * @param user
  102. */
  103. @RequestMapping(params = "datagrid")
  104. public void datagrid(PromotionTransferEntity promotionTransfer,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  105. CriteriaQuery cq = new CriteriaQuery(PromotionTransferEntity.class, dataGrid);
  106. //查询条件组装器
  107. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, promotionTransfer, request.getParameterMap());
  108. try{
  109. //自定义追加查询条件
  110. String query_outTime_begin = request.getParameter("outTime_begin");
  111. String query_outTime_end = request.getParameter("outTime_end");
  112. if(StringUtil.isNotEmpty(query_outTime_begin)){
  113. cq.ge("outTime", new SimpleDateFormat("yyyy-MM-dd").parse(query_outTime_begin));
  114. }
  115. if(StringUtil.isNotEmpty(query_outTime_end)){
  116. cq.le("outTime", new SimpleDateFormat("yyyy-MM-dd").parse(query_outTime_end));
  117. }
  118. String query_applyDate_begin = request.getParameter("applyDate_begin");
  119. String query_applyDate_end = request.getParameter("applyDate_end");
  120. if(StringUtil.isNotEmpty(query_applyDate_begin)){
  121. cq.ge("applyDate", new SimpleDateFormat("yyyy-MM-dd").parse(query_applyDate_begin));
  122. }
  123. if(StringUtil.isNotEmpty(query_applyDate_end)){
  124. cq.le("applyDate", new SimpleDateFormat("yyyy-MM-dd").parse(query_applyDate_end));
  125. }
  126. }catch (Exception e) {
  127. throw new BusinessException(e.getMessage());
  128. }
  129. cq.add();
  130. this.promotionTransferService.getDataGridReturn(cq, true);
  131. TagUtil.datagrid(response, dataGrid);
  132. }
  133. /**
  134. * 删除人事晋升申请表
  135. *
  136. * @return
  137. */
  138. @RequestMapping(params = "doDel")
  139. @ResponseBody
  140. public AjaxJson doDel(PromotionTransferEntity promotionTransfer, HttpServletRequest request) {
  141. String message = null;
  142. AjaxJson j = new AjaxJson();
  143. promotionTransfer = systemService.getEntity(PromotionTransferEntity.class, promotionTransfer.getId());
  144. message = "人事晋升申请表删除成功";
  145. try{
  146. promotionTransferService.delete(promotionTransfer);
  147. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  148. }catch(Exception e){
  149. e.printStackTrace();
  150. message = "人事晋升申请表删除失败";
  151. throw new BusinessException(e.getMessage());
  152. }
  153. j.setMsg(message);
  154. return j;
  155. }
  156. /**
  157. * 批量删除人事晋升申请表
  158. *
  159. * @return
  160. */
  161. @RequestMapping(params = "doBatchDel")
  162. @ResponseBody
  163. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  164. String message = null;
  165. AjaxJson j = new AjaxJson();
  166. message = "人事晋升申请表删除成功";
  167. try{
  168. for(String id:ids.split(",")){
  169. PromotionTransferEntity promotionTransfer = systemService.getEntity(PromotionTransferEntity.class,
  170. id
  171. );
  172. promotionTransferService.delete(promotionTransfer);
  173. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  174. }
  175. }catch(Exception e){
  176. e.printStackTrace();
  177. message = "人事晋升申请表删除失败";
  178. throw new BusinessException(e.getMessage());
  179. }
  180. j.setMsg(message);
  181. return j;
  182. }
  183. /**
  184. * 添加人事晋升申请表
  185. *
  186. * @param ids
  187. * @return
  188. */
  189. @RequestMapping(params = "doAdd")
  190. @ResponseBody
  191. public AjaxJson doAdd(PromotionTransferEntity promotionTransfer, HttpServletRequest request) {
  192. String message = null;
  193. AjaxJson j = new AjaxJson();
  194. message = "人事晋升申请表添加成功";
  195. try{
  196. String sa = promotionTransfer.getInUnitid();
  197. if(StringUtils.isNotEmpty(sa)){
  198. if(sa.indexOf(",") > 0){
  199. promotionTransfer.setInUnitid(sa.substring(0, sa.length()-1));
  200. }
  201. }
  202. String duid = promotionTransfer.getInDutiesid();
  203. if(StringUtils.isNotEmpty(duid)){
  204. if(duid.indexOf(",") > 0){
  205. promotionTransfer.setInDutiesid(duid.substring(0, duid.length()-1));
  206. }
  207. }
  208. String poid = promotionTransfer.getInPostid();
  209. if(StringUtils.isNotEmpty(poid)){
  210. if(poid.indexOf(",") > 0){
  211. promotionTransfer.setInPostid(poid.substring(0, poid.length()-1));
  212. }
  213. }
  214. String addtype = request.getParameter("addtype");
  215. if(Globals.MINUS.toString().equals(addtype)){
  216. promotionTransfer.setSalaryPay(promotionTransfer.getSalaryPay().negate());
  217. }
  218. promotionTransfer.setDeleteFlag(Globals.Delete_Normal.toString());
  219. HttpSession session = ContextHolderUtils.getSession();
  220. TSUser tuser = (TSUser)session.getAttribute("LOCAL_CLINET_USER");
  221. if(tuser != null){
  222. promotionTransfer.setApplicantId(tuser.getId());
  223. }
  224. TSDepart tsDepart = systemService.get(TSDepart.class, promotionTransfer.getBelongUnitid());
  225. if(tsDepart != null && tsDepart.getTSPDepart() != null){
  226. promotionTransfer.setBelongUnitPid(tsDepart.getTSPDepart().getId());
  227. }
  228. TSDepart tsDeparts = systemService.get(TSDepart.class, promotionTransfer.getInUnitid());
  229. if(tsDeparts != null && tsDeparts.getTSPDepart() != null){
  230. promotionTransfer.setInUnitPid(tsDeparts.getTSPDepart().getId());
  231. }
  232. SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
  233. ParsePosition pos = new ParsePosition(0);
  234. promotionTransfer.setApplyDate(sim.parse(sim.format(new Date()), pos));
  235. promotionTransferService.save(promotionTransfer);
  236. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  237. }catch(Exception e){
  238. e.printStackTrace();
  239. message = "人事晋升申请表添加失败";
  240. throw new BusinessException(e.getMessage());
  241. }
  242. j.setMsg(message);
  243. return j;
  244. }
  245. /**
  246. * 更新人事晋升申请表
  247. *
  248. * @param ids
  249. * @return
  250. */
  251. @RequestMapping(params = "doUpdate")
  252. @ResponseBody
  253. public AjaxJson doUpdate(PromotionTransferEntity promotionTransfer, HttpServletRequest request) {
  254. String message = null;
  255. AjaxJson j = new AjaxJson();
  256. message = "人事晋升申请表更新成功";
  257. PromotionTransferEntity t = promotionTransferService.get(PromotionTransferEntity.class, promotionTransfer.getId());
  258. try {
  259. MyBeanUtils.copyBeanNotNull2Bean(promotionTransfer, t);
  260. String sa = t.getInUnitid();
  261. if(StringUtils.isNotEmpty(sa)){
  262. if(sa.indexOf(",") > 0){
  263. t.setInUnitid(sa.substring(0, sa.length()-1));
  264. }
  265. }
  266. String indu = t.getInDutiesid();
  267. if(StringUtils.isNotEmpty(indu)){
  268. if(indu.indexOf(",") > 0){
  269. t.setInUnitid(indu.substring(0, indu.length()-1));
  270. }
  271. }
  272. String inpo = t.getInPostid();
  273. if(StringUtils.isNotEmpty(inpo)){
  274. if(inpo.indexOf(",") > 0){
  275. t.setInUnitid(inpo.substring(0, inpo.length()-1));
  276. }
  277. }
  278. String addtype = request.getParameter("addtype");
  279. if(Globals.MINUS.toString().equals(addtype)){
  280. t.setSalaryPay(promotionTransfer.getSalaryPay().negate());
  281. }
  282. TSDepart tsDepart = systemService.get(TSDepart.class, promotionTransfer.getBelongUnitid());
  283. if(tsDepart != null && tsDepart.getTSPDepart() != null){
  284. t.setBelongUnitPid(tsDepart.getTSPDepart().getId());
  285. }
  286. TSDepart tsDeparts = systemService.get(TSDepart.class, promotionTransfer.getInUnitid());
  287. if(tsDeparts != null && tsDeparts.getTSPDepart() != null){
  288. t.setInUnitPid(tsDeparts.getTSPDepart().getId());
  289. }
  290. promotionTransferService.saveOrUpdate(t);
  291. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  292. } catch (Exception e) {
  293. e.printStackTrace();
  294. message = "人事晋升申请表更新失败";
  295. throw new BusinessException(e.getMessage());
  296. }
  297. j.setMsg(message);
  298. return j;
  299. }
  300. /**
  301. * 人事晋升申请表新增页面跳转
  302. *
  303. * @return
  304. */
  305. @RequestMapping(params = "goAdd")
  306. public ModelAndView goAdd(PromotionTransferEntity promotionTransfer, HttpServletRequest req) {
  307. if (StringUtil.isNotEmpty(promotionTransfer.getId())) {
  308. promotionTransfer = promotionTransferService.getEntity(PromotionTransferEntity.class, promotionTransfer.getId());
  309. req.setAttribute("promotionTransferPage", promotionTransfer);
  310. }
  311. return new ModelAndView("cn/com/lzt/promotiontransfer/promotionTransfer-add");
  312. }
  313. /**
  314. * 人事晋升申请表编辑页面跳转
  315. *
  316. * @return
  317. */
  318. @RequestMapping(params = "goUpdate")
  319. public ModelAndView goUpdate(PromotionTransferEntity promotionTransfer, HttpServletRequest req) {
  320. if (StringUtil.isNotEmpty(promotionTransfer.getId())) {
  321. promotionTransfer = promotionTransferService.getEntity(PromotionTransferEntity.class, promotionTransfer.getId());
  322. req.setAttribute("promotionTransferPage", promotionTransfer);
  323. TSUser user = systemService.getEntity(TSUser.class, promotionTransfer.getUserid());
  324. req.setAttribute("user",user);
  325. Map map = new HashMap();
  326. map.put("departid","");
  327. map.put("departname","");
  328. map.put("dutiesid","");
  329. map.put("dutiesName","");
  330. map.put("postid","");
  331. map.put("postname","");
  332. if(StringUtils.isNotEmpty(promotionTransfer.getBelongUnitid())){
  333. TSDepart tsd = systemService.getEntity(TSDepart.class, promotionTransfer.getBelongUnitid());
  334. if(tsd != null){
  335. map.put("departid", tsd.getId());
  336. map.put("departname",modifyService.getByorgId(tsd.getId()));
  337. }
  338. }
  339. if(StringUtils.isNotEmpty(promotionTransfer.getInUnitid())){
  340. TSDepart tsd = systemService.getEntity(TSDepart.class, promotionTransfer.getInUnitid());
  341. if(tsd != null){
  342. req.setAttribute("tid", tsd.getId());
  343. req.setAttribute("tname", modifyService.getByorgId(tsd.getId()));
  344. }
  345. }
  346. if(StringUtils.isNotEmpty(promotionTransfer.getOldDutiesid())){
  347. DutiesEntity du = systemService.getEntity(DutiesEntity.class,promotionTransfer.getOldDutiesid());
  348. if(du != null){
  349. map.put("dutiesid", du.getId());
  350. map.put("dutiesName", du.getDutiesName());
  351. }
  352. }
  353. if(StringUtils.isNotEmpty(promotionTransfer.getOldPostid())){
  354. PostEntity po = systemService.getEntity(PostEntity.class, promotionTransfer.getOldPostid());
  355. if(po != null){
  356. map.put("postid", po.getId());
  357. map.put("postname", po.getPostName());
  358. }
  359. }
  360. if(StringUtils.isNotEmpty(promotionTransfer.getInDutiesid())){
  361. DutiesEntity du = systemService.getEntity(DutiesEntity.class,promotionTransfer.getInDutiesid());
  362. if(du != null){
  363. map.put("dutiesid1", du.getId());
  364. map.put("dutiesName1", du.getDutiesName());
  365. }
  366. }
  367. if(StringUtils.isNotEmpty(promotionTransfer.getInPostid())){
  368. PostEntity po = systemService.getEntity(PostEntity.class, promotionTransfer.getInPostid());
  369. if(po != null){
  370. map.put("postid1", po.getId());
  371. map.put("postname1", po.getPostName());
  372. }
  373. }
  374. req.setAttribute("map", map);
  375. //判断金额是否小于0,如果小于0,则把金额改成正数
  376. /*if(promotionTransfer.getSalaryPay().compareTo(BigDecimal.ZERO) == -1){//小于0
  377. req.setAttribute("addtype", Globals.MINUS.toString());
  378. req.setAttribute("salary", promotionTransfer.getSalaryPay().negate());
  379. }else if(promotionTransfer.getSalaryPay().compareTo(BigDecimal.ZERO) == 0){//等于0
  380. req.setAttribute("addtype", Globals.MINUS.toString());
  381. }else{
  382. req.setAttribute("addtype", Globals.PLUS.toString());
  383. }*/
  384. }
  385. return new ModelAndView("cn/com/lzt/promotiontransfer/promotionTransfer-update");
  386. }
  387. /**
  388. * 离职申请表编辑页面跳转
  389. *
  390. * @return
  391. */
  392. @RequestMapping(params = "goView")
  393. public ModelAndView goView(PromotionTransferEntity promotionTransfer, HttpServletRequest req) {
  394. if (StringUtil.isNotEmpty(promotionTransfer.getId())) {
  395. promotionTransfer = promotionTransferService.getEntity(PromotionTransferEntity.class, promotionTransfer.getId());
  396. req.setAttribute("promotionTransferPage", promotionTransfer);
  397. TSUser user = systemService.getEntity(TSUser.class, promotionTransfer.getUserid());
  398. req.setAttribute("user",user);
  399. Map map = new HashMap();
  400. map.put("departid","");
  401. map.put("departname","");
  402. map.put("dutiesid","");
  403. map.put("dutiesName","");
  404. map.put("postid","");
  405. map.put("postname","");
  406. if(StringUtils.isNotEmpty(promotionTransfer.getBelongUnitid())){
  407. TSDepart tsd = systemService.getEntity(TSDepart.class, promotionTransfer.getBelongUnitid());
  408. if(tsd != null){
  409. map.put("departid", tsd.getId());
  410. map.put("departname", modifyService.getByorgId(tsd.getId()));
  411. }
  412. }
  413. if(StringUtils.isNotEmpty(promotionTransfer.getInUnitid())){
  414. TSDepart tsd = systemService.getEntity(TSDepart.class, promotionTransfer.getInUnitid());
  415. if(tsd != null){
  416. req.setAttribute("tid", tsd.getId());
  417. req.setAttribute("tname", modifyService.getByorgId(tsd.getId()));
  418. }
  419. }
  420. if(StringUtils.isNotEmpty(promotionTransfer.getOldDutiesid())){
  421. DutiesEntity du = systemService.getEntity(DutiesEntity.class,promotionTransfer.getOldDutiesid());
  422. if(du != null){
  423. map.put("dutiesid", du.getId());
  424. map.put("dutiesName", du.getDutiesName());
  425. }
  426. }
  427. if(StringUtils.isNotEmpty(promotionTransfer.getOldPostid())){
  428. PostEntity po = systemService.getEntity(PostEntity.class, promotionTransfer.getOldPostid());
  429. if(po != null){
  430. map.put("postid", po.getId());
  431. map.put("postname", po.getPostName());
  432. }
  433. }
  434. if(StringUtils.isNotEmpty(promotionTransfer.getInDutiesid())){
  435. DutiesEntity du = systemService.getEntity(DutiesEntity.class,promotionTransfer.getInDutiesid());
  436. if(du != null){
  437. map.put("dutiesid1", du.getId());
  438. map.put("dutiesName1", du.getDutiesName());
  439. }
  440. }
  441. if(StringUtils.isNotEmpty(promotionTransfer.getInPostid())){
  442. PostEntity po = systemService.getEntity(PostEntity.class, promotionTransfer.getInPostid());
  443. if(po != null){
  444. map.put("postid1", po.getId());
  445. map.put("postname1", po.getPostName());
  446. }
  447. }
  448. req.setAttribute("map", map);
  449. //判断金额是否小于0,如果小于0,则把金额改成正数
  450. /*if(promotionTransfer.getSalaryPay().compareTo(BigDecimal.ZERO) == -1){//小于0
  451. req.setAttribute("addtype", Globals.MINUS.toString());
  452. req.setAttribute("salary", promotionTransfer.getSalaryPay().negate());
  453. }else if(promotionTransfer.getSalaryPay().compareTo(BigDecimal.ZERO) == 0){//等于0
  454. req.setAttribute("addtype", Globals.MINUS.toString());
  455. }else{
  456. req.setAttribute("addtype", Globals.PLUS.toString());
  457. }*/
  458. }
  459. String flage = oConvertUtils.getString(req.getParameter("flage"));
  460. if(oConvertUtils.isNotEmpty(flage)){
  461. req.setAttribute("flage",flage);
  462. }
  463. String taskId = oConvertUtils.getString(req.getParameter("taskId"));
  464. if(oConvertUtils.isNotEmpty(taskId)){
  465. FormProcUtil.initWorkflowParam(req);
  466. req.setAttribute("taskId",taskId);
  467. }
  468. return new ModelAndView("cn/com/lzt/promotiontransfer/promotionTransfer-view1");
  469. }
  470. /**
  471. * 导入功能跳转
  472. *
  473. * @return
  474. */
  475. @RequestMapping(params = "upload")
  476. public ModelAndView upload(HttpServletRequest req) {
  477. req.setAttribute("controller_name","promotionTransferController");
  478. return new ModelAndView("common/upload/pub_excel_upload");
  479. }
  480. /**
  481. * 导出excel
  482. *
  483. * @param request
  484. * @param response
  485. */
  486. @RequestMapping(params = "exportXls")
  487. public String exportXls(PromotionTransferEntity promotionTransfer,HttpServletRequest request,HttpServletResponse response
  488. , DataGrid dataGrid,ModelMap modelMap) {
  489. CriteriaQuery cq = new CriteriaQuery(PromotionTransferEntity.class, dataGrid);
  490. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, promotionTransfer, request.getParameterMap());
  491. List<PromotionTransferEntity> promotionTransfers = this.promotionTransferService.getListByCriteriaQuery(cq,false);
  492. modelMap.put(NormalExcelConstants.FILE_NAME,"人事晋升申请表");
  493. modelMap.put(NormalExcelConstants.CLASS,PromotionTransferEntity.class);
  494. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人事晋升申请表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  495. "导出信息"));
  496. modelMap.put(NormalExcelConstants.DATA_LIST,promotionTransfers);
  497. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  498. }
  499. /**
  500. * 导出excel 使模板
  501. *
  502. * @param request
  503. * @param response
  504. */
  505. @RequestMapping(params = "exportXlsByT")
  506. public String exportXlsByT(PromotionTransferEntity promotionTransfer,HttpServletRequest request,HttpServletResponse response
  507. , DataGrid dataGrid,ModelMap modelMap) {
  508. modelMap.put(NormalExcelConstants.FILE_NAME,"人事晋升申请表");
  509. modelMap.put(NormalExcelConstants.CLASS,PromotionTransferEntity.class);
  510. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("人事晋升申请表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  511. "导出信息"));
  512. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  513. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  514. }
  515. @SuppressWarnings("unchecked")
  516. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  517. @ResponseBody
  518. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  519. AjaxJson j = new AjaxJson();
  520. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  521. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  522. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  523. MultipartFile file = entity.getValue();// 获取上传文件对象
  524. ImportParams params = new ImportParams();
  525. params.setTitleRows(2);
  526. params.setHeadRows(1);
  527. params.setNeedSave(true);
  528. try {
  529. List<PromotionTransferEntity> listPromotionTransferEntitys = ExcelImportUtil.importExcel(file.getInputStream(),PromotionTransferEntity.class,params);
  530. for (PromotionTransferEntity promotionTransfer : listPromotionTransferEntitys) {
  531. promotionTransferService.save(promotionTransfer);
  532. }
  533. j.setMsg("文件导入成功!");
  534. } catch (Exception e) {
  535. j.setMsg("文件导入失败!");
  536. logger.error(ExceptionUtil.getExceptionMessage(e));
  537. }finally{
  538. try {
  539. file.getInputStream().close();
  540. } catch (IOException e) {
  541. e.printStackTrace();
  542. }
  543. }
  544. }
  545. return j;
  546. }
  547. @RequestMapping(method = RequestMethod.GET)
  548. @ResponseBody
  549. public List<PromotionTransferEntity> list() {
  550. List<PromotionTransferEntity> listPromotionTransfers=promotionTransferService.getList(PromotionTransferEntity.class);
  551. return listPromotionTransfers;
  552. }
  553. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  554. @ResponseBody
  555. public ResponseEntity<?> get(@PathVariable("id") String id) {
  556. PromotionTransferEntity task = promotionTransferService.get(PromotionTransferEntity.class, id);
  557. if (task == null) {
  558. return new ResponseEntity(HttpStatus.NOT_FOUND);
  559. }
  560. return new ResponseEntity(task, HttpStatus.OK);
  561. }
  562. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  563. @ResponseBody
  564. public ResponseEntity<?> create(@RequestBody PromotionTransferEntity promotionTransfer, UriComponentsBuilder uriBuilder) {
  565. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  566. Set<ConstraintViolation<PromotionTransferEntity>> failures = validator.validate(promotionTransfer);
  567. if (!failures.isEmpty()) {
  568. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  569. }
  570. //保存
  571. try{
  572. promotionTransferService.save(promotionTransfer);
  573. } catch (Exception e) {
  574. e.printStackTrace();
  575. return new ResponseEntity(HttpStatus.NO_CONTENT);
  576. }
  577. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  578. String id = promotionTransfer.getId();
  579. URI uri = uriBuilder.path("/rest/promotionTransferController/" + id).build().toUri();
  580. HttpHeaders headers = new HttpHeaders();
  581. headers.setLocation(uri);
  582. return new ResponseEntity(headers, HttpStatus.CREATED);
  583. }
  584. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  585. public ResponseEntity<?> update(@RequestBody PromotionTransferEntity promotionTransfer) {
  586. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  587. Set<ConstraintViolation<PromotionTransferEntity>> failures = validator.validate(promotionTransfer);
  588. if (!failures.isEmpty()) {
  589. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  590. }
  591. //保存
  592. try{
  593. promotionTransferService.saveOrUpdate(promotionTransfer);
  594. } catch (Exception e) {
  595. e.printStackTrace();
  596. return new ResponseEntity(HttpStatus.NO_CONTENT);
  597. }
  598. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  599. return new ResponseEntity(HttpStatus.NO_CONTENT);
  600. }
  601. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  602. @ResponseStatus(HttpStatus.NO_CONTENT)
  603. public void delete(@PathVariable("id") String id) {
  604. promotionTransferService.deleteEntityById(PromotionTransferEntity.class, id);
  605. }
  606. }