调用方法打印pdf的过程中遇到的封装问题的总结

xiaoxiao2021-02-28  11

@RequestMapping(value = "/print") //Controller层调用Service层 public void getdmspdf(HttpServletRequest request, HttpServletResponse response)throws Exception{ InputValue<OrderprintprecheckRequestDto> inputValue=this.getInputValue(request,new TypeReference<InputValue<OrderprintprecheckRequestDto>>(){}); PrintPrecheckFormBean printPrecheckFormBean = new PrintPrecheckFormBean(); printPrecheckFormBean.setCustompage("0"); printPrecheckFormBean.setPageindex("2"); //调用precheckService指定打印第二联 ReturnValue<Picvalue> rtnvalue = new ReturnValue<>(); Picvalue picvalue =newPrecheckService.printpdfPreOrder(request,response,DataUtil.getCurrent().getStoreid(), DataUtil.getCurrent().getStaffid(),inputValue.getReqdata().getOrderid(),printPrecheckFormBean); rtnvalue.setObject(picvalue); this.returnvalue(request,response,rtnvalue); } //Service层调用打印pdf的方法 public Picvalue printpdfPreOrder(HttpServletRequest request, HttpServletResponse response, int storeid, int userid, int orderid, PrintPrecheckFormBean printPrecheckFormBean) throws Exception { //daying String pageindex = printPrecheckFormBean.getPageindex(); String custompage = printPrecheckFormBean.getCustompage(); CheckOrderInfoDto dto = this.getCheckOrderInfo(storeid, userid, orderid, true); Picvalue picvalue = pdfPreCheckService.printpreviewthesingle(request, response, dto, pageindex,custompage); return picvalue; } //获取pdf的内容 public CheckOrderInfoDto getCheckOrderInfo(int storeid, int userid, int orderid, boolean isforpdf) { CheckOrderInfoDto checkOrderInfoDto = new CheckOrderInfoDto(); //表头信息 WorkOrderfororder order = increaseItemDao.getWorkOrderWithCarType(orderid); checkOrderInfoDto.setDmsno(order.getWodmsno()); //工单号 checkOrderInfoDto.setPlateall(order.getPlateall()); //车牌号 checkOrderInfoDto.setVin(order.getCvincode()); //车架号 checkOrderInfoDto.setCheckpersonname(order.getServiceadvisorname()); //服务顾问 checkOrderInfoDto.setCheckday(""); if(!Util.isEmpty(order.getWoenyardtime())){ String woenyardtime=order.getWoenyardtime().substring(0,8); StringBuilder cdate=new StringBuilder(woenyardtime); cdate.insert(4,"-"); cdate.insert(7,"-"); checkOrderInfoDto.setCdate(cdate.toString()); //日期 } checkOrderInfoDto.setCurmiles(order.getWocurmiles());//当前里程数 HealthcheckitemRequestDto healthcheckitemRequestDto = new HealthcheckitemRequestDto(); healthcheckitemRequestDto.setOrderid(orderid); HealthcheckitemResponseDto dto = healthcheckService.gethealthcheckitemlist(healthcheckitemRequestDto); checkOrderInfoDto.setCheckday(dto.getCheckdate()); List<HealthcheckDto> healthchecklist = dto.getHealthchecklist(); List<CheckItemDtoForPdf> list1 = new ArrayList<>(); //系统检查+外观检查 checkOrderInfoDto.setList1(list1); CheckItemDtoForPdf pdf1 = new CheckItemDtoForPdf(); pdf1.setHciid1(2); pdf1.setHciid2(12); list1.add(pdf1); CheckItemDtoForPdf pdf2 = new CheckItemDtoForPdf(); pdf2.setHciid1(3); pdf2.setHciid2(13); list1.add(pdf2); CheckItemDtoForPdf pdf3 = new CheckItemDtoForPdf(); pdf3.setHciid1(4); //雨刷器/清洗器/大灯清洗系统 pdf3.setHciid2(14);//液位(雨刮液、冷却液、刹车液) list1.add(pdf3); CheckItemDtoForPdf pdf4 = new CheckItemDtoForPdf(); pdf4.setHciid1(5); //离合器/换挡杆/手刹 pdf4.setHciid2(15);//减震器/饰条/盖罩密封情况/泄漏 list1.add(pdf4); CheckItemDtoForPdf pdf5 = new CheckItemDtoForPdf(); pdf5.setHciid1(6); //PCM功能及导航更新 pdf5.setHciid2(16);//备用轮胎 / 补胎 list1.add(pdf5); CheckItemDtoForPdf pdf6 = new CheckItemDtoForPdf(); pdf6.setHciid1(7); //组合仪表/娱乐信息系统/开关 pdf6.setHciid2(17);//改装 list1.add(pdf6); CheckItemDtoForPdf pdf7 = new CheckItemDtoForPdf(); pdf7.setHciid1(8); //机油油位 pdf7.setHciid2(0); // list1.add(pdf7); CheckItemDtoForPdf pdf8 = new CheckItemDtoForPdf(); pdf8.setHciid1(9); //点烟器/电源插座 pdf8.setHciid2(0);// list1.add(pdf8); CheckItemDtoForPdf pdf9 = new CheckItemDtoForPdf(); pdf9.setHciid1(10); //安全带/安全带扣 pdf9.setHciid2(0);// list1.add(pdf9); CheckItemDtoForPdf pdf10 = new CheckItemDtoForPdf(); pdf10.setHciid1(11); //空调系统和设置 pdf10.setHciid2(0);// list1.add(pdf10); List<CheckItemDtoForPdf> list2 = new ArrayList<>(); checkOrderInfoDto.setList2(list2); CheckItemDtoForPdf pdf11 = new CheckItemDtoForPdf(); pdf11.setHciid1(18); //散热器进气道(目测) pdf11.setHciid2(24); //轮胎磨损情况、车桥定位 list2.add(pdf11); CheckItemDtoForPdf pdf12 = new CheckItemDtoForPdf(); pdf12.setHciid1(19); //轮胎(N 标记、旋转) pdf12.setHciid2(25); //排气系统 list2.add(pdf12); CheckItemDtoForPdf pdf13 = new CheckItemDtoForPdf(); pdf13.setHciid1(20); //钢圈(基本状况) pdf13.setHciid2(26); //车底防护装置、护板、盖板 list2.add(pdf13); CheckItemDtoForPdf pdf14 = new CheckItemDtoForPdf(); pdf14.setHciid1(21); //制动盘(磨损、锈蚀、损坏) pdf14.setHciid2(27); //动力传输、万向节/驱动轴 list2.add(pdf14); CheckItemDtoForPdf pdf15 = new CheckItemDtoForPdf(); pdf15.setHciid1(22); //制动片(厚度) pdf15.setHciid2(28); //泄漏(液体、气体)和车底管路 list2.add(pdf15); CheckItemDtoForPdf pdf16 = new CheckItemDtoForPdf(); pdf16.setHciid1(23); //卡钳、软管(目测) pdf16.setHciid2(29); //悬挂和减震器(臂、接头、防尘套、衬套) list2.add(pdf16); List<PreCheckFile> needfiles=new ArrayList<>(); //所需文件 checkOrderInfoDto.setNeedfiles(needfiles); List<PreCheckPayType> paytypes=new ArrayList<>(); //付款方式 checkOrderInfoDto.setPaytypes(paytypes); List<PreCheckOtherService> otherservices =new ArrayList<>(); //其他服务 checkOrderInfoDto.setOtherservices(otherservices); for (HealthcheckDto healthcheckDto : healthchecklist) { if (healthcheckDto.getHealthitemtype() == 3) { //油表值 checkOrderInfoDto.setWohasfuel(new Float(healthcheckDto.getHealthitemvalue1())); } //订单概览 checkOrderInfoDto.setOrderinfo(0); if (healthcheckDto.getHealthitemid() == 30) { if (healthcheckDto.getHealthitemvalue1() == 1) { checkOrderInfoDto.setOrderinfo(1); } } if (healthcheckDto.getHealthitemid() == 31) { if (healthcheckDto.getHealthitemvalue1() == 1) { checkOrderInfoDto.setOrderinfo(2); } } if (healthcheckDto.getHealthitemid() == 32) { if (healthcheckDto.getHealthitemvalue1() == 1) { checkOrderInfoDto.setOrderinfo(3); } } if (healthcheckDto.getHealthitemid() == 33) { if (healthcheckDto.getHealthitemvalue1() == 1) { checkOrderInfoDto.setOrderinfo(4); } } if(healthcheckDto.getHealthitemid()==34){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //行驶证 file.setHpcfcid(1); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==35){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //客户授权书 file.setHpcfcid(2); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==36){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //保修和保养手册 file.setHpcfcid(3); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==37){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //车轮防盗螺栓套筒 file.setHpcfcid(4); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==38){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //驾驶证 file.setHpcfcid(5); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==39){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //延保证书 file.setHpcfcid(6); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==40){ PreCheckFile file=new PreCheckFile(); if(healthcheckDto.getHealthitemvalue1() == 1){ //交通事故认定书 file.setHpcfcid(7); needfiles.add(file); } } if(healthcheckDto.getHealthitemid()==42){ //接收车辆时客户是否在场 if(healthcheckDto.getHealthitemvalue1() == 1){ checkOrderInfoDto.setIsinfactory(1); }else if(healthcheckDto.getHealthitemvalue1() == 2){ checkOrderInfoDto.setIsinfactory(2); } else { checkOrderInfoDto.setIsinfactory(0); } } if(healthcheckDto.getHealthitemid()==44){ //是否在遇到噪音和驾驶动态问题时进行试驾 if(healthcheckDto.getHealthitemvalue1() == 1){ checkOrderInfoDto.setHastrycar(1); }else if(healthcheckDto.getHealthitemvalue1() == 2){ checkOrderInfoDto.setHastrycar(2); } else { checkOrderInfoDto.setHastrycar(0); } } if(healthcheckDto.getHealthitemid()==46){ //现金 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckPayType type=new PreCheckPayType(); type.setHpcpcid(1); paytypes.add(type); } } if(healthcheckDto.getHealthitemid()==47){ //借记/信用卡 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckPayType type=new PreCheckPayType(); type.setHpcpcid(2); paytypes.add(type); } } if(healthcheckDto.getHealthitemid()==48){ //其他 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckPayType type=new PreCheckPayType(); type.setHpcpcid(3); paytypes.add(type); } } if (healthcheckDto.getHealthitemid() == 49) { checkOrderInfoDto.setRemark(healthcheckDto.getHealthitemvalue2()); } for (CheckItemDtoForPdf checkItemDtoForPdf : list1) { if (checkItemDtoForPdf.getHciid1() == healthcheckDto.getHealthitemid()) { checkItemDtoForPdf.setItemname1(healthcheckDto.getHealthitemname()); checkItemDtoForPdf.setItemstate1(healthcheckDto.getHealthitemvalue1()); } if (checkItemDtoForPdf.getHciid2() == healthcheckDto.getHealthitemid()) { checkItemDtoForPdf.setItemname2(healthcheckDto.getHealthitemname()); checkItemDtoForPdf.setItemstate2(healthcheckDto.getHealthitemvalue1()); } } for (CheckItemDtoForPdf checkItemDtoForPdf : list2) { if (checkItemDtoForPdf.getHciid1() == healthcheckDto.getHealthitemid()) { checkItemDtoForPdf.setItemname1(healthcheckDto.getHealthitemname()); checkItemDtoForPdf.setItemstate1(healthcheckDto.getHealthitemvalue1()); } if (checkItemDtoForPdf.getHciid2() == healthcheckDto.getHealthitemid()) { checkItemDtoForPdf.setItemname2(healthcheckDto.getHealthitemname()); checkItemDtoForPdf.setItemstate2(healthcheckDto.getHealthitemvalue1()); } } if(healthcheckDto.getHealthitemid()==50){ //加满油液 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckOtherService service=new PreCheckOtherService(); service.setHpcscid(1); otherservices.add(service); } } if(healthcheckDto.getHealthitemid()==51){ //保留旧件 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckOtherService service=new PreCheckOtherService(); service.setHpcscid(2); otherservices.add(service); } } if(healthcheckDto.getHealthitemid()==52){ //标准清洗 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckOtherService service=new PreCheckOtherService(); service.setHpcscid(3); otherservices.add(service); } } if(healthcheckDto.getHealthitemid()==53){ //高级内饰清洗 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckOtherService service=new PreCheckOtherService(); service.setHpcscid(4); otherservices.add(service); } } if(healthcheckDto.getHealthitemid()==54){ //高级车身清洗 if(healthcheckDto.getHealthitemvalue1()==1){ PreCheckOtherService service=new PreCheckOtherService(); service.setHpcscid(5); otherservices.add(service); } } } checkOrderInfoDto.setNeedfiles(needfiles); checkOrderInfoDto.setPaytypes(paytypes); checkOrderInfoDto.setOtherservices(otherservices); HealthcheckallcarpartsproblemRequestDto healthcheckallcarpartsproblemRequestDto = new HealthcheckallcarpartsproblemRequestDto(); healthcheckallcarpartsproblemRequestDto.setOrderid(orderid); HealthcheckallcarpartsproblemResponseDto healthcheckcarpartsproblemResponseDto = healthcheckService.getallcarpartsproblemlist(healthcheckallcarpartsproblemRequestDto); if (healthcheckcarpartsproblemResponseDto.getHasimage() > 0) { checkOrderInfoDto.setPhotoinfo(1); } else { checkOrderInfoDto.setPhotoinfo(2); } List<AllcarpartsproblemDto> allcarpartsproblemlist = healthcheckcarpartsproblemResponseDto.getAllcarpartsproblemlist(); for (AllcarpartsproblemDto allcarpartsproblemDto : allcarpartsproblemlist) { if (allcarpartsproblemDto.getCarpartsid() == CarPartsEnum.CarParts1.getCode()) { checkOrderInfoDto.setTaiwen1(allcarpartsproblemDto.getCarpartstyreinfo().getWotpatterndepth() + ""); checkOrderInfoDto.setYear1(allcarpartsproblemDto.getCarpartstyreinfo().getWotypeuseyear()); } if (allcarpartsproblemDto.getCarpartsid() == CarPartsEnum.CarParts2.getCode()) { checkOrderInfoDto.setTaiwen2(allcarpartsproblemDto.getCarpartstyreinfo().getWotpatterndepth() + ""); checkOrderInfoDto.setYear2(allcarpartsproblemDto.getCarpartstyreinfo().getWotypeuseyear()); } if (allcarpartsproblemDto.getCarpartsid() == CarPartsEnum.CarParts3.getCode()) { checkOrderInfoDto.setTaiwen3(allcarpartsproblemDto.getCarpartstyreinfo().getWotpatterndepth() + ""); checkOrderInfoDto.setYear3(allcarpartsproblemDto.getCarpartstyreinfo().getWotypeuseyear()); } if (allcarpartsproblemDto.getCarpartsid() == CarPartsEnum.CarParts4.getCode()) { checkOrderInfoDto.setTaiwen4(allcarpartsproblemDto.getCarpartstyreinfo().getWotpatterndepth() + ""); checkOrderInfoDto.setYear4(allcarpartsproblemDto.getCarpartstyreinfo().getWotypeuseyear()); } } List<HcAttachmentInfo> attachmentsforsign =attachmentService.getCusSign(orderid,10); //检测人员签字 List<HcAttachmentInfo> attachmentsforsigncust =attachmentService.getCusSign(orderid,4); //客户签字 checkOrderInfoDto.setAttachmentsforsign(attachmentsforsign); checkOrderInfoDto.setAttachmentsforsigncust(attachmentsforsigncust); return checkOrderInfoDto; } 总结如下: 1.获取具体值的方式主要是调用Dao查询数据库得到。 2.单选框,多选框值的主要区别就是:单选框返回的值只有一个,多选框返回的值有多个,多 选框需要找到对应的选框显示√就需要一个数据库字段来锁定它,比如在本项目中使用的是itemid来判断,所有 pdf内容项都在一个表中以itemid为主键被存储。 3.多选框的显示可以使用ArrayList来封装,符合某个条件,就设置一个值给它,将它添加到List中,在pdf中通过 判断该List中的具体值来显示√ 4.单选框一般用一个属性来封装,每次pdf显示都直接找这个属性就可以。 5.单选框的判断分为两种,一种是多个选项中选一个的单选,另一种是是与否之间的单选。如果是后一种,可以 通过if...else...来赋值,前一种则不方便,因为如果以if...else...来判断,多选一的赋值是以最后一个符合条件的值为准,如果最后一个赋值 是符合if判断的赋值,那么没问题,除此之外所有的情况最后的值都是最后一个if...else...中的else判断的赋值。那么这就会导致这个单选 无法显示内容√;
转载请注明原文地址: https://www.6miu.com/read-2300116.html

最新回复(0)