Browse Source

订单项目调整修改

anderx 1 year ago
parent
commit
4f11012e8e

+ 1 - 1
src/main/java/com/goafanti/common/mapper/UserMidMapper.xml

@@ -719,7 +719,7 @@
   </select>
   <select id="selectStatisticsOrderProjectList" resultType="com.goafanti.order.bo.OutOrderProject">
     SELECT a.order_no as orderNo, a.order_type orderType,a.sales_type as salesType, b.service_type AS serviceType,
-    a.liquidation_status as liquidationStatus,b2.big_customer as bigCustomer,b.project_type as projectType,
+    a.liquidation_status as liquidationStatus,b2.big_customer as bigCustomer,b.project_type as projectType,b.dun_node_content DunNodeContent,
     a.total_amount as totalAmount,a.approval ,a.sign_time as signTime,date_format(a.create_time ,'%Y-%m-%d %H:%i:%S')  as createTime,
     b.buyer_name as buyerName,a.contract_no as contractNo, c.cname htlx,b.province_name province ,b.dep_name depName,
     b.order_receivables orderReceivables,a.refund_amount refundAmount,a.settlement_amount as settlementAmount,

+ 277 - 0
src/main/java/com/goafanti/common/utils/excel/NewExcelUtil.java

@@ -25,6 +25,8 @@ import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.text.DecimalFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -175,6 +177,223 @@ public class NewExcelUtil<T> {
 		this.downloadPath=uploadPath;
 		return exportExcel();
 	}
