BudgetCostBreakdownController.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. package cn.com.lzt.budget.costbreakdown.controller;
  2. import cn.com.lzt.budget.costbreakdown.entity.BudgetCostBreakdownEntity;
  3. import cn.com.lzt.budget.costbreakdown.service.BudgetCostBreakdownServiceI;
  4. import java.math.BigDecimal;
  5. import java.util.*;
  6. import java.text.SimpleDateFormat;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import cn.com.lzt.budget.costbreakdownmeasure.entity.BudgetCostBreakdownMeasureEntity;
  10. import cn.com.lzt.budget.data.dao.BudgetDataDao;
  11. import cn.com.lzt.budget.data.dto.BudgetCalc;
  12. import cn.com.lzt.budget.data.dto.BudgetContractEntity;
  13. import cn.com.lzt.budget.data.util.BudgetConstant;
  14. import cn.com.lzt.budget.dimfunction.service.BudgetDimFunctionServiceI;
  15. import cn.com.lzt.budget.entity.entity.BudgetEntity;
  16. import cn.com.lzt.budget.inst.entity.BudgetInstEntity;
  17. import cn.com.lzt.budget.instmeasure.entity.BudgetInstMeasureEntity;
  18. import cn.com.lzt.budget.measure.entity.BudgetMeasureEntity;
  19. import cn.com.lzt.common.util.DictUtil;
  20. import org.apache.commons.lang.xwork.StringUtils;
  21. import org.apache.log4j.Logger;
  22. import org.codehaus.jackson.map.ObjectMapper;
  23. import org.jeecgframework.core.aop.HibernateTableRename;
  24. import org.jeecgframework.web.system.pojo.base.TSType;
  25. import org.jeecgframework.web.system.pojo.base.TSUser;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Controller;
  28. import org.springframework.ui.ModelMap;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.ResponseBody;
  31. import org.springframework.web.servlet.ModelAndView;
  32. import org.jeecgframework.core.common.controller.BaseController;
  33. import org.jeecgframework.core.common.exception.BusinessException;
  34. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  35. import org.jeecgframework.core.common.model.common.TreeChildCount;
  36. import org.jeecgframework.core.common.model.json.AjaxJson;
  37. import org.jeecgframework.core.common.model.json.DataGrid;
  38. import org.jeecgframework.core.constant.Globals;
  39. import org.jeecgframework.core.util.StringUtil;
  40. import org.jeecgframework.tag.core.easyui.TagUtil;
  41. import org.jeecgframework.web.system.pojo.base.TSDepart;
  42. import org.jeecgframework.web.system.service.SystemService;
  43. import org.jeecgframework.core.util.MyBeanUtils;
  44. import java.io.OutputStream;
  45. import org.jeecgframework.core.util.BrowserUtils;
  46. import org.jeecgframework.poi.excel.ExcelExportUtil;
  47. import org.jeecgframework.poi.excel.ExcelImportUtil;
  48. import org.jeecgframework.poi.excel.entity.ExportParams;
  49. import org.jeecgframework.poi.excel.entity.ImportParams;
  50. import org.jeecgframework.poi.excel.entity.TemplateExportParams;
  51. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  52. import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants;
  53. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  54. import org.jeecgframework.core.util.ResourceUtil;
  55. import java.io.IOException;
  56. import org.springframework.web.bind.annotation.RequestMethod;
  57. import org.springframework.web.multipart.MultipartFile;
  58. import org.springframework.web.multipart.MultipartHttpServletRequest;
  59. import org.jeecgframework.core.util.ExceptionUtil;
  60. import org.springframework.http.ResponseEntity;
  61. import org.springframework.stereotype.Controller;
  62. import org.springframework.web.bind.annotation.PathVariable;
  63. import org.springframework.web.bind.annotation.RequestBody;
  64. import org.springframework.web.bind.annotation.RequestMapping;
  65. import org.springframework.web.bind.annotation.RequestMethod;
  66. import org.springframework.web.bind.annotation.ResponseBody;
  67. import org.springframework.web.bind.annotation.ResponseStatus;
  68. import org.springframework.http.HttpHeaders;
  69. import org.springframework.http.HttpStatus;
  70. import org.jeecgframework.core.beanvalidator.BeanValidators;
  71. import javax.validation.ConstraintViolation;
  72. import javax.validation.Validator;
  73. import java.net.URI;
  74. import org.springframework.http.MediaType;
  75. import org.springframework.web.util.UriComponentsBuilder;
  76. /**
  77. * @Title: Controller
  78. * @Description: t_b_budget_cost_breakdown
  79. * @author onlineGenerator
  80. * @date 2020-10-12 15:20:09
  81. * @version V1.0
  82. *
  83. */
  84. @Controller
  85. @RequestMapping("/budgetCostBreakdownController")
  86. public class BudgetCostBreakdownController extends BaseController {
  87. /**
  88. * Logger for this class
  89. */
  90. @Autowired
  91. private BudgetCostBreakdownServiceI budgetCostBreakdownService;
  92. @Autowired
  93. private SystemService systemService;
  94. @Autowired
  95. private Validator validator;
  96. @Autowired
  97. private BudgetDataDao budgetDataDao;
  98. @Autowired
  99. private BudgetDimFunctionServiceI budgetDimFunctionService;
  100. /**
  101. * t_b_budget_cost_breakdown列表 页面跳转
  102. *
  103. * @return
  104. */
  105. @RequestMapping(params = "list")
  106. public ModelAndView list(HttpServletRequest request) {
  107. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdownList");
  108. }
  109. /**
  110. * easyui AJAX请求数据
  111. *
  112. * @param request
  113. * @param response
  114. * @param dataGrid
  115. */
  116. @RequestMapping(params = "datagrid")
  117. public void datagrid(BudgetCostBreakdownEntity budgetCostBreakdown,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  118. CriteriaQuery cq = new CriteriaQuery(BudgetCostBreakdownEntity.class, dataGrid);
  119. String editAuth = request.getParameter("editAuth");
  120. //查询条件组装器
  121. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetCostBreakdown, request.getParameterMap());
  122. try{
  123. if(StringUtils.equals(editAuth,"yunying")){
  124. cq.ge("status", 1);
  125. }
  126. if(StringUtils.equals(editAuth,"renzi") ||StringUtils.equals(editAuth,"caigou") ){
  127. cq.eq("status", 2);
  128. }
  129. //自定义追加查询条件
  130. }catch (Exception e) {
  131. throw new BusinessException(e.getMessage());
  132. }
  133. cq.add();
  134. this.budgetCostBreakdownService.getDataGridReturn(cq, true);
  135. TagUtil.datagrid(response, dataGrid);
  136. }
  137. /**
  138. * 删除t_b_budget_cost_breakdown
  139. *
  140. * @return
  141. */
  142. @RequestMapping(params = "doDel")
  143. @ResponseBody
  144. public AjaxJson doDel(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  145. String message = null;
  146. AjaxJson j = new AjaxJson();
  147. budgetCostBreakdown = systemService.getEntity(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  148. message = "t_b_budget_cost_breakdown删除成功";
  149. try{
  150. budgetCostBreakdownService.delete(budgetCostBreakdown);
  151. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  152. }catch(Exception e){
  153. e.printStackTrace();
  154. message = "t_b_budget_cost_breakdown删除失败";
  155. throw new BusinessException(e.getMessage());
  156. }
  157. j.setMsg(message);
  158. return j;
  159. }
  160. /**
  161. * 批量删除t_b_budget_cost_breakdown
  162. *
  163. * @return
  164. */
  165. @RequestMapping(params = "doBatchDel")
  166. @ResponseBody
  167. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  168. String message = null;
  169. AjaxJson j = new AjaxJson();
  170. message = "t_b_budget_cost_breakdown删除成功";
  171. try{
  172. for(String id:ids.split(",")){
  173. BudgetCostBreakdownEntity budgetCostBreakdown = systemService.getEntity(BudgetCostBreakdownEntity.class,
  174. id
  175. );
  176. budgetCostBreakdownService.delete(budgetCostBreakdown);
  177. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  178. }
  179. }catch(Exception e){
  180. e.printStackTrace();
  181. message = "t_b_budget_cost_breakdown删除失败";
  182. throw new BusinessException(e.getMessage());
  183. }
  184. j.setMsg(message);
  185. return j;
  186. }
  187. /**
  188. * 添加t_b_budget_cost_breakdown
  189. *
  190. * @return
  191. */
  192. @RequestMapping(params = "doAdd")
  193. @ResponseBody
  194. public AjaxJson doAdd(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  195. if(StringUtils.isNotBlank(budgetCostBreakdown.getId())){
  196. return doUpdate(budgetCostBreakdown,request );
  197. }
  198. String message = null;
  199. AjaxJson j = new AjaxJson();
  200. message = "添加成功";
  201. try{
  202. List<?> exist = systemService.findByProperty(BudgetCostBreakdownEntity.class, "periodYear", budgetCostBreakdown.getPeriodYear());
  203. if(!exist.isEmpty()){
  204. j.setSuccess(false);
  205. j.setMsg(budgetCostBreakdown.getPeriodYear()+"年已存在预算成本总表。");
  206. return j;
  207. }
  208. budgetCostBreakdownService.save(budgetCostBreakdown);
  209. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  210. }catch(Exception e){
  211. e.printStackTrace();
  212. message = "添加失败";
  213. throw new BusinessException(e.getMessage());
  214. }
  215. j.setMsg(message);
  216. return j;
  217. }
  218. /**
  219. * 更新t_b_budget_cost_breakdown
  220. *
  221. * @return
  222. */
  223. @RequestMapping(params = "doUpdate")
  224. @ResponseBody
  225. public AjaxJson doUpdate(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  226. String message = null;
  227. AjaxJson j = new AjaxJson();
  228. message = "更新成功";
  229. BudgetCostBreakdownEntity t = budgetCostBreakdownService.get(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  230. try {
  231. MyBeanUtils.copyBeanNotNull2Bean(budgetCostBreakdown, t);
  232. budgetCostBreakdownService.saveOrUpdate(t);
  233. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  234. } catch (Exception e) {
  235. e.printStackTrace();
  236. message = "更新失败";
  237. throw new BusinessException(e.getMessage());
  238. }
  239. j.setMsg(message);
  240. return j;
  241. }
  242. /**
  243. * t_b_budget_cost_breakdown新增页面跳转
  244. *
  245. * @return
  246. */
  247. @RequestMapping(params = "goAdd")
  248. public ModelAndView goAdd(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  249. if (StringUtil.isNotEmpty(budgetCostBreakdown.getId())) {
  250. budgetCostBreakdown = budgetCostBreakdownService.getEntity(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  251. req.setAttribute("budgetCostBreakdownPage", budgetCostBreakdown);
  252. }
  253. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-add");
  254. }
  255. /**
  256. * t_b_budget_cost_breakdown编辑页面跳转
  257. *
  258. * @return
  259. */
  260. @RequestMapping(params = "goUpdate")
  261. public ModelAndView goUpdate(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  262. if (StringUtil.isNotEmpty(budgetCostBreakdown.getId())) {
  263. budgetCostBreakdown = budgetCostBreakdownService.getEntity(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  264. req.setAttribute("entity", budgetCostBreakdown);
  265. }
  266. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-add");
  267. }
  268. /**
  269. * 导入功能跳转
  270. *
  271. * @return
  272. */
  273. @RequestMapping(params = "upload")
  274. public ModelAndView upload(HttpServletRequest req) {
  275. req.setAttribute("controller_name","budgetCostBreakdownController");
  276. return new ModelAndView("common/upload/pub_excel_upload");
  277. }
  278. /**
  279. * 导出excel
  280. *
  281. * @param request
  282. * @param response
  283. */
  284. @RequestMapping(params = "exportXls")
  285. public String exportXls(BudgetCostBreakdownEntity budgetCostBreakdown,HttpServletRequest request,HttpServletResponse response
  286. , DataGrid dataGrid,ModelMap modelMap) {
  287. CriteriaQuery cq = new CriteriaQuery(BudgetCostBreakdownEntity.class, dataGrid);
  288. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, budgetCostBreakdown, request.getParameterMap());
  289. List<BudgetCostBreakdownEntity> budgetCostBreakdowns = this.budgetCostBreakdownService.getListByCriteriaQuery(cq,false);
  290. modelMap.put(NormalExcelConstants.FILE_NAME,"t_b_budget_cost_breakdown");
  291. modelMap.put(NormalExcelConstants.CLASS,BudgetCostBreakdownEntity.class);
  292. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("t_b_budget_cost_breakdown列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  293. "导出信息"));
  294. modelMap.put(NormalExcelConstants.DATA_LIST,budgetCostBreakdowns);
  295. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  296. }
  297. /**
  298. * 导出excel 使模板
  299. *
  300. * @param request
  301. * @param response
  302. */
  303. @RequestMapping(params = "exportXlsByT")
  304. public String exportXlsByT(BudgetCostBreakdownEntity budgetCostBreakdown,HttpServletRequest request,HttpServletResponse response
  305. , DataGrid dataGrid,ModelMap modelMap) {
  306. modelMap.put(NormalExcelConstants.FILE_NAME,"t_b_budget_cost_breakdown");
  307. modelMap.put(NormalExcelConstants.CLASS,BudgetCostBreakdownEntity.class);
  308. modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("t_b_budget_cost_breakdown列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  309. "导出信息"));
  310. modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  311. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  312. }
  313. @SuppressWarnings("unchecked")
  314. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  315. @ResponseBody
  316. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  317. AjaxJson j = new AjaxJson();
  318. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  319. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  320. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  321. MultipartFile file = entity.getValue();// 获取上传文件对象
  322. ImportParams params = new ImportParams();
  323. params.setTitleRows(2);
  324. params.setHeadRows(1);
  325. params.setNeedSave(true);
  326. try {
  327. List<BudgetCostBreakdownEntity> listBudgetCostBreakdownEntitys = ExcelImportUtil.importExcel(file.getInputStream(),BudgetCostBreakdownEntity.class,params);
  328. for (BudgetCostBreakdownEntity budgetCostBreakdown : listBudgetCostBreakdownEntitys) {
  329. budgetCostBreakdownService.save(budgetCostBreakdown);
  330. }
  331. j.setMsg("文件导入成功!");
  332. } catch (Exception e) {
  333. j.setMsg("文件导入失败!");
  334. log.error(ExceptionUtil.getExceptionMessage(e));
  335. }finally{
  336. try {
  337. file.getInputStream().close();
  338. } catch (IOException e) {
  339. e.printStackTrace();
  340. }
  341. }
  342. }
  343. return j;
  344. }
  345. @RequestMapping(method = RequestMethod.GET)
  346. @ResponseBody
  347. public List<BudgetCostBreakdownEntity> list() {
  348. List<BudgetCostBreakdownEntity> listBudgetCostBreakdowns=budgetCostBreakdownService.getList(BudgetCostBreakdownEntity.class);
  349. return listBudgetCostBreakdowns;
  350. }
  351. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  352. @ResponseBody
  353. public ResponseEntity<?> get(@PathVariable("id") String id) {
  354. BudgetCostBreakdownEntity task = budgetCostBreakdownService.get(BudgetCostBreakdownEntity.class, id);
  355. if (task == null) {
  356. return new ResponseEntity(HttpStatus.NOT_FOUND);
  357. }
  358. return new ResponseEntity(task, HttpStatus.OK);
  359. }
  360. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  361. @ResponseBody
  362. public ResponseEntity<?> create(@RequestBody BudgetCostBreakdownEntity budgetCostBreakdown, UriComponentsBuilder uriBuilder) {
  363. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  364. Set<ConstraintViolation<BudgetCostBreakdownEntity>> failures = validator.validate(budgetCostBreakdown);
  365. if (!failures.isEmpty()) {
  366. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  367. }
  368. //保存
  369. try{
  370. budgetCostBreakdownService.save(budgetCostBreakdown);
  371. } catch (Exception e) {
  372. e.printStackTrace();
  373. return new ResponseEntity(HttpStatus.NO_CONTENT);
  374. }
  375. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  376. String id = budgetCostBreakdown.getId();
  377. URI uri = uriBuilder.path("/rest/budgetCostBreakdownController/" + id).build().toUri();
  378. HttpHeaders headers = new HttpHeaders();
  379. headers.setLocation(uri);
  380. return new ResponseEntity(headers, HttpStatus.CREATED);
  381. }
  382. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  383. public ResponseEntity<?> update(@RequestBody BudgetCostBreakdownEntity budgetCostBreakdown) {
  384. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  385. Set<ConstraintViolation<BudgetCostBreakdownEntity>> failures = validator.validate(budgetCostBreakdown);
  386. if (!failures.isEmpty()) {
  387. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  388. }
  389. //保存
  390. try{
  391. budgetCostBreakdownService.saveOrUpdate(budgetCostBreakdown);
  392. } catch (Exception e) {
  393. e.printStackTrace();
  394. return new ResponseEntity(HttpStatus.NO_CONTENT);
  395. }
  396. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  397. return new ResponseEntity(HttpStatus.NO_CONTENT);
  398. }
  399. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  400. @ResponseStatus(HttpStatus.NO_CONTENT)
  401. public void delete(@PathVariable("id") String id) {
  402. budgetCostBreakdownService.deleteEntityById(BudgetCostBreakdownEntity.class, id);
  403. }
  404. @RequestMapping(params = "goFill")
  405. public ModelAndView goFill(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  406. budgetCostBreakdown = systemService.getEntity(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  407. String id=budgetCostBreakdown.getId();
  408. if(StringUtils.isBlank(budgetCostBreakdown.getJson())) {
  409. String sql = "select distinct bm.entity_id from t_b_budget_cost_breakdown_measure bm where bm.cost_breakdown_id=? ";
  410. List<String> existIdList = systemService.findListbySql(sql,id);
  411. List<BudgetContractEntity> contractInfo = budgetDataDao.getContractInfoByYear(budgetCostBreakdown.getPeriodYear(),existIdList);
  412. List<BudgetContractEntity> lastYearContractInfo = budgetDataDao.getContractInfoByYear(String.valueOf(Integer.valueOf(budgetCostBreakdown.getPeriodYear())-1),existIdList);
  413. for(BudgetContractEntity lastYearContract : lastYearContractInfo){
  414. String name = lastYearContract.getEntityName();
  415. boolean toAdd = true;
  416. for(BudgetContractEntity contract:contractInfo){
  417. String cName = contract.getEntityName();
  418. if(StringUtils.equals(name,cName)) {
  419. toAdd = false;
  420. break;
  421. }
  422. }
  423. if(toAdd){
  424. lastYearContract.setContractDate("");
  425. lastYearContract.setContractTotalAmount("");
  426. contractInfo.add(lastYearContract);
  427. }
  428. }
  429. Collections.sort(contractInfo, new Comparator<BudgetContractEntity>() {
  430. @Override
  431. public int compare(BudgetContractEntity o1, BudgetContractEntity o2) {
  432. return o1.getEntityName().compareTo(o2.getEntityName());
  433. }
  434. });
  435. req.setAttribute("contractInfo", contractInfo);
  436. }
  437. String measureHql = "from BudgetMeasureEntity where code like 'A02%'";
  438. List<BudgetMeasureEntity> measureList = systemService.findHql(measureHql);
  439. Map<String,BudgetMeasureEntity> measureEntityMap = new HashMap<>();
  440. for(BudgetMeasureEntity measureEntity : measureList){
  441. measureEntityMap.put(measureEntity.getId(), measureEntity);
  442. }
  443. ObjectMapper mapper = new ObjectMapper();
  444. try {
  445. req.setAttribute("costMeasure",mapper.writeValueAsString(measureEntityMap) );
  446. } catch (IOException e) {
  447. e.printStackTrace();
  448. }
  449. req.setAttribute("costEntity", budgetCostBreakdown);
  450. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-fill");
  451. }
  452. @RequestMapping(params = "doFill")
  453. @ResponseBody
  454. public AjaxJson doFill(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  455. String message = null;
  456. AjaxJson j = new AjaxJson();
  457. message = "保存成功";
  458. String saveAuth = request.getParameter("saveAuth");
  459. try {
  460. budgetCostBreakdownService.doFill(budgetCostBreakdown,saveAuth);
  461. } catch (Exception e) {
  462. e.printStackTrace();
  463. message = "保存失败";
  464. j.setSuccess(false);
  465. }
  466. j.setMsg(message);
  467. return j;
  468. }
  469. @RequestMapping(params = "changeStatus")
  470. @ResponseBody
  471. public AjaxJson changeStatus(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  472. String message = null;
  473. AjaxJson j = new AjaxJson();
  474. message = "操作成功";
  475. Integer newStatus = budgetCostBreakdown.getStatus();
  476. BudgetCostBreakdownEntity entity = systemService.getEntity(BudgetCostBreakdownEntity.class, budgetCostBreakdown.getId());
  477. if(entity.getUpdateDate()==null){
  478. message="请先保存";
  479. j.setSuccess(false);
  480. }else {
  481. entity.setStatus(newStatus);
  482. systemService.updateEntitie(entity);
  483. budgetCostBreakdownService.notice(entity, "changeStatus");
  484. }
  485. j.setMsg(message);
  486. return j;
  487. }
  488. @RequestMapping(params = "selectAuth")
  489. public ModelAndView selectAuth(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  490. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-selectAuth");
  491. }
  492. @RequestMapping(params = "selectAuth2")
  493. public ModelAndView selectAuth2(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  494. return new ModelAndView("cn/com/lzt/budget/tempsheet/budgetTempSheet-selectAuth");
  495. }
  496. @RequestMapping(params = "getMeasureInfo")
  497. @ResponseBody
  498. public AjaxJson getData(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest request) {
  499. String message = null;
  500. AjaxJson j = new AjaxJson();
  501. String hql = "from BudgetCostBreakdownMeasureEntity where costBreakdownId=? and dataFormula=''";
  502. List<BudgetCostBreakdownMeasureEntity> costBreakdownMeasureEntityList = systemService.findHql(hql,budgetCostBreakdown.getId());
  503. return j;
  504. }
  505. @RequestMapping(params = "selectEntity")
  506. public ModelAndView selectEntity(BudgetCostBreakdownEntity budgetCostBreakdown, HttpServletRequest req) {
  507. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-selectEntity");
  508. }
  509. @RequestMapping(params = "selectEntityDatagrid")
  510. public void selectEntityDatagrid(BudgetEntity budgetEntity,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  511. CriteriaQuery cq = new CriteriaQuery(BudgetEntity.class, dataGrid);
  512. String costEntityId = request.getParameter("costEntityId");
  513. //查询条件组装器
  514. try{
  515. if(StringUtils.isNotBlank(budgetEntity.getEntityName())){
  516. cq.like("entityName","%"+budgetEntity.getEntityName()+"%" );
  517. }
  518. String sql = "select distinct bm.entity_id from t_b_budget_cost_breakdown_measure bm where bm.cost_breakdown_id=? ";
  519. List<String> entityIdList = systemService.findListbySql(sql,costEntityId);
  520. cq.notin("id", entityIdList.toArray());
  521. }catch (Exception e) {
  522. throw new BusinessException(e.getMessage());
  523. }
  524. cq.add();
  525. this.systemService.getDataGridReturn(cq, false);
  526. TagUtil.treegrid(response, dataGrid);
  527. }
  528. @RequestMapping(params = "calcFunction")
  529. @ResponseBody
  530. public AjaxJson calcFunction(HttpServletRequest req) {
  531. AjaxJson j = new AjaxJson();
  532. List<Object[]> valueList = new ArrayList<>();
  533. Map<String,Object> attriMap = new HashMap<>();
  534. Long t1 =System.currentTimeMillis();
  535. String info=req.getParameter("info");
  536. String[] infoArray=StringUtils.split(info,",");
  537. log.error("calcFunction start size:"+infoArray.length);
  538. List<BudgetCalc> calcList = new ArrayList<>();
  539. for(String oneFunctionInfo : infoArray){
  540. String[] dArray = StringUtils.split(oneFunctionInfo, "#");
  541. String row = dArray[0];
  542. String col = dArray[1];
  543. String functionId = dArray[2];
  544. String measureId = dArray[3];
  545. String entityId = dArray[4];
  546. try {
  547. BudgetCalc budgetCalc = new BudgetCalc();
  548. budgetCalc.setRow(Integer.valueOf(row));
  549. budgetCalc.setCol(Integer.valueOf(col));
  550. budgetCalc.setFunctionId(functionId);
  551. budgetCalc.setMeasureId(measureId);
  552. budgetCalc.setEntityId(entityId);
  553. budgetCalc.setDeep(false);
  554. budgetCalc.setUpdate(false);
  555. calcList.add(budgetCalc);
  556. }catch (IllegalStateException e){//死循环
  557. log.error("维度公式循环引用:"+functionId);
  558. attriMap.put("errorMsg", "维度公式循环引用,请联系管理员");
  559. break;
  560. }
  561. }
  562. budgetDimFunctionService.batchCalc(calcList);
  563. for(BudgetCalc budgetCalc:calcList){
  564. BigDecimal value = budgetCalc.getValue();
  565. if(value!=null) {
  566. valueList.add(new Object[]{budgetCalc.getRow(), budgetCalc.getCol(), value.toPlainString()});
  567. }
  568. }
  569. Long t2 =System.currentTimeMillis();
  570. log.error("calcFunction end took:"+(t2-t1));
  571. j.setObj(valueList);
  572. j.setAttributes(attriMap);
  573. return j;
  574. }
  575. @RequestMapping(params = "goStatis")
  576. public ModelAndView goStatis(HttpServletRequest req) {
  577. String page = req.getParameter("page");
  578. return new ModelAndView("cn/com/lzt/budget/costbreakdown/budgetCostBreakdown-statis-"+page);
  579. }
  580. }