YbfController.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package com.zhcs.dt.controller.information.monthProgress;
  2. import java.math.BigDecimal;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.annotation.Resource;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.RequestMethod;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import org.springframework.web.servlet.ModelAndView;
  13. import com.zhcs.dt.controller.base.BaseController;
  14. import com.zhcs.dt.entity.Page;
  15. import com.zhcs.dt.service.information.monthProgress.YbfManager;
  16. import com.zhcs.dt.util.AppUtil;
  17. import com.zhcs.dt.util.Jurisdiction;
  18. import com.zhcs.dt.util.PageData;
  19. /**
  20. * 类名称:预备费
  21. * 创建人:zhengfei
  22. * 创建时间:2019-04-09
  23. */
  24. @Controller
  25. @RequestMapping(value="/ybf")
  26. class YbfController extends BaseController {
  27. String menuUrl = "ybf/list.do"; //菜单地址(权限用)
  28. String pageUrl = "information/monthProgress/ybf/";
  29. private final String MSG_SAVE = "save";
  30. private final String MSG_EDIT = "edit";
  31. @Resource(name="ybfManagerService")
  32. private YbfManager ybfManagerService;
  33. /**列表
  34. * @param page
  35. * @throws Exception
  36. */
  37. @RequestMapping(value="/list")
  38. public ModelAndView list(Page page) throws Exception{
  39. logBefore(logger, Jurisdiction.getUsername()+"预备费");
  40. //if(!Jurisdiction.buttonJurisdiction(menuUrl, "cha")){return null;} //校验权限(无权查看时页面会有提示,如果不注释掉这句代码就无法进入列表页面,所以根据情况是否加入本句代码)
  41. ModelAndView mv = this.getModelAndView();
  42. PageData pd = new PageData();
  43. pd = this.getPageData();
  44. List<PageData> loadCostList = ybfManagerService.findTotalCostByCompanyAndYear(pd);
  45. if(null != loadCostList && !loadCostList.isEmpty()){
  46. List<PageData> ybfList = ybfManagerService.listAll(pd);
  47. for (PageData l : loadCostList) {
  48. String loadId = l.getString("ROAD_ID");
  49. List<PageData> loadList = new ArrayList<PageData>();
  50. BigDecimal total = new BigDecimal(0);
  51. for (PageData y : ybfList){
  52. if(loadId.equals(y.getString("ROAD_ID"))){
  53. loadList.add(y);
  54. if(null != y.get("ACTUAL_COST"))
  55. total = total.add((BigDecimal)y.get("ACTUAL_COST"));
  56. }
  57. }
  58. l.put("count", loadList.size());
  59. l.put("total", total.toString());
  60. l.put("loadList", loadList);
  61. }
  62. }
  63. mv.setViewName(pageUrl+"ybf_list");
  64. mv.addObject("loadCostList", loadCostList);
  65. mv.addObject("pd",pd);
  66. mv.addObject("QX",Jurisdiction.getHC()); //按钮权限
  67. return mv;
  68. }
  69. /**
  70. * 去新增页面
  71. *
  72. * @param
  73. * @throws Exception
  74. */
  75. @RequestMapping(value = "/goAdd")
  76. public ModelAndView goAdd() throws Exception {
  77. ModelAndView mv = this.getModelAndView();
  78. PageData pd = new PageData();
  79. pd = this.getPageData();
  80. mv.setViewName(pageUrl+"ybf_edit");
  81. pd.put("table", "oa_department_"+pd.getString("year").toString());
  82. List<PageData> loadData = ybfManagerService.findLoadByParentId(pd);
  83. mv.addObject("loadData",loadData);
  84. mv.addObject("msg", MSG_SAVE);
  85. mv.addObject("pd", pd);
  86. return mv;
  87. }
  88. /**
  89. * 去修改页面
  90. *
  91. * @param
  92. * @throws Exception
  93. */
  94. @RequestMapping(value = "/goEdit")
  95. public ModelAndView goEdit() throws Exception {
  96. ModelAndView mv = this.getModelAndView();
  97. PageData pd = new PageData();
  98. pd = this.getPageData();
  99. pd = ybfManagerService.findByCompanyAndLoadAndYearAndProjectName(pd);
  100. mv.setViewName(pageUrl+"ybf_edit");
  101. mv.addObject("msg",MSG_EDIT);
  102. mv.addObject("pd", pd);
  103. return mv;
  104. }
  105. /**
  106. * 保存
  107. *
  108. * @param
  109. * @throws Exception
  110. */
  111. @RequestMapping(value = "/save",method=RequestMethod.POST)
  112. @ResponseBody
  113. public Object save() throws Exception {
  114. logBefore(logger, Jurisdiction.getUsername() + "新增预备费");
  115. if (!Jurisdiction.buttonJurisdiction(menuUrl, "add")) {
  116. return null;
  117. } // 校验权限
  118. PageData pd = new PageData();
  119. pd = this.getPageData();
  120. ybfManagerService.save(pd);
  121. Map<String,String> map = new HashMap<String,String>();
  122. map.put("result", "success");
  123. return AppUtil.returnObject(new PageData(), map);
  124. }
  125. /**判断路段项目是否存在
  126. * @param
  127. * @throws Exception
  128. */
  129. @RequestMapping(value="/checkProjectName")
  130. @ResponseBody
  131. public Object checkProjectName()throws Exception{
  132. Map<String,String> map = new HashMap<String,String>();
  133. PageData pd = new PageData();
  134. pd = this.getPageData();
  135. String tipmsg = "success";
  136. List<PageData> list = ybfManagerService.checkLoadId(pd);
  137. if(null == list || list.size()==0){
  138. tipmsg = "error";
  139. map.put("result", tipmsg);
  140. map.put("error", "该路段计划金额为空");
  141. return AppUtil.returnObject(new PageData(), map);
  142. }
  143. String msg = pd.getString("msg");
  144. PageData data = ybfManagerService.findByCompanyAndLoadAndYearAndProjectName(pd);
  145. if(MSG_SAVE.equals(msg) && null != data){
  146. tipmsg = "error";
  147. map.put("error", "该项目名称已存在");
  148. }else{
  149. if(null != data && !pd.getString("oldProjectName").equals(pd.getString("projectName"))){
  150. tipmsg = "error";
  151. map.put("error", "该项目名称已存在");
  152. }
  153. }
  154. //查询系统已存在的养护计划
  155. map.put("result", tipmsg);
  156. return AppUtil.returnObject(new PageData(), map);
  157. }
  158. /**删除预备费
  159. * @param
  160. * @throws Exception
  161. */
  162. @RequestMapping(value="/del")
  163. @ResponseBody
  164. public Object delAnnualPlan()throws Exception{
  165. Map<String,String> map = new HashMap<String,String>();
  166. PageData pd = new PageData();
  167. pd = this.getPageData();
  168. try{
  169. ybfManagerService.delete(pd);
  170. map.put("result", "success");
  171. }catch(Exception e){
  172. map.put("result", "删除失败");
  173. }
  174. return AppUtil.returnObject(new PageData(), map);
  175. }
  176. /**
  177. *
  178. * @Title: checkLoadId
  179. * @Description: 校验预备费是否存在
  180. * @param @return
  181. * @param @throws Exception
  182. * @return Object
  183. * @throws
  184. */
  185. @RequestMapping(value = "/checkLoadId")
  186. @ResponseBody
  187. public Object checkLoadId() throws Exception {
  188. Map<String,String> map = new HashMap<String,String>();
  189. PageData pd = new PageData();
  190. pd = this.getPageData();
  191. map.put("result", "error");
  192. try{
  193. List<PageData> list = ybfManagerService.checkLoadId(pd);
  194. if(null != list && list.size() >0)
  195. map.put("result", "success");
  196. }catch(Exception e){
  197. e.printStackTrace();
  198. }
  199. return AppUtil.returnObject(new PageData(), map);
  200. }
  201. }