+
+	/**
+	 * 	将数据合并按订单合并并导出CXCEL表到指定目录
+	 * @param list 导出数据集合
+	 * @param sheetName 工作表的名称
+	 * @param uploadPath 导出本地地址
+	 */
+	public Result OrderMergeAndExportExcel(List<T> list, String sheetName, String uploadPath) {
+		this.init(list, sheetName);
+		this.downloadPath=uploadPath;
+		return OrderMergeAndExportExcel();
+	}
+
+	private Result OrderMergeAndExportExcel() {
+		OutputStream out = null;
+		String filename="";
+		try {
+			// 取出一共有多少个sheet.
+			int sheetNo =  (list.size() / sheetSize);
+			for (int index = 0; index <= sheetNo; index++) {
+				createSheet(sheetNo, index);
+				int line=0;
+				// 产生一行
+				Row title = sheet.createRow(line);
+				Cell cell = title.createCell(0);
+				cell.setCellValue(sheetName);
+				CellRangeAddress region = new CellRangeAddress(0, 0, 0, fields.size()-1);
+				sheet.addMergedRegion(region);
+				cell.setCellStyle(styles.get("total"));
+				if (StringUtils.isNotEmpty(screen)){
+					log.debug(screen);
+					Row r = sheet.createRow(++line);
+					Cell c = r.createCell(0);
+					c.setCellValue(screen);
+					CellRangeAddress rg = new CellRangeAddress(line, line, 0, fields.size()-1);
+					sheet.addMergedRegion(rg);
+					c.setCellStyle(styles.get("header"));
+				}
+				Row row = sheet.createRow(++line);
+				// 产生一行
+				int column = 0;
+				// 写入各个字段的列头名称
+				for (Object[] os : fields) {
+					Excel excel = (Excel) os[1];
+					this.createCell(excel, row, column++);
+				}
+				filename = encodingFilename(sheetName);
+				out = Files.newOutputStream(Paths.get(getAbsoluteFile(filename)));
+				fillMergeExcelData(index,++line);
+				//新增合并
+//				mergeOrderNo();
+				addStatisticsRow();
+			}
+			wb.write(out);
+			return new Result().data(filename);
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new BusinessException("导出Excel失败,请联系网站管理员!");
+		} finally {
+			if (wb != null) {
+				try {
+					wb.close();
+				} catch (IOException e1) {
+					e1.printStackTrace();
+				}
+			}
+			if (out != null) {
+				try {
+					out.close();
+				} catch (IOException e1) {
+					e1.printStackTrace();
+				}
+			}
+		}
+	}
+
+	private void fillMergeExcelData(int index, Integer line) throws Exception {
+		int startNo = index * sheetSize;
+		int endNo = Math.min(startNo + sheetSize, list.size());
+		if(line==null)line=2;
+		for (int i = startNo; i < endNo; i++) {
+			int start=i + line - startNo;
+			Row row = sheet.createRow(start);
+			// 得到导出对象.
+			T vo = (T) list.get(i);
+
+			String orderNo = (String) getValue(vo, "orderNo");
+			int x = i+1;
+			int  count =0;
+			while (x<endNo){
+				T t1 = list.get(x);
+				String orderNo1 = (String) getValue(t1, "orderNo");
+				if (orderNo.equals(orderNo1)){
+					count++;
+					x++;
+				}else{
+					break;
+				}
+			}
+			if(count>0){
+				int column = 0;
+				for (Object[] os : fields) {
+					Field field = (Field) os[0];
+					Excel excel = (Excel) os[1];
+					// 设置实体类私有属性可访问
+					field.setAccessible(true);
+					if (column<35){
+						this.addOrderMegerCell(excel, row, vo, field, column);
+						CellRangeAddress region = new CellRangeAddress(start, start+count, column, column);
+						sheet.addMergedRegion(region);
+						Row row1 = sheet.getRow(start);
+						Cell cell1 = row1.getCell(column);
+						CellStyle style = styles.get("data4");
+						cell1.setCellStyle(style);
+						column++;
+					}else {
+						this.addOrderMegerCell(excel, row, vo, field, column++);
+					}
+				}
+				for (int j = 1; j <= count; j++) {
+					T vo3 = (T) list.get(i+j);
+					Row row3 = sheet.createRow(start+j);
+					int column3 = 0;
+					for (Object[] os : fields) {
+						Field field = (Field) os[0];
+						Excel excel = (Excel) os[1];
+						// 设置实体类私有属性可访问
+						field.setAccessible(true);
+						if (column3>34){
+							this.addOrderMegerCell(excel, row3, vo3, field, column3++);
+						}else {
+							column3++;
+						}
+
+					}
+				}
+				i=i+count;
+			}else {
+				int column = 0;
+				for (Object[] os : fields) {
+					Field field = (Field) os[0];
+					Excel excel = (Excel) os[1];
+					// 设置实体类私有属性可访问
+					field.setAccessible(true);
+					Cell cell = this.addCell(excel, row, vo, field, column++);
+					cell.setCellStyle(styles.get("data4"));
+				}
+			}
+		}
+	}
+
+	private void mergeOrderNo() throws Exception {
+		int max = list.size();
+		for (int i = 0; i < max; i++) {
+			T t = list.get(i);
+			String orderNo = (String) getValue(t, "orderNo");
+			int  count =0;
+			if (i!=max-1){
+				int x = i+1;
+				while (x<max){
+					T t1 = list.get(x);
+					String orderNo1 = (String) getValue(t1, "orderNo");
+					if (orderNo.equals(orderNo1)){
+						count++;
+						x++;
+					}else{
+						break;
+					}
+				}
+				if (count>0&&orderNo.equals("1015315879283802112")){
+					int rowNum = i+2;
+					int rowNum1 = x+1;
+					Row row = sheet.getRow(rowNum);
+					Row row1 = sheet.getRow(rowNum1);
+					System.out.println("orderNo="+orderNo+",count="+count+",rowNum="+rowNum+",rowNum1="+rowNum1);
+					int index=0;
+					for (Object[] e : fields) {
+						Field field = (Field) e[0];
+						Excel attr = (Excel) e[1];
+						// 设置实体类私有属性可访问
+						field.setAccessible(true);
+						Object value = getTargetValue(t, field, attr);
+						Cell cell = row.createCell(index);
+						String dateFormat = attr.dateFormat();
+						String readConverterExp = attr.readConverterExp();
+						String separator = attr.separator();
+						String enumsName = attr.enumsName();
+						String methodName="getValueByCode";
+						if (StringUtils.isNotBlank(enumsName)&& StringUtils.isNotNull(value)) {
+							Class<?> clazz=Class.forName(enumsName);
+							Method method=clazz.getDeclaredMethod(methodName,Integer.class);
+							Object s=method.invoke(clazz,value);
+							setCellVo(s.toString(), attr, cell);
+						}else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) {
+							value=DateUtils.parseDateToStr(dateFormat, (Date) value);
+						} else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) {
+							value=convertByExp(toStr(value), readConverterExp, separator);
+						} else if (value instanceof BigDecimal && -1 != attr.scale()) {
+							value=(((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).stripTrailingZeros().toPlainString();
+						} else{
+							// 设置列类型
+							setCellVo(value, attr, cell);
+						}
+						if (value==null)value="";
+						cell.setCellValue(value.toString());
+						CellRangeAddress region = new CellRangeAddress(rowNum, rowNum1, index, index);
+						sheet.addMergedRegion(region);
+						index++;
+					}
+
+				}
+			}
+		}
+//		CellRangeAddress region = new CellRangeAddress(4, 5, 0, fields.size()-1);
+//		sheet.addMergedRegion(region);
+	}
+
 	/**
 	 * 	直接导出CXCEL表
 	 * @param list 导出数据集合
@@ -423,6 +642,22 @@ public class NewExcelUtil<T> {
 		style.setAlignment(HorizontalAlignment.RIGHT);
 		styles.put("data3", style);
 
+
+		style = wb.createCellStyle();
+		style.cloneStyleFrom(styles.get("data"));
+		style.setAlignment(HorizontalAlignment.CENTER);
+		style.setVerticalAlignment(VerticalAlignment.CENTER);
+		style.setBorderRight(BorderStyle.THIN);
+		style.setRightBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
+		style.setBorderLeft(BorderStyle.THIN);
+		style.setLeftBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
+		style.setBorderTop(BorderStyle.THIN);
+		style.setTopBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
+		style.setBorderBottom(BorderStyle.THIN);
+		style.setBottomBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
+		styles.put("data4", style);
+
+
 		return styles;
 	}
 
@@ -551,7 +786,49 @@ public class NewExcelUtil<T> {
 				cell = row.createCell(column);
 				int align = attr.align().value();
 				cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
+				// 用于读取对象中的属性
+				Object value = getTargetValue(vo, field, attr);
+				String dateFormat = attr.dateFormat();
+				String readConverterExp = attr.readConverterExp();
+				String separator = attr.separator();
+				String enumsName = attr.enumsName();
+				String methodName="getValueByCode";
+				if (StringUtils.isNotBlank(enumsName)&& StringUtils.isNotNull(value)) {
+					Class<?> clazz=Class.forName(enumsName);
+					Object[] os=clazz.getEnumConstants();
+					Method method=clazz.getDeclaredMethod(methodName,Integer.class);
+					Object s=method.invoke(clazz,value);
+					setCellVo(s.toString(), attr, cell);
+				}else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) {
+					cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
+				} else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) {
+					cell.setCellValue(convertByExp(toStr(value), readConverterExp, separator));
+				} else if (value instanceof BigDecimal && -1 != attr.scale()) {
+					cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).stripTrailingZeros().toPlainString());
+				} else{
+					// 设置列类型
+					setCellVo(value, attr, cell);
+				}
+				addStatisticsData(column, toStr(value), attr);
+			}
+		} catch (Exception e) {
+			log.error("导出Excel失败{}", e);
+		}
+		return cell;
+	}
+
 
+	public Cell addOrderMegerCell(Excel attr, Row row, T vo, Field field, int column) {
+		Cell cell = null;
+		try {
+			// 设置行高
+			row.setHeight(maxHeight);
+			// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
+			if (attr.isExport()) {
+				// 创建cell
+				cell = row.createCell(column);
+				int align = attr.align().value();
+				cell.setCellStyle(styles.get("data4"));
 				// 用于读取对象中的属性
 				Object value = getTargetValue(vo, field, attr);
 				String dateFormat = attr.dateFormat();

+ 33 - 31
src/main/java/com/goafanti/order/bo/OutOrderProject.java

@@ -15,7 +15,7 @@ public class OutOrderProject {
     /**
      * 销售类型 0=电话新开发,1=电话自带资源,2=网络,3=渠道,4=转介绍,5=其他,6=高新复购,7=其他复购,8=私有/渠道
      */
