package com.thhy.materials.modules.biz.concret.service.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.util.StringUtil; import com.thhy.general.common.BasicResult; import com.thhy.general.config.SysUserInfo; import com.thhy.general.utils.UserInfoUtils; import com.thhy.materials.modules.biz.concret.entity.SysSteel; import com.thhy.materials.modules.biz.concret.entity.TSteelConsumption; import com.thhy.materials.modules.biz.concret.entity.TSteelNeed; import com.thhy.materials.modules.biz.concret.entity.dto.RecordDto; import com.thhy.materials.modules.biz.concret.mapper.SysSteelMapper; import com.thhy.materials.modules.biz.concret.mapper.TSteelConsumptionMapper; import com.thhy.materials.modules.biz.concret.service.TSteelConsumptionService; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.bouncycastle.asn1.eac.EACTags; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.OutputStream; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class TSteelConsumptionServiceImpl implements TSteelConsumptionService { @Resource private TSteelConsumptionMapper consumptionMapper; @Resource private SysSteelMapper steelMapper; @Override @Transactional public BasicResult consumptionInsert(Map values) { String consumptionId = consumptionMapper.allByOne(values); if(!StringUtil.isEmpty(consumptionId)){ return BasicResult.faild("11111","类型重复","error"); } values.put("consumptionId",""); consumptionMapper.consumptionInsert(values); List> needList = (List>) values.get("needList"); for (Map objectMap : needList){ objectMap.put("consumptionId",values.get("consumptionId")); consumptionMapper.steelNeedInsert(objectMap); } return BasicResult.success("添加成功"); } @Override public BasicResult consumptionList(HashMap values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); Integer pageSize = Integer.valueOf(values.get("pageSize").toString()); Integer pageNum = Integer.valueOf(values.get("pageNum").toString()); PageHelper.startPage(pageNum,pageSize); List consumptions = consumptionMapper.consumptionList(values); if(consumptions.size()>0){ for (TSteelConsumption consumption :consumptions){ List steelNeeds = consumptionMapper.steelNeedList(consumption.getConsumptionId()); System.out.println(steelNeeds); if(steelNeeds!=null && steelNeeds.size()>0){ for (TSteelNeed steelNeed : steelNeeds ){ // Double i = (Double.valueOf(steelNeed.getNeedNum().toString()) * Double.valueOf(steelNeed.getCoefficient().toString())); BigDecimal b1 = new BigDecimal(Double.toString(Double.valueOf(steelNeed.getNeedNum().toString()))); BigDecimal b2 = new BigDecimal(Double.toString(Double.valueOf(steelNeed.getCoefficient().toString()))); Double v = b1.multiply(b2).doubleValue(); System.out.println(b1+"*"+b2+"="+v); //转化为 4位 DecimalFormat decimalFormat = new DecimalFormat("#.####"); String format = decimalFormat.format(v); steelNeed.setTotals(format); } } consumption.setTSteelNeeds(steelNeeds); } } PageInfo tSteelConsumptionPageInfo = new PageInfo<>(consumptions); return BasicResult.success(tSteelConsumptionPageInfo); } @Override @Transactional public BasicResult consumptionDel(String consumptionId) { consumptionMapper.consumptionDel(consumptionId); consumptionMapper.consumptionNeedDel(consumptionId); return BasicResult.success("删除成功"); } @Override public BasicResult consumptionInfo(String consumptionId) { TSteelConsumption consumption = consumptionMapper.consumptionInfo(consumptionId); List steelNeeds = consumptionMapper.steelNeedList(consumption.getConsumptionId()); consumption.setTSteelNeeds(steelNeeds); return BasicResult.success(consumption); } @Override @Transactional public BasicResult consumptionUpdate(Map values) { String consumptionId = values.get("consumptionId").toString(); String consumptionId1 = consumptionMapper.allByOne(values); if(!StringUtil.isEmpty(consumptionId1)&&!consumptionId.equals(consumptionId1)){ return BasicResult.faild("11111","类型重复","error"); } consumptionMapper.consumptionUpdate(values); consumptionMapper.consumptionNeedDel(consumptionId); List> needList = (List>) values.get("needList"); for (Map objectMap : needList){ objectMap.put("consumptionId",values.get("consumptionId")); consumptionMapper.steelNeedInsert(objectMap); } return BasicResult.success("修改成功"); } @Override public BasicResult consumptionExcel(HashMap values, HttpServletResponse response) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); List consumptions = consumptionMapper.consumptionList(values); for (TSteelConsumption consumption :consumptions){ List steelNeeds = consumptionMapper.steelNeedList(consumption.getConsumptionId()); for (TSteelNeed steelNeed : steelNeeds ){ // Double i = (Double.valueOf(steelNeed.getNeedNum().toString()) * Double.valueOf(steelNeed.getCoefficient().toString())); BigDecimal b1 = new BigDecimal(Double.toString(Double.valueOf(steelNeed.getNeedNum().toString()))); BigDecimal b2 = new BigDecimal(Double.toString(Double.valueOf(steelNeed.getCoefficient().toString()))); Double v = b1.multiply(b2).doubleValue(); steelNeed.setTotals(v.toString()); } consumption.setTSteelNeeds(steelNeeds); } //List recordDtos = new ArrayList<>(); XSSFWorkbook book = new XSSFWorkbook(); XSSFSheet sheet = book.createSheet(); XSSFRow row1 = sheet.createRow(0); row1.createCell(0).setCellValue("项目名称"); row1.createCell(1).setCellValue("尺寸"); row1.createCell(2).setCellValue("配筋"); row1.createCell(3).setCellValue("块号"); List steels = steelMapper.steelPull(sysUserInfo.getCompanyId()); int leg=4; // int rowSizes=1; // int legs=4; for (int i =0 ;i tSteelNeeds = consumptions.get(i).getTSteelNeeds(); for (int is =0 ;is