package com.jeeplus.modules.sg.overheadline.service; import com.jeeplus.common.utils.excel.ImportExcel; import com.jeeplus.common.utils.sg.ExcelUtil; import com.jeeplus.modules.sg.overheadline.entity.JkxlAdjustFee; import com.jeeplus.modules.sg.overheadline.entity.JkxlDetailFee; import com.jeeplus.modules.sg.overheadline.entity.WbsProject; import com.jeeplus.modules.sg.overheadline.mapper.OverheadLineMapper; import com.jeeplus.modules.sg.overheadline.util.BashInfo; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; @Service public class OverheadLineService { @Autowired private OverheadLineMapper overheadLineMapper; @Autowired private FeeAdjustService feeAdjustService; @Autowired private RuleRatioService ruleRatioService; public List getList(String id){ return overheadLineMapper.getList(id); } public List findList(String id){ List list = overheadLineMapper.findList(id); double btTotal = 0.00; double qtTotal = 0.00; for(JkxlDetailFee jkxlDetailFee : list){ //本体费用求和 if(jkxlDetailFee.getOriginalTotalCost() != null){ btTotal += jkxlDetailFee.getTotalFee(); } //其他费用求和 if(jkxlDetailFee.getOriginalTotalCost() == null && jkxlDetailFee.getTotalFee() != null){ qtTotal += jkxlDetailFee.getTotalFee(); } } for(JkxlDetailFee jkxlDetailFee : list){ if(jkxlDetailFee.getWbsCode().equals("30000000")){ jkxlDetailFee.setTotalFee(btTotal+qtTotal); } if(jkxlDetailFee.getWbsCode().equals("39000000")){ jkxlDetailFee.setTotalFee(btTotal); } if(jkxlDetailFee.getWbsCode().equals("34000000")){ jkxlDetailFee.setTotalFee(qtTotal); } } return list; } public JkxlDetailFee getDate(String id, String wbsCode){ return overheadLineMapper.getData(id,wbsCode); } @Transactional public void updataDate(JkxlDetailFee jkxlDetailFee){ overheadLineMapper.updateDate(jkxlDetailFee); } @Transactional public void saveProject(WbsProject wbsProject){ overheadLineMapper.saveProject(wbsProject); } public void save(MultipartFile file,double sl,String name,String id) throws IOException, InvalidFormatException { WbsProject wbsProject = new WbsProject(); wbsProject.setId(id); wbsProject.setName(name); wbsProject.setCreateDate(new Date()); //保存项目 overheadLineMapper.saveProject(wbsProject); //获取调差系数 double[] tcRate = new double[3]; tcRate[0] = ruleRatioService.getValueByName(BashInfo.RATIO_RGTC).getValue()/100; tcRate[1] = ruleRatioService.getValueByName(BashInfo.RATIO_CLTC).getValue()/100; tcRate[2] = ruleRatioService.getValueByName(BashInfo.RATIO_JXTC).getValue()/100; //读取表格 ImportExcel importExcel = new ImportExcel(file,1,BashInfo.SHEET_FBFXJJ); //分部分项工程量清单计价表 ImportExcel csqd = new ImportExcel(file,1,BashInfo.SHEET_CSB); // 措施项目清单计价表(一) ImportExcel gf = new ImportExcel(file,1,BashInfo.SHEET_GFQD); //规费项目清单计价表 ImportExcel qt = new ImportExcel(file,1,BashInfo.SHEET_QTFY); //其他项目清单计价表 ImportExcel total = new ImportExcel(file,1,BashInfo.SHEET_HZB ); //工程项目竣工结算汇总表 ImportExcel gzhz = new ImportExcel(file,1,BashInfo.SHEET_GCHZ ); //架空线路工程费用汇总表 //获取补增值税税率调整差额和扣减甲供材超供材料费 double[] wsbFees = ExcelUtil.getDoubleArray(total, new String[]{BashInfo.BZZSSL,BashInfo.KJJGCC},1,2); double[] originalTotalFees = ExcelUtil.getDoubleArray(gzhz,BashInfo.HZ_ALL,1,2); //获取合计费 double[] zjgcFees = ExcelUtil.getDoubleArray(gzhz,BashInfo.HZ_ALL,1,3); //获取直接工程费 double[][] originalFees = ExcelUtil.getDoubleArrays(importExcel,BashInfo.MX_ALL,2, new int[]{13, 14, 15, 17}); //获取原始费用 double texRate = ExcelUtil.getTexRate(total); //获取税率 double totalFee = ExcelUtil.getDouble(importExcel,BashInfo.PROJECTNAME,2,12); //获取架空线路合计金额 double[] csRate = BashInfo.getCsRate(csqd); //获取措施费率 double[] gfRate = BashInfo.getGfRate(gf); //获取规费率 double[] qtFees = BashInfo.getQtFees(qt); //获取其他费用 double gcjsFee = BashInfo.getGcjsFee(total); //获取工程结算价 //将本体工程费用明细存入集合 List list = new ArrayList<>(); for(int i=0;itz){ double gxFee = gcjsFee-tz-qtFees[0]-qtFees[1]-wsbFees[0]-wsbFees[1]; double rate1 = 0.00; double gxFee1 = 0.00; double totalF = 0.00; for(JkxlDetailFee jkxlDetailFee : list){ rate1 = jkxlDetailFee.getTotalFee()/tz; gxFee1 = gxFee*rate1; totalF = gxFee1 + jkxlDetailFee.getTotalFee(); jkxlDetailFee.setGxFee(Math.abs(gxFee1)); jkxlDetailFee.setTotalFee(totalF); } }else { double gxFee = tz+qtFees[0]+qtFees[1]+wsbFees[0]+wsbFees[1]-gcjsFee; double rate1 = 0.00; double gxFee1 = 0.00; double totalF = 0.00; for(JkxlDetailFee jkxlDetailFee : list){ rate1 = jkxlDetailFee.getTotalFee()/tz; gxFee1 = gxFee*rate1; totalF = jkxlDetailFee.getTotalFee()-gxFee1; jkxlDetailFee.setGxFee(Math.abs(gxFee1)); jkxlDetailFee.setTotalFee(totalF); } } //将其他费用存入集合 JkxlDetailFee jkxlDetailFee1 = new JkxlDetailFee(); JkxlDetailFee jkxlDetailFee2 = new JkxlDetailFee(); jkxlDetailFee1.setId(id); jkxlDetailFee1.setWbsCode("34120000"); jkxlDetailFee1.setTotalFee(qtFees[0]); jkxlDetailFee2.setWbsCode("34220000"); jkxlDetailFee2.setTotalFee(qtFees[1]); jkxlDetailFee2.setId(id); list.add(jkxlDetailFee1); list.add(jkxlDetailFee2); //保存费用明细 for(JkxlDetailFee jkxlDetailFee:list){ overheadLineMapper.save(jkxlDetailFee); } //保存未识别费用 JkxlAdjustFee jkxlAdjustFee = new JkxlAdjustFee(); jkxlAdjustFee.setId(id); jkxlAdjustFee.setType(BashInfo.BZZSSL); jkxlAdjustFee.setFee(wsbFees[0]); feeAdjustService.save(jkxlAdjustFee); JkxlAdjustFee jkxlAdjustFee1 = new JkxlAdjustFee(); jkxlAdjustFee1.setId(id); jkxlAdjustFee1.setType(BashInfo.KJJGCC); jkxlAdjustFee1.setFee(wsbFees[1]); feeAdjustService.save(jkxlAdjustFee1); } }