TBExchangeAccountController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. package cn.com.lzt.exchangeaccount.controller;
  2. import cn.com.lzt.common.util.UserUtil;
  3. import cn.com.lzt.exchangeaccount.dao.ExchangeAccountDao;
  4. import cn.com.lzt.exchangeaccount.dto.ExchangeAccountDto;
  5. import cn.com.lzt.exchangeaccount.entity.TBExchangeAccountEntity;
  6. import cn.com.lzt.exchangeaccount.service.TBExchangeAccountServiceI;
  7. import java.text.ParseException;
  8. import java.util.*;
  9. import java.text.SimpleDateFormat;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import cn.com.lzt.useractiviti.data.dao.UseractivitiDataDao;
  13. import org.apache.commons.lang.StringUtils;
  14. import org.apache.log4j.Logger;
  15. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  16. import org.jeecgframework.web.system.pojo.base.TSUser;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.ui.ModelMap;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.servlet.ModelAndView;
  22. import org.jeecgframework.core.common.controller.BaseController;
  23. import org.jeecgframework.core.common.exception.BusinessException;
  24. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  25. import org.jeecgframework.core.common.model.common.TreeChildCount;
  26. import org.jeecgframework.core.common.model.json.AjaxJson;
  27. import org.jeecgframework.core.common.model.json.DataGrid;
  28. import org.jeecgframework.core.constant.Globals;
  29. import org.jeecgframework.core.util.StringUtil;
  30. import org.jeecgframework.tag.core.easyui.TagUtil;
  31. import org.jeecgframework.web.system.pojo.base.TSDepart;
  32. import org.jeecgframework.web.system.service.SystemService;
  33. import org.jeecgframework.core.util.MyBeanUtils;
  34. import java.io.OutputStream;
  35. import org.jeecgframework.core.util.BrowserUtils;
  36. import org.jeecgframework.poi.excel.ExcelExportUtil;
  37. import org.jeecgframework.poi.excel.ExcelImportUtil;
  38. import org.jeecgframework.poi.excel.entity.ExportParams;
  39. import org.jeecgframework.poi.excel.entity.ImportParams;
  40. import org.jeecgframework.poi.excel.entity.TemplateExportParams;
  41. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  42. import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
  43. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  44. import org.jeecgframework.core.util.ResourceUtil;
  45. import java.io.IOException;
  46. import org.springframework.web.multipart.MultipartFile;
  47. import org.springframework.web.multipart.MultipartHttpServletRequest;
  48. import org.jeecgframework.core.util.ExceptionUtil;
  49. import org.springframework.http.ResponseEntity;
  50. import org.springframework.stereotype.Controller;
  51. import org.springframework.web.bind.annotation.RequestMapping;
  52. import org.springframework.web.bind.annotation.RequestMethod;
  53. import org.springframework.web.bind.annotation.ResponseBody;
  54. import org.springframework.http.HttpHeaders;
  55. import org.springframework.http.HttpStatus;
  56. import org.jeecgframework.core.beanvalidator.BeanValidators;
  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-10-17 21:14:51
  67. * @version V1.0
  68. *
  69. */
  70. @Controller
  71. @RequestMapping("/tBExchangeAccountController")
  72. public class TBExchangeAccountController extends BaseController {
  73. /**
  74. * Logger for this class
  75. */
  76. private static final Logger logger = Logger.getLogger(TBExchangeAccountController.class);
  77. @Autowired
  78. private TBExchangeAccountServiceI tBExchangeAccountService;
  79. @Autowired
  80. private SystemService systemService;
  81. @Autowired
  82. private Validator validator;
  83. @Autowired
  84. private ExchangeAccountDao exchangeAccountDao;
  85. @Autowired
  86. private UseractivitiDataDao useractivitiDataDao;
  87. /**
  88. * 调休账户列表 页面跳转
  89. *
  90. * @return
  91. */
  92. @RequestMapping(params = "list")
  93. public ModelAndView list(HttpServletRequest request) {
  94. TSUser user = ResourceUtil.getSessionUser();
  95. boolean projectUser =UserUtil.isProjectUser(user.getId());
  96. request.setAttribute("projectUser", projectUser);
  97. Calendar c = Calendar.getInstance();
  98. request.setAttribute("curYear", c.get(Calendar.YEAR));
  99. if(projectUser) {
  100. TSDepart tsDepart = useractivitiDataDao.getUserDep(user.getId());
  101. request.setAttribute("depart", tsDepart);
  102. }
  103. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccountList");
  104. }
  105. @RequestMapping(params = "listProject")
  106. public ModelAndView listProject(HttpServletRequest request) {
  107. request.setAttribute("projectUser", true);
  108. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccountList_project");
  109. }
  110. /**
  111. * easyui AJAX请求数据
  112. *
  113. * @param request
  114. * @param response
  115. * @param dataGrid
  116. */
  117. @RequestMapping(params = "datagrid")
  118. public void datagrid(ExchangeAccountDto dto, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  119. TSUser user = ResourceUtil.getSessionUser();
  120. boolean projectUser =UserUtil.isProjectUser(user.getId());
  121. if(projectUser){
  122. dto.setLoginUserId(user.getId());
  123. }
  124. if(StringUtils.isBlank(request.getParameter("departname"))){
  125. dto.setDepartId(null);
  126. }
  127. MiniDaoPage<ExchangeAccountDto> list = exchangeAccountDao.getAccountList(dto, 1,Integer.MAX_VALUE);
  128. dataGrid.setResults(list.getResults());
  129. TagUtil.datagrid(response, dataGrid);
  130. }
  131. @RequestMapping(params = "datagridProject")
  132. public void datagridProject(ExchangeAccountDto dto, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  133. TSUser user = ResourceUtil.getSessionUser();
  134. boolean projectUser =UserUtil.isProjectUser(user.getId());
  135. if(projectUser){
  136. dto.setLoginUserId(user.getId());
  137. }
  138. MiniDaoPage<ExchangeAccountDto> list = exchangeAccountDao.getAccountList(dto, dataGrid.getPage(), dataGrid.getRows());
  139. dataGrid.setTotal(list.getTotal());
  140. dataGrid.setResults(list.getResults());
  141. TagUtil.datagrid(response, dataGrid);
  142. }
  143. /**
  144. * 删除调休账户
  145. *
  146. * @return
  147. */
  148. @RequestMapping(params = "doDel")
  149. @ResponseBody
  150. public AjaxJson doDel(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest request) {
  151. String message = null;
  152. AjaxJson j = new AjaxJson();
  153. tBExchangeAccount = systemService.getEntity(TBExchangeAccountEntity.class, tBExchangeAccount.getId());
  154. message = "调休账户删除成功";
  155. try{
  156. tBExchangeAccountService.delete(tBExchangeAccount);
  157. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  158. }catch(Exception e){
  159. e.printStackTrace();
  160. message = "调休账户删除失败";
  161. throw new BusinessException(e.getMessage());
  162. }
  163. j.setMsg(message);
  164. return j;
  165. }
  166. /**
  167. * 批量删除调休账户
  168. *
  169. * @return
  170. */
  171. @RequestMapping(params = "doBatchDel")
  172. @ResponseBody
  173. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  174. String message = null;
  175. AjaxJson j = new AjaxJson();
  176. message = "调休账户删除成功";
  177. try{
  178. for(String id:ids.split(",")){
  179. TBExchangeAccountEntity tBExchangeAccount = systemService.getEntity(TBExchangeAccountEntity.class,
  180. id
  181. );
  182. tBExchangeAccountService.delete(tBExchangeAccount);
  183. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  184. }
  185. }catch(Exception e){
  186. e.printStackTrace();
  187. message = "调休账户删除失败";
  188. throw new BusinessException(e.getMessage());
  189. }
  190. j.setMsg(message);
  191. return j;
  192. }
  193. /**
  194. * 添加调休账户
  195. *
  196. * @return
  197. */
  198. @RequestMapping(params = "doAdd")
  199. @ResponseBody
  200. public AjaxJson doAdd(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest request) {
  201. String message = null;
  202. AjaxJson j = new AjaxJson();
  203. message = "调休账户添加成功";
  204. try{
  205. tBExchangeAccountService.save(tBExchangeAccount);
  206. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  207. }catch(Exception e){
  208. e.printStackTrace();
  209. message = "调休账户添加失败";
  210. throw new BusinessException(e.getMessage());
  211. }
  212. j.setMsg(message);
  213. return j;
  214. }
  215. /**
  216. * 更新调休账户
  217. *
  218. * @return
  219. */
  220. @RequestMapping(params = "doUpdate")
  221. @ResponseBody
  222. public AjaxJson doUpdate(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest request) {
  223. String message = null;
  224. AjaxJson j = new AjaxJson();
  225. message = "调休账户更新成功";
  226. TBExchangeAccountEntity t = tBExchangeAccountService.get(TBExchangeAccountEntity.class, tBExchangeAccount.getId());
  227. try {
  228. MyBeanUtils.copyBeanNotNull2Bean(tBExchangeAccount, t);
  229. tBExchangeAccountService.saveOrUpdate(t);
  230. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  231. } catch (Exception e) {
  232. e.printStackTrace();
  233. message = "调休账户更新失败";
  234. throw new BusinessException(e.getMessage());
  235. }
  236. j.setMsg(message);
  237. return j;
  238. }
  239. /**
  240. * 调休账户新增页面跳转
  241. *
  242. * @return
  243. */
  244. @RequestMapping(params = "goAdd")
  245. public ModelAndView goAdd(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest req) {
  246. if (StringUtil.isNotEmpty(tBExchangeAccount.getId())) {
  247. tBExchangeAccount = tBExchangeAccountService.getEntity(TBExchangeAccountEntity.class, tBExchangeAccount.getId());
  248. req.setAttribute("tBExchangeAccountPage", tBExchangeAccount);
  249. }
  250. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccount-add");
  251. }
  252. @RequestMapping(params = "goClearAccount")
  253. public ModelAndView goClearAccount(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest req) {
  254. return new ModelAndView("cn/com/lzt/exchangeaccount/clear_account");
  255. }
  256. @RequestMapping(params = "goClearLastYearAccount")
  257. public ModelAndView goClearLastYearAccount(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest req) {
  258. return new ModelAndView("cn/com/lzt/exchangeaccount/clear_lastyear_account");
  259. }
  260. /**
  261. * 调休账户编辑页面跳转
  262. *
  263. * @return
  264. */
  265. @RequestMapping(params = "goUpdate")
  266. public ModelAndView goUpdate(TBExchangeAccountEntity tBExchangeAccount, HttpServletRequest req) {
  267. if (StringUtil.isNotEmpty(tBExchangeAccount.getId())) {
  268. tBExchangeAccount = tBExchangeAccountService.getEntity(TBExchangeAccountEntity.class, tBExchangeAccount.getId());
  269. req.setAttribute("tBExchangeAccountPage", tBExchangeAccount);
  270. }
  271. return new ModelAndView("cn/com/lzt/exchangeaccount/tBExchangeAccount-update");
  272. }
  273. /**
  274. * 导入功能跳转
  275. *
  276. * @return
  277. */
  278. @RequestMapping(params = "upload")
  279. public ModelAndView upload(HttpServletRequest req) {
  280. req.setAttribute("controller_name","tBExchangeAccountController");
  281. return new ModelAndView("common/upload/pub_excel_upload");
  282. }
  283. /**
  284. * 导出excel
  285. *
  286. * @param request
  287. * @param response
  288. */
  289. @RequestMapping(params = "exportXls")
  290. public String exportXls(ExchangeAccountDto dto,HttpServletRequest request,HttpServletResponse response
  291. , DataGrid dataGrid,ModelMap modelMap) {
  292. // CriteriaQuery cq = new CriteriaQuery(TBExchangeAccountEntity.class, dataGrid);
  293. // org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tBExchangeAccount, request.getParameterMap());
  294. // List<TBExchangeAccountEntity> tBExchangeAccounts = this.tBExchangeAccountService.getListByCriteriaQuery(cq,false);
  295. TSUser user = ResourceUtil.getSessionUser();
  296. boolean projectUser =UserUtil.isProjectUser(user.getId());
  297. if(projectUser){
  298. dto.setLoginUserId(user.getId());
  299. }
  300. MiniDaoPage<ExchangeAccountDto> list = exchangeAccountDao.getAccountList(dto, 1, Integer.MAX_VALUE);
  301. modelMap.put(NormalExcelConstants.FILE_NAME,"调休账户");
  302. modelMap.put(NormalExcelConstants.CLASS,ExchangeAccountDto.class);
  303. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("调休账户列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  304. "导出信息"));
  305. modelMap.put(NormalExcelConstants.DATA_LIST,list.getResults());
  306. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  307. }
  308. /**
  309. * 导出excel 使模板
  310. *
  311. * @param request
  312. * @param response
  313. */
  314. @RequestMapping(params = "exportXlsByT")
  315. public String exportXlsByT(TBExchangeAccountEntity tBExchangeAccount,HttpServletRequest request,HttpServletResponse response
  316. , DataGrid dataGrid,ModelMap modelMap) {
  317. modelMap.put(NormalExcelConstants.FILE_NAME,"调休账户");
  318. modelMap.put(NormalExcelConstants.CLASS,TBExchangeAccountEntity.class);
  319. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("调休账户列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  320. "导出信息"));
  321. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  322. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  323. }
  324. @SuppressWarnings("unchecked")
  325. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  326. @ResponseBody
  327. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  328. AjaxJson j = new AjaxJson();
  329. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  330. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  331. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  332. MultipartFile file = entity.getValue();// 获取上传文件对象
  333. ImportParams params = new ImportParams();
  334. params.setTitleRows(2);
  335. params.setHeadRows(1);
  336. params.setNeedSave(true);
  337. try {
  338. List<TBExchangeAccountEntity> listTBExchangeAccountEntitys = ExcelImportUtil.importExcel(file.getInputStream(),TBExchangeAccountEntity.class,params);
  339. for (TBExchangeAccountEntity tBExchangeAccount : listTBExchangeAccountEntitys) {
  340. tBExchangeAccountService.save(tBExchangeAccount);
  341. }
  342. j.setMsg("文件导入成功!");
  343. } catch (Exception e) {
  344. j.setMsg("文件导入失败!");
  345. logger.error(ExceptionUtil.getExceptionMessage(e));
  346. }finally{
  347. try {
  348. file.getInputStream().close();
  349. } catch (IOException e) {
  350. e.printStackTrace();
  351. }
  352. }
  353. }
  354. return j;
  355. }
  356. @RequestMapping(method = RequestMethod.GET)
  357. @ResponseBody
  358. public List<TBExchangeAccountEntity> list() {
  359. List<TBExchangeAccountEntity> listTBExchangeAccounts=tBExchangeAccountService.getList(TBExchangeAccountEntity.class);
  360. return listTBExchangeAccounts;
  361. }
  362. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  363. @ResponseBody
  364. public ResponseEntity<?> get(@PathVariable("id") String id) {
  365. TBExchangeAccountEntity task = tBExchangeAccountService.get(TBExchangeAccountEntity.class, id);
  366. if (task == null) {
  367. return new ResponseEntity(HttpStatus.NOT_FOUND);
  368. }
  369. return new ResponseEntity(task, HttpStatus.OK);
  370. }
  371. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  372. @ResponseBody
  373. public ResponseEntity<?> create(@RequestBody TBExchangeAccountEntity tBExchangeAccount, UriComponentsBuilder uriBuilder) {
  374. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  375. Set<ConstraintViolation<TBExchangeAccountEntity>> failures = validator.validate(tBExchangeAccount);
  376. if (!failures.isEmpty()) {
  377. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  378. }
  379. //保存
  380. try{
  381. tBExchangeAccountService.save(tBExchangeAccount);
  382. } catch (Exception e) {
  383. e.printStackTrace();
  384. return new ResponseEntity(HttpStatus.NO_CONTENT);
  385. }
  386. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  387. String id = tBExchangeAccount.getId();
  388. URI uri = uriBuilder.path("/rest/tBExchangeAccountController/" + id).build().toUri();
  389. HttpHeaders headers = new HttpHeaders();
  390. headers.setLocation(uri);
  391. return new ResponseEntity(headers, HttpStatus.CREATED);
  392. }
  393. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  394. public ResponseEntity<?> update(@RequestBody TBExchangeAccountEntity tBExchangeAccount) {
  395. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  396. Set<ConstraintViolation<TBExchangeAccountEntity>> failures = validator.validate(tBExchangeAccount);
  397. if (!failures.isEmpty()) {
  398. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  399. }
  400. //保存
  401. try{
  402. tBExchangeAccountService.saveOrUpdate(tBExchangeAccount);
  403. } catch (Exception e) {
  404. e.printStackTrace();
  405. return new ResponseEntity(HttpStatus.NO_CONTENT);
  406. }
  407. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  408. return new ResponseEntity(HttpStatus.NO_CONTENT);
  409. }
  410. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  411. @ResponseStatus(HttpStatus.NO_CONTENT)
  412. public void delete(@PathVariable("id") String id) {
  413. tBExchangeAccountService.deleteEntityById(TBExchangeAccountEntity.class, id);
  414. }
  415. @RequestMapping(params = "clearLastYearAccount")
  416. @ResponseBody
  417. public AjaxJson clearLastYearAccount(@RequestParam("yearMonth") String yearMonth,@RequestParam("ids") String ids) {
  418. AjaxJson j = new AjaxJson();
  419. String message = "批量结算成功";
  420. try {
  421. List<String> idList = Arrays.asList(StringUtils.split(ids, ','));
  422. tBExchangeAccountService.clearAccountByIds(idList, yearMonth);
  423. }catch (Exception e){
  424. e.printStackTrace();
  425. message="批量结算失败";
  426. }
  427. j.setMsg(message);
  428. return j;
  429. }
  430. @RequestMapping(params = "clearAccount")
  431. @ResponseBody
  432. public AjaxJson clearAccount(@RequestParam("userId")String userId,@RequestParam("year") String year,@RequestParam("yearMonth") String yearMonth) {
  433. AjaxJson j = new AjaxJson();
  434. String message = "结算账户余额成功";
  435. tBExchangeAccountService.clearAccount(userId,year,yearMonth);
  436. j.setMsg(message);
  437. return j;
  438. }
  439. @RequestMapping(params = "getAccountBalance")
  440. @ResponseBody
  441. public double getAccountBalance(@RequestParam("userId")String userId,@RequestParam("year") String yearMonth) {
  442. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
  443. String year = null;
  444. try {
  445. Date date = format.parse(yearMonth);
  446. year = tBExchangeAccountService.getYear(date);
  447. } catch (ParseException e) {
  448. e.printStackTrace();
  449. }
  450. return tBExchangeAccountService.getBalance(userId,year,null);
  451. }
  452. }