-    @Excel(name = "销售类型",readConverterExp = "1=电话自带资源,2=网络,3=渠道,4=转介绍,5=其他,6=高新复购,7=其他复购,8=私有/渠道")
+    @Excel(name = "销售类型",readConverterExp = "0=电话新开发,1=电话自带资源,2=网络,3=渠道,4=转介绍,5=其他,6=高新复购,7=其他复购8=私有/渠道")
     private Integer salesType;
     /**
      * 订单类型(服务类型)
@@ -166,6 +166,36 @@ public class OutOrderProject {
     @Excel(name = "营销负责人")
     private String salesmanName;
     /**
+     * 核算比例
+     */
+    @Excel(name = "核算比例")
+    private String hsbl;
+    /**
+     * 订单情况 ,readConverterExp = "0=待签单,1=签单待审,2=签单审核通过,3=签单审核拒绝,4=已结项,5=已驳回,6=已退单"
+     */
+    @Excel(name = "订单情况")
+    private String orderStatus;
+    /**
+     * 变更情况
+     */
+    @Excel(name = "变更情况")
+    private String changeType;
+    /**
+     * 退单退款
+     */
+    @Excel(name = "退单退款")
+    private String refundType;
+    /**
+     * 是否重报
+     */
+    @Excel(name = "是否重报")
+    private String restatementType;
+    /**
+     * 是否科技项目(订单类型) 0认证项目 1科技项目 2 两化融化管理体系认证项目
+     */
+    @Excel(name = "是否科技项目")
+    private String orderType;
+    /**
      * 项目名称
      */
     @Excel(name = "项目名称")
