BudgetEntityController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package cn.com.lzt.budget.entity.controller;
  2. import cn.com.lzt.budget.control.entity.BudgetControlEntity;
  3. import cn.com.lzt.budget.data.util.BudgetConstant;
  4. import cn.com.lzt.budget.entity.entity.BudgetEntity;
  5. import cn.com.lzt.budget.entity.service.BudgetEntityServiceI;
  6. import cn.com.lzt.budget.tempsheet.entity.BudgetTempSheetEntity;
  7. import org.apache.commons.lang.StringUtils;
  8. import org.apache.log4j.Logger;
  9. import org.jeecgframework.core.beanvalidator.BeanValidators;
  10. import org.jeecgframework.core.common.controller.BaseController;
  11. import org.jeecgframework.core.common.exception.BusinessException;
  12. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  13. import org.jeecgframework.core.common.model.json.AjaxJson;
  14. import org.jeecgframework.core.common.model.json.DataGrid;
  15. import org.jeecgframework.core.constant.Globals;
  16. import org.jeecgframework.core.util.ExceptionUtil;
  17. import org.jeecgframework.core.util.MyBeanUtils;
  18. import org.jeecgframework.core.util.ResourceUtil;
  19. import org.jeecgframework.core.util.StringUtil;
  20. import org.jeecgframework.poi.excel.ExcelImportUtil;
  21. import org.jeecgframework.poi.excel.entity.ExportParams;
  22. import org.jeecgframework.poi.excel.entity.ImportParams;
  23. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  24. import org.jeecgframework.tag.core.easyui.TagUtil;
  25. import org.jeecgframework.web.system.service.SystemService;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.http.HttpHeaders;
  28. import org.springframework.http.HttpStatus;
  29. import org.springframework.http.MediaType;
  30. import org.springframework.http.ResponseEntity;
  31. import org.springframework.stereotype.Controller;
  32. import org.springframework.ui.ModelMap;
  33. import org.springframework.web.bind.annotation.*;
  34. import org.springframework.web.multipart.MultipartFile;
  35. import org.springframework.web.multipart.MultipartHttpServletRequest;
  36. import org.springframework.web.servlet.ModelAndView;
  37. import org.springframework.web.util.UriComponentsBuilder;
  38. import javax.servlet.http.HttpServletRequest;
  39. import javax.servlet.http.HttpServletResponse;
  40. import javax.validation.ConstraintViolation;
  41. import javax.validation.Validator;
  42. import java.io.IOException;
  43. import java.net.URI;
  44. import java.util.*;
  45. /**
  46. * @Title: Controller
  47. * @Description: 预算主体
  48. * @author onlineGenerator
  49. * @date 2020-06-28 20:13:45
  50. * @version V1.0
  51. *
  52. */
  53. @Controller
  54. @RequestMapping("/budgetEntityController")
  55. public class BudgetEntityController extends BaseController {
  56. /**
  57. * Logger for this class
  58. */
  59. private static final Logger logger = Logger.getLogger(BudgetEntityController.class);
  60. @Autowired
  61. private BudgetEntityServiceI budgetEntityService;
  62. @Autowired
  63. private SystemService systemService;
  64. @Autowired
  65. private Validator validator;
  66. /**
  67. * 预算主体列表 页面跳转
  68. *
  69. * @return
  70. */
  71. @RequestMapping(params = "list")
  72. public ModelAndView list(HttpServletRequest request) {
  73. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntityList");
  74. }
  75. /**
  76. * easyui AJAX请求数据
  77. *
  78. * @param request
  79. * @param response
  80. * @param dataGrid
  81. */
  82. @RequestMapping(params = "datagrid")
  83. public void datagrid(BudgetEntity budgetEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  84. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  85. if(StringUtil.isNotEmpty(budgetEntity.getId())){
  86. cq.eq("parentId", budgetEntity.getId());
  87. budgetEntity.setId(null);
  88. }
  89. if(StringUtils.isNotBlank(budgetEntity.getEntityName())){
  90. cq.like("entityName", "%"+ budgetEntity.getEntityName()+"%");
  91. budgetEntity.setEntityName(null);
  92. }
  93. if(StringUtils.isNotBlank(budgetEntity.getEntityUserRealname())){
  94. cq.like("entityUserRealname", "%"+ budgetEntity.getEntityUserRealname()+"%");
  95. budgetEntity.setEntityUserRealname(null);
  96. }
  97. //查询条件组装器
  98. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetEntity, request.getParameterMap());
  99. try{
  100. //自定义追加查询条件
  101. }catch (Exception e) {
  102. throw new BusinessException(e.getMessage());
  103. }
  104. cq.add();
  105. this.budgetEntityService.getDataGridReturn(cq, false);
  106. TagUtil.treegrid(response, dataGrid);
  107. }
  108. /**
  109. * 删除预算主体
  110. *
  111. * @return
  112. */
  113. @RequestMapping(params = "doDel")
  114. @ResponseBody
  115. public AjaxJson doDel(BudgetEntity budgetDept, HttpServletRequest request) {
  116. String message = null;
  117. AjaxJson j = new AjaxJson();
  118. budgetDept = systemService.getEntity(BudgetEntity.class, budgetDept.getId());
  119. message = "预算主体删除成功";
  120. try{
  121. budgetEntityService.delete(budgetDept);
  122. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  123. }catch (IllegalStateException e){
  124. message =e.getMessage();
  125. }catch(Exception e){
  126. e.printStackTrace();
  127. message = "预算主体删除失败";
  128. throw new BusinessException(e.getMessage());
  129. }
  130. j.setMsg(message);
  131. return j;
  132. }
  133. /**
  134. * 批量删除预算主体
  135. *
  136. * @return
  137. */
  138. @RequestMapping(params = "doBatchDel")
  139. @ResponseBody
  140. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  141. String message = null;
  142. AjaxJson j = new AjaxJson();
  143. message = "预算主体删除成功";
  144. try{
  145. for(String id:ids.split(",")){
  146. BudgetEntity budgetDept = systemService.getEntity(BudgetEntity.class,
  147. id
  148. );
  149. budgetEntityService.delete(budgetDept);
  150. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  151. }
  152. }catch(Exception e){
  153. e.printStackTrace();
  154. message = "预算主体删除失败";
  155. throw new BusinessException(e.getMessage());
  156. }
  157. j.setMsg(message);
  158. return j;
  159. }
  160. /**
  161. * 添加预算主体
  162. *
  163. * @return
  164. */
  165. @RequestMapping(params = "doAdd")
  166. @ResponseBody
  167. public AjaxJson doAdd(BudgetEntity budgetDept, HttpServletRequest request) {
  168. if(StringUtils.isNotBlank(budgetDept.getId())){
  169. return doUpdate(budgetDept,request);
  170. }
  171. String message = null;
  172. AjaxJson j = new AjaxJson();
  173. message = "预算主体添加成功";
  174. try{
  175. if(StringUtil.isEmpty(budgetDept.getParentId())){
  176. budgetDept.setParentId(null);
  177. }
  178. budgetEntityService.save(budgetDept);
  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. *
  191. * @return
  192. */
  193. @RequestMapping(params = "doUpdate")
  194. @ResponseBody
  195. public AjaxJson doUpdate(BudgetEntity budgetDept, HttpServletRequest request) {
  196. String message = null;
  197. AjaxJson j = new AjaxJson();
  198. message = "预算主体更新成功";
  199. BudgetEntity t = budgetEntityService.get(BudgetEntity.class, budgetDept.getId());
  200. try {
  201. MyBeanUtils.copyBeanNotNull2Bean(budgetDept, t);
  202. if(StringUtil.isEmpty(t.getParentId())){
  203. t.setParentId(null);
  204. }
  205. budgetEntityService.saveOrUpdate(t);
  206. systemService.addLog(message, Globals.Log_Type_UPDATE, 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 = "goAdd")
  221. public ModelAndView goAdd(BudgetEntity budgetDept, HttpServletRequest req) {
  222. if (StringUtil.isNotEmpty(budgetDept.getId())) {
  223. budgetDept = budgetEntityService.getEntity(BudgetEntity.class, budgetDept.getId());
  224. req.setAttribute("budgetDeptPage", budgetDept);
  225. }
  226. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntity-add");
  227. }
  228. /**
  229. * 预算主体编辑页面跳转
  230. *
  231. * @return
  232. */
  233. @RequestMapping(params = "goUpdate")
  234. public ModelAndView goUpdate(BudgetEntity budgetDept, HttpServletRequest req) {
  235. if (StringUtil.isNotEmpty(budgetDept.getId())) {
  236. budgetDept = budgetEntityService.getEntity(BudgetEntity.class, budgetDept.getId());
  237. req.setAttribute("entity", budgetDept);
  238. }
  239. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntity-add");
  240. }
  241. /**
  242. * 导入功能跳转
  243. *
  244. * @return
  245. */
  246. @RequestMapping(params = "upload")
  247. public ModelAndView upload(HttpServletRequest req) {
  248. req.setAttribute("controller_name","budgetEntityController");
  249. return new ModelAndView("common/upload/pub_excel_upload");
  250. }
  251. /**
  252. * 导出excel
  253. *
  254. * @param request
  255. * @param response
  256. */
  257. @RequestMapping(params = "exportXls")
  258. public String exportXls(BudgetEntity budgetDept, HttpServletRequest request, HttpServletResponse response
  259. , DataGrid dataGrid, ModelMap modelMap) {
  260. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  261. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetDept, request.getParameterMap());
  262. List<BudgetEntity> budgetDepts = this.budgetEntityService.getListByCriteriaQuery(cq,false);
  263. modelMap.put(NormalExcelConstants.FILE_NAME,"预算主体");
  264. modelMap.put(NormalExcelConstants.CLASS,BudgetEntity.class);
  265. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("预算主体列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  266. "导出信息"));
  267. modelMap.put(NormalExcelConstants.DATA_LIST,budgetDepts);
  268. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  269. }
  270. /**
  271. * 导出excel 使模板
  272. *
  273. * @param request
  274. * @param response
  275. */
  276. @RequestMapping(params = "exportXlsByT")
  277. public String exportXlsByT(BudgetEntity budgetDept, HttpServletRequest request, HttpServletResponse response
  278. , DataGrid dataGrid, ModelMap modelMap) {
  279. modelMap.put(NormalExcelConstants.FILE_NAME,"预算主体");
  280. modelMap.put(NormalExcelConstants.CLASS,BudgetEntity.class);
  281. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("预算主体列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  282. "导出信息"));
  283. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  284. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  285. }
  286. @SuppressWarnings("unchecked")
  287. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  288. @ResponseBody
  289. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  290. AjaxJson j = new AjaxJson();
  291. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  292. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  293. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  294. MultipartFile file = entity.getValue();// 获取上传文件对象
  295. ImportParams params = new ImportParams();
  296. params.setTitleRows(2);
  297. params.setHeadRows(1);
  298. params.setNeedSave(true);
  299. try {
  300. List<BudgetEntity> listBudgetEntities = ExcelImportUtil.importExcel(file.getInputStream(),BudgetEntity.class,params);
  301. for (BudgetEntity budgetDept : listBudgetEntities) {
  302. budgetEntityService.save(budgetDept);
  303. }
  304. j.setMsg("文件导入成功!");
  305. } catch (Exception e) {
  306. j.setMsg("文件导入失败!");
  307. logger.error(ExceptionUtil.getExceptionMessage(e));
  308. }finally{
  309. try {
  310. file.getInputStream().close();
  311. } catch (IOException e) {
  312. e.printStackTrace();
  313. }
  314. }
  315. }
  316. return j;
  317. }
  318. @RequestMapping(method = RequestMethod.GET)
  319. @ResponseBody
  320. public List<BudgetEntity> list() {
  321. List<BudgetEntity> listBudgetDepts=budgetEntityService.getList(BudgetEntity.class);
  322. return listBudgetDepts;
  323. }
  324. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  325. @ResponseBody
  326. public ResponseEntity<?> get(@PathVariable("id") String id) {
  327. BudgetEntity task = budgetEntityService.get(BudgetEntity.class, id);
  328. if (task == null) {
  329. return new ResponseEntity(HttpStatus.NOT_FOUND);
  330. }
  331. return new ResponseEntity(task, HttpStatus.OK);
  332. }
  333. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  334. @ResponseBody
  335. public ResponseEntity<?> create(@RequestBody BudgetEntity budgetDept, UriComponentsBuilder uriBuilder) {
  336. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  337. Set<ConstraintViolation<BudgetEntity>> failures = validator.validate(budgetDept);
  338. if (!failures.isEmpty()) {
  339. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  340. }
  341. //保存
  342. try{
  343. budgetEntityService.save(budgetDept);
  344. } catch (Exception e) {
  345. e.printStackTrace();
  346. return new ResponseEntity(HttpStatus.NO_CONTENT);
  347. }
  348. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  349. String id = budgetDept.getId();
  350. URI uri = uriBuilder.path("/rest/budgetEntityController/" + id).build().toUri();
  351. HttpHeaders headers = new HttpHeaders();
  352. headers.setLocation(uri);
  353. return new ResponseEntity(headers, HttpStatus.CREATED);
  354. }
  355. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  356. public ResponseEntity<?> update(@RequestBody BudgetEntity budgetDept) {
  357. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  358. Set<ConstraintViolation<BudgetEntity>> failures = validator.validate(budgetDept);
  359. if (!failures.isEmpty()) {
  360. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  361. }
  362. //保存
  363. try{
  364. budgetEntityService.saveOrUpdate(budgetDept);
  365. } catch (Exception e) {
  366. e.printStackTrace();
  367. return new ResponseEntity(HttpStatus.NO_CONTENT);
  368. }
  369. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  370. return new ResponseEntity(HttpStatus.NO_CONTENT);
  371. }
  372. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  373. @ResponseStatus(HttpStatus.NO_CONTENT)
  374. public void delete(@PathVariable("id") String id) {
  375. budgetEntityService.deleteEntityById(BudgetEntity.class, id);
  376. }
  377. @RequestMapping(params = "select")
  378. public ModelAndView select(HttpServletRequest request) {
  379. String excludeIds = request.getParameter("excludeIds");
  380. request.getSession().setAttribute("budgetEntitySelectExcludeIds", excludeIds);
  381. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntity-select");
  382. }
  383. /**
  384. * easyui AJAX请求数据
  385. *
  386. * @param request
  387. * @param response
  388. * @param dataGrid
  389. */
  390. @RequestMapping(params = "selectDatagrid")
  391. public void selectDatagrid(BudgetEntity budgetEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  392. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  393. if(StringUtil.isEmpty(budgetEntity.getId())){
  394. cq.isNull("parentId");
  395. }else{
  396. cq.eq("parentId", budgetEntity.getId());
  397. budgetEntity.setId(null);
  398. }
  399. String tempSheetId = request.getParameter("tempSheetId");
  400. List<String> entityIdList = Collections.emptyList();
  401. if(StringUtils.isNotBlank(tempSheetId)) {
  402. BudgetTempSheetEntity tempSheetEntity = systemService.getEntity(BudgetTempSheetEntity.class, tempSheetId);
  403. Integer actual = tempSheetEntity.getActual();
  404. String type = tempSheetEntity.getType();
  405. if (actual == 1 && StringUtils.equals(type, BudgetConstant.TEMPSHEET_TYPE_ACTUAL_STA)) {//执行统计表只能下发公司主体
  406. cq.eq("id", BudgetConstant.COMPANY_ENTITY_ID);
  407. }
  408. String sql = "select distinct entity_id from t_b_budget_inst where tempsheet_id =? and status<>? ";
  409. entityIdList = systemService.findListbySql(sql,tempSheetId,BudgetConstant.INST_STATUS_FROZEN);
  410. }
  411. String publish = request.getParameter("publish");
  412. if(StringUtils.isNotBlank(budgetEntity.getDepName())){
  413. cq.like("depName", "%"+budgetEntity.getDepName()+"%");
  414. budgetEntity.setDepName(null);
  415. }
  416. //排除列表
  417. String excludeIds = (String) request.getSession().getAttribute("budgetEntitySelectExcludeIds");
  418. if(StringUtils.isNotBlank(excludeIds)){
  419. cq.notin("id", excludeIds.split(","));
  420. request.getSession().removeAttribute("budgetEntitySelectExcludeIds");
  421. }
  422. //查询条件组装器
  423. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetEntity, request.getParameterMap());
  424. try{
  425. if(StringUtils.equals(publish,"1" )){//下发
  426. if(!entityIdList.isEmpty()){
  427. cq.notin("id",entityIdList.toArray());
  428. }
  429. }else if(StringUtils.equals(publish,"0")){//撤回
  430. if(StringUtils.isNotBlank(tempSheetId)) {//填报列表 查询用
  431. if (!entityIdList.isEmpty()) {
  432. cq.in("id", entityIdList.toArray());
  433. } else {//空list 应该没有记录
  434. cq.eq("id", "-1");
  435. }
  436. }
  437. }
  438. }catch (Exception e) {
  439. throw new BusinessException(e.getMessage());
  440. }
  441. cq.add();
  442. this.budgetEntityService.getDataGridReturn(cq, false);
  443. TagUtil.treegrid(response, dataGrid);
  444. }
  445. @RequestMapping(params = "selectByTempSheet")
  446. public ModelAndView selectByTempSheet(HttpServletRequest request) {
  447. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntity-selectByTempSheet");
  448. }
  449. /**
  450. * easyui AJAX请求数据
  451. *
  452. * @param request
  453. * @param response
  454. * @param dataGrid
  455. */
  456. @RequestMapping(params = "selectByTempSheetDatagrid")
  457. public void selectByTempSheetDatagrid(BudgetEntity budgetDept, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  458. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  459. //查询条件组装器
  460. // org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetDept, request.getParameterMap());
  461. try{
  462. String type = request.getParameter("type");
  463. if(StringUtils.equals(type,"cost")){
  464. String costBreakdownId = request.getParameter("costBreakdownId");
  465. String sql = "select distinct entity_id from t_b_budget_cost_breakdown_measure " +
  466. " where cost_breakdown_id=? ";
  467. List<String> idList = systemService.findListbySql(sql, costBreakdownId);
  468. if (idList.isEmpty()) {
  469. cq.eq("id", "-1");
  470. } else {
  471. cq.in("id", idList.toArray());
  472. }
  473. }else {
  474. String tempSheetId = request.getParameter("tempSheetId");
  475. String sql = "select dd.entity_id from t_b_budget_inst dd " +
  476. " where dd.tempsheet_id='%s'";
  477. List<String> idList = systemService.findListbySql(String.format(sql, tempSheetId));
  478. if (idList.isEmpty()) {
  479. cq.eq("id", "-1");
  480. } else {
  481. cq.in("id", idList.toArray());
  482. }
  483. }
  484. }catch (Exception e) {
  485. throw new BusinessException(e.getMessage());
  486. }
  487. cq.add();
  488. this.budgetEntityService.getDataGridReturn(cq, false);
  489. TagUtil.treegrid(response, dataGrid);
  490. }
  491. @RequestMapping(params = "autoGen")
  492. @ResponseBody
  493. public AjaxJson autoGen(HttpServletRequest request) {
  494. String message = null;
  495. AjaxJson j = new AjaxJson();
  496. message="生成成功";
  497. try{
  498. budgetEntityService.autoGen();
  499. }catch(Exception e){
  500. message="生成失败";
  501. e.printStackTrace();
  502. throw new BusinessException(e.getMessage());
  503. }
  504. j.setMsg(message);
  505. return j;
  506. }
  507. @RequestMapping(params = "getMapPoint4Postnum")
  508. @ResponseBody
  509. public AjaxJson estimate(HttpServletRequest request) {
  510. AjaxJson j = new AjaxJson();
  511. String sql = "select entity.id,entity.entity_name,project.lnglat " +
  512. " from t_b_budget_entity entity ,t_s_depart depart ,t_b_project project " +
  513. " where entity.depart_id = depart.id and depart.projectid = project.id ";
  514. List<Object[]> entityLnglatList = systemService.findListbySql(sql);
  515. j.setObj(entityLnglatList);
  516. return j;
  517. }
  518. /**
  519. * 预算控制选择
  520. * @param request
  521. * @return
  522. */
  523. @RequestMapping(params = "select4control")
  524. public ModelAndView select4control(HttpServletRequest request) {
  525. String excludeIds = request.getParameter("excludeIds");
  526. request.getSession().setAttribute("budgetEntitySelectExcludeIds", excludeIds);
  527. return new ModelAndView("cn/com/lzt/budget/entity/budgetEntity-select4control");
  528. }
  529. /**
  530. * easyui AJAX请求数据
  531. *
  532. * @param request
  533. * @param response
  534. * @param dataGrid
  535. */
  536. @RequestMapping(params = "selectDatagrid4control")
  537. public void selectDatagrid4control(BudgetEntity budgetEntity, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  538. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  539. if(StringUtil.isEmpty(budgetEntity.getId())){
  540. cq.isNull("parentId");
  541. }else{
  542. cq.eq("parentId", budgetEntity.getId());
  543. budgetEntity.setId(null);
  544. }
  545. String controlId = request.getParameter("controlId");
  546. BudgetControlEntity controlEntity = systemService.getEntity(BudgetControlEntity.class, controlId);
  547. String sql = "select distinct entity_id from t_b_budget_control_publish where control_type=? ";
  548. List<String> entityIdList = systemService.findListbySql(sql,controlEntity.getType());
  549. String publish = request.getParameter("publish");
  550. if(StringUtils.isNotBlank(budgetEntity.getDepName())){
  551. cq.like("depName", "%"+budgetEntity.getDepName()+"%");
  552. budgetEntity.setDepName(null);
  553. }
  554. //排除列表
  555. String excludeIds = (String) request.getSession().getAttribute("budgetEntitySelectExcludeIds");
  556. if(StringUtils.isNotBlank(excludeIds)){
  557. cq.notin("id", excludeIds.split(","));
  558. request.getSession().removeAttribute("budgetEntitySelectExcludeIds");
  559. }
  560. //查询条件组装器
  561. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetEntity, request.getParameterMap());
  562. try{
  563. if(StringUtils.equals(publish,"1" )){//下发
  564. if(!entityIdList.isEmpty()){
  565. cq.notin("id",entityIdList.toArray());
  566. }
  567. }else if(StringUtils.equals(publish,"0")){//撤回
  568. sql = "select distinct entity_id from t_b_budget_control_publish where control_id=? ";
  569. entityIdList = systemService.findListbySql(sql,controlId);
  570. if (!entityIdList.isEmpty()) {
  571. cq.in("id", entityIdList.toArray());
  572. } else {//空list 应该没有记录
  573. cq.eq("id", "-1");
  574. }
  575. }
  576. }catch (Exception e) {
  577. throw new BusinessException(e.getMessage());
  578. }
  579. cq.add();
  580. this.budgetEntityService.getDataGridReturn(cq, false);
  581. TagUtil.treegrid(response, dataGrid);
  582. }
  583. }