JkxlController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. package com.jeeplus.modules.sg.web;
  2. import com.jeeplus.common.utils.DateUtils;
  3. import com.jeeplus.common.utils.StringUtils;
  4. import com.jeeplus.common.utils.excel.ExportExcel;
  5. import com.jeeplus.common.utils.excel.ImportExcel;
  6. import com.jeeplus.core.web.BaseController;
  7. import com.jeeplus.modules.sg.entity.JkxlData;
  8. import com.jeeplus.modules.sg.entity.TzData;
  9. import com.jeeplus.modules.sg.entity.WbsProject;
  10. import com.jeeplus.modules.sg.service.JkxlService;
  11. import com.jeeplus.modules.sg.util.BashInfo;
  12. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  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.math.BigDecimal;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. /**
  27. * 架空线路
  28. */
  29. @Controller
  30. @RequestMapping(value = "${adminPath}/jkxl")
  31. public class JkxlController extends BaseController {
  32. @Autowired
  33. private JkxlService jkxlService;
  34. @RequestMapping("/index")
  35. public String toImport(){
  36. return "modules/sg/free/indexProject";
  37. }
  38. @RequestMapping("/import")
  39. public String importFile(MultipartFile file, RedirectAttributes redirectAttributes, HttpServletRequest request, Model model){
  40. double sl = Double.valueOf(request.getParameter("jxsl"));
  41. String projectName = request.getParameter("name");
  42. String id = getId();
  43. try {
  44. double[] rate = getRate();
  45. WbsProject wbsProject = new WbsProject();
  46. wbsProject.setId(id);
  47. wbsProject.setName(projectName);
  48. wbsProject.setCreateDate(new Date());
  49. jkxlService.saveProject(wbsProject);
  50. List<JkxlData> list = getData(file,rate,id,sl);
  51. for(JkxlData jkxlData : list){
  52. jkxlService.save(jkxlData);
  53. }
  54. double[] tzfee = getTzFee(file);
  55. jkxlService.saveTzFee(tzfee,id);
  56. } catch (Exception e){
  57. addMessage(redirectAttributes, "导入失败");
  58. }
  59. addMessage(redirectAttributes, "导入成功");
  60. return "redirect:/a/jkxl/list?id="+id;
  61. }
  62. @RequestMapping("/gettz")
  63. @ResponseBody
  64. public List<JkxlData> getTz(TzData tzData){
  65. String id = tzData.getId();
  66. List<JkxlData> list = jkxlService.getList(id);
  67. List<JkxlData> list1 = new ArrayList<>();
  68. for(JkxlData jkxlData: list){
  69. if(jkxlData.getOriginalTotalCost() != null){
  70. list1.add(jkxlData);
  71. }
  72. }
  73. return list1;
  74. }
  75. // @RequestMapping("/relist")
  76. // public String reList(){
  77. //
  78. // }
  79. @RequestMapping("/list")
  80. public String list(HttpServletRequest request,Model model){
  81. String id = request.getParameter("id");
  82. JkxlData jkxlData = new JkxlData();
  83. TzData tzData = new TzData();
  84. jkxlData.setId(id);
  85. tzData.setId(id);
  86. List<JkxlData> list1 = new ArrayList<>();
  87. list1.add(jkxlData);
  88. List<JkxlData> list = jkxlService.getList(id);
  89. List<TzData> list2 = jkxlService.getTzFee(tzData);
  90. HashMap map = new HashMap();
  91. map.put("list1",list1);
  92. map.put("list",list);
  93. map.put("list2",list2);
  94. model.addAttribute("map",map);
  95. return "modules/sg/free/wbslist";
  96. }
  97. @RequestMapping("/export")
  98. public String export(HttpServletRequest request, HttpServletResponse response,Model model,RedirectAttributes redirectAttributes) {
  99. String id = request.getParameter("id");
  100. try{
  101. String fileName = "架空线路"+ DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
  102. List<JkxlData> list = jkxlService.findList(id);
  103. new ExportExcel(null,JkxlData.class).setDataList(list).write(response, fileName).dispose();
  104. return null;
  105. }catch (Exception e){
  106. addMessage(redirectAttributes, "导出失败");
  107. }
  108. addMessage(redirectAttributes, "导出成功");
  109. return "redirect:/a/jkxl/list?id="+id;
  110. }
  111. public List<JkxlData> getData(MultipartFile file,double[] rate,String id,double sl) throws IOException, InvalidFormatException {
  112. ImportExcel importExcel = new ImportExcel(file,1,BashInfo.SHEET_FBFXJJ); //分部分项工程量清单计价表
  113. ImportExcel csqd = new ImportExcel(file,1,BashInfo.SHEET_CSB); // 措施项目清单计价表(一)
  114. ImportExcel gf = new ImportExcel(file,1,BashInfo.SHEET_GFQD); //规费项目清单计价表
  115. ImportExcel qt = new ImportExcel(file,1,BashInfo.SHEET_QTFY); //其他项目清单计价表
  116. ImportExcel total = new ImportExcel(file,1,BashInfo.SHEET_HZB ); //工程项目竣工结算汇总表
  117. ImportExcel gzhz = new ImportExcel(file,1,BashInfo.SHEET_GCHZ ); //架空线路工程费用汇总表
  118. double[] csRate = getCsRate(csqd);
  119. double[] gfRate = getGfRate(gf);
  120. double[] qtFees = getQtFees(qt);
  121. double[] wsbFees = getFees(total);
  122. int[] zjgcFee = getZjgcFee(gzhz);
  123. double totalFee = 0.00;
  124. List<JkxlData> list = new ArrayList<>();
  125. int lastRow = importExcel.getLastDataRowNum();
  126. int[] row = new int[6];
  127. for(int i=0;i<lastRow;i++){
  128. String type = importExcel.getValue(i+1,2);
  129. if(type.equals(BashInfo.PROJECTNAME)){
  130. totalFee = importExcel.getDouble(i+1,12);
  131. continue;
  132. }
  133. if(type.equals(BashInfo.JCGC)){
  134. row[0] = i+1;
  135. continue;
  136. }
  137. if(type.equals(BashInfo.GTGC)){
  138. row[1] = i+1;
  139. continue;
  140. }
  141. if(type.equals(BashInfo.JDGC)){
  142. row[2] = i+1;
  143. continue;
  144. }
  145. if(type.equals(BashInfo.JXGC)){
  146. row[3] = i+1;
  147. continue;
  148. }
  149. if(type.equals(BashInfo.FJAZGC)){
  150. row[4] = i+1;
  151. continue;
  152. }
  153. if(type.equals(BashInfo.FZGC)){
  154. row[5] = i+1;
  155. break;
  156. }
  157. }
  158. for(int i=0;i<6;i++){
  159. JkxlData jkxlData = new JkxlData();
  160. double originalTotalCost = importExcel.getDouble(row[i],12); //原合计
  161. double otherRate = originalTotalCost/totalFee; //其他费用分摊比例
  162. double orRate = new BigDecimal(otherRate).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue(); //四舍五入
  163. double btc = wsbFees[0]*orRate; //补调差额
  164. double jcl = wsbFees[1]*orRate; //减材料费
  165. double otherFee = qtFees[2]*otherRate; //其他费用
  166. double zjgcFees = gzhz.getDouble(zjgcFee[i],3);//直接工程费
  167. double originalRgCost = importExcel.getDouble(row[i],13); //原人工费
  168. double rgCost = originalRgCost/(1+rate[0]); //后人工费
  169. double originalCbrCost = importExcel.getDouble(row[i],14); //原承包人采购
  170. double cbrCost = originalCbrCost/(1+rate[1]); //后承包人采购
  171. double originalFbrCost = importExcel.getDouble(row[i],15); //原发包人采购
  172. double fbrCost = originalFbrCost/(1+sl); //后发包人采购
  173. double originalJxrCost = importExcel.getDouble(row[i],17); //原机械费
  174. double jxCost = originalJxrCost/(1+rate[2]); //后机械费
  175. double measuresFee1 = ((zjgcFees-fbrCost)/(1+sl)*sl)*csRate[0]; //措施费1
  176. // double measuresFee1 = (rgCost+cbrCost+fbrCost+jxCost)*csRate[0]; //措施费1
  177. double measuresFee2 = rgCost*csRate[1]; //措施费2
  178. double fees = rgCost*gfRate[1]*1.12+rgCost*gfRate[0]; //规费
  179. double tax = (originalTotalCost+measuresFee1+measuresFee2+fees+otherFee)*0.09; //税金
  180. double totalfee = rgCost+cbrCost+fbrCost+jxCost+measuresFee1+measuresFee2+fees+otherFee+tax-fbrCost; //合计
  181. jkxlData.setOriginalTotalCost(originalTotalCost);
  182. jkxlData.setOriginalRate(orRate);
  183. jkxlData.setOriginalRgCost(originalRgCost);
  184. jkxlData.setRgCost(rgCost);
  185. jkxlData.setOriginalCbrCost(originalCbrCost);
  186. jkxlData.setCbrCost(cbrCost);
  187. jkxlData.setOriginalFbrCost(originalFbrCost);
  188. jkxlData.setFbrCost(fbrCost);
  189. jkxlData.setOriginalJxCost(originalJxrCost);
  190. jkxlData.setJxCost(jxCost);
  191. jkxlData.setMeasuresFee1(measuresFee1);
  192. jkxlData.setMeasuresFee2(measuresFee2);
  193. jkxlData.setFees(fees);
  194. jkxlData.setOtherCost(otherFee);
  195. jkxlData.setTex(tax);
  196. jkxlData.setTotalFee(totalfee);
  197. jkxlData.setBzFee(btc);
  198. jkxlData.setJkFee(jcl);
  199. jkxlData.setZjgcFee(zjgcFees);
  200. jkxlData.setWbsCode(BashInfo.ids[i]);
  201. jkxlData.setId(id);
  202. list.add(jkxlData);
  203. }
  204. JkxlData jkxlData1 = new JkxlData();
  205. JkxlData jkxlData2 = new JkxlData();
  206. jkxlData1.setId(id);
  207. jkxlData1.setWbsCode("34120000");
  208. jkxlData1.setTotalFee(qtFees[0]);
  209. jkxlData2.setWbsCode("34220000");
  210. jkxlData2.setTotalFee(qtFees[1]);
  211. jkxlData2.setId(id);
  212. list.add(jkxlData1);
  213. list.add(jkxlData2);
  214. return list;
  215. }
  216. /**
  217. *获取措施费率
  218. */
  219. public double[] getCsRate(ImportExcel importExcel){
  220. int lastRow = importExcel.getLastDataRowNum();
  221. double lsRate = 0.00;
  222. double aqRate = 0.00;
  223. double totalRate = 0.00;
  224. for(int i=2;i<lastRow;i++){
  225. String type = importExcel.getValue(i+1,1);
  226. if(type.equals(BashInfo.CS_LS)){
  227. lsRate = importExcel.getDouble(i+1,3);
  228. }
  229. if(type.equals(BashInfo.CS_AQWM)){
  230. aqRate = importExcel.getDouble(i+1,3);
  231. }
  232. totalRate += importExcel.getDouble(i+1,3);
  233. }
  234. double[] rate = new double[2];
  235. rate[0] = (lsRate+aqRate)/100;
  236. rate[1] = (totalRate-lsRate-aqRate)/100;
  237. return rate;
  238. }
  239. /**
  240. *获取规费率
  241. */
  242. public double[] getGfRate(ImportExcel importExcel) {
  243. int lastRow = importExcel.getLastDataRowNum();
  244. double totalRate = 0.00;
  245. double wxzyRate = 0.00;
  246. for (int i = 2; i < lastRow; i++) {
  247. String type = importExcel.getValue(i + 1, 1);
  248. if (type.equals(BashInfo.GF_WXZY)) {
  249. wxzyRate = importExcel.getDouble(i + 1, 3);
  250. }
  251. if (!importExcel.getValue(i + 1, 2).equals("")) {
  252. totalRate += importExcel.getDouble(i + 1, 3);
  253. }
  254. }
  255. double[] rate = new double[2];
  256. rate[0] = wxzyRate / 100;
  257. rate[1] = (totalRate - wxzyRate) / 100;
  258. return rate;
  259. }
  260. /**
  261. * 获取其他费用
  262. */
  263. public double[] getQtFees(ImportExcel importExcel) {
  264. int lastRow = importExcel.getLastDataRowNum();
  265. double cdFree = 0.00;
  266. double zbFree = 0.00;
  267. double totalFree = 0.00;
  268. for(int i=2;i<lastRow;i++){
  269. String type = importExcel.getValue(i+1,1);
  270. String type1 = importExcel.getValue(i+1,0);
  271. if(type.equals(BashInfo.QT_SGCDZY)){
  272. cdFree = importExcel.getDouble(i+1,2);
  273. }
  274. if(type.equals(BashInfo.QT_ZBDL)){
  275. zbFree = importExcel.getDouble(i+1,2);
  276. }
  277. if(type1.equals(BashInfo.QT_HJ)){
  278. totalFree = importExcel.getDouble(i+1,2);
  279. }
  280. }
  281. double[] rate = new double[3];
  282. rate[0] = cdFree;
  283. rate[1] = zbFree;
  284. rate[2] = totalFree-cdFree-zbFree;
  285. return rate;
  286. }
  287. /**
  288. * 获取调差系数
  289. * @return
  290. */
  291. public double[] getRate(){
  292. double[] rate = new double[3];
  293. rate[0] = jkxlService.getValueByName(BashInfo.RATIO_RGTC).getValue()/100;
  294. rate[1] = jkxlService.getValueByName(BashInfo.RATIO_CLTC).getValue()/100;
  295. rate[2] = jkxlService.getValueByName(BashInfo.RATIO_JXTC).getValue()/100;
  296. return rate;
  297. }
  298. /**
  299. * 获取补增值税税率调整差额和扣减甲供材超供材料费
  300. */
  301. public double[] getFees(ImportExcel importExcel){
  302. int lastRow = importExcel.getLastDataRowNum();
  303. double bzFree = 0.00;
  304. double kcFree = 0.00;
  305. for(int i=0;i<lastRow;i++){
  306. String type = importExcel.getValue(i+1,1);
  307. if(type.equals(BashInfo.BZZSSL)){
  308. bzFree = importExcel.getDouble(i+1,2);
  309. continue;
  310. }
  311. if(type.equals(BashInfo.KJJGCC)){
  312. kcFree = importExcel.getDouble(i+1,2);
  313. break;
  314. }
  315. }
  316. double[] wsb = new double[2];
  317. wsb[0] = bzFree;
  318. wsb[1] = kcFree;
  319. return wsb;
  320. }
  321. /**
  322. *获取直接工程费
  323. */
  324. public int[] getZjgcFee(ImportExcel importExcel) {
  325. int lastRow = importExcel.getLastDataRowNum();
  326. int[] row = new int[6];
  327. for(int i=0;i<lastRow;i++){
  328. String type = importExcel.getValue(i+1,1);
  329. if(type.equals(BashInfo.HZ_JCGC)){
  330. row[0] = i+1;
  331. continue;
  332. }
  333. if(type.equals(BashInfo.HZ_GTGC)){
  334. row[1] = i+1;
  335. continue;
  336. }
  337. if(type.equals(BashInfo.HZ_JDGC)){
  338. row[2] = i+1;
  339. continue;
  340. }
  341. if(type.equals(BashInfo.HZ_JXGC)){
  342. row[3] = i+1;
  343. continue;
  344. }
  345. if(type.equals(BashInfo.HZ_FJAZGC)){
  346. row[4] = i+1;
  347. continue;
  348. }
  349. if(type.equals(BashInfo.HZ_FZ)){
  350. row[5] = i+1;
  351. break;
  352. }
  353. }
  354. return row;
  355. }
  356. public double[] getTzFee(MultipartFile file) throws IOException, InvalidFormatException {
  357. ImportExcel total = new ImportExcel(file,1,BashInfo.SHEET_HZB );
  358. double[] wsb = getFees(total);
  359. return wsb;
  360. }
  361. /**
  362. * 创建项目ID
  363. */
  364. public String getId() {
  365. SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
  366. String newDate=sdf.format(new Date());
  367. String result="";
  368. Random random=new Random();
  369. for(int i=0;i<3;i++){
  370. result+=random.nextInt(10);
  371. }
  372. return newDate+result;
  373. }
  374. }