TBCostPettyCashAccountController.java 16 KB

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