TBusUserTechangController.java 15 KB

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