提交代码

dev
胡锐 3 days ago
parent 5b522d0deb
commit 3ab085b4bc
  1. 2
      bweb/src/main/java/com/bweb/config/AuthConfig.java
  2. 20
      bweb/src/main/java/com/bweb/controller/BsGasOrderController.java
  3. 237
      bweb/src/main/java/com/bweb/controller/BsGasOrderCountController.java
  4. 30
      bweb/src/main/java/com/bweb/excel/ExcelUtil.java
  5. 2
      bweb/src/main/resources/dev/application.yml
  6. 39
      service/src/main/java/com/hfkj/dao/BsGasOrderMapperExt.java
  7. 25
      service/src/main/java/com/hfkj/service/gas/BsGasOrderCountService.java
  8. 26
      service/src/main/java/com/hfkj/service/gas/impl/BsGasOrderCountServiceImpl.java

@ -102,6 +102,8 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/userSpread/*")
.excludePathPatterns("/cms/*")
.excludePathPatterns("/fileUpload/*")
.excludePathPatterns("/gasOrderCount/*")
.excludePathPatterns("/gasOrder/countOilData")
;
}

@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
@Controller
@ -123,7 +124,24 @@ public class BsGasOrderController {
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
}
return ResponseMsgUtil.success(gasOrderService.getGasOrderCount(param));
Map<String, Object> deductionCouponParam = new HashMap<>(param);
Map<String, Object> map = gasOrderService.getGasOrderCount(param);
// 优惠卷订单
deductionCouponParam.put("deductionCouponNotNull", "deductionCouponNotNull");
Map<String, Object> deductionCouponNotNull = gasOrderService.getGasOrderCount(deductionCouponParam);
map.put("deductionCouponCount", deductionCouponNotNull.get("totalCount"));
if (Integer.parseInt(map.get("totalCount").toString()) > 0) {
map.put("deductionCouponRate", new BigDecimal(map.get("deductionCouponCount").toString())
.divide(new BigDecimal(map.get("totalCount").toString()),2, BigDecimal.ROUND_DOWN)
.multiply(new BigDecimal("100")));
} else {
map.put("deductionCouponRate", 0);
}
return ResponseMsgUtil.success(map);
} catch (Exception e) {
log.error("error!",e);

@ -0,0 +1,237 @@
package com.bweb.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.fill.FillWrapper;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.bweb.excel.ExcelUtil;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.CommonSysConst;
import com.hfkj.entity.BsMerchant;
import com.hfkj.model.ResponseData;
import com.hfkj.service.gas.BsGasOrderCountService;
import com.hfkj.service.merchant.BsMerchantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping(value = "/gasOrderCount")
@Api(value = "加油订单统计")
public class BsGasOrderCountController {
private static Logger log = LoggerFactory.getLogger(BsGasOrderCountController.class);
@Resource
private BsGasOrderCountService gasOrderCountService;
@Resource
private BsMerchantService merchantService;
@RequestMapping(value="/countOilData",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "统计加油数据")
public ResponseData exportOilOrder(@RequestParam(name = "channelType", required = false) Integer channelType,
@RequestParam(name = "startTime", required = true) Long startTime) {
try {
// 获取统计数据
Calendar startDate = Calendar.getInstance();
startDate.setTime(new Date(startTime));
startDate.set(Calendar.HOUR_OF_DAY, 0);
startDate.set(Calendar.MINUTE, 0);
startDate.set(Calendar.SECOND, 0);
List<HashMap<String,Object>> dataList = new LinkedList<>();
int day = 1; // 当天
// 当天数据
List<HashMap<String, Object>> mapList = gasOrderCountService.countOrderRatio(channelType, DateUtil.date2String(startDate.getTime(), DateUtil.Y_M_D_HMS), day-1);
// 利用当天数据比例进行倒序排序
List<HashMap<String, Object>> merList = new LinkedList<>();
for (HashMap<String, Object> data : mapList) {
HashMap<String,Object> mer = new HashMap<>();
mer.put("merNo", data.get("merNo"));
mer.put("merName", data.get("merName"));
merList.add(mer);
}
// 当天
HashMap<String,Object> dataMap = new HashMap<>();
dataMap.put("day", day);
dataMap.put("data", mapList);
dataList.add(dataMap);
// 前3天
HashMap<String,Object> dataMap3 = new HashMap<>();
day = 3;
dataMap3.put("day", day);
dataMap3.put("data", gasOrderCountService.countOrderRatio(channelType, DateUtil.date2String(startDate.getTime(), DateUtil.Y_M_D_HMS), day-1));
dataList.add(dataMap3);
// 前10天
HashMap<String,Object> dataMap10 = new HashMap<>();
day = 10;
dataMap10.put("day", day);
dataMap10.put("data", gasOrderCountService.countOrderRatio(channelType, DateUtil.date2String(startDate.getTime(), DateUtil.Y_M_D_HMS), day-1));
dataList.add(dataMap10);
// 前30天
HashMap<String,Object> dataMap30 = new HashMap<>();
day = 30;
dataMap30.put("day", day);
dataMap30.put("data", gasOrderCountService.countOrderRatio(channelType, DateUtil.date2String(startDate.getTime(), DateUtil.Y_M_D_HMS), day-1));
dataList.add(dataMap30);
// 前60天
HashMap<String,Object> dataMap60 = new HashMap<>();
day = 60;
dataMap60.put("day", day);
dataMap60.put("data", gasOrderCountService.countOrderRatio(channelType, DateUtil.date2String(startDate.getTime(), DateUtil.Y_M_D_HMS), day-1));
dataList.add(dataMap60);
List<List<Object>> excelDataList = new ArrayList<>();
for (HashMap<String,Object> merchant : merList) {
List<Object> excelData = new ArrayList<>();
excelData.add(merchant.get("merNo"));
excelData.add(merchant.get("merName"));
for (HashMap<String,Object> data : dataList) {
List<HashMap<String, Object>> totalCountCollect = ((List<HashMap<String,Object>>) data.get("data")).stream()
.filter(o -> o.get("merNo").equals(merchant.get("merNo"))).collect(Collectors.toList());
if (!totalCountCollect.isEmpty()) {
excelData.add(totalCountCollect.get(0).get("totalPrice"));
excelData.add(totalCountCollect.get(0).get("totalPriceRatio")+"%");
excelData.add(totalCountCollect.get(0).get("totalCount"));
excelData.add(totalCountCollect.get(0).get("totalCountRatio")+"%");
} else {
excelData.add(0);
excelData.add(0+"%");
excelData.add(0);
excelData.add(0+"%");
}
}
excelDataList.add(excelData);
}
List<Object> footData = new ArrayList<>();
footData.add("合计");
footData.add(merList.size()+"家油站");
footData.add(countPrice((List<HashMap<String, Object>>) dataMap.get("data")));
footData.add("");
footData.add(countOilNumber((List<HashMap<String, Object>>) dataMap.get("data")));
footData.add("");
footData.add(countPrice((List<HashMap<String, Object>>) dataMap3.get("data")));
footData.add("");
footData.add(countOilNumber((List<HashMap<String, Object>>) dataMap3.get("data")));
footData.add("");
footData.add(countPrice((List<HashMap<String, Object>>) dataMap10.get("data")));
footData.add("");
footData.add(countOilNumber((List<HashMap<String, Object>>) dataMap10.get("data")));
footData.add("");
footData.add(countPrice((List<HashMap<String, Object>>) dataMap30.get("data")));
footData.add("");
footData.add(countOilNumber((List<HashMap<String, Object>>) dataMap30.get("data")));
footData.add("");
footData.add(countPrice((List<HashMap<String, Object>>) dataMap60.get("data")));
footData.add("");
footData.add(countOilNumber((List<HashMap<String, Object>>) dataMap60.get("data")));
footData.add("");
excelDataList.add(footData);
// 设置内容的策略
WriteCellStyle contentWriteCellStyle = ExcelUtil.getWriteCellStyle();
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 设置头部水平居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 设置头部垂直居中对齐
headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
String path = "/temporary/"+System.currentTimeMillis()+".xlsx";
EasyExcel.write( CommonSysConst.getSysConfig().getFilesystem() + path)
.head(getSaleSheetHeadList(startTime, dataList))
.registerWriteHandler(new SimpleColumnWidthStyleStrategy(20))
.registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle))
.sheet("统计")
.doWrite(excelDataList);
return ResponseMsgUtil.success(path);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
public static BigDecimal countPrice(List<HashMap<String, Object>> mapList) {
BigDecimal totalprice = new BigDecimal("0");
for (HashMap<String, Object> map : mapList) {
if (StringUtils.isNotBlank(MapUtils.getString(map, "totalPrice"))) {
totalprice = totalprice.add(new BigDecimal(MapUtils.getString(map, "totalPrice")));
}
}
return totalprice;
}
public static BigDecimal countOilNumber(List<HashMap<String, Object>> mapList) {
BigDecimal totalprice = new BigDecimal("0");
for (HashMap<String, Object> map : mapList) {
if (StringUtils.isNotBlank(MapUtils.getString(map, "totalCount"))) {
totalprice = totalprice.add(new BigDecimal(MapUtils.getString(map, "totalCount")));
}
}
return totalprice;
}
private static List<List<String>> getSaleSheetHeadList(Long startTime, List<HashMap<String,Object>> dataList) {
List<List<String>> list = new ArrayList<List<String>>();
List<String> merNo = new ArrayList<String>();
merNo.add("油站编码");
list.add(merNo);
List<String> merName = new ArrayList<String>();
merName.add("油站名称");
list.add(merName);
for (HashMap<String,Object> data : dataList) {
// 获取时间
Calendar date = Calendar.getInstance();
date.setTime(new Date(startTime));
date.add(Calendar.DAY_OF_MONTH, 1 - Integer.parseInt(data.get("day").toString()));
List<String> daysHead = new ArrayList<String>();
daysHead.add(DateUtil.date2String(date.getTime(), DateUtil.Y_M_D));
daysHead.add("加油金额");
list.add(daysHead);
List<String> daysHead2 = new ArrayList<String>();
daysHead2.add(DateUtil.date2String(date.getTime(), DateUtil.Y_M_D));
daysHead2.add("占比");
list.add(daysHead2);
List<String> daysHead3 = new ArrayList<String>();
daysHead3.add(DateUtil.date2String(date.getTime(), DateUtil.Y_M_D));
daysHead3.add("加油订单");
list.add(daysHead3);
List<String> daysHead4 = new ArrayList<String>();
daysHead4.add(DateUtil.date2String(date.getTime(), DateUtil.Y_M_D));
daysHead4.add("占比");
list.add(daysHead4);
}
return list;
}
}

@ -0,0 +1,30 @@
package com.bweb.excel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
/**
* @className: excelUtil
* @author: HuRui
* @date: 2025/8/28
**/
public class ExcelUtil {
public static WriteCellStyle getWriteCellStyle() {
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
// 设置内容水平居中对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
// 设置内容垂直居中对齐
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
// 自动换行
contentWriteCellStyle.setWrapped(false);
// 设置字体样式和大小
/*WriteFont contentWriteFont = new WriteFont();
contentWriteFont.setFontHeightInPoints((short) 12);
contentWriteFont.setFontName("微软雅黑");
contentWriteCellStyle.setWriteFont(contentWriteFont);*/
return contentWriteCellStyle;
}
}

