UserCertificateController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. package cn.com.lzt.usercertificate.controller;
  2. import cn.com.lzt.certificatesubsidy.entity.CertificateSubsidyEntity;
  3. import cn.com.lzt.usercertificate.entity.UserCertificateEntity;
  4. import cn.com.lzt.usercertificate.service.UserCertificateServiceI;
  5. import org.apache.log4j.Logger;
  6. import org.jeecgframework.core.beanvalidator.BeanValidators;
  7. import org.jeecgframework.core.common.controller.BaseController;
  8. import org.jeecgframework.core.common.exception.BusinessException;
  9. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  10. import org.jeecgframework.core.common.model.json.AjaxJson;
  11. import org.jeecgframework.core.common.model.json.DataGrid;
  12. import org.jeecgframework.core.constant.Globals;
  13. import org.jeecgframework.core.util.ExceptionUtil;
  14. import org.jeecgframework.core.util.MyBeanUtils;
  15. import org.jeecgframework.core.util.ResourceUtil;
  16. import org.jeecgframework.core.util.StringUtil;
  17. import org.jeecgframework.poi.excel.ExcelImportUtil;
  18. import org.jeecgframework.poi.excel.entity.ExportParams;
  19. import org.jeecgframework.poi.excel.entity.ImportParams;
  20. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  21. import org.jeecgframework.tag.core.easyui.TagUtil;
  22. import org.jeecgframework.web.system.pojo.base.DictEntity;
  23. import org.jeecgframework.web.system.service.SystemService;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.http.HttpHeaders;
  26. import org.springframework.http.HttpStatus;
  27. import org.springframework.http.MediaType;
  28. import org.springframework.http.ResponseEntity;
  29. import org.springframework.stereotype.Controller;
  30. import org.springframework.ui.ModelMap;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import org.springframework.web.multipart.MultipartHttpServletRequest;
  34. import org.springframework.web.servlet.ModelAndView;
  35. import org.springframework.web.util.UriComponentsBuilder;
  36. import javax.servlet.http.HttpServletRequest;
  37. import javax.servlet.http.HttpServletResponse;
  38. import javax.validation.ConstraintViolation;
  39. import javax.validation.Validator;
  40. import java.io.IOException;
  41. import java.net.URI;
  42. import java.util.*;
  43. /**
  44. * @Title: Controller
  45. * @Description: 员工证书信息表
  46. * @author onlineGenerator
  47. * @date 2017-10-24 15:40:34
  48. * @version V1.0
  49. *
  50. */
  51. @Controller
  52. @RequestMapping("/userCertificateController")
  53. public class UserCertificateController extends BaseController {
  54. /**
  55. * Logger for this class
  56. */
  57. private static final Logger logger = Logger.getLogger(UserCertificateController.class);
  58. @Autowired
  59. private UserCertificateServiceI userCertificateService;
  60. @Autowired
  61. private SystemService systemService;
  62. @Autowired
  63. private Validator validator;
  64. /**
  65. * 员工证书信息表列表 页面跳转
  66. *
  67. * @return
  68. */
  69. @RequestMapping(params = "list")
  70. public ModelAndView list(String userId, HttpServletRequest request) {
  71. request.setAttribute("userId", userId);
  72. return new ModelAndView("cn/com/lzt/usercertificate/userCertificateList");
  73. }
  74. /**
  75. * 员工证书信息表查看 页面跳转
  76. *
  77. * @return
  78. */
  79. @RequestMapping(params = "view")
  80. public ModelAndView view(String userId, HttpServletRequest request) {
  81. request.setAttribute("userId", userId);
  82. return new ModelAndView("cn/com/lzt/usercertificate/userCertificateList-view");
  83. }
  84. /**
  85. * easyui AJAX请求数据
  86. *
  87. * @param request
  88. * @param response
  89. * @param dataGrid
  90. * @param user
  91. */
  92. @RequestMapping(params = "datagrid")
  93. public void datagrid(String userId, UserCertificateEntity userCertificate,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  94. CriteriaQuery cq = new CriteriaQuery(UserCertificateEntity.class, dataGrid);
  95. //查询条件组装器
  96. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, userCertificate, request.getParameterMap());
  97. try{
  98. //自定义追加查询条件
  99. cq.notEq("deleteFlag", Globals.Delete_Forbidden.toString());
  100. cq.eq("userid", userId);
  101. }catch (Exception e) {
  102. throw new BusinessException(e.getMessage());
  103. }
  104. cq.add();
  105. this.userCertificateService.getDataGridReturn(cq, true);
  106. TagUtil.datagrid(response, dataGrid);
  107. }
  108. /**
  109. * 保存新增/更新的行数据
  110. * @param page
  111. * @return
  112. */
  113. @RequestMapping(params = "saveRows")
  114. @ResponseBody
  115. public AjaxJson saveRows(UserCertificateEntity userCertificate,HttpServletRequest request){
  116. String message = null;
  117. AjaxJson j = new AjaxJson();
  118. message = "";
  119. // 根据证书名称、有效期限、审证日期判断用户是否已经维护了员工证书信息表
  120. String userCertificateHql = "from UserCertificateEntity where userid =? and certificateid =? and effectSdate =? and effectEdate =? and auditDate =? and deleteFlag != 1";
  121. List<UserCertificateEntity> userCertificateEntityList = userCertificateService.findHql(userCertificateHql, userCertificate.getUserid(), userCertificate.getCertificateid(), userCertificate.getEffectSdate(), userCertificate.getEffectEdate(), userCertificate.getAuditDate());
  122. if(userCertificateEntityList.size() > 0) {
  123. userCertificate.setId(userCertificateEntityList.get(0).getId());
  124. }
  125. if (StringUtil.isNotEmpty(userCertificate.getId())) {
  126. UserCertificateEntity t = userCertificateService.get(UserCertificateEntity.class, userCertificate.getId());
  127. try {
  128. MyBeanUtils.copyBeanNotNull2Bean(userCertificate, t);
  129. userCertificateService.saveOrUpdate(t);
  130. message = "证书信息更新成功";
  131. j.setSuccess(true);
  132. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  133. } catch (Exception e) {
  134. e.printStackTrace();
  135. message = "证书信息更新失败";
  136. j.setSuccess(false);
  137. throw new BusinessException(e.getMessage());
  138. }
  139. } else {
  140. try{
  141. userCertificate.setDeleteFlag(Globals.Delete_Normal.toString());
  142. userCertificateService.save(userCertificate);
  143. message = "证书信息添加成功";
  144. j.setSuccess(true);
  145. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  146. }catch(Exception e){
  147. e.printStackTrace();
  148. message = "证书信息添加失败";
  149. j.setSuccess(false);
  150. throw new BusinessException(e.getMessage());
  151. }
  152. }
  153. j.setMsg(message);
  154. return j;
  155. }
  156. /**
  157. * 批量逻辑删除证书信息
  158. *
  159. * @return
  160. */
  161. @RequestMapping(params = "doBatchLogicDel")
  162. @ResponseBody
  163. public AjaxJson doBatchLogicDel(String ids,HttpServletRequest request){
  164. String message = null;
  165. AjaxJson j = new AjaxJson();
  166. message = "证书信息删除成功";
  167. try{
  168. for(String id:ids.split(",")){
  169. UserCertificateEntity userCertificate = systemService.getEntity(UserCertificateEntity.class, id);
  170. userCertificate.setDeleteFlag(Globals.Delete_Forbidden.toString());
  171. userCertificateService.saveOrUpdate(userCertificate);
  172. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  173. j.setSuccess(true);
  174. }
  175. }catch(Exception e){
  176. e.printStackTrace();
  177. message = "证书信息删除失败";
  178. j.setSuccess(false);
  179. throw new BusinessException(e.getMessage());
  180. }
  181. j.setMsg(message);
  182. return j;
  183. }
  184. /**
  185. * 删除员工证书信息表
  186. *
  187. * @return
  188. */
  189. @RequestMapping(params = "doDel")
  190. @ResponseBody
  191. public AjaxJson doDel(UserCertificateEntity userCertificate, HttpServletRequest request) {
  192. String message = null;
  193. AjaxJson j = new AjaxJson();
  194. userCertificate = systemService.getEntity(UserCertificateEntity.class, userCertificate.getId());
  195. message = "员工证书信息表删除成功";
  196. try{
  197. userCertificateService.delete(userCertificate);
  198. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  199. }catch(Exception e){
  200. e.printStackTrace();
  201. message = "员工证书信息表删除失败";
  202. throw new BusinessException(e.getMessage());
  203. }
  204. j.setMsg(message);
  205. return j;
  206. }
  207. /**
  208. * 批量删除员工证书信息表
  209. *
  210. * @return
  211. */
  212. @RequestMapping(params = "doBatchDel")
  213. @ResponseBody
  214. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  215. String message = null;
  216. AjaxJson j = new AjaxJson();
  217. message = "员工证书信息表删除成功";
  218. try{
  219. for(String id:ids.split(",")){
  220. UserCertificateEntity userCertificate = systemService.getEntity(UserCertificateEntity.class,
  221. id
  222. );
  223. userCertificateService.delete(userCertificate);
  224. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  225. }
  226. }catch(Exception e){
  227. e.printStackTrace();
  228. message = "员工证书信息表删除失败";
  229. throw new BusinessException(e.getMessage());
  230. }
  231. j.setMsg(message);
  232. return j;
  233. }
  234. /**
  235. * 添加员工证书信息表
  236. *
  237. * @param ids
  238. * @return
  239. */
  240. @RequestMapping(params = "doAdd")
  241. @ResponseBody
  242. public AjaxJson doAdd(UserCertificateEntity userCertificate, HttpServletRequest request) {
  243. String message = null;
  244. AjaxJson j = new AjaxJson();
  245. message = "员工证书信息表添加成功";
  246. try{
  247. userCertificateService.save(userCertificate);
  248. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  249. }catch(Exception e){
  250. e.printStackTrace();
  251. message = "员工证书信息表添加失败";
  252. throw new BusinessException(e.getMessage());
  253. }
  254. j.setMsg(message);
  255. return j;
  256. }
  257. /**
  258. * 更新员工证书信息表
  259. *
  260. * @param ids
  261. * @return
  262. */
  263. @RequestMapping(params = "doUpdate")
  264. @ResponseBody
  265. public AjaxJson doUpdate(UserCertificateEntity userCertificate, HttpServletRequest request) {
  266. String message = null;
  267. AjaxJson j = new AjaxJson();
  268. message = "员工证书信息表更新成功";
  269. UserCertificateEntity t = userCertificateService.get(UserCertificateEntity.class, userCertificate.getId());
  270. try {
  271. MyBeanUtils.copyBeanNotNull2Bean(userCertificate, t);
  272. userCertificateService.saveOrUpdate(t);
  273. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  274. } catch (Exception e) {
  275. e.printStackTrace();
  276. message = "员工证书信息表更新失败";
  277. throw new BusinessException(e.getMessage());
  278. }
  279. j.setMsg(message);
  280. return j;
  281. }
  282. /**
  283. * 员工证书信息表新增页面跳转
  284. *
  285. * @return
  286. */
  287. @RequestMapping(params = "goAdd")
  288. public ModelAndView goAdd(UserCertificateEntity userCertificate, HttpServletRequest req) {
  289. if (StringUtil.isNotEmpty(userCertificate.getId())) {
  290. userCertificate = userCertificateService.getEntity(UserCertificateEntity.class, userCertificate.getId());
  291. req.setAttribute("userCertificatePage", userCertificate);
  292. }
  293. return new ModelAndView("cn/com/lzt/usercertificate/userCertificate-add");
  294. }
  295. /**
  296. * 员工证书信息表编辑页面跳转
  297. *
  298. * @return
  299. */
  300. @RequestMapping(params = "goUpdate")
  301. public ModelAndView goUpdate(UserCertificateEntity userCertificate, HttpServletRequest req) {
  302. if (StringUtil.isNotEmpty(userCertificate.getId())) {
  303. userCertificate = userCertificateService.getEntity(UserCertificateEntity.class, userCertificate.getId());
  304. req.setAttribute("userCertificatePage", userCertificate);
  305. }
  306. return new ModelAndView("cn/com/lzt/usercertificate/userCertificate-update");
  307. }
  308. /**
  309. * 导入功能跳转
  310. *
  311. * @return
  312. */
  313. @RequestMapping(params = "upload")
  314. public ModelAndView upload(HttpServletRequest req) {
  315. req.setAttribute("controller_name","userCertificateController");
  316. return new ModelAndView("common/upload/pub_excel_upload");
  317. }
  318. /**
  319. * 导出excel
  320. *
  321. * @param request
  322. * @param response
  323. */
  324. @RequestMapping(params = "exportXls")
  325. public String exportXls(UserCertificateEntity userCertificate,HttpServletRequest request,HttpServletResponse response
  326. , DataGrid dataGrid,ModelMap modelMap) {
  327. CriteriaQuery cq = new CriteriaQuery(UserCertificateEntity.class, dataGrid);
  328. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, userCertificate, request.getParameterMap());
  329. List<UserCertificateEntity> userCertificates = this.userCertificateService.getListByCriteriaQuery(cq,false);
  330. modelMap.put(NormalExcelConstants.FILE_NAME,"员工证书信息表");
  331. modelMap.put(NormalExcelConstants.CLASS,UserCertificateEntity.class);
  332. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("员工证书信息表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  333. "导出信息"));
  334. modelMap.put(NormalExcelConstants.DATA_LIST,userCertificates);
  335. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  336. }
  337. /**
  338. * 导出excel 使模板
  339. *
  340. * @param request
  341. * @param response
  342. */
  343. @RequestMapping(params = "exportXlsByT")
  344. public String exportXlsByT(UserCertificateEntity userCertificate,HttpServletRequest request,HttpServletResponse response
  345. , DataGrid dataGrid,ModelMap modelMap) {
  346. modelMap.put(NormalExcelConstants.FILE_NAME,"员工证书信息表");
  347. modelMap.put(NormalExcelConstants.CLASS,UserCertificateEntity.class);
  348. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("员工证书信息表列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  349. "导出信息"));
  350. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  351. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  352. }
  353. @SuppressWarnings("unchecked")
  354. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  355. @ResponseBody
  356. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  357. AjaxJson j = new AjaxJson();
  358. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  359. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  360. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  361. MultipartFile file = entity.getValue();// 获取上传文件对象
  362. ImportParams params = new ImportParams();
  363. params.setTitleRows(2);
  364. params.setHeadRows(1);
  365. params.setNeedSave(true);
  366. try {
  367. List<UserCertificateEntity> listUserCertificateEntitys = ExcelImportUtil.importExcel(file.getInputStream(),UserCertificateEntity.class,params);
  368. for (UserCertificateEntity userCertificate : listUserCertificateEntitys) {
  369. userCertificateService.save(userCertificate);
  370. }
  371. j.setMsg("文件导入成功!");
  372. } catch (Exception e) {
  373. j.setMsg("文件导入失败!");
  374. logger.error(ExceptionUtil.getExceptionMessage(e));
  375. }finally{
  376. try {
  377. file.getInputStream().close();
  378. } catch (IOException e) {
  379. e.printStackTrace();
  380. }
  381. }
  382. }
  383. return j;
  384. }
  385. @RequestMapping(method = RequestMethod.GET)
  386. @ResponseBody
  387. public List<UserCertificateEntity> list() {
  388. List<UserCertificateEntity> listUserCertificates=userCertificateService.getList(UserCertificateEntity.class);
  389. return listUserCertificates;
  390. }
  391. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  392. @ResponseBody
  393. public ResponseEntity<?> get(@PathVariable("id") String id) {
  394. UserCertificateEntity task = userCertificateService.get(UserCertificateEntity.class, id);
  395. if (task == null) {
  396. return new ResponseEntity(HttpStatus.NOT_FOUND);
  397. }
  398. return new ResponseEntity(task, HttpStatus.OK);
  399. }
  400. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  401. @ResponseBody
  402. public ResponseEntity<?> create(@RequestBody UserCertificateEntity userCertificate, UriComponentsBuilder uriBuilder) {
  403. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  404. Set<ConstraintViolation<UserCertificateEntity>> failures = validator.validate(userCertificate);
  405. if (!failures.isEmpty()) {
  406. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  407. }
  408. //保存
  409. try{
  410. userCertificateService.save(userCertificate);
  411. } catch (Exception e) {
  412. e.printStackTrace();
  413. return new ResponseEntity(HttpStatus.NO_CONTENT);
  414. }
  415. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  416. String id = userCertificate.getId();
  417. URI uri = uriBuilder.path("/rest/userCertificateController/" + id).build().toUri();
  418. HttpHeaders headers = new HttpHeaders();
  419. headers.setLocation(uri);
  420. return new ResponseEntity(headers, HttpStatus.CREATED);
  421. }
  422. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  423. public ResponseEntity<?> update(@RequestBody UserCertificateEntity userCertificate) {
  424. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  425. Set<ConstraintViolation<UserCertificateEntity>> failures = validator.validate(userCertificate);
  426. if (!failures.isEmpty()) {
  427. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  428. }
  429. //保存
  430. try{
  431. userCertificateService.saveOrUpdate(userCertificate);
  432. } catch (Exception e) {
  433. e.printStackTrace();
  434. return new ResponseEntity(HttpStatus.NO_CONTENT);
  435. }
  436. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  437. return new ResponseEntity(HttpStatus.NO_CONTENT);
  438. }
  439. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  440. @ResponseStatus(HttpStatus.NO_CONTENT)
  441. public void delete(@PathVariable("id") String id) {
  442. userCertificateService.deleteEntityById(UserCertificateEntity.class, id);
  443. }
  444. /**
  445. * //获奖证书根据后台选择,根据status='0',delete_flag='0'
  446. * @author zbw
  447. * 2017-12-27
  448. * @param ids
  449. * @param request
  450. * @return
  451. */
  452. @RequestMapping(params = "selectCertificateId")
  453. @ResponseBody
  454. public AjaxJson selectCertificateId(String ids,HttpServletRequest request){
  455. String message = null;
  456. AjaxJson j = new AjaxJson();
  457. StringBuffer hql = new StringBuffer(" from CertificateSubsidyEntity c where c.status='0'and c.deleteFlag='0' ");
  458. List<CertificateSubsidyEntity> certificateSubsidyEntityList = systemService.findHql(hql.toString());
  459. Map<String, Object> myMap=new HashMap<String, Object>();
  460. myMap.put("0", certificateSubsidyEntityList);
  461. j.setAttributes(myMap);
  462. return j;
  463. }
  464. /**
  465. * 附件上传类型
  466. * @author zbw
  467. * 2017-12-27
  468. * @param ids
  469. * @param request
  470. * @return
  471. */
  472. @RequestMapping(params = "selectfujianshangchuanleixing")
  473. @ResponseBody
  474. public AjaxJson selectfujianshangchuanleixing(String ids,HttpServletRequest request){
  475. String message = null;
  476. AjaxJson j = new AjaxJson();
  477. //附件上传类型
  478. List<DictEntity> selectfujianshangchuanleixingList=systemService.queryDict(null, "fujianshangchuanleixing", null);
  479. Map<String, Object> myMap=new HashMap<String, Object>();
  480. myMap.put("0", selectfujianshangchuanleixingList);
  481. j.setAttributes(myMap);
  482. return j;
  483. }
  484. }