报表分析

This commit is contained in:
airven 2023-02-28 18:14:36 +08:00
parent 4d0220f62f
commit 901f6aa02f
13 changed files with 226 additions and 43 deletions

View File

@ -1,6 +1,7 @@
package com.jeequan.jeepay.core.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -62,6 +63,19 @@ public class OrderStatisticsDept implements Serializable {
*/
private String deptName;
/**
* 公司名称
*/
@TableField(exist=false)
private String companyName;
/**
* 部门id
*/
@TableField(exist=false)
private String deptId;
/**
* 部门账单金额,单位分
*/
@ -72,5 +86,4 @@ public class OrderStatisticsDept implements Serializable {
*/
private Date createdAt;
}

View File

@ -1,13 +1,33 @@
package com.jeequan.jeepay.mgr.task.job;
import com.jeequan.jeepay.service.impl.OrderStatisticsCompanyService;
import com.jeequan.jeepay.service.impl.OrderStatisticsDeptService;
import com.jeequan.jeepay.service.impl.OrderStatisticsMerchantService;
import com.jeequan.jeepay.service.impl.PayOrderExtendService;
import ch.qos.logback.core.joran.conditional.ElseAction;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
import com.jeequan.jeepay.core.entity.OrderStatisticsDept;
import com.jeequan.jeepay.mgr.util.TimeUtil;
import com.jeequan.jeepay.service.impl.*;
import org.apache.commons.lang3.tuple.MutablePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Component("analysisTask")
@Configuration
public class AnalysisTask {
@Value(value = "${qiDi.gateWay.url}")
private String gateWay;
@Value(value = "${qiDi.gateWay.secret-key}")
private String secretKey;
@Autowired
private PayOrderService payOrderService;
@Autowired
private PayOrderExtendService payOrderExtendService;
@ -20,7 +40,54 @@ public class AnalysisTask {
@Autowired
private OrderStatisticsMerchantService orderStatisticsMerchantService;
public void Analyse(){
//企业结算
/**
* 根据周期段进行分析
*
* @param cycle 1表示年2表示月 3表示周
*/
@Transactional(rollbackFor = Exception.class)
public void Analyse(int cycle) throws Exception {
String createTimeStart = "";//开始时间
String createTimeEnd = "";//结束时间
if (1 == cycle) {
createTimeStart = TimeUtil.getBeforeFirstYearDate();
createTimeEnd = TimeUtil.getBeforeLastYearDate();
} else if (2 == cycle) {
createTimeStart = TimeUtil.getBeforeFirstMonthDate();
createTimeEnd = TimeUtil.getBeforeLastMonthDate();
} else if (3 == cycle) {
createTimeStart = TimeUtil.getBeforeFirstDayDate();
createTimeEnd = TimeUtil.getBeforeLastDayDate();
}
//产生版本号
Long analyseId=0L;
List<OrderStatisticsDept> orderStatisticsDeptList = payOrderService.selectOrderCountByDept(createTimeStart, createTimeEnd);
if (!CollectionUtil.isEmpty(orderStatisticsDeptList)) {
orderStatisticsDeptList.forEach(item -> {
//去启迪查询部门信息
MutablePair<String, Object> mutablePair = getDept(item.getDeptId());
item.setDeptName("");
item.setCompanyName("");
});
boolean stepOne = orderStatisticsDeptService.saveBatch(orderStatisticsDeptList, 200);
if (stepOne) {
}
}
}
/**
* 根据部门Id得到部门信息
* @param deptId
* @return MutablePair<String, Object>
*/
private MutablePair<String, Object> getDept(String deptId) {
return MutablePair.of("deptName", "compnayName");
}
}

View File

@ -10,13 +10,13 @@ import java.util.Date;
@Component
public class TimeUtil {
private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 获取昨天0点0分0秒的时间
*/
@SneakyThrows
public String getBeforeFirstDayDate() throws Exception {
public static String getBeforeFirstDayDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
System.out.println("当前星期(日期)" + format.format(calendar.getTime()));
@ -33,7 +33,7 @@ public class TimeUtil {
* 获取昨天天23点59分59秒的时间
*/
@SneakyThrows
public String getBeforeLastDayDate() throws Exception {
public static String getBeforeLastDayDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.set(Calendar.HOUR_OF_DAY, 23);//将小时至23
@ -48,7 +48,7 @@ public class TimeUtil {
* 获取上一周1号0点0分0秒的时间
*/
@SneakyThrows
public String getBeforeFirstWeekDate() throws Exception {
public static String getBeforeFirstWeekDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.WEEK_OF_YEAR, -1);
@ -66,7 +66,7 @@ public class TimeUtil {
* 获取上一周最后一天23点59分59秒的时间
*/
@SneakyThrows
public String getBeforeLastWeekDate() throws Exception {
public static String getBeforeLastWeekDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.WEEK_OF_YEAR, -1);
@ -82,7 +82,7 @@ public class TimeUtil {
* 获取上一个月1号0点0分0秒的时间
*/
@SneakyThrows
public String getBeforeFirstMonthDate() throws Exception {
public static String getBeforeFirstMonthDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
@ -98,7 +98,7 @@ public class TimeUtil {
* 获取上个月的最后一天23点59分59秒的时间
*/
@SneakyThrows
public String getBeforeLastMonthDate() throws Exception {
public static String getBeforeLastMonthDate() throws Exception {
Calendar calendar = Calendar.getInstance();
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month - 1);
@ -114,7 +114,7 @@ public class TimeUtil {
* 获取上年1号0点0分0秒的时间
*/
@SneakyThrows
public String getBeforeFirstYearDate() throws Exception {
public static String getBeforeFirstYearDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, -1);
@ -131,7 +131,7 @@ public class TimeUtil {
* 获取上年的最后一天23点59分59秒的时间
*/
@SneakyThrows
public String getBeforeLastYearDate() throws Exception {
public static String getBeforeLastYearDate() throws Exception {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, -1);

View File

@ -7,6 +7,11 @@ spring:
# profiles:
# active: dev
qiDi:
gateWay:
url: https://api-shanghai.sz9wang.com/api/v1
secret-key: ""
#系统业务参数
isys:
jwt-secret: t7w3P8X6472qWc3u #生成jwt的秘钥。 要求每个系统有单独的秘钥管理机制。

View File

@ -28,10 +28,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeequan.jeepay.core.aop.Action;
import com.jeequan.jeepay.core.aop.MethodLog;
import com.jeequan.jeepay.core.constants.CS;
import com.jeequan.jeepay.core.entity.IsvInfo;
import com.jeequan.jeepay.core.entity.MchInfo;
import com.jeequan.jeepay.core.entity.PayOrder;
import com.jeequan.jeepay.core.entity.PayWay;
import com.jeequan.jeepay.core.entity.*;
import com.jeequan.jeepay.service.mapper.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.aop.framework.AopContext;
@ -455,4 +452,17 @@ public class PayOrderService extends ServiceImpl<PayOrderMapper, PayOrder> {
return page(iPage, wrapper);
}
public List<OrderStatisticsDept> selectOrderCountByDept(String createTimeStart,String createTimeEnd)
{
Map<String, String> paramMap = new HashMap<>();
paramMap.put("createTimeStart",createTimeStart);
paramMap.put("createTimeEnd",createTimeEnd);
return this.getBaseMapper().selectOrderCountByDept(paramMap);
}
/** 更新订单状态为已完成 **/
public int updateOrderStateBatch(List<PayOrder> orderList){
return this.getBaseMapper().updateOrderStateBatch(orderList);
}
}

View File

@ -2,6 +2,9 @@ package com.jeequan.jeepay.service.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeequan.jeepay.core.entity.OrderStatisticsCompany;
import com.jeequan.jeepay.core.entity.OrderStatisticsMerchant;
import java.util.List;
/**
* <p>
@ -13,4 +16,5 @@ import com.jeequan.jeepay.core.entity.OrderStatisticsCompany;
*/
public interface OrderStatisticsCompanyMapper extends BaseMapper<OrderStatisticsCompany> {
public int insertBatch(List<OrderStatisticsCompany> orderStatisticsCompanyList);
}

View File

@ -4,18 +4,35 @@
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.jeequan.jeepay.core.entity.OrderStatisticsCompany">
<id column="id" property="id" />
<result column="mch_no" property="mchNo" />
<result column="app_id" property="appId" />
<result column="app_name" property="appName" />
<result column="mch_name" property="mchName" />
<result column="amount" property="amount" />
<result column="dept_name" property="deptName" />
<result column="amount_infact" property="amountInfact" />
<result column="analyse_id" property="analyseId" />
<result column="static_state" property="staticState" />
<result column="remark" property="remark" />
<result column="created_at" property="createdAt" />
<id column="id" property="id"/>
<result column="mch_no" property="mchNo"/>
<result column="app_id" property="appId"/>
<result column="app_name" property="appName"/>
<result column="mch_name" property="mchName"/>
<result column="amount" property="amount"/>
<result column="dept_name" property="deptName"/>
<result column="amount_infact" property="amountInfact"/>
<result column="analyse_id" property="analyseId"/>
<result column="static_state" property="staticState"/>
<result column="remark" property="remark"/>
<result column="created_at" property="createdAt"/>
</resultMap>
<!-- 批量新增 -->
<insert id="insertBatch">
INSERT INTO t_order_statistics_company (mch_no,app_id, app_name, mch_name,
amount,dept_name,amount_infact,analyse_id,static_state,remark) VALUES
<foreach collection="list" separator="," item="item">
(#{item.mchNo},
#{item.appId},
#{item.appName},
#{item.mchName},
#{item.amount},
#{item.deptName},
#{item.amountInfact},
#{item.analyseId},
#{item.staticState},
#{item.remark})
</foreach>
</insert>
</mapper>

View File

@ -1,8 +1,11 @@
package com.jeequan.jeepay.service.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeequan.jeepay.core.entity.OrderStatisticsCompany;
import com.jeequan.jeepay.core.entity.OrderStatisticsDept;
import java.util.List;
/**
* <p>
* 订单分析部门表 Mapper 接口
@ -13,4 +16,6 @@ import com.jeequan.jeepay.core.entity.OrderStatisticsDept;
*/
public interface OrderStatisticsDeptMapper extends BaseMapper<OrderStatisticsDept> {
public int insertBatch(List<OrderStatisticsDept> orderStatisticsDeptList);
}

View File

@ -15,4 +15,12 @@
<result column="created_at" property="createdAt" />
</resultMap>
<!-- 批量新增 -->
<insert id="insertBatch">
INSERT INTO t_order_statistics_dept (analyse_id, mch_no, app_id, app_name, mch_name,dept_name,amount) VALUES
<foreach collection="list" separator="," item="item">
(#{item.analyseId},#{item.mchNo},#{item.appId},#{item.appName},#{item.mchName},#{item.deptName},#{item.amount})
</foreach>
</insert>
</mapper>

View File

@ -3,6 +3,8 @@ package com.jeequan.jeepay.service.mapper;
import com.jeequan.jeepay.core.entity.OrderStatisticsMerchant;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* <p>
* 订单分析主表 Mapper 接口
@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface OrderStatisticsMerchantMapper extends BaseMapper<OrderStatisticsMerchant> {
public int insertBatch(List<OrderStatisticsMerchant> orderStatisticsMerchantList);
}

View File

@ -4,17 +4,33 @@
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.jeequan.jeepay.core.entity.OrderStatisticsMerchant">
<id column="id" property="id" />
<result column="mch_no" property="mchNo" />
<result column="app_id" property="appId" />
<result column="app_name" property="appName" />
<result column="mch_name" property="mchName" />
<result column="amount" property="amount" />
<result column="amount_infact" property="amountInfact" />
<result column="analyse_id" property="analyseId" />
<result column="static_state" property="staticState" />
<result column="remark" property="remark" />
<result column="created_at" property="createdAt" />
<id column="id" property="id"/>
<result column="mch_no" property="mchNo"/>
<result column="app_id" property="appId"/>
<result column="app_name" property="appName"/>
<result column="mch_name" property="mchName"/>
<result column="amount" property="amount"/>
<result column="amount_infact" property="amountInfact"/>
<result column="analyse_id" property="analyseId"/>
<result column="static_state" property="staticState"/>
<result column="remark" property="remark"/>
<result column="created_at" property="createdAt"/>
</resultMap>
<!-- 批量新增 -->
<insert id="insertBatch">
INSERT INTO t_order_statistics_merchant (mch_no, app_id, app_name, mch_name,
amount,amount_infact,analyse_id,static_state,remark) VALUES
<foreach collection="list" separator="," item="item">
(#{item.mchNo},
#{item.appId},
#{item.appName},
#{item.mchName},
#{item.amount},
#{item.amountInfact},
#{item.analyseId}),
#{item.staticState}),
#{item.remark}),
</foreach>
</insert>
</mapper>

View File

@ -16,6 +16,7 @@
package com.jeequan.jeepay.service.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jeequan.jeepay.core.entity.OrderStatisticsDept;
import com.jeequan.jeepay.core.entity.PayOrder;
import org.apache.ibatis.annotations.Param;
@ -38,6 +39,12 @@ public interface PayOrderMapper extends BaseMapper<PayOrder> {
List<Map> selectOrderCount(Map param);
/** 更统计企业在各个档口的消费情况 **/
List<OrderStatisticsDept> selectOrderCountByDept(Map param);
/** 更新订单状态为已完成 **/
int updateOrderStateBatch(List<PayOrder> orderList);
/** 更新订单退款金额和次数 **/
int updateRefundAmountAndCount(@Param("payOrderId") String payOrderId, @Param("currentRefundAmount") Long currentRefundAmount);
}

View File

@ -81,6 +81,34 @@
GROUP BY groupDate
ORDER BY groupDate desc
</select>
<!--企业消费统计-->
<select id="selectOrderCountByDept" resultType="com.jeequan.jeepay.core.entity.OrderStatisticsDept" parameterType="java.util.Map" >
select e.deptId,o.mch_no,o.mch_name,o.app_id,a.app_name,ROUND(IFNULL(SUM(o.amount) - SUM(o.refund_amount), 0)/100, 2) AS amount
from t_pay_order o
join t_pay_order_extend e on o.pay_order_id=e.pay_order_id
join t_mch_app a on o.app_id=a.app_id
where 1=1
<if test="createTimeStart != null"> AND created_at &gt;= #{createTimeStart} </if>
<if test="createTimeEnd != null"> AND created_at &lt;= #{createTimeEnd} </if>
and o.state in (2,5)
group by e.deptId,o.mch_no,o.mch_name,o.app_id,a.app_name
</select>
<!--更新订单状态为已完成-->
<update id="updateOrderStateBatch" parameterType="java.util.List">
update t_pay_order
<trim prefix="set" suffixOverrides=",">
<trim prefix="state =case" suffix="end,">
<foreach collection="list" item="item" index="index">
when pay_order_id=#{item.payOrderId} then #{item.state}
</foreach>
</trim>
</trim>
where pay_order_id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.payOrderId,jdbcType=VARCHAR}
</foreach>
</update>
<!-- 更新订单退款金额和次数 -->
<update id="updateRefundAmountAndCount">