@ -9,7 +9,7 @@ debug: false
#datasource数据源设置
spring:
datasource:
url: jdbc:mysql://139.9.154.68:3306/hai_oil?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
url: jdbc:mysql://139.9.154.68:3306/hai_oil_prod?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: HF123456.
type: com.alibaba.druid.pool.DruidDataSource

@ -24,6 +24,7 @@ public interface BsGasOrderMapperExt {
" FROM" +
" bs_gas_order" +
" where 1 = 1" +
" <if test='param.deductionCouponNotNull != null'> <![CDATA[ and deduction_coupon_price > 0 ]]> </if>" +
" <if test='param.merChainBrandId != null'> and mer_chain_brand_id = #{param.merChainBrandId} </if>" +
" <if test='param.merId != null'> and mer_id = #{param.merId} </if>" +
" <if test='param.merNo != null'> and mer_no = #{param.merNo} </if>" +
@ -148,4 +149,42 @@ public interface BsGasOrderMapperExt {
@Result(column="ext_6", property="ext6", jdbcType=JdbcType.VARCHAR)
})
List<HashMap<String,Object>> queryOilOrderSpread(@Param("param") Map<String,Object> param);
@Select("<script>" +
" SET @totalCount := (select count(1) totalCount from bs_gas_order where status = 2 " +
" <if test='channelType != null'> and channel_type = #{channelType} </if>" +
" and TO_DAYS(#{startTime}) - TO_DAYS(create_time) = #{days});" +
" SET @totalPrice := (select sum(gas_refuel_price) totalPrice from bs_gas_order where status = 2" +
" <if test='channelType != null'> and channel_type = #{channelType} </if>" +
" and TO_DAYS(#{startTime}) - TO_DAYS(create_time) = #{days});" +
" "+
" select " +
" a.id merId," +
" a.mer_no merNo," +
" a.mer_name merName," +
" case when b.totalCount is not null then b.totalCount else 0 end totalCount," +
" case when b.totalCountRatio is not null then b.totalCountRatio else 0 end totalCountRatio," +
" case when b.totalPrice is not null then b.totalPrice else 0 end totalPrice," +
" case when b.totalPriceRatio is not null then b.totalPriceRatio else 0 end totalPriceRatio" +
" from bs_merchant a" +
" LEFT JOIN (" +
" SELECT " +
" mer_id," +
" mer_no," +
" mer_name," +
" order_no," +
" count(1) totalCount," +
" ROUND((count(1) / @totalCount) * 100,2) totalCountRatio," +
" sum(gas_refuel_price) totalPrice," +
" ROUND((sum(gas_refuel_price) / @totalPrice) * 100 ,2) totalPriceRatio" +
" from bs_gas_order" +
" where TO_DAYS(#{startTime}) - TO_DAYS(create_time) = #{days} and status = 2" +
" <if test='channelType != null'> and channel_type = #{channelType} </if>" +
" GROUP BY mer_no" +
" ) b on b.mer_id = a.id" +
" where 1 = 1 " +
" <if test='channelType != null'> and a.source_type = #{channelType} </if>" +
" ORDER BY totalCountRatio desc" +
"</script>")
List<HashMap<String,Object>> countOrderRatio(Integer channelType, String startTime,Integer days);
}

@ -0,0 +1,25 @@
package com.hfkj.service.gas;
import com.hfkj.entity.BsGasOrder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 加油订单
* @className: HighGasOrderService
* @author: HuRui
* @date: 2022/9/6
**/
public interface BsGasOrderCountService {
/**
* 统计订单占比
* @param channelType 渠道
* @param days 天数
* @return
*/
List<HashMap<String, Object>> countOrderRatio(Integer channelType, String startTime, Integer days);
}

@ -0,0 +1,26 @@
package com.hfkj.service.gas.impl;
import com.hfkj.dao.BsGasOrderMapper;
import com.hfkj.dao.BsGasOrderMapperExt;
import com.hfkj.service.gas.BsGasOrderCountService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
/**
* @className: BsGasOrderCountServiceImpl
* @author: HuRui
* @date: 2025/8/28
**/
@Service("gasOrderCountService")
public class BsGasOrderCountServiceImpl implements BsGasOrderCountService {
@Resource
private BsGasOrderMapper gasOrderMapper;
@Override
public List<HashMap<String, Object>> countOrderRatio(Integer channelType, String startTime, Integer days) {
return gasOrderMapper.countOrderRatio(channelType,startTime,days);
}
}
Loading…
Cancel
Save