BudgetWriteBackLogController.java 14 KB

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