@@ -190,16 +220,7 @@ public class OutOrderProject {
      */
     @Excel(name = "项目转入时间")
     private String taskDistributionTime;
-    /**
-     * 是否重报
-     */
-    @Excel(name = "是否重报")
-    private String restatementType;
-    /**
-     * 是否科技项目(订单类型) 0认证项目 1科技项目 2 两化融化管理体系认证项目
-     */
-    @Excel(name = "是否科技项目")
-    private String orderType;
+
     /**
      * 项目数
      */
@@ -245,26 +266,7 @@ public class OutOrderProject {
      */
     @Excel(name = "项目备注")
     private String taskComment;
-    /**
-     * 核算比例
-     */
-    @Excel(name = "核算比例")
-    private String hsbl;
-    /**
-     * 订单情况 ,readConverterExp = "0=待签单,1=签单待审,2=签单审核通过,3=签单审核拒绝,4=已结项,5=已驳回,6=已退单"
-     */
-    @Excel(name = "订单情况")
-    private String orderStatus;
-    /**
-     * 变更情况
-     */
-    @Excel(name = "变更情况")
-    private String changeType;
-    /**
-     * 退单退款
-     */
-    @Excel(name = "退单退款")
-    private String refundType;
+
 
     public String getOrderNo() {
         return orderNo;

+ 1 - 1
src/main/java/com/goafanti/order/controller/StatisticsApiController.java

@@ -207,7 +207,7 @@ public class StatisticsApiController extends CertifyApiController {
 		Pagination<OutOrderProject> p = userStaticticsService.orderProject(in);
 		List<OutOrderProject> list = (List<OutOrderProject>) p.getList();
 		NewExcelUtil<OutOrderProject> excelUtil=new NewExcelUtil<>(OutOrderProject.class);
-		return excelUtil.exportExcel(list,"订单项目数据统计表",uploadPath);
+		return excelUtil.OrderMergeAndExportExcel(list,"订单项目数据统计表",uploadPath);
 	}