package com.idea.ifpug.service; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import com.alibaba.excel.ExcelWriter; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.fill.FillConfig; import com.github.pagehelper.PageInfo; import com.idea.ifpug.excel.TestExcel; import com.idea.ifpug.model.*; import com.idea.ifpug.utils.IfpugDataUtils; import com.idea.ifpug.vo.ExcelResultModel; import com.rockstar.common.conf.V2Config; import com.rockstar.frame.model.extend.DateTrans; import com.rockstar.frame.model.extend.Tablepar; import com.rockstar.util.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.util.*; @Service public class SysIfpugService { @Autowired private SysIfpugResultService resultService; @Autowired private SysIfpugTcfService tcfService; @Autowired private SysIfpugFpsService fpsService; @Autowired private SysIfpugIlfsService ilfsService; @Autowired private SysIfpugEifsService eifsService; @Autowired private SysIfpugEisService eisService; @Autowired private SysIfpugEosService eosService; @Autowired private SysIfpugEqsService eqsService; public PageInfo historyList(Tablepar tablepar, SysIfpugResult model, DateTrans dt) { return resultService.list(tablepar, model, dt); } public Object getResultDesc(String id) { Map resultMap = new HashMap<>(); SysIfpugResult result = resultService.selectByPrimaryKey(id); resultMap.put("result", result); // TCF SysIfpugTcfExample tcfExample = new SysIfpugTcfExample(); tcfExample.createCriteria().andResultIdEqualTo(id); List tcfList = tcfService.selectByExample(tcfExample); resultMap.put("tcf", tcfList.size()>0?tcfList.get(0):null); // FPS SysIfpugFpsExample fpsExample = new SysIfpugFpsExample(); fpsExample.setOrderByClause("sort asc"); fpsExample.createCriteria().andResultIdEqualTo(id); List fpsList = fpsService.selectByExample(fpsExample); resultMap.put("fps", fpsList); // ILFS SysIfpugIlfsExample ilfsExample = new SysIfpugIlfsExample(); ilfsExample.createCriteria().andResultIdEqualTo(id); List ilfsList = ilfsService.selectByExample(ilfsExample); resultMap.put("ilfs", ilfsList); // EIFS SysIfpugEifsExample eifsExample = new SysIfpugEifsExample(); eifsExample.createCriteria().andResultIdEqualTo(id); List eifsList = eifsService.selectByExample(eifsExample); resultMap.put("eifs", eifsList); // EIS SysIfpugEisExample eisExample = new SysIfpugEisExample(); eisExample.createCriteria().andResultIdEqualTo(id); List eisList = eisService.selectByExample(eisExample); resultMap.put("eis", eisList); // EOS SysIfpugEosExample eosExample = new SysIfpugEosExample(); eosExample.createCriteria().andResultIdEqualTo(id); List eosList = eosService.selectByExample(eosExample); resultMap.put("eos", eosList); // EQS SysIfpugEqsExample eqsExample = new SysIfpugEqsExample(); eqsExample.createCriteria().andResultIdEqualTo(id); List eqsList = eqsService.selectByExample(eqsExample); resultMap.put("eqs", eqsList); return resultMap; } public void saveResult(JSONObject json){ SysIfpugResult record = new SysIfpugResult(); JSONObject info = json.getJSONObject("info"); record.setId(info.getStr("id")); record.setProjectDesc(info.getStr("projectDesc")); record.setCustomerName(info.getStr("customerName")); record.setProjectName(info.getStr("projectName")); record.setProjectCode(info.getStr("projectCode")); record.setCalculateUser(info.getStr("calculateUser")); record.setCalculateDate(info.getDate("calculateDate")); JSONArray array = json.getJSONArray("list"); for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { String title = jsonObject.getStr("param"); String value = jsonObject.getStr("value"); if("未调整功能点计数(UFC)".equals(title)){ record.setUfc(value); }else if("技术复杂度因子(TCF)".equals(title)){ record.setTcf(value); }else if("调整后功能点计数(AFP)".equals(title)){ record.setAfp(value); }else if("项目生产率(PE)".equals(title)){ record.setPe(value); }else if("项目所需工时".equals(title)){ record.setWorkTime(value); }else if("工时价格".equals(title)){ record.setWorkPrice(new BigDecimal(value)); }else if("项目成本".equals(title)){ record.setProjectCost(new BigDecimal(value)); } } record.setCreateTime(new Date()); resultService.insertSelective(record); } public SysIfpugResult getResult(String id){ return resultService.selectByPrimaryKey(id); } public void saveTcf(SysIfpugTcf result){ tcfService.insertSelective(result); } public SysIfpugTcf getTcf(String id){ return tcfService.selectByPrimaryKey(id); } public void saveFps(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); // for (JSONObject jsonObject : array.toList(JSONObject.class)) { for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugFps fps = new SysIfpugFps(); fps.setResultId(resultId); fps.setFpType(jsonObject.getStr("fpType")); fps.setCommplex(jsonObject.getStr("commplex")); fps.setNum(jsonObject.getStr("num")); fps.setWeights(jsonObject.getStr("weights")); fps.setFps(jsonObject.getStr("fps")); fps.setFp(jsonObject.getStr("fp")); fpsService.insertSelective(fps); } } public SysIfpugFps getFps(String id){ return fpsService.selectByPrimaryKey(id); } public void saveIlfs(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugIlfs sysIfpugIlfs = jsonObject.toBean(SysIfpugIlfs.class); sysIfpugIlfs.setResultId(resultId); ilfsService.insertSelective(sysIfpugIlfs); } // for (SysIfpugIlfs sysIfpugIlfs : array.toList(SysIfpugIlfs.class)) { // sysIfpugIlfs.setResultId(resultId); // ilfsService.insertSelective(sysIfpugIlfs); // } } public SysIfpugIlfs getIlfs(String id){ return ilfsService.selectByPrimaryKey(id); } public void saveEifs(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); // for (SysIfpugEifs sysIfpugEifs : array.toList(SysIfpugEifs.class)) { for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugEifs sysIfpugEifs = jsonObject.toBean(SysIfpugEifs.class); sysIfpugEifs.setResultId(resultId); eifsService.insertSelective(sysIfpugEifs); } } public SysIfpugEifs getEifs(String id){ return eifsService.selectByPrimaryKey(id); } public void saveEis(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); // for (SysIfpugEis sysIfpugEifs : array.toList(SysIfpugEis.class)) { for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugEis sysIfpugEifs = jsonObject.toBean(SysIfpugEis.class); sysIfpugEifs.setResultId(resultId); eisService.insertSelective(sysIfpugEifs); } } public SysIfpugEis getEis(String id){ return eisService.selectByPrimaryKey(id); } public void saveEos(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); // for (SysIfpugEos sysIfpugEos : array.toList(SysIfpugEos.class)) { for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugEos sysIfpugEos = jsonObject.toBean(SysIfpugEos.class); sysIfpugEos.setResultId(resultId); eosService.insertSelective(sysIfpugEos); } } public SysIfpugEos getEos(String id){ return eosService.selectByPrimaryKey(id); } public void saveEqs(JSONObject json){ String resultId = json.getStr("id"); JSONArray array = json.getJSONArray("list"); // for (SysIfpugEqs sysIfpugEqs : array.toList(SysIfpugEqs.class)) { for (JSONObject jsonObject : array.toArray(new JSONObject[]{})) { SysIfpugEqs sysIfpugEqs = jsonObject.toBean(SysIfpugEqs.class); sysIfpugEqs.setResultId(resultId); eqsService.insertSelective(sysIfpugEqs); } } public SysIfpugEqs getEqs(String id){ return eqsService.selectByPrimaryKey(id); } private List> readFile(MultipartFile file) throws IOException{ ExcelReader reader = ExcelUtil.getReader(file.getInputStream()); List> readAll = reader.read(); return readAll; } // 读取ILFS文件 public List readIlfsFile(MultipartFile file) throws IOException { List> readAll = readFile(file); List ifpugList = new ArrayList<>(); for (int i = 0; i < readAll.size(); i++) { if(i < 4) continue; SysIfpugIlfs ilfs = new SysIfpugIlfs(); ilfs.setFileName(readAll.get(i).get(1).toString()); ilfs.setDet(readAll.get(i).get(2).toString()); ilfs.setRet(readAll.get(i).get(3).toString()); ilfs.setDi(readAll.get(i).get(4).toString()); ilfs.setZhong(readAll.get(i).get(5).toString()); ilfs.setGao(readAll.get(i).get(6).toString()); ilfs.setRemark(readAll.get(i).get(7).toString()); ifpugList.add(ilfs); } return ifpugList; } // 读取EIFS文件 public List readEifsFile(MultipartFile file) throws IOException { List> readAll = readFile(file); List ifpugList = new ArrayList<>(); for (int i = 0; i < readAll.size(); i++) { if(i < 4) continue; SysIfpugEifs eifs = new SysIfpugEifs(); eifs.setFileName(readAll.get(i).get(1).toString()); eifs.setDet(readAll.get(i).get(2).toString()); eifs.setRet(readAll.get(i).get(3).toString()); eifs.setDi(readAll.get(i).get(4).toString()); eifs.setZhong(readAll.get(i).get(5).toString()); eifs.setGao(readAll.get(i).get(6).toString()); eifs.setRemark(readAll.get(i).get(7).toString()); ifpugList.add(eifs); } return ifpugList; } // 读取EIS文件 public List readEisFile(MultipartFile file) throws IOException { List> readAll = readFile(file); List ifpugList = new ArrayList<>(); for (int i = 0; i < readAll.size(); i++) { if(i < 4) continue; SysIfpugEis eis = new SysIfpugEis(); eis.setInputName(readAll.get(i).get(1).toString()); eis.setDet(readAll.get(i).get(2).toString()); eis.setFtr(readAll.get(i).get(3).toString()); eis.setDi(readAll.get(i).get(4).toString()); eis.setZhong(readAll.get(i).get(5).toString()); eis.setGao(readAll.get(i).get(6).toString()); eis.setRemark(readAll.get(i).get(7).toString()); ifpugList.add(eis); } return ifpugList; } // 读取EOS文件 public List readEosFile(MultipartFile file) throws IOException { List> readAll = readFile(file); List ifpugList = new ArrayList<>(); for (int i = 0; i < readAll.size(); i++) { if(i < 4) continue; SysIfpugEos eos = new SysIfpugEos(); eos.setOutputName(readAll.get(i).get(1).toString()); eos.setDet(readAll.get(i).get(2).toString()); eos.setFtr(readAll.get(i).get(3).toString()); eos.setDi(readAll.get(i).get(4).toString()); eos.setZhong(readAll.get(i).get(5).toString()); eos.setGao(readAll.get(i).get(6).toString()); eos.setRemark(readAll.get(i).get(7).toString()); ifpugList.add(eos); } return ifpugList; } // 读取EQS文件 public List readEqsFile(MultipartFile file) throws IOException { List> readAll = readFile(file); List ifpugList = new ArrayList<>(); for (int i = 0; i < readAll.size(); i++) { if(i < 4) continue; SysIfpugEqs eqs = new SysIfpugEqs(); eqs.setSeachName(readAll.get(i).get(1).toString()); eqs.setInputDet(readAll.get(i).get(2).toString()); eqs.setInputFtr(readAll.get(i).get(3).toString()); eqs.setInputFzd(readAll.get(i).get(4).toString()); eqs.setOutputDet(readAll.get(i).get(5).toString()); eqs.setOutputFtr(readAll.get(i).get(6).toString()); eqs.setOutputFzd(readAll.get(i).get(7).toString()); eqs.setDi(readAll.get(i).get(8).toString()); eqs.setZhong(readAll.get(i).get(9).toString()); eqs.setGao(readAll.get(i).get(10).toString()); eqs.setRemark(readAll.get(i).get(11).toString()); ifpugList.add(eqs); } return ifpugList; } // 结果导出 public void resultDownload(String resultId, OutputStream out) throws Exception { TestExcel excelUtils = new TestExcel(); String template = V2Config.getProfile()+"Template/excelTemplate.xlsx"; ExcelWriter excelWriter = excelUtils.getExcelWriter(out, template); { // 核算结果 WriteSheet resultSheet = excelUtils.getWriteSheet(0, "核算结果"); SysIfpugResult result = resultService.selectByPrimaryKey(resultId); Map resultMap = BeanUtil.beanToMap(result); excelWriter.fill(resultMap, resultSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(new ArrayList(), fillConfig, resultSheet); } { // TCF SysIfpugTcfExample tcfExample = new SysIfpugTcfExample(); tcfExample.createCriteria().andResultIdEqualTo(resultId); List tcfList = tcfService.selectByExample(tcfExample); SysIfpugTcf tcf = tcfList.size()>0?tcfList.get(0):new SysIfpugTcf(); WriteSheet tcfSheet = excelUtils.getWriteSheet(1, "TCF"); Map resultMap = BeanUtil.beanToMap(tcf); excelWriter.fill(resultMap, tcfSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(new ArrayList<>(), fillConfig, tcfSheet); }{ // FPS - TODO 待完善 // SysIfpugFpsExample fpsExample = new SysIfpugFpsExample(); // fpsExample.createCriteria().andResultIdEqualTo(resultId); // List tcfList = fpsService.selectByExample(fpsExample); // SysIfpugFps fps = tcfList.size()>0?tcfList.get(0):new SysIfpugFps(); // WriteSheet tcfSheet = excelUtils.getWriteSheet(2, "FPs"); // Map resultMap = BeanUtil.beanToMap(fps); // excelWriter.fill(resultMap, tcfSheet); // FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); // excelWriter.fill(new ArrayList<>(), fillConfig, tcfSheet); }{ // ILFS SysIfpugIlfsExample ilfsExample = new SysIfpugIlfsExample(); ilfsExample.createCriteria().andResultIdEqualTo(resultId); List ilfsList = ilfsService.selectByExample(ilfsExample); Map ilfsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; for (SysIfpugIlfs item : ilfsList) { diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); } ilfsMap.put("diCount", diCount); ilfsMap.put("zhongCount", zhongCount); ilfsMap.put("gaoCount", gaoCount); WriteSheet ilfsSheet = excelUtils.getWriteSheet(3, "ILFs"); excelWriter.fill(ilfsMap, ilfsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(ilfsList, fillConfig, ilfsSheet); }{ // EIFS SysIfpugEifsExample eifsExample = new SysIfpugEifsExample(); eifsExample.createCriteria().andResultIdEqualTo(resultId); List eifsList = eifsService.selectByExample(eifsExample); Map eifsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; for (SysIfpugEifs item : eifsList) { diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); } eifsMap.put("diCount", diCount); eifsMap.put("zhongCount", zhongCount); eifsMap.put("gaoCount", gaoCount); WriteSheet ilfsSheet = excelUtils.getWriteSheet(3, "EIFs"); excelWriter.fill(eifsMap, ilfsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eifsList, fillConfig, ilfsSheet); }{ // EIS SysIfpugEisExample eisExample = new SysIfpugEisExample(); eisExample.createCriteria().andResultIdEqualTo(resultId); List eisList = eisService.selectByExample(eisExample); Map eisMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; for (SysIfpugEis item : eisList) { diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); } eisMap.put("diCount", diCount); eisMap.put("zhongCount", zhongCount); eisMap.put("gaoCount", gaoCount); WriteSheet eisSheet = excelUtils.getWriteSheet(4, "EIs"); excelWriter.fill(eisMap, eisSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eisList, fillConfig, eisSheet); }{ // EOS SysIfpugEosExample eosExample = new SysIfpugEosExample(); eosExample.createCriteria().andResultIdEqualTo(resultId); List eosList = eosService.selectByExample(eosExample); Map eosMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; for (SysIfpugEos item : eosList) { diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); } eosMap.put("diCount", diCount); eosMap.put("zhongCount", zhongCount); eosMap.put("gaoCount", gaoCount); WriteSheet eosSheet = excelUtils.getWriteSheet(5, "EOs"); excelWriter.fill(eosMap, eosSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eosList, fillConfig, eosSheet); }{ // EQS SysIfpugEqsExample eqsExample = new SysIfpugEqsExample(); eqsExample.createCriteria().andResultIdEqualTo(resultId); List eqsList = eqsService.selectByExample(eqsExample); Map eqsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; for (SysIfpugEqs item : eqsList) { diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); } eqsMap.put("diCount", diCount); eqsMap.put("zhongCount", zhongCount); eqsMap.put("gaoCount", gaoCount); WriteSheet eqsSheet = excelUtils.getWriteSheet(6, "EQs"); excelWriter.fill(eqsMap, eqsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eqsList, fillConfig, eqsSheet); } excelUtils.clse(excelWriter); } // init - index public void initDataIndex(List dataList){ int indez = 1; for (Object obj : dataList) { ReflectUtil.invoke(obj, "setIndex", String.valueOf(indez)); indez++; } } // 页面结果导出 public void resultViewDownload(ExcelResultModel resultModel, OutputStream out) throws Exception { TestExcel excelUtils = new TestExcel(); String template = V2Config.getProfile()+"Template/excelTemplate.xlsx"; ExcelWriter excelWriter = excelUtils.getExcelWriter(out, template); { // 核算结果 WriteSheet resultSheet = excelUtils.getWriteSheet(0, "核算结果"); SysIfpugResult result = resultModel.getResult(); Map resultMap = BeanUtil.beanToMap(result); excelWriter.fill(resultMap, resultSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(new ArrayList(), fillConfig, resultSheet); }{ // TCF SysIfpugTcf tcf = resultModel.getTcf(); WriteSheet tcfSheet = excelUtils.getWriteSheet(1, "TCF"); tcf = initSysIfpugTcf(tcf); Map resultMap = BeanUtil.beanToMap(tcf); excelWriter.fill(resultMap, tcfSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(new ArrayList<>(), fillConfig, tcfSheet); }{ // FPS List fpsList = resultModel.getFpsList(); int fpsCount = 0; for (SysIfpugFps sysIfpugFps : fpsList) { fpsCount += Integer.parseInt(sysIfpugFps.getFps()); } Map fpsMap = new HashMap<>(); fpsMap.put("fpsCount", fpsCount); fpsMap.put("fpCount", "100%"); WriteSheet fpsSheet = excelUtils.getWriteSheet(2, "FPs"); excelWriter.fill(fpsMap, fpsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(fpsList, fillConfig, fpsSheet); }{ // ILFS List ilfsList = resultModel.getIlfsList(); Map ilfsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; int index = 1; for (SysIfpugIlfs item : ilfsList) { item.setDi(!StringUtils.isNotEmpty(item.getDi())?"0":item.getDi()); item.setZhong(!StringUtils.isNotEmpty(item.getZhong())?"0":item.getZhong()); item.setGao(!StringUtils.isNotEmpty(item.getGao())?"0":item.getGao()); diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); item.setIndex(String.valueOf(index)); index++; } ilfsMap.put("diCount", diCount); ilfsMap.put("zhongCount", zhongCount); ilfsMap.put("gaoCount", gaoCount); WriteSheet ilfsSheet = excelUtils.getWriteSheet(3, "ILFs"); excelWriter.fill(ilfsMap, ilfsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(ilfsList, fillConfig, ilfsSheet); }{ // EIFS List eifsList = resultModel.getEifsList(); Map eifsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; int index = 1; for (SysIfpugEifs item : eifsList) { item.setDi(!StringUtils.isNotEmpty(item.getDi())?"0":item.getDi()); item.setZhong(!StringUtils.isNotEmpty(item.getZhong())?"0":item.getZhong()); item.setGao(!StringUtils.isNotEmpty(item.getGao())?"0":item.getGao()); diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); item.setIndex(String.valueOf(index)); index++; } eifsMap.put("diCount", diCount); eifsMap.put("zhongCount", zhongCount); eifsMap.put("gaoCount", gaoCount); WriteSheet ilfsSheet = excelUtils.getWriteSheet(4, "EIFs"); excelWriter.fill(eifsMap, ilfsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eifsList, fillConfig, ilfsSheet); }{ // EIS List eisList = resultModel.getEisList(); Map eisMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; int index = 1; for (SysIfpugEis item : eisList) { item.setDi(!StringUtils.isNotEmpty(item.getDi())?"0":item.getDi()); item.setZhong(!StringUtils.isNotEmpty(item.getZhong())?"0":item.getZhong()); item.setGao(!StringUtils.isNotEmpty(item.getGao())?"0":item.getGao()); diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); item.setIndex(String.valueOf(index)); index++; } eisMap.put("diCount", diCount); eisMap.put("zhongCount", zhongCount); eisMap.put("gaoCount", gaoCount); WriteSheet eisSheet = excelUtils.getWriteSheet(5, "EIs"); excelWriter.fill(eisMap, eisSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eisList, fillConfig, eisSheet); }{ // EOS List eosList = resultModel.getEosList(); Map eosMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; int index = 1; for (SysIfpugEos item : eosList) { item.setDi(!StringUtils.isNotEmpty(item.getDi())?"0":item.getDi()); item.setZhong(!StringUtils.isNotEmpty(item.getZhong())?"0":item.getZhong()); item.setGao(!StringUtils.isNotEmpty(item.getGao())?"0":item.getGao()); diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); item.setIndex(String.valueOf(index)); index++; } eosMap.put("diCount", diCount); eosMap.put("zhongCount", zhongCount); eosMap.put("gaoCount", gaoCount); WriteSheet eosSheet = excelUtils.getWriteSheet(6, "EOs"); excelWriter.fill(eosMap, eosSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eosList, fillConfig, eosSheet); }{ // EQS List eqsList = resultModel.getEqsList(); Map eqsMap = new HashMap<>(); int diCount = 0; int zhongCount = 0; int gaoCount = 0; int index = 1; for (SysIfpugEqs item : eqsList) { item.setDi(!StringUtils.isNotEmpty(item.getDi())?"0":item.getDi()); item.setZhong(!StringUtils.isNotEmpty(item.getZhong())?"0":item.getZhong()); item.setGao(!StringUtils.isNotEmpty(item.getGao())?"0":item.getGao()); diCount += Integer.parseInt(item.getDi()); zhongCount += Integer.parseInt(item.getZhong()); gaoCount += Integer.parseInt(item.getGao()); item.setIndex(String.valueOf(index)); index++; } eqsMap.put("diCount", diCount); eqsMap.put("zhongCount", zhongCount); eqsMap.put("gaoCount", gaoCount); WriteSheet eqsSheet = excelUtils.getWriteSheet(7, "EQs"); excelWriter.fill(eqsMap, eqsSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(eqsList, fillConfig, eqsSheet); }{ // 功能点规模计算明细 List detailList = getPointScaleDetail(resultModel.getIlfsList(), resultModel.getEifsList(), resultModel.getEisList(), resultModel.getEosList(), resultModel.getEqsList()); WriteSheet pointScaleSheet = excelUtils.getWriteSheet(8, "功能点规模计算明细"); // 统计数据 int ilfDetCount = 0, ilfRetCount = 0, eifDetCount = 0, eifRetCount = 0, eiDetCount = 0, eiFtrCount = 0, eoDetCount = 0, eoFtrCount = 0, eqImputDetCount = 0, eqImputFtrCount = 0, eqoutputDetCount = 0, eqoutputFtrCount = 0; for (IfpugPointScaleDetailsExcel detailsExcel : detailList) { ilfDetCount += StringUtils.isNotEmpty(detailsExcel.getIlfDet())?Integer.parseInt(detailsExcel.getIlfDet()):0; ilfRetCount += StringUtils.isNotEmpty(detailsExcel.getIlfRet())?Integer.parseInt(detailsExcel.getIlfRet()):0; eifDetCount += StringUtils.isNotEmpty(detailsExcel.getEifDet())?Integer.parseInt(detailsExcel.getEifDet()):0; eifRetCount += StringUtils.isNotEmpty(detailsExcel.getEifRet())?Integer.parseInt(detailsExcel.getEifRet()):0; eiDetCount += StringUtils.isNotEmpty(detailsExcel.getEiDet())?Integer.parseInt(detailsExcel.getEiDet()):0; eiFtrCount += StringUtils.isNotEmpty(detailsExcel.getEiFtr())?Integer.parseInt(detailsExcel.getEiFtr()):0; eoDetCount += StringUtils.isNotEmpty(detailsExcel.getEoDet())?Integer.parseInt(detailsExcel.getEoDet()):0; eoFtrCount += StringUtils.isNotEmpty(detailsExcel.getEoFtr())?Integer.parseInt(detailsExcel.getEoFtr()):0; eqImputDetCount += StringUtils.isNotEmpty(detailsExcel.getEqImputDet())?Integer.parseInt(detailsExcel.getEqImputDet()):0; eqImputFtrCount += StringUtils.isNotEmpty(detailsExcel.getEqImputFtr())?Integer.parseInt(detailsExcel.getEqImputFtr()):0; eqoutputDetCount += StringUtils.isNotEmpty(detailsExcel.getEqoutputDet())?Integer.parseInt(detailsExcel.getEqoutputDet()):0; eqoutputFtrCount += StringUtils.isNotEmpty(detailsExcel.getEqoutputFtr())?Integer.parseInt(detailsExcel.getEqoutputFtr()):0; } Map pointScaleMap = new HashMap<>(); pointScaleMap.put("ilfDetCount", ilfDetCount); pointScaleMap.put("ilfRetCount", ilfRetCount); pointScaleMap.put("eifDetCount", eifDetCount); pointScaleMap.put("eifRetCount", eifRetCount); pointScaleMap.put("eiDetCount", eiDetCount); pointScaleMap.put("eiFtrCount", eiFtrCount); pointScaleMap.put("eoDetCount", eoDetCount); pointScaleMap.put("eoFtrCount", eoFtrCount); pointScaleMap.put("eqImputDetCount", eqImputDetCount); pointScaleMap.put("eqImputFtrCount", eqImputFtrCount); pointScaleMap.put("eqoutputDetCount", eqoutputDetCount); pointScaleMap.put("eqoutputFtrCount", eqoutputFtrCount); excelWriter.fill(pointScaleMap, pointScaleSheet); FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); excelWriter.fill(detailList, fillConfig, pointScaleSheet); } excelUtils.clse(excelWriter); } public String notEmptyToString(String reslt){ return StringUtils.isNotEmpty(reslt)?reslt:"0"; } public SysIfpugTcf initSysIfpugTcf(SysIfpugTcf tcf){ tcf.setDataComm(notEmptyToString(tcf.getDataComm())); tcf.setDataHandle(notEmptyToString(tcf.getDataHandle())); tcf.setBehavior(notEmptyToString(tcf.getBehavior())); tcf.setLoads(notEmptyToString(tcf.getLoads())); tcf.setThings(notEmptyToString(tcf.getThings())); tcf.setDataInput(notEmptyToString(tcf.getDataInput())); tcf.setUserRatio(notEmptyToString(tcf.getUserRatio())); tcf.setLineUpdate(notEmptyToString(tcf.getLineUpdate())); tcf.setComplex(notEmptyToString(tcf.getComplex())); tcf.setMultiplex(notEmptyToString(tcf.getMultiplex())); tcf.setInstalls(notEmptyToString(tcf.getInstalls())); tcf.setOperate(notEmptyToString(tcf.getOperate())); tcf.setPlatform(notEmptyToString(tcf.getPlatform())); tcf.setExtends(notEmptyToString(tcf.getExtend())); return tcf; } // 结果导入 public Map resultImport(InputStream inputStream) throws Exception { ExcelReader reader = ExcelUtil.getReader(inputStream); List> readAll = reader.read(4); // 载体 List ilfsList = new ArrayList<>(); List eifsList = new ArrayList<>(); List eisList = new ArrayList<>(); List eosList = new ArrayList<>(); List eqsList = new ArrayList<>(); for (List objects : readAll) { resultDataInit(objects, ilfsList, eifsList, eisList, eosList, eqsList); } Map resultMap = new HashMap<>(); resultMap.put("ilfs", ilfsList); resultMap.put("eifs", eifsList); resultMap.put("eis", eisList); resultMap.put("eos", eosList); resultMap.put("eqs", eqsList); IfpugDataUtils utils = new IfpugDataUtils(); List fpsList = utils.initFps(ilfsList, eifsList, eisList, eosList, eqsList); resultMap.put("fps", fpsList); SysIfpugResult result = utils.initResult(fpsList); resultMap.put("result", result); return resultMap; } // 结果判空 private boolean judgData(String... data) { boolean falg = false; for (String datum : data) { if(falg) continue; if(StringUtils.isNotEmpty(datum) && Integer.parseInt(datum) > 0) falg = true; } return falg; } // 结果装载 private void resultDataInit(List list, List ilfsList, List eifsList, List eisList, List eosList, List eqsList) { // 功能点 TODO 未处理=== String gnName = list.get(4).toString(); // ILF String ilfDet = list.get(9).toString(); String ilfRet = list.get(10).toString(); // EIF String eifDet = list.get(11).toString(); String eifRet = list.get(12).toString(); // EI String eiDet = list.get(13).toString(); String eiFtr = list.get(14).toString(); // EO String eoDet = list.get(15).toString(); String eoFtr = list.get(16).toString(); // EQ String eqImDet = list.get(17).toString(); String eqImFtr = list.get(18).toString(); String eqOutDet = list.get(19).toString(); String eqOutFtr = list.get(20).toString(); // 备注 String remark = list.get(21).toString(); // ILF if(judgData(ilfDet, ilfRet)){ SysIfpugIlfs ilfs = new SysIfpugIlfs(); ilfs.setFileName(gnName); ilfs.setDet(ilfDet); ilfs.setRet(ilfRet); ilfs.setRemark(remark); // 计算复杂度 IfpugDataUtils.ilfsFzd(ilfs); ilfsList.add(ilfs); } // EIF if(judgData(eifDet, eifRet)){ SysIfpugEifs eifs = new SysIfpugEifs(); eifs.setFileName(gnName); eifs.setDet(eifDet); eifs.setRet(eifRet); eifs.setRemark(remark); // 计算复杂度 IfpugDataUtils.eifsFzd(eifs); eifsList.add(eifs); } // EI if(judgData(eiDet, eiFtr)){ SysIfpugEis eis = new SysIfpugEis(); eis.setInputName(gnName); eis.setDet(eiDet); eis.setFtr(eiFtr); eis.setRemark(remark); // 计算复杂度 IfpugDataUtils.eisFzd(eis); eisList.add(eis); } // EO if(judgData(eoDet, eoFtr)){ SysIfpugEos eos = new SysIfpugEos(); eos.setOutputName(gnName); eos.setDet(eoDet); eos.setFtr(eoFtr); eos.setRemark(remark); // 计算复杂度 IfpugDataUtils.eosFzd(eos); eosList.add(eos); } // EQ if(judgData(eqImDet, eqImFtr, eqOutDet, eqOutFtr)){ SysIfpugEqs eqs = new SysIfpugEqs(); eqs.setSeachName(gnName); eqs.setInputDet(eqImDet); eqs.setInputFtr(eqImFtr); eqs.setOutputDet(eqOutDet); eqs.setOutputFtr(eqOutFtr); eqs.setRemark(remark); // 计算复杂度 IfpugDataUtils.eqsFzd(eqs); eqsList.add(eqs); } } // 获取EQ复杂度 public String getEQCommplex(String inPfz, String ouFzd){ if("低".equals(inPfz) && "低".equals(ouFzd)){ return "低"; }else if("高".equals(inPfz) && "高".equals(ouFzd)){ return "高"; }else{ return "中"; } } // 获取功能复杂度 public String getCommplex(String di, String zhong, String gao){ if(StringUtils.isNotEmpty(di) || StringUtils.isNotEmpty(zhong) || StringUtils.isNotEmpty(gao)){ int diNum = StringUtils.isNotEmpty(di)?Integer.parseInt(di):0; int zhongNum = StringUtils.isNotEmpty(zhong)?Integer.parseInt(zhong):0; int gaoNum = StringUtils.isNotEmpty(gao)?Integer.parseInt(gao):0; if(diNum > 0 && zhongNum <= 0 && gaoNum <= 0){ return "低"; }else if(diNum <= 0 && zhongNum <= 0 && gaoNum > 0){ return "高"; }else{ return "中"; } } return ""; } // 获取功能点数 public String getCommplexNum(String di, String zhong, String gao){ if(StringUtils.isNotEmpty(di) || StringUtils.isNotEmpty(zhong) || StringUtils.isNotEmpty(gao)){ int diNum = StringUtils.isNotEmpty(di)?Integer.parseInt(di):0; int zhongNum = StringUtils.isNotEmpty(zhong)?Integer.parseInt(zhong):0; int gaoNum = StringUtils.isNotEmpty(gao)?Integer.parseInt(gao):0; if(diNum > 0 && zhongNum <= 0 && gaoNum <= 0){ return String.valueOf(diNum); }else if(diNum <= 0 && zhongNum <= 0 && gaoNum > 0){ return String.valueOf(gaoNum); }else{ return String.valueOf(zhongNum); } } return "0"; } // 计算权重 public String getWeights(String type, String fzd){ if("ILF".equals(type)){ if("低".equals(fzd)){ return "7"; }else if("中".equals(fzd)){ return "10"; }else if("高".equals(fzd)){ return "15"; } }else if("EIF".equals(type)){ if("低".equals(fzd)){ return "5"; }else if("中".equals(fzd)){ return "7"; }else if("高".equals(fzd)){ return "10"; } }else if("EI".equals(type)){ if("低".equals(fzd)){ return "3"; }else if("中".equals(fzd)){ return "4"; }else if("高".equals(fzd)){ return "6"; } }else if("EO".equals(type)){ if("低".equals(fzd)){ return "4"; }else if("中".equals(fzd)){ return "5"; }else if("高".equals(fzd)){ return "7"; } }else if("EQ".equals(type)){ if("低".equals(fzd)){ return "3"; }else if("中".equals(fzd)){ return "4"; }else if("高".equals(fzd)){ return "6"; } } return "0"; } // 生成功能点规模计算明细 private List getPointScaleDetail(List ilfsList, List eifsList, List eisList, List eosList, List eqsList) { int indexNo = 0; List result = new ArrayList<>(); for (SysIfpugIlfs item : ilfsList) { indexNo++; IfpugPointScaleDetailsExcel detailsExcel = new IfpugPointScaleDetailsExcel(); detailsExcel.setIndexNo(String.valueOf(indexNo)); detailsExcel.setFourthLayer(item.getFileName()); detailsExcel.setFtype("ILF"); String commplex = getCommplex(item.getDi(),item.getZhong(),item.getGao()); detailsExcel.setCommplex(commplex); detailsExcel.setWeights(getWeights("ILF", commplex)); detailsExcel.setNum(getCommplexNum(item.getDi(),item.getZhong(),item.getGao())); detailsExcel.setIlfDet(item.getDet()); detailsExcel.setIlfRet(item.getRet()); detailsExcel.setRemark(item.getRemark()); result.add(detailsExcel); } for (SysIfpugEifs item : eifsList) { indexNo++; IfpugPointScaleDetailsExcel detailsExcel = new IfpugPointScaleDetailsExcel(); detailsExcel.setIndexNo(String.valueOf(indexNo)); detailsExcel.setFourthLayer(item.getFileName()); detailsExcel.setFtype("EIF"); String commplex = getCommplex(item.getDi(),item.getZhong(),item.getGao()); detailsExcel.setCommplex(commplex); detailsExcel.setWeights(getWeights("EIF", commplex)); detailsExcel.setNum(getCommplexNum(item.getDi(),item.getZhong(),item.getGao())); detailsExcel.setEifDet(item.getDet()); detailsExcel.setEifRet(item.getRet()); detailsExcel.setRemark(item.getRemark()); result.add(detailsExcel); } for (SysIfpugEis item : eisList) { indexNo++; IfpugPointScaleDetailsExcel detailsExcel = new IfpugPointScaleDetailsExcel(); detailsExcel.setIndexNo(String.valueOf(indexNo)); detailsExcel.setFourthLayer(item.getInputName()); detailsExcel.setFtype("EI"); String commplex = getCommplex(item.getDi(),item.getZhong(),item.getGao()); detailsExcel.setCommplex(commplex); detailsExcel.setWeights(getWeights("EI", commplex)); detailsExcel.setNum(getCommplexNum(item.getDi(),item.getZhong(),item.getGao())); detailsExcel.setEiDet(item.getDet()); detailsExcel.setEiFtr(item.getFtr()); detailsExcel.setRemark(item.getRemark()); result.add(detailsExcel); } for (SysIfpugEos item : eosList) { indexNo++; IfpugPointScaleDetailsExcel detailsExcel = new IfpugPointScaleDetailsExcel(); detailsExcel.setIndexNo(String.valueOf(indexNo)); detailsExcel.setFourthLayer(item.getOutputName()); detailsExcel.setFtype("EO"); String commplex = getCommplex(item.getDi(),item.getZhong(),item.getGao()); detailsExcel.setCommplex(commplex); detailsExcel.setWeights(getWeights("EO", commplex)); detailsExcel.setNum(getCommplexNum(item.getDi(),item.getZhong(),item.getGao())); detailsExcel.setEoDet(item.getDet()); detailsExcel.setEoFtr(item.getFtr()); detailsExcel.setRemark(item.getRemark()); result.add(detailsExcel); } for (SysIfpugEqs item : eqsList) { indexNo++; IfpugPointScaleDetailsExcel detailsExcel = new IfpugPointScaleDetailsExcel(); detailsExcel.setIndexNo(String.valueOf(indexNo)); detailsExcel.setFourthLayer(item.getSeachName()); detailsExcel.setFtype("EQ"); String commplex = getEQCommplex(item.getInputFzd(), item.getOutputFtr()); detailsExcel.setCommplex(commplex); detailsExcel.setWeights(getWeights("EQ", commplex)); detailsExcel.setNum(getCommplexNum(item.getDi(),item.getZhong(),item.getGao())); detailsExcel.setEqImputDet(item.getInputDet()); detailsExcel.setEqImputFtr(item.getInputDet()); detailsExcel.setEqoutputDet(item.getOutputDet()); detailsExcel.setEqoutputFtr(item.getOutputFtr()); detailsExcel.setRemark(item.getRemark()); result.add(detailsExcel); } return result; } public static void main(String[] args) { System.err.println(SecureUtil.md5("IndustrySupervisionSuperviseDistribute")); } }