TBExchangeAccountLogController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. package cn.com.lzt.exchangeaccount.controller;
  2. import cn.com.lzt.exchangeaccount.entity.TBExchangeAccountLogEntity;
  3. import cn.com.lzt.exchangeaccount.service.TBExchangeAccountLogServiceI;
  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.common.TreeChildCount;
  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 java.util.HashMap;
  45. import org.jeecgframework.core.util.ExceptionUtil;
  46. import org.springframework.http.ResponseEntity;
  47. import org.springframework.stereotype.Controller;
  48. import org.springframework.web.bind.annotation.PathVariable;
  49. import org.springframework.web.bind.annotation.RequestBody;
  50. import org.springframework.web.bind.annotation.RequestMapping;
  51. import org.springframework.web.bind.annotation.RequestMethod;
  52. import org.springframework.web.bind.annotation.ResponseBody;
  53. import org.springframework.web.bind.annotation.ResponseStatus;
  54. import org.springframework.http.HttpHeaders;
  55. import org.springframework.http.HttpStatus;
  56. import org.jeecgframework.core.beanvalidator.BeanValidators;
  57. import java.util.Set;
  58. import javax.validation.ConstraintViolation;
  59. import javax.validation.Validator;
  60. import java.net.URI;
  61. import org.springframework.http.MediaType;
  62. import org.springframework.web.util.UriComponentsBuilder;
  63. /**
  64. * @Title: Controller
  65. * @Description: 调休账户日志
  66. * @author onlineGenerator
  67. * @date 2019-10-17 21:15:02
  68. * @version V1.0
  69. *
  70. */
  71. @Controller
  72. @RequestMapping("/tBExchangeAccountLogController")
  73. public class TBExchangeAccountLogController extends BaseController {
  74. /**
  75. * Logger for this class
  76. */
  77. private static final Logger logger = Logger.getLogger(TBExchangeAccountLogController.class);
  78. @Autowired
  79. private TBExchangeAccountLogServiceI tBExchangeAccountLogService;
  80. @Autowired
  81. private SystemService systemService;
  82. @Autowired
  83. private Validator validator;
  84. /**
  85. * 调休账户日志列表 页面跳转
  86. *
  87. * @return
  88. */
  89. @RequestMapping(params = "list")
  90. public ModelAndView list(HttpServletRequest request) {
  91. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccountLogList");
  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(TBExchangeAccountLogEntity tBExchangeAccountLog,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  103. CriteriaQuery cq = new CriteriaQuery(TBExchangeAccountLogEntity.class, dataGrid);
  104. //查询条件组装器
  105. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBExchangeAccountLog, request.getParameterMap());
  106. try{
  107. //自定义追加查询条件
  108. }catch (Exception e) {
  109. throw new BusinessException(e.getMessage());
  110. }
  111. cq.add();
  112. this.tBExchangeAccountLogService.getDataGridReturn(cq, true);
  113. TagUtil.datagrid(response, dataGrid);
  114. }
  115. @RequestMapping(params = "goExchangeHistory")
  116. public ModelAndView goExchangeHistory(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest req) {
  117. return new ModelAndView("cn/com/lzt/exchangeaccount/exchange_history");
  118. }
  119. @RequestMapping(params = "historyDatagrid")
  120. public void historyDatagrid(TBExchangeAccountLogEntity tBExchangeAccountLog,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  121. CriteriaQuery cq = new CriteriaQuery(TBExchangeAccountLogEntity.class, dataGrid);
  122. //查询条件组装器
  123. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBExchangeAccountLog, request.getParameterMap());
  124. try{
  125. //自定义追加查询条件
  126. }catch (Exception e) {
  127. throw new BusinessException(e.getMessage());
  128. }
  129. cq.add();
  130. this.tBExchangeAccountLogService.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(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest request) {
  141. String message = null;
  142. AjaxJson j = new AjaxJson();
  143. tBExchangeAccountLog = systemService.getEntity(TBExchangeAccountLogEntity.class, tBExchangeAccountLog.getId());
  144. message = "调休账户日志删除成功";
  145. try{
  146. tBExchangeAccountLogService.delete(tBExchangeAccountLog);
  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. TBExchangeAccountLogEntity tBExchangeAccountLog = systemService.getEntity(TBExchangeAccountLogEntity.class,
  170. id
  171. );
  172. tBExchangeAccountLogService.delete(tBExchangeAccountLog);
  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(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest request) {
  192. String message = null;
  193. AjaxJson j = new AjaxJson();
  194. message = "调休账户日志添加成功";
  195. try{
  196. tBExchangeAccountLogService.save(tBExchangeAccountLog);
  197. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  198. }catch(Exception e){
  199. e.printStackTrace();
  200. message = "调休账户日志添加失败";
  201. throw new BusinessException(e.getMessage());
  202. }
  203. j.setMsg(message);
  204. return j;
  205. }
  206. /**
  207. * 更新调休账户日志
  208. *
  209. * @param ids
  210. * @return
  211. */
  212. @RequestMapping(params = "doUpdate")
  213. @ResponseBody
  214. public AjaxJson doUpdate(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest request) {
  215. String message = null;
  216. AjaxJson j = new AjaxJson();
  217. message = "调休账户日志更新成功";
  218. TBExchangeAccountLogEntity t = tBExchangeAccountLogService.get(TBExchangeAccountLogEntity.class, tBExchangeAccountLog.getId());
  219. try {
  220. MyBeanUtils.copyBeanNotNull2Bean(tBExchangeAccountLog, t);
  221. tBExchangeAccountLogService.saveOrUpdate(t);
  222. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  223. } catch (Exception e) {
  224. e.printStackTrace();
  225. message = "调休账户日志更新失败";
  226. throw new BusinessException(e.getMessage());
  227. }
  228. j.setMsg(message);
  229. return j;
  230. }
  231. /**
  232. * 调休账户日志新增页面跳转
  233. *
  234. * @return
  235. */
  236. @RequestMapping(params = "goAdd")
  237. public ModelAndView goAdd(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest req) {
  238. if (StringUtil.isNotEmpty(tBExchangeAccountLog.getId())) {
  239. tBExchangeAccountLog = tBExchangeAccountLogService.getEntity(TBExchangeAccountLogEntity.class, tBExchangeAccountLog.getId());
  240. req.setAttribute("tBExchangeAccountLogPage", tBExchangeAccountLog);
  241. }
  242. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccountLog-add");
  243. }
  244. /**
  245. * 调休账户日志编辑页面跳转
  246. *
  247. * @return
  248. */
  249. @RequestMapping(params = "goUpdate")
  250. public ModelAndView goUpdate(TBExchangeAccountLogEntity tBExchangeAccountLog, HttpServletRequest req) {
  251. if (StringUtil.isNotEmpty(tBExchangeAccountLog.getId())) {
  252. tBExchangeAccountLog = tBExchangeAccountLogService.getEntity(TBExchangeAccountLogEntity.class, tBExchangeAccountLog.getId());
  253. req.setAttribute("tBExchangeAccountLogPage", tBExchangeAccountLog);
  254. }
  255. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccountLog-update");
  256. }
  257. /**
  258. * 导入功能跳转
  259. *
  260. * @return
  261. */
  262. @RequestMapping(params = "upload")
  263. public ModelAndView upload(HttpServletRequest req) {
  264. req.setAttribute("controller_name","tBExchangeAccountLogController");
  265. return new ModelAndView("common/upload/pub_excel_upload");
  266. }
  267. /**
  268. * 导出excel
  269. *
  270. * @param request
  271. * @param response
  272. */
  273. @RequestMapping(params = "exportXls")
  274. public String exportXls(TBExchangeAccountLogEntity tBExchangeAccountLog,HttpServletRequest request,HttpServletResponse response
  275. , DataGrid dataGrid,ModelMap modelMap) {
  276. CriteriaQuery cq = new CriteriaQuery(TBExchangeAccountLogEntity.class, dataGrid);
  277. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBExchangeAccountLog, request.getParameterMap());
  278. List<TBExchangeAccountLogEntity> tBExchangeAccountLogs = this.tBExchangeAccountLogService.getListByCriteriaQuery(cq,false);
  279. modelMap.put(NormalExcelConstants.FILE_NAME,"调休账户日志");
  280. modelMap.put(NormalExcelConstants.CLASS,TBExchangeAccountLogEntity.class);
  281. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("调休账户日志列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  282. "导出信息"));
  283. modelMap.put(NormalExcelConstants.DATA_LIST,tBExchangeAccountLogs);
  284. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  285. }
  286. /**
  287. * 导出excel 使模板
  288. *
  289. * @param request
  290. * @param response
  291. */
  292. @RequestMapping(params = "exportXlsByT")
  293. public String exportXlsByT(TBExchangeAccountLogEntity tBExchangeAccountLog,HttpServletRequest request,HttpServletResponse response
  294. , DataGrid dataGrid,ModelMap modelMap) {
  295. modelMap.put(NormalExcelConstants.FILE_NAME,"调休账户日志");
  296. modelMap.put(NormalExcelConstants.CLASS,TBExchangeAccountLogEntity.class);
  297. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("调休账户日志列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  298. "导出信息"));
  299. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  300. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  301. }
  302. @SuppressWarnings("unchecked")
  303. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  304. @ResponseBody
  305. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  306. AjaxJson j = new AjaxJson();
  307. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  308. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  309. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  310. MultipartFile file = entity.getValue();// 获取上传文件对象
  311. ImportParams params = new ImportParams();
  312. params.setTitleRows(2);
  313. params.setHeadRows(1);
  314. params.setNeedSave(true);
  315. try {
  316. List<TBExchangeAccountLogEntity> listTBExchangeAccountLogEntitys = ExcelImportUtil.importExcel(file.getInputStream(),TBExchangeAccountLogEntity.class,params);
  317. for (TBExchangeAccountLogEntity tBExchangeAccountLog : listTBExchangeAccountLogEntitys) {
  318. tBExchangeAccountLogService.save(tBExchangeAccountLog);
  319. }
  320. j.setMsg("文件导入成功!");
  321. } catch (Exception e) {
  322. j.setMsg("文件导入失败!");
  323. logger.error(ExceptionUtil.getExceptionMessage(e));
  324. }finally{
  325. try {
  326. file.getInputStream().close();
  327. } catch (IOException e) {
  328. e.printStackTrace();
  329. }
  330. }
  331. }
  332. return j;
  333. }
  334. @RequestMapping(method = RequestMethod.GET)
  335. @ResponseBody
  336. public List<TBExchangeAccountLogEntity> list() {
  337. List<TBExchangeAccountLogEntity> listTBExchangeAccountLogs=tBExchangeAccountLogService.getList(TBExchangeAccountLogEntity.class);
  338. return listTBExchangeAccountLogs;
  339. }
  340. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  341. @ResponseBody
  342. public ResponseEntity<?> get(@PathVariable("id") String id) {
  343. TBExchangeAccountLogEntity task = tBExchangeAccountLogService.get(TBExchangeAccountLogEntity.class, id);
  344. if (task == null) {
  345. return new ResponseEntity(HttpStatus.NOT_FOUND);
  346. }
  347. return new ResponseEntity(task, HttpStatus.OK);
  348. }
  349. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  350. @ResponseBody
  351. public ResponseEntity<?> create(@RequestBody TBExchangeAccountLogEntity tBExchangeAccountLog, UriComponentsBuilder uriBuilder) {
  352. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  353. Set<ConstraintViolation<TBExchangeAccountLogEntity>> failures = validator.validate(tBExchangeAccountLog);
  354. if (!failures.isEmpty()) {
  355. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  356. }
  357. //保存
  358. try{
  359. tBExchangeAccountLogService.save(tBExchangeAccountLog);
  360. } catch (Exception e) {
  361. e.printStackTrace();
  362. return new ResponseEntity(HttpStatus.NO_CONTENT);
  363. }
  364. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  365. String id = tBExchangeAccountLog.getId();
  366. URI uri = uriBuilder.path("/rest/tBExchangeAccountLogController/" + id).build().toUri();
  367. HttpHeaders headers = new HttpHeaders();
  368. headers.setLocation(uri);
  369. return new ResponseEntity(headers, HttpStatus.CREATED);
  370. }
  371. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  372. public ResponseEntity<?> update(@RequestBody TBExchangeAccountLogEntity tBExchangeAccountLog) {
  373. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  374. Set<ConstraintViolation<TBExchangeAccountLogEntity>> failures = validator.validate(tBExchangeAccountLog);
  375. if (!failures.isEmpty()) {
  376. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  377. }
  378. //保存
  379. try{
  380. tBExchangeAccountLogService.saveOrUpdate(tBExchangeAccountLog);
  381. } catch (Exception e) {
  382. e.printStackTrace();
  383. return new ResponseEntity(HttpStatus.NO_CONTENT);
  384. }
  385. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  386. return new ResponseEntity(HttpStatus.NO_CONTENT);
  387. }
  388. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  389. @ResponseStatus(HttpStatus.NO_CONTENT)
  390. public void delete(@PathVariable("id") String id) {
  391. tBExchangeAccountLogService.deleteEntityById(TBExchangeAccountLogEntity.class, id);
  392. }
  393. }