ComageSubsidyController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. package cn.com.lzt.comagesubsidy.controller;
  2. import cn.com.lzt.comagesubsidy.entity.ComageSubsidyEntity;
  3. import cn.com.lzt.comagesubsidy.service.ComageSubsidyServiceI;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.text.SimpleDateFormat;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import org.apache.log4j.Logger;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.ModelMap;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import org.springframework.web.servlet.ModelAndView;
  16. import org.jeecgframework.core.common.controller.BaseController;
  17. import org.jeecgframework.core.common.exception.BusinessException;
  18. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  19. import org.jeecgframework.core.common.model.json.AjaxJson;
  20. import org.jeecgframework.core.common.model.json.DataGrid;
  21. import org.jeecgframework.core.constant.Globals;
  22. import org.jeecgframework.core.util.StringUtil;
  23. import org.jeecgframework.tag.core.easyui.TagUtil;
  24. import org.jeecgframework.web.system.pojo.base.TSDepart;
  25. import org.jeecgframework.web.system.service.SystemService;
  26. import org.jeecgframework.core.util.MyBeanUtils;
  27. import java.io.OutputStream;
  28. import org.jeecgframework.core.util.BrowserUtils;
  29. import org.jeecgframework.poi.excel.ExcelExportUtil;
  30. import org.jeecgframework.poi.excel.ExcelImportUtil;
  31. import org.jeecgframework.poi.excel.entity.ExportParams;
  32. import org.jeecgframework.poi.excel.entity.ImportParams;
  33. import org.jeecgframework.poi.excel.entity.TemplateExportParams;
  34. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  35. import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
  36. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  37. import org.jeecgframework.core.util.ResourceUtil;
  38. import java.io.IOException;
  39. import org.springframework.web.bind.annotation.RequestMethod;
  40. import org.springframework.web.multipart.MultipartFile;
  41. import org.springframework.web.multipart.MultipartHttpServletRequest;
  42. import java.util.Map;
  43. import org.jeecgframework.core.util.ExceptionUtil;
  44. import org.springframework.http.ResponseEntity;
  45. import org.springframework.stereotype.Controller;
  46. import org.springframework.web.bind.annotation.PathVariable;
  47. import org.springframework.web.bind.annotation.RequestBody;
  48. import org.springframework.web.bind.annotation.RequestMapping;
  49. import org.springframework.web.bind.annotation.RequestMethod;
  50. import org.springframework.web.bind.annotation.ResponseBody;
  51. import org.springframework.web.bind.annotation.ResponseStatus;
  52. import org.springframework.http.HttpHeaders;
  53. import org.springframework.http.HttpStatus;
  54. import org.jeecgframework.core.beanvalidator.BeanValidators;
  55. import java.util.Set;
  56. import javax.validation.ConstraintViolation;
  57. import javax.validation.Validator;
  58. import java.net.URI;
  59. import org.springframework.http.MediaType;
  60. import org.springframework.web.util.UriComponentsBuilder;
  61. /**
  62. * @Title: Controller
  63. * @Description: 司龄补贴
  64. * @author onlineGenerator
  65. * @date 2019-10-31 16:03:50
  66. * @version V1.0
  67. *
  68. */
  69. @Controller
  70. @RequestMapping("/comageSubsidyController")
  71. public class ComageSubsidyController extends BaseController {
  72. /**
  73. * Logger for this class
  74. */
  75. private static final Logger logger = Logger.getLogger(ComageSubsidyController.class);
  76. @Autowired
  77. private ComageSubsidyServiceI comageSubsidyService;
  78. @Autowired
  79. private SystemService systemService;
  80. @Autowired
  81. private Validator validator;
  82. /**
  83. * 司龄补贴列表 页面跳转
  84. *
  85. * @return
  86. */
  87. @RequestMapping(params = "list")
  88. public ModelAndView list(HttpServletRequest request) {
  89. return new ModelAndView("cn/com/lzt/comagesubsidy/comageSubsidyList");
  90. }
  91. /**
  92. * easyui AJAX请求数据
  93. *
  94. * @param request
  95. * @param response
  96. * @param dataGrid
  97. * @param user
  98. */
  99. @RequestMapping(params = "datagrid")
  100. public void datagrid(ComageSubsidyEntity comageSubsidy,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  101. CriteriaQuery cq = new CriteriaQuery(ComageSubsidyEntity.class, dataGrid);
  102. //查询条件组装器
  103. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, comageSubsidy, request.getParameterMap());
  104. try{
  105. //自定义追加查询条件
  106. }catch (Exception e) {
  107. throw new BusinessException(e.getMessage());
  108. }
  109. cq.add();
  110. this.comageSubsidyService.getDataGridReturn(cq, true);
  111. TagUtil.datagrid(response, dataGrid);
  112. }
  113. /**
  114. * 删除司龄补贴
  115. *
  116. * @return
  117. */
  118. @RequestMapping(params = "doDel")
  119. @ResponseBody
  120. public AjaxJson doDel(ComageSubsidyEntity comageSubsidy, HttpServletRequest request) {
  121. String message = null;
  122. AjaxJson j = new AjaxJson();
  123. comageSubsidy = systemService.getEntity(ComageSubsidyEntity.class, comageSubsidy.getId());
  124. message = "司龄补贴删除成功";
  125. try{
  126. comageSubsidyService.delete(comageSubsidy);
  127. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  128. }catch(Exception e){
  129. e.printStackTrace();
  130. message = "司龄补贴删除失败";
  131. throw new BusinessException(e.getMessage());
  132. }
  133. j.setMsg(message);
  134. return j;
  135. }
  136. /**
  137. * 批量删除司龄补贴
  138. *
  139. * @return
  140. */
  141. @RequestMapping(params = "doBatchDel")
  142. @ResponseBody
  143. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  144. String message = null;
  145. AjaxJson j = new AjaxJson();
  146. message = "司龄补贴删除成功";
  147. try{
  148. for(String id:ids.split(",")){
  149. ComageSubsidyEntity comageSubsidy = systemService.getEntity(ComageSubsidyEntity.class,
  150. id
  151. );
  152. comageSubsidyService.delete(comageSubsidy);
  153. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  154. }
  155. }catch(Exception e){
  156. e.printStackTrace();
  157. message = "司龄补贴删除失败";
  158. throw new BusinessException(e.getMessage());
  159. }
  160. j.setMsg(message);
  161. return j;
  162. }
  163. /**
  164. * 添加司龄补贴
  165. *
  166. * @param ids
  167. * @return
  168. */
  169. @RequestMapping(params = "doAdd")
  170. @ResponseBody
  171. public AjaxJson doAdd(ComageSubsidyEntity comageSubsidy, HttpServletRequest request) {
  172. String message = null;
  173. AjaxJson j = new AjaxJson();
  174. message = "司龄补贴添加成功";
  175. try{
  176. comageSubsidyService.save(comageSubsidy);
  177. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  178. }catch(Exception e){
  179. e.printStackTrace();
  180. message = "司龄补贴添加失败";
  181. throw new BusinessException(e.getMessage());
  182. }
  183. j.setMsg(message);
  184. return j;
  185. }
  186. /**
  187. * 更新司龄补贴
  188. *
  189. * @param ids
  190. * @return
  191. */
  192. @RequestMapping(params = "doUpdate")
  193. @ResponseBody
  194. public AjaxJson doUpdate(ComageSubsidyEntity comageSubsidy, HttpServletRequest request) {
  195. String message = null;
  196. AjaxJson j = new AjaxJson();
  197. message = "司龄补贴更新成功";
  198. ComageSubsidyEntity t = comageSubsidyService.get(ComageSubsidyEntity.class, "1");
  199. try {
  200. MyBeanUtils.copyBeanNotNull2Bean(comageSubsidy, t);
  201. comageSubsidyService.saveOrUpdate(t);
  202. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  203. } catch (Exception e) {
  204. e.printStackTrace();
  205. message = "司龄补贴更新失败";
  206. throw new BusinessException(e.getMessage());
  207. }
  208. j.setMsg(message);
  209. return j;
  210. }
  211. /**
  212. * 司龄补贴新增页面跳转
  213. *
  214. * @return
  215. */
  216. @RequestMapping(params = "goAdd")
  217. public ModelAndView goAdd(ComageSubsidyEntity comageSubsidy, HttpServletRequest req) {
  218. if (StringUtil.isNotEmpty(comageSubsidy.getId())) {
  219. comageSubsidy = comageSubsidyService.getEntity(ComageSubsidyEntity.class, comageSubsidy.getId());
  220. req.setAttribute("comageSubsidyPage", comageSubsidy);
  221. }
  222. return new ModelAndView("cn/com/lzt/comagesubsidy/comageSubsidy-add");
  223. }
  224. /**
  225. * 司龄补贴编辑页面跳转
  226. *
  227. * @return
  228. */
  229. @RequestMapping(params = "goUpdate")
  230. public ModelAndView goUpdate(ComageSubsidyEntity comageSubsidy, HttpServletRequest req) {
  231. comageSubsidy = comageSubsidyService.getEntity(ComageSubsidyEntity.class, "1");
  232. req.setAttribute("comageSubsidyPage", comageSubsidy);
  233. return new ModelAndView("cn/com/lzt/comagesubsidy/comageSubsidy-update");
  234. }
  235. /**
  236. * 导入功能跳转
  237. *
  238. * @return
  239. */
  240. @RequestMapping(params = "upload")
  241. public ModelAndView upload(HttpServletRequest req) {
  242. req.setAttribute("controller_name","comageSubsidyController");
  243. return new ModelAndView("common/upload/pub_excel_upload");
  244. }
  245. /**
  246. * 导出excel
  247. *
  248. * @param request
  249. * @param response
  250. */
  251. @RequestMapping(params = "exportXls")
  252. public String exportXls(ComageSubsidyEntity comageSubsidy,HttpServletRequest request,HttpServletResponse response
  253. , DataGrid dataGrid,ModelMap modelMap) {
  254. CriteriaQuery cq = new CriteriaQuery(ComageSubsidyEntity.class, dataGrid);
  255. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, comageSubsidy, request.getParameterMap());
  256. List<ComageSubsidyEntity> comageSubsidys = this.comageSubsidyService.getListByCriteriaQuery(cq,false);
  257. modelMap.put(NormalExcelConstants.FILE_NAME,"司龄补贴");
  258. modelMap.put(NormalExcelConstants.CLASS,ComageSubsidyEntity.class);
  259. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("司龄补贴列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  260. "导出信息"));
  261. modelMap.put(NormalExcelConstants.DATA_LIST,comageSubsidys);
  262. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  263. }
  264. /**
  265. * 导出excel 使模板
  266. *
  267. * @param request
  268. * @param response
  269. */
  270. @RequestMapping(params = "exportXlsByT")
  271. public String exportXlsByT(ComageSubsidyEntity comageSubsidy,HttpServletRequest request,HttpServletResponse response
  272. , DataGrid dataGrid,ModelMap modelMap) {
  273. modelMap.put(NormalExcelConstants.FILE_NAME,"司龄补贴");
  274. modelMap.put(NormalExcelConstants.CLASS,ComageSubsidyEntity.class);
  275. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("司龄补贴列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  276. "导出信息"));
  277. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  278. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  279. }
  280. @SuppressWarnings("unchecked")
  281. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  282. @ResponseBody
  283. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  284. AjaxJson j = new AjaxJson();
  285. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  286. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  287. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  288. MultipartFile file = entity.getValue();// 获取上传文件对象
  289. ImportParams params = new ImportParams();
  290. params.setTitleRows(2);
  291. params.setHeadRows(1);
  292. params.setNeedSave(true);
  293. try {
  294. List<ComageSubsidyEntity> listComageSubsidyEntitys = ExcelImportUtil.importExcel(file.getInputStream(),ComageSubsidyEntity.class,params);
  295. for (ComageSubsidyEntity comageSubsidy : listComageSubsidyEntitys) {
  296. comageSubsidyService.save(comageSubsidy);
  297. }
  298. j.setMsg("文件导入成功!");
  299. } catch (Exception e) {
  300. j.setMsg("文件导入失败!");
  301. logger.error(ExceptionUtil.getExceptionMessage(e));
  302. }finally{
  303. try {
  304. file.getInputStream().close();
  305. } catch (IOException e) {
  306. e.printStackTrace();
  307. }
  308. }
  309. }
  310. return j;
  311. }
  312. @RequestMapping(method = RequestMethod.GET)
  313. @ResponseBody
  314. public List<ComageSubsidyEntity> list() {
  315. List<ComageSubsidyEntity> listComageSubsidys=comageSubsidyService.getList(ComageSubsidyEntity.class);
  316. return listComageSubsidys;
  317. }
  318. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  319. @ResponseBody
  320. public ResponseEntity<?> get(@PathVariable("id") String id) {
  321. ComageSubsidyEntity task = comageSubsidyService.get(ComageSubsidyEntity.class, id);
  322. if (task == null) {
  323. return new ResponseEntity(HttpStatus.NOT_FOUND);
  324. }
  325. return new ResponseEntity(task, HttpStatus.OK);
  326. }
  327. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  328. @ResponseBody
  329. public ResponseEntity<?> create(@RequestBody ComageSubsidyEntity comageSubsidy, UriComponentsBuilder uriBuilder) {
  330. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  331. Set<ConstraintViolation<ComageSubsidyEntity>> failures = validator.validate(comageSubsidy);
  332. if (!failures.isEmpty()) {
  333. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  334. }
  335. //保存
  336. try{
  337. comageSubsidyService.save(comageSubsidy);
  338. } catch (Exception e) {
  339. e.printStackTrace();
  340. return new ResponseEntity(HttpStatus.NO_CONTENT);
  341. }
  342. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  343. String id = comageSubsidy.getId();
  344. URI uri = uriBuilder.path("/rest/comageSubsidyController/" + id).build().toUri();
  345. HttpHeaders headers = new HttpHeaders();
  346. headers.setLocation(uri);
  347. return new ResponseEntity(headers, HttpStatus.CREATED);
  348. }
  349. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  350. public ResponseEntity<?> update(@RequestBody ComageSubsidyEntity comageSubsidy) {
  351. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  352. Set<ConstraintViolation<ComageSubsidyEntity>> failures = validator.validate(comageSubsidy);
  353. if (!failures.isEmpty()) {
  354. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  355. }
  356. //保存
  357. try{
  358. comageSubsidyService.saveOrUpdate(comageSubsidy);
  359. } catch (Exception e) {
  360. e.printStackTrace();
  361. return new ResponseEntity(HttpStatus.NO_CONTENT);
  362. }
  363. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  364. return new ResponseEntity(HttpStatus.NO_CONTENT);
  365. }
  366. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  367. @ResponseStatus(HttpStatus.NO_CONTENT)
  368. public void delete(@PathVariable("id") String id) {
  369. comageSubsidyService.deleteEntityById(ComageSubsidyEntity.class, id);
  370. }
  371. }