ProjectTemController.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package com.jeeplus.modules.sg.project.web;
  2. import com.jeeplus.common.json.AjaxJson;
  3. import com.jeeplus.common.utils.DateUtils;
  4. import com.jeeplus.common.utils.StringUtils;
  5. import com.jeeplus.core.web.BaseController;
  6. import com.jeeplus.modules.sg.overheadline.entity.JkxlDetailFee;
  7. import com.jeeplus.modules.sg.overheadline.service.OverheadLineService;
  8. import com.jeeplus.modules.sg.project.entity.WbsItem;
  9. import com.jeeplus.modules.sg.project.entity.WbsProject;
  10. import com.jeeplus.modules.sg.project.entity.WbsSelection;
  11. import com.jeeplus.modules.sg.project.service.ProjectService;
  12. import com.jeeplus.modules.sg.project.util.ExportUtil;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Controller;
  15. import org.springframework.ui.Model;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.IOException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.*;
  25. @Controller
  26. @RequestMapping("${adminPath}/project/tem")
  27. public class ProjectTemController extends BaseController {
  28. @Autowired
  29. private HttpServletRequest request;
  30. @Autowired
  31. private ProjectService projectService;
  32. @Autowired
  33. private OverheadLineService overheadLineService;
  34. @RequestMapping("/index")
  35. public String toIndex(){
  36. return "/modules/sg/project/managementtem";
  37. }
  38. @RequestMapping(value = {"list", ""})
  39. public String list(WbsSelection wbsSelection, HttpServletRequest request, HttpServletResponse response, Model model) {
  40. List<WbsProject> list = projectService.findList(wbsSelection);
  41. model.addAttribute("list",list);
  42. return "modules/sg/project/management";
  43. }
  44. @RequestMapping("/form")
  45. public String form(WbsProject wbsProject, Model model) {
  46. WbsProject wbsProject1 = projectService.get(wbsProject.getId());
  47. List<WbsProject> list = new ArrayList<>();
  48. list.add(wbsProject1);
  49. model.addAttribute("list", list);
  50. String view = "updateItemForm";
  51. String tabId = request.getParameter("tabId");
  52. if("1".equals(tabId)){
  53. view = "lookItemForm";
  54. }
  55. return "modules/sg/project/"+view;
  56. }
  57. //项目保存
  58. @ResponseBody
  59. @RequestMapping("/save")
  60. public AjaxJson save(WbsProject wbsProject, Model model, RedirectAttributes redirectAttributes){
  61. AjaxJson j = new AjaxJson();
  62. //数据验证
  63. String errMsg = beanValidator(wbsProject);
  64. if (StringUtils.isNotBlank(errMsg)){
  65. j.setSuccess(false);
  66. j.setMsg(errMsg);
  67. return j;
  68. }
  69. //新增或编辑表单保存
  70. projectService.save(wbsProject);//保存
  71. j.setSuccess(true);
  72. addMessage(redirectAttributes, "保存成功");
  73. return j;
  74. }
  75. /**
  76. *数据导入
  77. */
  78. @RequestMapping("/import")
  79. public String importFile(MultipartFile file, RedirectAttributes redirectAttributes, HttpServletRequest request, Model model)throws Exception {
  80. String projectName = request.getParameter("projectName"); //项目名称
  81. String itemName = request.getParameter("itemName"); //项目名称
  82. String projectId = request.getParameter("projectId"); //工程ID
  83. String type = request.getParameter("type"); //工程类型
  84. String id = getId();
  85. try {
  86. WbsProject wbsProject = new WbsProject();
  87. wbsProject.setProjectName(projectName);
  88. projectService.save(wbsProject);
  89. // 保存数据到数据库
  90. if(type.equals("1")) {
  91. overheadLineService.saveJk(file,itemName, id, projectId, type);
  92. }
  93. if (type.equals("2")) {
  94. overheadLineService.saveDl(file,itemName, id, projectId, type);
  95. }
  96. } catch (RuntimeException e) {
  97. addMessage(redirectAttributes, "导入失败,"+e.getMessage());
  98. return "redirect:/a/project/list";
  99. } catch (Exception e){
  100. addMessage(redirectAttributes, "导入失败");
  101. return "redirect:/a/project/list";
  102. }
  103. addMessage(redirectAttributes, "导入成功");
  104. return "redirect:/a/jkxl/list?id="+id+"&type="+type;
  105. }
  106. //导出
  107. @RequestMapping("/export")
  108. public String toList(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException {
  109. String id = request.getParameter("id");
  110. WbsProject wbsProject = projectService.get(id);
  111. String fileName = wbsProject.getProjectName()+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
  112. List<WbsItem> wbsItems = wbsProject.getWbsItems();
  113. String[] sts = new String[wbsItems.size()+1];
  114. sts[0] = "合计";
  115. for (int i=0;i<wbsItems.size();i++){
  116. sts[i+1] = wbsItems.get(i).getItemName();
  117. }
  118. List<JkxlDetailFee> list = new ArrayList<>();
  119. for(WbsItem wbsItem :wbsItems){
  120. List<JkxlDetailFee> jkxlDetailFees = overheadLineService.findList(wbsItem.getId(),wbsItem.getType());
  121. list.addAll(jkxlDetailFees);
  122. }
  123. //集合去重合并
  124. List<JkxlDetailFee> list1 = getNewList(list);
  125. //加序号
  126. for (int i=0;i<list1.size();i++){
  127. list1.get(i).setIndex(i+1);
  128. }
  129. ExportUtil exportUtil = new ExportUtil(null, JkxlDetailFee.class,sts);
  130. //写合计
  131. exportUtil.setDataList(list1,0);
  132. //分别写入项目
  133. for(int j=0;j<wbsItems.size();j++){
  134. List<JkxlDetailFee> jkxlDetailFees = overheadLineService.findList(wbsItems.get(j).getId(),wbsItems.get(j).getType());
  135. exportUtil.setDataList(jkxlDetailFees,j+1);
  136. }
  137. exportUtil.write(response,fileName).dispose();
  138. return "redirect:/a/project/list";
  139. }
  140. /**
  141. * 数据去重合并
  142. * @param list
  143. * @return
  144. */
  145. private List<JkxlDetailFee> getNewList(List<JkxlDetailFee> list) {
  146. List<JkxlDetailFee> list1 = new ArrayList<>();
  147. for(JkxlDetailFee jkxlDetailFee: list){
  148. String wbsCode = jkxlDetailFee.getWbsCode();
  149. if(!list1.contains(jkxlDetailFee)){
  150. list1.add(jkxlDetailFee);
  151. }else {
  152. for(JkxlDetailFee jkxlDetailFee1 : list1){
  153. if(jkxlDetailFee1.getWbsCode().equals(wbsCode)){
  154. double azFee = jkxlDetailFee1.getAzFee()!=null? jkxlDetailFee1.getAzFee():0.00;
  155. double azFee1 = jkxlDetailFee.getAzFee()!=null? jkxlDetailFee.getAzFee():0.00;
  156. double qtFee = jkxlDetailFee1.getQtFee()!=null? jkxlDetailFee1.getQtFee():0.00;
  157. double qtFee1 = jkxlDetailFee.getQtFee()!=null? jkxlDetailFee.getQtFee():0.00;
  158. double totalFee = jkxlDetailFee1.getTotalFee()!=null? jkxlDetailFee1.getTotalFee():0.00;
  159. double totalFee1 = jkxlDetailFee.getTotalFee()!=null? jkxlDetailFee.getTotalFee():0.00;
  160. double jsFee = jkxlDetailFee1.getJsFee()!=null? jkxlDetailFee1.getJsFee():0.00;
  161. double jsFee1 = jkxlDetailFee.getJsFee()!=null? jkxlDetailFee.getJsFee():0.00;
  162. double cFee = jkxlDetailFee1.getcFee()!=null? jkxlDetailFee1.getcFee():0.00;
  163. double cFee1 = jkxlDetailFee.getcFee()!=null? jkxlDetailFee.getcFee():0.00;
  164. jkxlDetailFee1.setAzFee(azFee+azFee1);
  165. jkxlDetailFee1.setQtFee(qtFee+qtFee1);
  166. jkxlDetailFee1.setTotalFee(totalFee+totalFee1);
  167. jkxlDetailFee1.setJsFee(jsFee+jsFee1);
  168. jkxlDetailFee1.setcFee(cFee+cFee1);
  169. }
  170. }
  171. }
  172. }
  173. //按照wbs码排序
  174. Collections.sort(list1, new Comparator<JkxlDetailFee>() {
  175. @Override
  176. public int compare(JkxlDetailFee o1, JkxlDetailFee o2) {
  177. return o1.getWbsCode().compareTo(o2.getWbsCode());
  178. }
  179. });
  180. return list1;
  181. }
  182. //项目删除
  183. @ResponseBody
  184. @RequestMapping(value = "delete")
  185. public AjaxJson delete(WbsProject wbsProject) {
  186. AjaxJson j = new AjaxJson();
  187. projectService.delete(wbsProject);
  188. j.setMsg("删除项目成功");
  189. return j;
  190. }
  191. @RequestMapping(value = "tolist")
  192. public String toList(){
  193. return "redirect:/a/project/list";
  194. }
  195. /**
  196. * 创建项目ID
  197. */
  198. public String getId() {
  199. SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
  200. String newDate=sdf.format(new Date());
  201. String result="";
  202. Random random=new Random();
  203. for(int i=0;i<3;i++){
  204. result+=random.nextInt(10);
  205. }
  206. return newDate+result;
  207. }
  208. }