Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package data.services; import data.dao.EventDao; import data.entity.BaseParam; import data.entity.Car; import data.entity.Event; import data.entity.FreeValueRange; import data.entity.Mark; import data.entity.Model; import data.entity.Sequence; import data.entity.SequenceValueRange; import data.entity.SubModel; import data.services.parent.PrimService; import java.io.File; import java.io.FileOutputStream; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import logic.EntityCar; import logic.EntityProperty; import logic.EntityPropertyHolder; import logic.IdealEntityParam; import logic.Rank; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFHyperlink; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.util.CellRangeAddress; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import support.StringAdapter; /** * * @author bezdatiuzer */ @Service @Transactional @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) public class EventService extends PrimService { @Autowired private EventDao eventDao; @Autowired private FreeValueRangeService freeValueRangeService; @Autowired private BaseParamService baseParamService; @Autowired private SubModelService subModelService; public List<Event> getEvents() { return eventDao.getAllDesc("eventId"); } public void createEvent(Event ev) throws Exception { if (validate(ev)) { eventDao.save(ev); } } public Event find(Long eventId) throws Exception { return eventDao.find(eventId); } public void delete(Long eventId) throws Exception { Event ev = eventDao.find(eventId); for (FreeValueRange fvr : ev.getFreeValueRanges()) { freeValueRangeService.delete(fvr.getId()); } ev.setMarks(new ArrayList()); eventDao.update(ev); eventDao.delete(eventId); } public void update(Event ev) { if (ev != null) { eventDao.update(ev); } } public void updateMarksInEvent(List<Mark> mlist, Long evId) { Event ev = eventDao.find(evId); if (ev != null) { ev.setMarks(mlist); if (validate(ev)) { eventDao.update(ev); } } } public List<Mark> getMarksInEvent(Long evId) { Event ev = eventDao.find(evId); return ev.getMarks(); } public String getMarksInEventAsString(Long evId) { Event ev = eventDao.find(evId); String res = "? ?;"; List<Mark> mlist = ev.getMarks(); if (!mlist.isEmpty()) { res = ""; for (Mark m : mlist) { res += m.getTitle() + "; "; } } return res; } public void saveLog(Long evId, List<EntityCar> carList, List<IdealEntityParam> ieplist, List<EntityCar> cutCarList, Sequence seq) throws Exception { Logger log = Logger.getLogger(this.getClass()); //Event ev = eventDao.find(evId); try { HashSet<String> iepuids = new HashSet(); for (IdealEntityParam iep : ieplist) { iepuids.add(iep.getBaseParam().getUid()); } List<BaseParam> bpList = baseParamService.getParams(); HashMap<Long, String> genMap = subModelService.getGenerationUrls(); HSSFWorkbook workbook = new HSSFWorkbook(); Event ev = eventDao.find(evId); HashMap<Long, SubModel> bodyMap = subModelService.getBodies(); HSSFCellStyle style = workbook.createCellStyle(); //style.setFillBackgroundColor(HSSFColor.ORANGE.index); style.setFillForegroundColor(HSSFColor.ORANGE.index); style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFSheet idealEntitySheet = workbook.createSheet("? ??"); HSSFSheet chosenSheet = workbook.createSheet(" ?"); HSSFSheet cutedSheet = workbook.createSheet(" ?"); HSSFSheet moneySheet = workbook.createSheet(" "); HSSFSheet instChosenSheet = workbook.createSheet(""); int complectList = 1; int ierownum = 1; idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(": " + ev.getName() + "; " + ev.getId() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue("?: " + ev.getAuthor() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(": " + ev.getAddDate() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(": " + ev.getScene().getName() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(": " + ev.getMoney() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(" ???: " + ev.getPerception().getName() + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue(": " + ev.getRadical() + "(" + ev.getColor() + ")" + ";"); idealEntitySheet.createRow(ierownum++).createCell(0) .setCellValue("?: " + seq.getRadCore() + ";"); HSSFRow ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? A1: "); ierowhead.createCell(1).setCellValue(ev.getStrategyA1().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? B1: "); ierowhead.createCell(1).setCellValue(ev.getStrategyB1().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("?? : "); ierowhead.createCell(1).setCellValue(ev.getResourceType().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("?? -: "); ierowhead.createCell(1).setCellValue(ev.getParamTox1().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("?? ?: "); ierowhead.createCell(1).setCellValue(ev.getValueTox1().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue(" ?: "); ierowhead.createCell(1).setCellValue(seq.getAllowance() + "%"); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? A2: "); ierowhead.createCell(1).setCellValue(ev.getStrategyA2().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? B2: "); ierowhead.createCell(1).setCellValue(ev.getStrategyB2().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("?? -, . ?: "); ierowhead.createCell(1).setCellValue(ev.getParamTox2().getName()); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("?? ?, . ?: "); ierowhead.createCell(1).setCellValue(ev.getValueTox2().getName()); ierownum++; int phn = 1; HSSFRow paramsierowhead = idealEntitySheet.createRow(ierownum++); paramsierowhead.createCell(phn++).setCellValue("UID"); paramsierowhead.createCell(phn++).setCellValue("?"); paramsierowhead.createCell(phn++).setCellValue("?"); paramsierowhead.createCell(phn++).setCellValue(" ."); paramsierowhead.createCell(phn++).setCellValue(""); paramsierowhead.createCell(phn++).setCellValue("?"); paramsierowhead.createCell(phn++).setCellValue(" ?."); paramsierowhead.createCell(phn++).setCellValue(""); int A = 0; int B = 0; for (IdealEntityParam iep : ieplist) { int pbn = 0; HSSFRow paramsierowbody = idealEntitySheet.createRow(ierownum++); paramsierowbody.createCell(pbn++).setCellValue(iep.getNumber()); paramsierowbody.createCell(pbn++).setCellValue(iep.getBaseParam().getUid()); paramsierowbody.createCell(pbn++).setCellValue(iep.getBaseParam().getName()); paramsierowbody.createCell(pbn++).setCellValue(iep.getIepClass().getName()); paramsierowbody.createCell(pbn++).setCellValue(iep.getAmin().doubleValue()); paramsierowbody.createCell(pbn++).setCellValue(iep.getValueMin().doubleValue()); paramsierowbody.createCell(pbn++).setCellValue(iep.getValueMax().doubleValue()); paramsierowbody.createCell(pbn++).setCellValue(iep.getAmax().doubleValue()); paramsierowbody.createCell(pbn++).setCellValue(StringAdapter.getString(iep.getRank())); if (Rank.A.equals(iep.getRank())) { A++; } else if (Rank.B.equals(iep.getRank())) { B++; } } ierownum++; ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? - ?:"); ierowhead.createCell(1).setCellValue((double) A); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? - B"); ierowhead.createCell(1).setCellValue((double) B); ierownum++; ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(0).setCellValue("? :"); ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(1).setCellValue("UID"); ierowhead.createCell(2).setCellValue("?"); for (SequenceValueRange svr : seq.getSequenceValueRanges()) { String uid = svr.getUid(); if (!iepuids.contains(uid)) { ierowhead = idealEntitySheet.createRow(ierownum++); ierowhead.createCell(1).setCellValue(svr.getUid()); ierowhead.createCell(2).setCellValue(baseParamService.getBaseParam(bpList, uid).getName()); } } int rowheadNumCell = 0; HSSFRow rowhead = chosenSheet.createRow(0); rowhead.createCell(rowheadNumCell++).setCellValue(""); rowhead.createCell(rowheadNumCell++).setCellValue("?"); rowhead.createCell(rowheadNumCell++).setCellValue(""); rowhead.createCell(rowheadNumCell++).setCellValue("?"); rowhead.createCell(rowheadNumCell++).setCellValue("?"); rowhead.createCell(rowheadNumCell++).setCellValue(" ?"); rowhead.createCell(rowheadNumCell++).setCellValue("??"); rowhead.createCell(rowheadNumCell++).setCellValue("?? ??"); rowhead.createCell(rowheadNumCell++).setCellValue("? A"); rowhead.createCell(rowheadNumCell++).setCellValue(" A"); rowhead.createCell(rowheadNumCell++).setCellValue("? ? A "); rowhead.createCell(rowheadNumCell++).setCellValue("? B"); rowhead.createCell(rowheadNumCell++).setCellValue(" "); rowhead.createCell(rowheadNumCell++).setCellValue("? ? B"); rowhead.createCell(rowheadNumCell++).setCellValue("? ???"); rowhead.createCell(rowheadNumCell++).setCellValue("? ?? ??"); rowhead.createCell(rowheadNumCell++).setCellValue("? ?? ???"); rowhead.createCell(rowheadNumCell++).setCellValue("? ?? ???"); int numscell = 0; HSSFRow instrowhead = instChosenSheet.createRow(0); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue(" ?"); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue("??? 1"); instrowhead.createCell(numscell++).setCellValue("??? 2"); instrowhead.createCell(numscell++).setCellValue("? ???"); instrowhead.createCell(numscell++).setCellValue("? ??"); moneySheet.addMergedRegion(new CellRangeAddress(0, 0, 6, 13)); moneySheet.addMergedRegion(new CellRangeAddress(0, 0, 14, 18)); moneySheet.addMergedRegion(new CellRangeAddress(0, 0, 19, 26)); moneySheet.addMergedRegion(new CellRangeAddress(0, 0, 27, 32)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4)); moneySheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5)); HSSFRow firstRowMoneyHead = moneySheet.createRow(0); HSSFRow secondRowMoneyHead = moneySheet.createRow(1); int frn = 0; firstRowMoneyHead.createCell(frn++).setCellValue(""); firstRowMoneyHead.createCell(frn++).setCellValue("?"); firstRowMoneyHead.createCell(frn++).setCellValue(""); firstRowMoneyHead.createCell(frn++).setCellValue("?"); firstRowMoneyHead.createCell(frn++).setCellValue("?"); firstRowMoneyHead.createCell(frn++).setCellValue(" ?"); firstRowMoneyHead.createCell(frn++).setCellValue("??? I"); firstRowMoneyHead.createCell(frn + 7).setCellValue("?? I"); firstRowMoneyHead.createCell(frn + 12).setCellValue("??? II"); firstRowMoneyHead.createCell(frn + 20).setCellValue("?? II"); int srn = 6; secondRowMoneyHead.createCell(srn++) .setCellValue("- ?? ??? ?"); secondRowMoneyHead.createCell(srn++) .setCellValue("- ?? ??? "); secondRowMoneyHead.createCell(srn++).setCellValue(" ?"); secondRowMoneyHead.createCell(srn++) .setCellValue(" ?? ?? ??? ?"); secondRowMoneyHead.createCell(srn++) .setCellValue(" ?? ?? ??? "); secondRowMoneyHead.createCell(srn++).setCellValue("? ??"); secondRowMoneyHead.createCell(srn++).setCellValue("? ?"); secondRowMoneyHead.createCell(srn++).setCellValue("? ??"); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? "); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? ???"); secondRowMoneyHead.createCell(srn++).setCellValue("- ?? "); secondRowMoneyHead.createCell(srn++).setCellValue(""); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? ?"); secondRowMoneyHead.createCell(srn++) .setCellValue("- ?? ??? ?"); secondRowMoneyHead.createCell(srn++) .setCellValue("- ?? ??? "); secondRowMoneyHead.createCell(srn++).setCellValue(" ?"); secondRowMoneyHead.createCell(srn++) .setCellValue(" ?? ?? ??? ?"); secondRowMoneyHead.createCell(srn++) .setCellValue(" ?? ?? ??? "); secondRowMoneyHead.createCell(srn++).setCellValue("? ??"); secondRowMoneyHead.createCell(srn++).setCellValue("? ?"); secondRowMoneyHead.createCell(srn++).setCellValue("? ??"); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? "); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? ???"); secondRowMoneyHead.createCell(srn++).setCellValue("- ?? "); secondRowMoneyHead.createCell(srn++).setCellValue(""); secondRowMoneyHead.createCell(srn++).setCellValue("? ?? ?"); int n = 1; int optrownum = 1; if (!carList.isEmpty()) { //while (optrownum < 50000) { for (EntityCar car : carList) { if (optrownum > 60000) { instChosenSheet = workbook.createSheet(" " + complectList++); optrownum = 1; numscell = 0; instrowhead = instChosenSheet.createRow(0); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue("?"); instrowhead.createCell(numscell++).setCellValue(" ?"); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue(""); instrowhead.createCell(numscell++).setCellValue("??"); instrowhead.createCell(numscell++).setCellValue("??? 1"); instrowhead.createCell(numscell++).setCellValue("??? 2"); instrowhead.createCell(numscell++).setCellValue("? ???"); instrowhead.createCell(numscell++).setCellValue("? ??"); } Car realCar = car.car; SubModel sm = bodyMap.get(car.car.getCmsqId()); String body = ""; if (sm != null) { body = sm.getBody(); } int m = n + 1; int bpropsCount = 0; int cn = 0; HSSFRow carRow = instChosenSheet.createRow(optrownum); carRow.createCell(cn++).setCellValue(StringAdapter.getString(car.car.getCarId())); carRow.createCell(cn++).setCellValue(StringAdapter.getString(car.getMarkTitle())); carRow.createCell(cn++).setCellValue(StringAdapter.getString(car.getModelTitle())); carRow.createCell(cn++).setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); carRow.createCell(cn++).setCellValue(StringAdapter.getString(car.getCarTitle())); carRow.createCell(cn++).setCellValue(StringAdapter.getString(body)); carRow.createCell(cn++).setCellValue(car.fullPrice.doubleValue()); carRow.createCell(cn++).setCellValue(""); carRow.createCell(cn + 6).setCellValue(car.dinamicRateA.add(car.dinamicRateB).doubleValue()); optrownum++; /*carRow.createCell(3).setCellValue(renderDecimalNoPoint(car.basePrice).replace(".", ",")); carRow.createCell(6).setCellValue(StringAdapter.getString(car.staticRate).replace(".", ",")); carRow.createCell(7).setCellValue(StringAdapter.getString(car.staticRate.add(car.dinamicRate)).replace(".", ","));*/ for (String uid : car.aprops.keySet()) { EntityPropertyHolder eph = car.aprops.get(uid); boolean alternatives = false; List<EntityProperty> insttalledElems = eph.getActiveProperty(); if (insttalledElems.size() > 1) { alternatives = true; } for (EntityProperty ep : insttalledElems) { HSSFRow optRow = instChosenSheet.createRow(optrownum); int on = 0; optRow.createCell(on++).setCellValue(StringAdapter.getString(car.car.getCarId())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getMarkTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getModelTitle())); optRow.createCell(on++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getCarTitle())); optRow.createCell(on++).setCellValue(body); //optRow.createCell(on++).setCellValue(RenderSupport.renderDecimalNoPoint(ep.getPrice()).replace(".", ",")); optRow.createCell(on++).setCellValue(" - "); HSSFCell uidCell = optRow.createCell(on++); uidCell.setCellValue(uid); if (alternatives) { uidCell.setCellStyle(style); } optRow.createCell(on++).setCellValue("A"); optRow.createCell(on++).setCellValue(ep.sign); optRow.createCell(on++).setCellValue(ep.type.getName()); optRow.createCell(on++).setCellValue(ep.name); optRow.createCell(on++).setCellValue(ep.title); optRow.createCell(on++).setCellValue(ep.value.doubleValue()); optRow.createCell(on++).setCellValue(eph.dinamicRate.doubleValue()); optrownum++; /*optRow.createCell(1).setCellValue("A"); optRow.createCell(2).setCellValue(ep.type.getName()); optRow.createCell(3).setCellValue(ep.name); optRow.createCell(4).setCellValue(ep.title); optRow.createCell(5).setCellValue(StringAdapter.getString(ep.value).replace(".", ",")); optRow.createCell(6).setCellValue(StringAdapter.getString(eph.dinamicRate).replace(".", ",")); optRow.createCell(7).setCellValue(StringAdapter.getString(eph.staticRate).replace(".", ","));*/ } } for (String uid : car.bprops.keySet()) { EntityPropertyHolder eph = car.bprops.get(uid); boolean alternatives = false; List<EntityProperty> insttalledElems = eph.getActiveProperty(); if (insttalledElems.size() > 1) { alternatives = true; } if (!insttalledElems.isEmpty()) { bpropsCount++; for (EntityProperty ep : eph.getActiveProperty()) { HSSFRow optRow = instChosenSheet.createRow(optrownum); int on = 0; optRow.createCell(on++).setCellValue(StringAdapter.getString(car.car.getCarId())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getMarkTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getModelTitle())); optRow.createCell(on++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getCarTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(body)); //optRow.createCell(on++).setCellValue(RenderSupport.renderDecimalNoPoint(ep.getPrice()).replace(".", ",")); //optRow.createCell(on++).setCellValue(RenderSupport.renderDecimalNoPoint(ep.price)); optRow.createCell(on++).setCellValue(" - "); HSSFCell uidCell = optRow.createCell(on++); uidCell.setCellValue(uid); if (alternatives) { uidCell.setCellStyle(style); } optRow.createCell(on++).setCellValue("B"); optRow.createCell(on++).setCellValue(ep.sign); optRow.createCell(on++).setCellValue(ep.type.getName()); optRow.createCell(on++).setCellValue(ep.name); optRow.createCell(on++).setCellValue(ep.title); optRow.createCell(on++).setCellValue(ep.value.doubleValue()); optRow.createCell(on++).setCellValue(eph.dinamicRate.doubleValue()); optrownum++; /*HSSFRow optRow = instChosenSheet.createRow((short) optrownum); HSSFCell uidCell = optRow.createCell(0); uidCell.setCellValue(uid); if(alternatives){ //optRow.createCell(8).setCellValue(""); uidCell.setCellStyle(style); } optRow.createCell(1).setCellValue("B"); optRow.createCell(2).setCellValue(ep.type.getName()); optRow.createCell(3).setCellValue(ep.name); optRow.createCell(4).setCellValue(ep.title); optRow.createCell(5).setCellValue(StringAdapter.getString(ep.value).replace(".", ",")); optRow.createCell(6).setCellValue(StringAdapter.getString(eph.dinamicRate).replace(".", ",")); optRow.createCell(7).setCellValue(StringAdapter.getString(eph.staticRate).replace(".", ",")); optrownum++;*/ } } else { BaseParam bp = baseParamService.getBaseParam(uid); HSSFRow optRow = instChosenSheet.createRow(optrownum); int on = 0; optRow.createCell(on++).setCellValue(StringAdapter.getString(car.car.getCarId())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getMarkTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getModelTitle())); optRow.createCell(on++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(car.getCarTitle())); optRow.createCell(on++).setCellValue(StringAdapter.getString(body)); //optRow.createCell(on++).setCellValue(RenderSupport.renderDecimalNoPoint(ep.getPrice()).replace(".", ",")); optRow.createCell(on++).setCellValue(" - "); HSSFCell uidCell = optRow.createCell(on++); uidCell.setCellValue(uid); optRow.createCell(on++).setCellValue("B"); optRow.createCell(on++).setCellValue(" - "); optRow.createCell(on++).setCellValue(" - "); optRow.createCell(on++).setCellValue(bp.getName()); optRow.createCell(on++).setCellValue(" - "); optRow.createCell(on++).setCellValue("null"); optRow.createCell(on++).setCellValue(" - "); optrownum++; } } /*String aRate = " - "; if(car.dinamicRateA.compareTo(BigDecimal.valueOf(0))>0){ aRate = StringAdapter.getString(car.dinamicRateA).replace(".", ","); } String acount = " - "; if(car.aprops.keySet().size()>0){ acount = StringAdapter.getString(car.aprops.keySet().size()); }*/ String msA = " - "; BigDecimal medA = BigDecimal.valueOf(0); if (car.aprops.keySet().size() > 0) { medA = car.dinamicRateA.divide(BigDecimal.valueOf(car.aprops.keySet().size()), 2, RoundingMode.HALF_UP); msA = StringAdapter.getString(medA).replace(".", ","); } /* String bRate = " - "; if(car.dinamicRateB.compareTo(BigDecimal.valueOf(0))>0){ bRate = StringAdapter.getString(car.dinamicRateB).replace(".", ","); }*/ String bcount = " - "; if (bpropsCount > 0) { bcount = StringAdapter.getString(bpropsCount); } String msB = " - "; BigDecimal medB = BigDecimal.valueOf(0); if (bpropsCount > 0) { medB = car.dinamicRateB.divide(BigDecimal.valueOf(bpropsCount), 2, RoundingMode.HALF_UP); msB = StringAdapter.getString(medB).replace(".", ","); } /*String bsr = " - "; if(car.baseStaticRate2.compareTo(BigDecimal.valueOf(0))>0){ bsr = StringAdapter.getString(car.baseStaticRate2).replace(".", ","); } String fsr = " - "; if(car.freeStaticRate2.compareTo(BigDecimal.valueOf(0))>0){ fsr = StringAdapter.getString(car.freeStaticRate2).replace(".", ","); } String msr = " - "; if(car.monetaryStaticRate2.compareTo(BigDecimal.valueOf(0))>0){ msr = StringAdapter.getString(car.monetaryStaticRate2).replace(".", ","); }*/ Model model = realCar.getModel(); HSSFRow rowbody = chosenSheet.createRow(n); int rowbodynum = 0; rowbody.createCell(rowbodynum++).setCellValue(StringAdapter.getString(car.car.getCarId())); rowbody.createCell(rowbodynum++).setCellValue(StringAdapter.getString(car.getMarkTitle())); rowbody.createCell(rowbodynum++).setCellValue(StringAdapter.getString(car.getModelTitle())); rowbody.createCell(rowbodynum++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); HSSFCell nameCellWithLink = rowbody.createCell(rowbodynum++); nameCellWithLink.setCellValue(StringAdapter.getString(car.getCarTitle())); HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL); link.setAddress("http://quto.ru/" + model.getMark().getUrl() + "/" + model.getUrl() + "/" + genMap.get(realCar.getCmgqId()) + "/" + bodyMap.get(realCar.getCmsqId()).getUrl() + "/" + realCar.getUrl()); nameCellWithLink.setHyperlink(link); rowbody.createCell(rowbodynum++).setCellValue(StringAdapter.getString(body)); rowbody.createCell(rowbodynum++).setCellValue(car.basePrice.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.fullPrice.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.dinamicRateA.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue((double) car.aprops.keySet().size()); rowbody.createCell(rowbodynum++).setCellValue(medA.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.dinamicRateB.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue((double) bpropsCount); rowbody.createCell(rowbodynum++).setCellValue(medB.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(medA.add(medB).doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.baseStaticRate2.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.freeStaticRate2.doubleValue()); rowbody.createCell(rowbodynum++).setCellValue(car.monetaryStaticRate2.doubleValue()); int rmbn = 0; HSSFRow rowMoneyBody = moneySheet.createRow(m); rowMoneyBody.createCell(rmbn++).setCellValue(StringAdapter.getString(car.car.getId())); rowMoneyBody.createCell(rmbn++).setCellValue(StringAdapter.getString(car.getMarkTitle())); rowMoneyBody.createCell(rmbn++).setCellValue(StringAdapter.getString(car.getModelTitle())); rowMoneyBody.createCell(rmbn++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); rowMoneyBody.createCell(rmbn++).setCellValue(StringAdapter.getString(car.getCarTitle())); rowMoneyBody.createCell(rmbn++).setCellValue(StringAdapter.getString(body)); rowMoneyBody.createCell(rmbn++).setCellValue((double) car.aprops.keySet().size()); rowMoneyBody.createCell(rmbn++).setCellValue((double) bpropsCount); rowMoneyBody.createCell(rmbn++).setCellValue(car.basePrice.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.aFund1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.bFund1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.aFund1.add(car.bFund1).doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue( ev.getMoney().subtract(car.aFund1.add(car.bFund1).add(car.basePrice)).doubleValue()); rowMoneyBody.createCell(rmbn++) .setCellValue(car.dinamicRateA.add(car.dinamicRateB).doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.baseStaticRate1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.freeStaticRate1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.payStaticCount1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.staticFund1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.monetaryStaticRate1.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue((double) car.aCount2); rowMoneyBody.createCell(rmbn++).setCellValue((double) car.bCount2); rowMoneyBody.createCell(rmbn++).setCellValue(car.basePrice.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.aFund2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.bFund2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.aFund2.add(car.bFund2).doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue( ev.getMoney().subtract(car.aFund2.add(car.bFund2).add(car.basePrice)).doubleValue()); rowMoneyBody.createCell(rmbn++) .setCellValue(car.dinamicRateA.add(car.dinamicRateB).doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.baseStaticRate2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.freeStaticRate2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.payStaticCount2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.staticFund2.doubleValue()); rowMoneyBody.createCell(rmbn++).setCellValue(car.monetaryStaticRate2.doubleValue()); n++; HSSFRow carStaticRowHead = instChosenSheet.createRow(optrownum); int csn = 0; carStaticRowHead.createCell(csn++).setCellValue(StringAdapter.getString(car.car.getCarId())); carStaticRowHead.createCell(csn++).setCellValue(StringAdapter.getString(car.getMarkTitle())); carStaticRowHead.createCell(csn++).setCellValue(StringAdapter.getString(car.getModelTitle())); carStaticRowHead.createCell(csn++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); carStaticRowHead.createCell(csn++).setCellValue(StringAdapter.getString(car.getCarTitle())); carStaticRowHead.createCell(csn++).setCellValue(StringAdapter.getString(body)); //carStaticRowHead.createCell(3).setCellValue(RenderSupport.renderDecimalNoPoint(ep.getPrice())); carStaticRowHead.createCell(csn++).setCellValue(":"); carStaticRowHead.createCell(csn + 7).setCellValue(car.staticRate.doubleValue()); optrownum++; Map<String, List<EntityProperty>> StaticMap = car.staticProps; for (String uid : StaticMap.keySet()) { List<EntityProperty> insttalledElems = StaticMap.get(uid); if (insttalledElems != null && !insttalledElems.isEmpty()) { boolean alternatives = false; if (insttalledElems.size() > 1) { alternatives = true; } for (EntityProperty ep : insttalledElems) { String title = ep.title; if (!ep.description.trim().equals("")) { title += " - " + ep.description; } HSSFRow carStaticRow = instChosenSheet.createRow(optrownum); int cson = 0; carStaticRow.createCell(cson++) .setCellValue(StringAdapter.getString(car.car.getCarId())); carStaticRow.createCell(cson++) .setCellValue(StringAdapter.getString(car.getMarkTitle())); carStaticRow.createCell(cson++) .setCellValue(StringAdapter.getString(car.getModelTitle())); carStaticRow.createCell(cson++) .setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); carStaticRow.createCell(cson++) .setCellValue(StringAdapter.getString(car.getCarTitle())); carStaticRow.createCell(cson++).setCellValue(StringAdapter.getString(body)); //carStaticRow.createCell(cson++).setCellValue(StringAdapter.getString(ep.getPrice()).replace(".", ",")); carStaticRow.createCell(cson++).setCellValue(" - "); HSSFCell uidCell = carStaticRow.createCell(cson++); uidCell.setCellValue(uid); if (alternatives) { uidCell.setCellStyle(style); } //carStaticRow.createCell(5).setCellValue(uid); carStaticRow.createCell(cson++).setCellValue("S"); carStaticRow.createCell(cson++).setCellValue(ep.sign); carStaticRow.createCell(cson++).setCellValue(ep.type.getName()); carStaticRow.createCell(cson++).setCellValue(ep.name); carStaticRow.createCell(cson++).setCellValue(title); carStaticRow.createCell(cson++).setCellValue(ep.radicalValue); carStaticRow.createCell(cson + 1).setCellValue(ep.value.doubleValue()); /*carStaticRow.createCell(1).setCellValue(ep.name); carStaticRow.createCell(2).setCellValue(ep.title); carStaticRow.createCell(3).setCellValue(ep.type.getName()); carStaticRow.createCell(5).setCellValue(StringAdapter.getString(ep.value).replace(".", ","));*/ optrownum++; } } } /*break;*/ } } int k = 0; HSSFRow rowhead20 = cutedSheet.createRow(k++); HSSFRow rowhead21 = cutedSheet.createRow(k++); HSSFRow rowhead22 = cutedSheet.createRow(k++); int ccn = 0; rowhead20.createCell(0).setCellValue("UID ??"); rowhead21.createCell(ccn++).setCellValue(""); rowhead21.createCell(ccn++).setCellValue("?"); rowhead21.createCell(ccn++).setCellValue(""); rowhead21.createCell(ccn++).setCellValue("?"); rowhead21.createCell(ccn++).setCellValue("?"); rowhead21.createCell(ccn++).setCellValue(" ?"); rowhead22.createCell(0).setCellValue(" ???"); int cutoptrownum = 0; for (IdealEntityParam iep : ieplist) { rowhead20.createCell(ccn).setCellValue(StringAdapter.getString(iep.baseParam.getUid())); rowhead21.createCell(ccn).setCellValue(iep.number + "." + iep.baseParam.getName()); rowhead22.createCell(ccn++).setCellValue(iep.aimBefore.doubleValue()); } if (!cutCarList.isEmpty()) { for (EntityCar car : cutCarList) { SubModel sm = bodyMap.get(car.car.getCmsqId()); String body = ""; if (sm != null) { body = sm.getBody(); } HSSFRow rowbody = cutedSheet.createRow(k++); int con = 0; rowbody.createCell(con++).setCellValue(StringAdapter.getString(car.car.getCarId())); rowbody.createCell(con++).setCellValue(StringAdapter.getString(car.getMarkTitle())); rowbody.createCell(con++).setCellValue(StringAdapter.getString(car.getModelTitle())); rowbody.createCell(con++).setCellValue(StringAdapter.getString(car.car.getCompletionTitle())); rowbody.createCell(con++).setCellValue(StringAdapter.getString(car.getCarTitle())); rowbody.createCell(con).setCellValue(body); int num = 0; if (car.cutNum != null) { num = car.cutNum; } String cutValue = car.cutVal; if (cutValue == null || cutValue.equals("null")) { cutValue = "? "; } try { Double cutedValue = Double.valueOf(car.cutVal); rowbody.createCell(con + num).setCellValue(cutedValue); } catch (Exception e) { rowbody.createCell(con + num).setCellValue(cutValue.replace(".", ",")); } /*HSSFRow carRow = instCutedSheet.createRow(cutoptrownum); carRow.createCell(0).setCellValue(StringAdapter.getString(car.car.getCarId())); carRow.createCell(1).setCellValue(StringAdapter.getString(car.getMarkTitle())); carRow.createCell(2).setCellValue(StringAdapter.getString(car.getModelTitle())); carRow.createCell(3).setCellValue(StringAdapter.getString(car.getCarTitle())); carRow.createCell(4).setCellValue(RenderSupport.renderDecimalNoPoint(car.basePrice).replace(".", ",")); carRow.createCell(5).setCellValue(RenderSupport.renderDecimalNoPoint(car.fixPrice).replace(".", ",")); carRow.createCell(6).setCellValue(StringAdapter.getString(car.dinamicRateA.add(car.dinamicRateB)).replace(".", ",")); carRow.createCell(7).setCellValue(StringAdapter.getString(car.staticRate).replace(".", ",")); carRow.createCell(8).setCellValue(StringAdapter.getString(car.staticRate.add(car.dinamicRateA.add(car.dinamicRateB))).replace(".", ",")); cutoptrownum++; HSSFRow carRowHead = instCutedSheet.createRow(cutoptrownum); carRowHead.createCell(0).setCellValue(StringAdapter.getString("")); carRowHead.createCell(1).setCellValue(StringAdapter.getString("")); carRowHead.createCell(2).setCellValue(StringAdapter.getString("??")); carRowHead.createCell(3).setCellValue(StringAdapter.getString("?????")); carRowHead.createCell(4).setCellValue(StringAdapter.getString("???")); carRowHead.createCell(5).setCellValue(StringAdapter.getString("%")); carRowHead.createCell(6).setCellValue(StringAdapter.getString("??")); cutoptrownum++;*/ /*for (PropertyName pn : car.car.getPropertyNames()) { CarProperty p = pn.getCarProperty(); if (p != null) { HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); if (p.getUid() != null) { optRow.createCell(0).setCellValue(p.getUid()); } else { optRow.createCell(0).setCellValue("? "); } optRow.createCell(1).setCellValue("?"); if (p.getTitle() != null) { optRow.createCell(2).setCellValue(p.getTitle()); } else { optRow.createCell(2).setCellValue("? "); } if (pn.getPropertyNameValue() != null && !pn.getPropertyNameValue().equals("")) { optRow.createCell(3).setCellValue(pn.getPropertyNameValue()); } else { optRow.createCell(3).setCellValue("? "); } if (pn.getParamValue() != null && !pn.getParamValue().equals("")) { optRow.createCell(4).setCellValue(pn.getParamValue()); } else { optRow.createCell(4).setCellValue("? "); } if (pn.getPercentValue() != null && !pn.getPercentValue().equals("")) { optRow.createCell(5).setCellValue(pn.getPercentValue()); } else { optRow.createCell(5).setCellValue("? "); } if (pn.getRadical() != null && !pn.getRadical().equals("")) { optRow.createCell(6).setCellValue(pn.getRadical()); } else { optRow.createCell(6).setCellValue("? "); } cutoptrownum++; } } List<Feature> flist = carService.getFeatures(car.car); for (Feature f : flist) { HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); if (f.getUid() != null) { optRow.createCell(0).setCellValue(f.getUid()); } else { optRow.createCell(0).setCellValue("? "); } optRow.createCell(1).setCellValue("??"); optRow.createCell(2).setCellValue(""); if (f.getTitle() != null) { optRow.createCell(3).setCellValue(f.getTitle()); } else { optRow.createCell(3).setCellValue("? "); } if (f.getParamValue() != null) { optRow.createCell(4).setCellValue(f.getParamValue()); } else { optRow.createCell(4).setCellValue("? "); } if (f.getPercentValue() != null) { optRow.createCell(5).setCellValue(f.getPercentValue()); } else { optRow.createCell(5).setCellValue("? "); } if (f.getRadical() != null) { optRow.createCell(6).setCellValue(f.getRadical()); } else { optRow.createCell(6).setCellValue("? "); } cutoptrownum++; }*/ /*for (CarOptionValue cov : car.car.getCarOptionValues()) { CarCompletionOption cco = cov.getCCO(); if (cco != null) { HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); if (cco.getUid() != null) { optRow.createCell(0).setCellValue(cco.getUid()); } else { optRow.createCell(0).setCellValue("? "); } optRow.createCell(1).setCellValue("?"); if (cco.getTitle() != null) { optRow.createCell(2).setCellValue(cco.getTitle()); } else { optRow.createCell(2).setCellValue("? "); } if (cov.getTitle() != null) { optRow.createCell(3).setCellValue(cov.getTitle()); } else { optRow.createCell(3).setCellValue("? "); } if (cco.getParamValue() != null) { optRow.createCell(4).setCellValue(cco.getParamValue()); } else { optRow.createCell(4).setCellValue("? "); } if (cco.getPercentValue() != null) { optRow.createCell(5).setCellValue(cco.getPercentValue()); } else { optRow.createCell(5).setCellValue("? "); } if (cco.getRadical() != null) { optRow.createCell(6).setCellValue(cco.getRadical()); } else { optRow.createCell(6).setCellValue("? "); } cutoptrownum++; } } for (CarColorValue ccv : car.car.getCarColorValues()) { Color col = ccv.getColor(); if (col != null) { HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); if (col.getUid() != null) { optRow.createCell(0).setCellValue(col.getUid()); } else { optRow.createCell(0).setCellValue("? "); } optRow.createCell(1).setCellValue(""); if (col.getTitle() != null) { optRow.createCell(2).setCellValue(col.getTitle()); } else { optRow.createCell(2).setCellValue("? "); } if (col.getName() != null) { optRow.createCell(3).setCellValue(col.getName()); } else { optRow.createCell(3).setCellValue("? "); } if (col.getParamValue() != null) { optRow.createCell(4).setCellValue(col.getParamValue()); } else { optRow.createCell(4).setCellValue("? "); } if (col.getPercentValue() != null) { optRow.createCell(5).setCellValue(col.getPercentValue()); } else { optRow.createCell(5).setCellValue("? "); } if (col.getRadical() != null) { optRow.createCell(6).setCellValue(col.getRadical()); } else { optRow.createCell(6).setCellValue("? "); } cutoptrownum++; } }*/ /*for(String uid:car.aprops.keySet()){ for(EntityProperty ep:car.aprops.get(uid).getPropList()){ HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); optRow.createCell(0).setCellValue(uid); optRow.createCell(1).setCellValue(ep.name); optRow.createCell(2).setCellValue(ep.title); optRow.createCell(3).setCellValue(ep.type.getName()); optRow.createCell(4).setCellValue(StringAdapter.getString(ep.value)); cutoptrownum++; } } for(String uid:car.bprops.keySet()){ for(EntityProperty ep:car.bprops.get(uid).getPropList()){ HSSFRow optRow = instCutedSheet.createRow((short) cutoptrownum); optRow.createCell(0).setCellValue(uid); optRow.createCell(1).setCellValue(ep.name); optRow.createCell(2).setCellValue(ep.title); optRow.createCell(3).setCellValue(ep.type.getName()); optRow.createCell(4).setCellValue(StringAdapter.getString(ep.value)); cutoptrownum++; } }*/ } } File f = new File("/usr/local/etc/xls/" + evId + ".xls"); if (f.exists()) { f.delete(); } workbook.write(new FileOutputStream("/usr/local/etc/xls/" + evId + ".xls")); } catch (Exception e) { //log.warn("HSSFWorkbook.getXls()", e); throw new Exception(e); } } /*public HSSFWorkbook getXls() { Logger log = Logger.getLogger(this.getClass()); try { HSSFWorkbook workbook = new HSSFWorkbook(); List<Color> oblist = colorDao.getAllAsc(); HSSFSheet sheet = workbook.createSheet("FirsSheet"); HSSFRow rowhead = sheet.createRow((short) 0); rowhead.createCell(0).setCellValue("ID"); rowhead.createCell(1).setCellValue("TITLE"); rowhead.createCell(2).setCellValue("????"); rowhead.createCell(3).setCellValue("UID"); rowhead.createCell(4).setCellValue(""); rowhead.createCell(5).setCellValue(""); rowhead.createCell(6).setCellValue(""); int n = 1; if (!oblist.isEmpty()) { for (Color ob : oblist) { HSSFRow rowbody = sheet.createRow((short) n); rowbody.createCell(0).setCellValue(StringAdapter.getString(ob.getColorId())); rowbody.createCell(1).setCellValue(StringAdapter.getString(ob.getName())); rowbody.createCell(2).setCellValue(StringAdapter.getString(ob.getTitle())); rowbody.createCell(3).setCellValue(StringAdapter.getString(ob.getUid())); rowbody.createCell(4).setCellValue(StringAdapter.getString(ob.getParamValue())); rowbody.createCell(5).setCellValue(StringAdapter.getString(ob.getPercentValue())); rowbody.createCell(6).setCellValue(StringAdapter.getString(ob.getRadical())); n++; }; } return workbook; } catch (Exception e) { log.warn("HSSFWorkbook.getXls()", e); } return null; }*/ /** * ? "" * * @param data * @return */ /*private String renderDecimalNoPoint(Object data) { if (data != null) { ChainValidator chain = new ChainValidator(); chain.addChain(ValidatorTypes.DECIMALFILTER); chain.execute(data); String res = chain.getData().toString(); return res; } else { return ""; } }*/ }