临时提交

This commit is contained in:
磷叶 2025-03-03 18:04:08 +08:00
parent 35e0086429
commit 6213e5114e
27 changed files with 594 additions and 203 deletions

View File

@ -1,13 +1,23 @@
package com.ruoyi.common.utils.collection;
import com.ruoyi.common.utils.DateUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils;
/**
* @author wjh
* 2024/4/29
@ -237,4 +247,44 @@ public class CollectionUtils extends org.springframework.util.CollectionUtils {
return result;
}
/**
* 将列表转换为树结构
* @param list 列表
* @param idFunc 唯一标识获取方法
* @param parentIdFunc 父级标识获取方法
* @return 树结构
*/
public static <T extends TreeVO> List<T> toTree(List<T> list) {
if (isEmpty(list)) {
return new ArrayList<>();
}
// 使用 Map 优化查找性能
Map<Object, T> idMap = new HashMap<>();
for (T node : list) {
idMap.put(node.getId(), node);
}
List<T> result = new ArrayList<>();
for (T node : list) {
Object parentId = node.getParentId();
T parent = (T) idMap.get(parentId);
if (parent != null) {
// 找到父节点将当前节点添加到父节点的子节点列表中
List<T> children = (List<T>) parent.getChildren();
if (children == null) {
children = new ArrayList<>();
parent.setChildren(children);
}
children.add(node);
} else {
// 没有父节点作为根节点
result.add(node);
}
}
return result;
}
}

View File

@ -0,0 +1,210 @@
package com.ruoyi.common.utils.idcard;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @Description身份证号的util
* @Author:
* @Date: Created in 11:26 2019-03-27
* @Modified By:
*/
@Slf4j
public class IDCardUtil {
/**
* 15位身份证号
*/
private static final Integer FIFTEEN_ID_CARD=15;
/**
* 18位身份证号
*/
private static final Integer EIGHTEEN_ID_CARD=18;
private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
/**
* 根据身份证号获取性别
* @param IDCard
* @return
*/
public static String getSex(String IDCard){
String sex ="";
if (StringUtils.isNotBlank(IDCard)){
//15位身份证号
if (IDCard.length() == FIFTEEN_ID_CARD){
if (Integer.parseInt(IDCard.substring(14, 15)) % 2 == 0) {
sex = "";
} else {
sex = "";
}
//18位身份证号
}else if(IDCard.length() == EIGHTEEN_ID_CARD){
// 判断性别
if (Integer.parseInt(IDCard.substring(16).substring(0, 1)) % 2 == 0) {
sex = "";
} else {
sex = "";
}
}
}
return sex;
}
/**
* 根据身份证号获取年龄
* @param IDCard
* @return
*/
public static Integer getAge(String IDCard){
Integer age = 0;
Date date = new Date();
if (StringUtils.isNotBlank(IDCard)&& isValid(IDCard)){
//15位身份证号
if (IDCard.length() == FIFTEEN_ID_CARD){
// 身份证上的年份(15位身份证为1980年前的)
String uyear = "19" + IDCard.substring(6, 8);
// 身份证上的月份
String uyue = IDCard.substring(8, 10);
// 当前年份
String fyear = format.format(date).substring(0, 4);
// 当前月份
String fyue = format.format(date).substring(5, 7);
if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) {
age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;
// 当前用户还没过生
} else {
age = Integer.parseInt(fyear) - Integer.parseInt(uyear);
}
//18位身份证号
}else if(IDCard.length() == EIGHTEEN_ID_CARD){
// 身份证上的年份
String year = IDCard.substring(6).substring(0, 4);
// 身份证上的月份
String yue = IDCard.substring(10).substring(0, 2);
// 当前年份
String fyear = format.format(date).substring(0, 4);
// 当前月份
String fyue = format.format(date).substring(5, 7);
// 当前月份大于用户出身的月份表示已过生日
if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) {
age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;
// 当前用户还没过生日
} else {
age = Integer.parseInt(fyear) - Integer.parseInt(year);
}
}
}
return age;
}
/**
* 获取出生日期 yyyy年MM月dd日
* @param IDCard
* @return
*/
public static String getBirthday(String IDCard){
String birthday="";
String year="";
String month="";
String day="";
if (StringUtils.isNotBlank(IDCard)){
//15位身份证号
if (IDCard.length() == FIFTEEN_ID_CARD){
// 身份证上的年份(15位身份证为1980年前的)
year = "19" + IDCard.substring(6, 8);
//身份证上的月份
month = IDCard.substring(8, 10);
//身份证上的日期
day= IDCard.substring(10, 12);
//18位身份证号
}else if(IDCard.length() == EIGHTEEN_ID_CARD){
// 身份证上的年份
year = IDCard.substring(6).substring(0, 4);
// 身份证上的月份
month = IDCard.substring(10).substring(0, 2);
//身份证上的日期
day=IDCard.substring(12).substring(0,2);
}
birthday=year+""+month+""+day+"";
}
return birthday;
}
/**
* 身份证验证
* @param id 号码内容
* @return 是否有效
*/
public static boolean isValid(String id){
Boolean validResult = true;
//校验长度只能为15或18
int len = id.length();
if (len != FIFTEEN_ID_CARD && len != EIGHTEEN_ID_CARD){
validResult = false;
}
//校验生日
if (!validDate(id)){
validResult = false;
}
return validResult;
}
/**
* 校验生日
* @param id
* @return
*/
private static boolean validDate(String id)
{
try
{
String birth = id.length() == 15 ? "19" + id.substring(6, 12) : id.substring(6, 14);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date birthDate = sdf.parse(birth);
if (!birth.equals(sdf.format(birthDate))){
return false;
}
}
catch (ParseException e)
{
return false;
}
return true;
}
/**
* ocr身份证识别
* @param url 身份证地址
* @return
*/
public static IdCardVo ocr(String url){
String host = "https://swidcard.market.alicloudapi.com/ocr/idcard";
String appcode = SpringUtils.getRequiredProperty("idcardOcr.appCode");
Map<String, String> headers = new HashMap<>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
//根据API的要求定义相对应的Content-Type
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, Object> bodys = new HashMap<>();
bodys.put("image_url", url);
String result= HttpUtil.createRequest(Method.POST, host).addHeaders(headers).form(bodys).execute().body();
log.info("ocr身份识别返回==================="+result);
IdCardVo idResponse = JSONObject.parseObject(result, IdCardVo.class);
log.info("ocr身份识别返回识别对象后==================="+ JSON.toJSONString(idResponse));
return idResponse;
}
}

View File

@ -0,0 +1,46 @@
package com.ruoyi.common.utils.idcard;
import lombok.Data;
/**
* 身份证对象
*
*/
@Data
public class IdCardVo {
/** 是否收费*/
private String charge;
private PersonInfo result;
/**调用成功 0000 */
private String result_code;
private String result_msg;
private String request_id;
@Data
public static class PersonInfo {
/** 身份证号*/
private String number;
/** 地址*/
private String address;
/** 年*/
private String year;
/** 月*/
private String month;
/** 民族*/
private String nation;
/** 日*/
private String day;
/** 性别*/
private String sex;
/** 姓名*/
private String name;
/** 公安局*/
private String authority;
/** 有效期*/
private String timelimit;
}
}

View File

@ -82,7 +82,7 @@ public interface BonusMapper
/**
* 批量更新分成金额
*/
int batchUpdateAmount(@Param("list") List<Bonus> list);
int batchUpdateAmount(@Param("list") List<? extends Bonus> list);
/**
* 根据到账方统计

View File

@ -18,7 +18,7 @@ import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
*/
public interface BonusConverter {
/**
* 分成列表
* 成设备分成列表
*/
List<Bonus> toPoList(SysDept platform, DeviceVO device, List<StoreStaffVO> staffList);
@ -28,7 +28,7 @@ public interface BonusConverter {
List<Bonus> toPoList(VipOrderVO order, Long channelId);
/**
* 转为分成数据
* 生成店铺分成列表
*/
List<Bonus> toPoListByVip(StoreVo store, List<StoreStaffVO> staffList, boolean isPlatform);

View File

@ -85,27 +85,12 @@ public interface BonusService
int payBonus(BonusVO bonus);
/**
* 处理分成按照比例分出金额
* 分配分成金额按照比例分出金额
*
* @param bonusList 分成列表
* @param money 总金额
*/
void partBonus(List<Bonus> bonusList, BigDecimal money);
/**
* 根据到账方统计
*/
List<CommonCountVO<Long>> selectCountByArrival(BonusQuery query);
/**
* 根据到账方统计订单金额
*/
List<CommonSumVO<Long>> selectBillAmountByArrival(BonusQuery query);
/**
* 查询提供分成
*/
List<ProvideBonusVO> selectProvideBonus(BonusProvideQuery query);
int partBonus(List<? extends Bonus> bonusList, BigDecimal money);
/**
* 当未分成时退款
@ -117,11 +102,6 @@ public interface BonusService
*/
int refundWhenDividend(Long id, BigDecimal amount);
/**
* 数据隔离过滤
*/
<T extends Bonus> List<T> filterBonusScope(List<T> bonusList);
/**
* 按月查询分成金额
*/
@ -179,11 +159,6 @@ public interface BonusService
*/
List<BonusVO> selectBonusByBstId(BonusBstType bstType, Long bstId);
/**
* 查询收入金额已分成 + 待分成
*/
BigDecimal selectSumOfIncomeAmount(BonusQuery query);
/**
* 查询总金额
*/

View File

@ -9,8 +9,11 @@ import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.ruoyi.ss.bonus.utils.BonusUtil;
import com.ruoyi.ss.channel.domain.Channel;
import com.ruoyi.ss.channel.domain.ChannelVO;
import com.ruoyi.system.domain.enums.config.ConfigKey;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -52,16 +55,7 @@ public class BonusConverterImpl implements BonusConverter {
private ISysDeptService deptService;
@Autowired
private StoreStaffService storeStaffService;
@Autowired
private BonusService bonusService;
@Autowired
private UserService userService;
@Autowired
private UserAssembler userAssembler;
private ISysConfigService sysConfigService;
@Autowired
private StoreService storeService;
@ -164,11 +158,9 @@ public class BonusConverterImpl implements BonusConverter {
bonus.setBillNo(order.getOrderNo());
bonus.setToBalance(isPlatform);
bonus.setChannelId(channelId);
bonus.setStatus(BonusStatus.UN_DIVIDEND.getStatus());
}
// 分钱
bonusService.partBonus(result, order.getAmount());
return result;
}
@ -207,7 +199,7 @@ public class BonusConverterImpl implements BonusConverter {
public List<Bonus> toPoList(DeviceVO device, TransactionBillVO bill, ChannelVO channel) {
// 只有通过平台渠道支付的才需要分成给余额
if (ChannelType.PLATFORM.getType().equals(channel.getType())) {
// 获取设备分成数据
// 拼接设备分成数据
deviceAssembler.assembleBonusList(device);
// 构造分成列表
return this.buildBonusListByPlatform(device.getBonusList(), bill, channel);
@ -227,9 +219,12 @@ public class BonusConverterImpl implements BonusConverter {
bonus.setBillNo(bill.getBillNo());
bonus.setToBalance(true);
bonus.setChannelId(channel.getChannelId());
bonus.setStatus(BonusStatus.UN_DIVIDEND.getStatus());
}
// 计算分成金额
bonusService.partBonus(bonusList, bill.getMoney());
// 平台最低需要的分成金额
BigDecimal minService = sysConfigService.getBigDecimal(ConfigKey.RECHARGE_MIN_SERVICE);
BonusUtil.partBonusAmount(bonusList, bill.getMoney(), minService);
return bonusList;
}

View File

@ -1,7 +1,6 @@
package com.ruoyi.ss.bonus.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
@ -206,46 +205,24 @@ public class BonusServiceImpl implements BonusService
}
@Override
public void partBonus(List<Bonus> bonusList, BigDecimal money) {
public int partBonus(List<? extends Bonus> bonusList, BigDecimal money) {
if (CollectionUtils.isEmptyElement(bonusList) || money == null) {
return;
return 0;
}
BigDecimal decimal100 = new BigDecimal(100);
// 获取平台的分成
Bonus platform = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.PLATFORM.getType())).findFirst().orElse(null);
// 平台存在分成的情况需要处理最低分成
if (platform != null) {
BigDecimal minService = sysConfigService.getBigDecimal(ConfigKey.RECHARGE_MIN_SERVICE); // 平台最低需要的分成金额
BigDecimal platformAmount = money.multiply(platform.getPoint()).divide(decimal100, 2, RoundingMode.HALF_UP); // 平台预计分成金额
// 若总金额 < 最低分成则平台全收
if (money.compareTo(minService) < 0) {
BonusUtil.partBonusAllPlatform(platform, money);
}
// 若平台分成 < 最低金额则收取最低金额其他金额给其他分成方分成
else if (platformAmount.compareTo(minService) < 0) {
BonusUtil.partBonusMinService(bonusList, money, platform, minService);
}
// 其余正常收取
else {
BonusUtil.partBonusNormal(bonusList, money);
}
}
// 其余情况正常收取费用
else {
BonusUtil.partBonusNormal(bonusList, money);
}
// 误差处理将误差值交给可以处理的分成方处理
BigDecimal dividedAmount = CollectionUtils.sumDecimal(bonusList, Bonus::getAmount);
BonusUtil.handlePartDiff(bonusList, money.subtract(dividedAmount));
// 处理误差后的分配金额
dividedAmount = CollectionUtils.sumDecimal(bonusList, Bonus::getAmount);
ServiceUtil.assertion(dividedAmount.compareTo(money) != 0, "分成金额分配出错");
// 设置预计分成时间等数据
this.setWaitBonusInfo(bonusList);
// 更新数据库
return this.batchUpdateAmount(bonusList);
}
/**
* 设置待分成数据
*/
private void setWaitBonusInfo(List<? extends Bonus> bonusList) {
LocalDateTime now = LocalDateTime.now();
// 获取用户列表
List<SmUserVO> userList = userService.selectByUserIds(bonusList.stream()
.filter(item -> BonusArrivalType.userList().contains(item.getArrivalType()))
@ -254,9 +231,9 @@ public class BonusServiceImpl implements BonusService
);
// 拼接用户实际到账延迟
userAssembler.assembleRealArrivalDelay(userList);
for (Bonus bonus : bonusList) {
bonus.setStatus(BonusStatus.WAIT_DIVIDE.getStatus());
bonus.setWaitAmount(bonus.getAmount());
// 设置预计分成时间
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
SmUserVO user = userList.stream().filter(item -> item.getUserId().equals(bonus.getArrivalId())).findFirst().orElse(null);
@ -270,22 +247,6 @@ public class BonusServiceImpl implements BonusService
}
}
@Override
public List<CommonCountVO<Long>> selectCountByArrival(BonusQuery query) {
return bonusMapper.selectCountByArrival(query);
}
@Override
public List<CommonSumVO<Long>> selectBillAmountByArrival(BonusQuery query) {
return bonusMapper.selectBillAmountByArrival(query);
}
@Override
public List<ProvideBonusVO> selectProvideBonus(BonusProvideQuery query) {
return bonusMapper.selectProvideBonus(query);
}
@Override
public int refundWhenWaitDivide(Long id, BigDecimal amount) {
if (id == null) {
@ -304,33 +265,6 @@ public class BonusServiceImpl implements BonusService
return bonusMapper.refundWhenDividend(id, amount);
}
@Override
public <T extends Bonus> List<T> filterBonusScope(List<T> bonusList) {
LoginUser loginUser = SecurityUtils.getLoginUser();
Long userId = loginUser.getUserId();
Long deptId = loginUser.getDeptId();
return bonusList.stream().filter(bonus -> {
// 前台用户过滤
if (LoginType.FRONT.equals(loginUser.getLoginType())) {
return BonusArrivalType.userList().contains(bonus.getArrivalType()) && (
Arrays.asList(bonus.getAncestors().split(",")).contains(userId.toString())
|| bonus.getArrivalId().equals(userId)
);
}
// 后台用户过滤
else if (LoginType.ADMIN.equals(loginUser.getLoginType())) {
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
return true;
}
if (BonusArrivalType.deptList().contains(bonus.getArrivalType())) {
return Arrays.asList(bonus.getAncestors().split(",")).contains(deptId.toString())
|| bonus.getArrivalId().equals(deptId);
}
}
return false;
}).collect(Collectors.toList());
}
@Override
public List<BonusMonthAmountVO> selectMonthPayedAmount(BonusQuery query) {
return bonusMapper.selectMonthPayedAmount(query);
@ -437,18 +371,13 @@ public class BonusServiceImpl implements BonusService
return this.selectBonusList(query);
}
private int batchUpdateAmount(List<Bonus> list) {
private int batchUpdateAmount(List<? extends Bonus> list) {
if (CollectionUtils.isEmptyElement(list)) {
return 0;
}
return bonusMapper.batchUpdateAmount(list);
}
@Override
public BigDecimal selectSumOfIncomeAmount(BonusQuery query) {
return bonusMapper.selectSumOfIncomeAmount(query);
}
@Override
public BigDecimal selectSumOfAmount(BonusQuery query) {
return bonusMapper.selectSumOfAmount(query);

View File

@ -2,13 +2,17 @@ package com.ruoyi.ss.bonus.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.List;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.bonus.domain.Bonus;
import com.ruoyi.ss.bonus.domain.BonusVO;
import com.ruoyi.ss.bonus.domain.enums.BonusArrivalType;
import com.ruoyi.ss.bonus.domain.enums.BonusStatus;
import com.ruoyi.ss.user.domain.SmUserVO;
/**
* @author wjh
@ -26,7 +30,7 @@ public class BonusUtil {
/**
* 最低服务费分成处理
*/
public static void partBonusMinService(List<Bonus> bonusList, BigDecimal money, Bonus platform, BigDecimal minService) {
public static void partBonusMinService(List<? extends Bonus> bonusList, BigDecimal money, Bonus platform, BigDecimal minService) {
// 平台设置分成为最低金额
setAmount(platform, minService);
BigDecimal decimal100 = new BigDecimal("100");
@ -47,7 +51,7 @@ public class BonusUtil {
/**
* 基础处理分成
*/
public static void partBonusNormal(List<Bonus> bonusList, BigDecimal money) {
public static void partBonusNormal(List<? extends Bonus> bonusList, BigDecimal money) {
BigDecimal decimal100 = new BigDecimal("100");
// 循环遍历构造分成金额
for (Bonus bonus : bonusList) {
@ -65,7 +69,7 @@ public class BonusUtil {
/**
* 处理分成的误差
*/
public static void handlePartDiff(List<Bonus> bonusList, BigDecimal diff) {
public static void handlePartDiff(List<? extends Bonus> bonusList, BigDecimal diff) {
// 若误差金额为正数或者0则交给第一个分成方处理
if (diff.compareTo(BigDecimal.ZERO) >= 0) {
Bonus bonus = bonusList.get(0);
@ -83,7 +87,7 @@ public class BonusUtil {
// 计算当前分成方可以承担的误差金额确保不会导致金额为负
BigDecimal maxDeductible = bonus.getAmount(); // 最大可扣除金额
BigDecimal adjustAmount = maxDeductible.min(remainingDiff.abs());
// 直接调整金额
setAmount(bonus, bonus.getAmount().subtract(adjustAmount));
remainingDiff = remainingDiff.add(adjustAmount);
@ -163,4 +167,38 @@ public class BonusUtil {
throw new ServiceException("退款金额分配出错:无法处理误差金额,剩余误差:" + remainingDiff);
}
}
public static void partBonusAmount(List<? extends Bonus> bonusList, BigDecimal money, BigDecimal minService) {
BigDecimal decimal100 = new BigDecimal(100);
// 获取平台的分成
Bonus platform = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.PLATFORM.getType())).findFirst().orElse(null);
// 平台存在分成的情况需要处理最低分成
if (platform != null) {
BigDecimal platformAmount = money.multiply(platform.getPoint()).divide(decimal100, 2, RoundingMode.HALF_UP); // 平台预计分成金额
// 若总金额 < 最低分成则平台全收
if (money.compareTo(minService) < 0) {
BonusUtil.partBonusAllPlatform(platform, money);
}
// 若平台分成 < 最低金额则收取最低金额其他金额给其他分成方分成
else if (platformAmount.compareTo(minService) < 0) {
BonusUtil.partBonusMinService(bonusList, money, platform, minService);
}
// 其余正常收取
else {
BonusUtil.partBonusNormal(bonusList, money);
}
}
// 其余情况正常收取费用
else {
BonusUtil.partBonusNormal(bonusList, money);
}
// 误差处理将误差值交给可以处理的分成方处理
BigDecimal dividedAmount = CollectionUtils.sumDecimal(bonusList, Bonus::getAmount);
BonusUtil.handlePartDiff(bonusList, money.subtract(dividedAmount));
// 处理误差后的分配金额
dividedAmount = CollectionUtils.sumDecimal(bonusList, Bonus::getAmount);
ServiceUtil.assertion(dividedAmount.compareTo(money) != 0, "分成金额分配出错");
}
}

View File

@ -37,4 +37,7 @@ public class StoreType extends BaseEntity
@NotNull(message = "排序不能为空")
private Integer sort;
@Excel(name = "上级ID")
@ApiModelProperty("上级ID")
private Long parentId;
}

View File

@ -1,8 +1,21 @@
package com.ruoyi.ss.storeType.domain;
import java.util.List;
import com.ruoyi.common.utils.collection.TreeVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class StoreTypeVO extends StoreType {
public class StoreTypeVO extends StoreType implements TreeVO {
@ApiModelProperty("子节点")
private List<StoreTypeVO> children;
@Override
public void setChildren(List<? extends TreeVO> children) {
this.children = (List<StoreTypeVO>) children;
}
}

View File

@ -9,6 +9,9 @@ public class StoreTypeNameVO {
@ApiModelProperty("ID")
private Long id;
@ApiModelProperty("上级ID")
private Long parentId;
@ApiModelProperty("名称")
private String name;
}

View File

@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sst.name,
sst.icon,
sst.sort,
sst.parent_id,
sst.create_time
from ss_store_type sst
</sql>
@ -19,6 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="searchCondition">
<if test="query.id != null "> and sst.id = #{query.id}</if>
<if test="query.name != null and query.name != ''"> and sst.name like concat('%', #{query.name}, '%')</if>
<if test="query.parentId != null "> and sst.parent_id = #{query.parentId}</if>
${query.params.dataScope}
</sql>
@ -41,12 +43,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="icon != null and icon != ''">icon,</if>
<if test="sort != null">sort,</if>
<if test="createTime != null">create_time,</if>
<if test="parentId != null">parent_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
<if test="icon != null and icon != ''">#{icon},</if>
<if test="sort != null">#{sort},</if>
<if test="createTime != null">#{createTime},</if>
<if test="parentId != null">#{parentId},</if>
</trim>
</insert>
@ -63,6 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.icon != null and data.icon != ''">icon = #{data.icon},</if>
<if test="data.sort != null">sort = #{data.sort},</if>
<if test="data.createTime != null">create_time = #{data.createTime},</if>
<if test="data.parentId != null">parent_id = #{data.parentId},</if>
</sql>
<delete id="deleteStoreTypeById" parameterType="Long">
@ -79,7 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectListName" parameterType="StoreTypeQuery" resultType="StoreTypeNameVO">
select
sst.id,
sst.name
sst.name,
sst.parent_id
from ss_store_type sst
<where>
<include refid="searchCondition"/>

View File

@ -2,7 +2,6 @@ package com.ruoyi.ss.storeType.service;
import java.util.List;
import com.ruoyi.ss.store.domain.StoreNameVO;
import com.ruoyi.ss.storeType.domain.StoreType;
import com.ruoyi.ss.storeType.domain.StoreTypeQuery;
import com.ruoyi.ss.storeType.domain.StoreTypeVO;
@ -59,5 +58,5 @@ public interface StoreTypeService
* 查询全部店铺类型名称
* @return
*/
public List<StoreNameVO> selectListAllName();
public List<StoreTypeVO> selectListAllName();
}

View File

@ -11,7 +11,6 @@ import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.store.domain.StoreNameVO;
import com.ruoyi.ss.storeType.domain.StoreType;
import com.ruoyi.ss.storeType.domain.StoreTypeQuery;
import com.ruoyi.ss.storeType.domain.StoreTypeVO;
@ -124,11 +123,11 @@ public class StoreTypeServiceImpl implements StoreTypeService
* @return
*/
@Override
public List<StoreNameVO> selectListAllName() {
List<StoreNameVO> list = redisCache.getCacheObject(CacheConstants.STORE_TYPE_NAME_LIST);
public List<StoreTypeVO> selectListAllName() {
List<StoreTypeVO> list = redisCache.getCacheObject(CacheConstants.STORE_TYPE_NAME_LIST);
if (CollectionUtils.isEmptyElement(list)) {
PageHelper.orderBy("sst.sort asc");
list = storeTypeMapper.selectListName(new StoreTypeQuery());
list = storeTypeMapper.selectStoreTypeList(new StoreTypeQuery());
if (CollectionUtils.isNotEmptyElement(list)) {
redisCache.setCacheObject(CacheConstants.STORE_TYPE_NAME_LIST, list);
}

View File

@ -365,4 +365,8 @@ public class TransactionBill extends BaseEntity
@Excel(name = "提现账户")
@ApiModelProperty("提现账户")
private AccountVO withdrawAccount;
@Excel(name = "是否已经处理过结束流程")
@ApiModelProperty("是否已经处理过结束流程")
private Boolean finished;
}

View File

@ -89,6 +89,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.vip_name,
stb.discount_amount,
stb.discount_refund_amount,
stb.finished,
</sql>
<sql id="selectSmTransactionBillVo">
@ -229,6 +230,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.channelType != null and query.channelType != ''"> and stb.channel_type = #{query.channelType}</if>
<if test="query.vipId != null "> and stb.vip_id = #{query.vipId}</if>
<if test="query.vipName != null and query.vipName != ''"> and vip_name like concat('%', #{query.vipName}, '%')</if>
<if test="query.finished != null"> and stb.finished = #{query.finished}</if>
<if test="query.isNullSuitEndTime != null">
and stb.suit_end_time is
<if test="!query.isNullSuitEndTime">
@ -655,6 +657,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="discountAmount != null">discount_amount,</if>
<if test="discountRefundAmount != null">discount_refund_amount,</if>
<if test="withdrawAccount != null">withdraw_account,</if>
<if test="finished != null">finished,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="billNo != null">#{billNo},</if>
@ -732,6 +735,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="discountAmount != null">#{discountAmount},</if>
<if test="discountRefundAmount != null">#{discountRefundAmount},</if>
<if test="withdrawAccount != null">#{withdrawAccount,typeHandler=com.ruoyi.ss.account.mapper.typehandler.AccountJsonTypehandler},</if>
<if test="finished != null">#{finished},</if>
</trim>
</insert>
@ -825,6 +829,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.discountAmount != null">stb.discount_amount = #{data.discountAmount},</if>
<if test="data.discountRefundAmount != null">stb.discount_refund_amount = #{data.discountRefundAmount},</if>
<if test="data.withdrawAccount != null">stb.withdraw_account = #{data.withdrawAccount,typeHandler=com.ruoyi.ss.account.mapper.typehandler.AccountJsonTypehandler},</if>
<if test="data.finished != null">stb.finished = #{data.finished},</if>
</sql>
<update id="updateByQuery">

View File

@ -391,4 +391,9 @@ public interface TransactionBillService {
*/
BigDecimal calcTimingCountAmount(Long billId);
/**
* 处理已结束订单
*/
boolean handleFinished(TransactionBillVO bill);
}

View File

@ -120,9 +120,6 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
// 创建分成
int bonusInsert = bonusService.batchInsert(bonusList);
ServiceUtil.assertion(bonusInsert != bonusList.size(), "创建分成失败");
// 处理分成将金额分好
Bonus platform = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.PLATFORM.getType())).findFirst().orElse(null);
Bonus mch = bonusList.stream().filter(bonus -> bonus.getArrivalType().equals(BonusArrivalType.MCH.getType())).findFirst().orElse(null);
// 修改订单的数据
TransactionBill data = new TransactionBill();
@ -132,14 +129,6 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
data.setChannelCost(pay.getChannelCost());
data.setChannelType(channel.getType());
data.setPayId(pay.getPayId());
// 平台信息
if (platform != null) {
data.setServiceCharge(platform.getAmount());
}
// 商户信息
if (mch != null) {
data.setArrivalAmount(mch.getAmount());
}
// 订单使用时长电量设置
LocalDateTime now = LocalDateTime.now();
LocalDateTime startTime = bill.getDeviceExpireTime() == null || now.isAfter(bill.getDeviceExpireTime()) ? now : bill.getDeviceExpireTime();
@ -183,10 +172,6 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
// 操作成功
if (result != null && result == 1) {
// 立即执行一次分成
scheduledExecutorService.schedule(() -> {
bonusService.payBonusBeforeTime(LocalDateTime.now());
}, 3, TimeUnit.SECONDS);
// 充值设备
transactionBillService.rechargeDevice(bill.getBillId());

View File

@ -1890,4 +1890,46 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
public List<LocalDateTimeIntegerVO> selectDailyCount(TransactionBillQuery query) {
return transactionBillMapper.selectDailyCount(query);
}
@Override
public boolean handleFinished(TransactionBillVO bill) {
if (bill == null) {
return false;
}
if (bill.getFinished()) {
return true;
}
Boolean result = transactionTemplate.execute(status -> {
// TODO 更新订单流程状态
// TODO 若订单没有结束时间则更新订单的结束时间
TransactionBill data = new TransactionBill();
data.setFinished(true);
if (data.getSuitEndTime() == null) {
data.setSuitEndTime(LocalDateTime.now());
}
TransactionBillQuery query = new TransactionBillQuery();
query.setType(TransactionBillType.RECHARGE.getType());
query.setIsFinished(true);
query.setFinished(false);
query.setStatusList(TransactionBillStatus.payedOrder());
query.setBillId(bill.getBillId());
int rows = this.updateByQuery(data, query);
if (rows == 1 && bill.getBonusList() != null) {
// 过滤未出账的分成
List<BonusVO> waitDivideBonusList = bill.getBonusList().stream()
.filter(item -> BonusStatus.UN_DIVIDEND.getStatus().equals(item.getStatus()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmptyElement(waitDivideBonusList)) {
// 出账
bonusService.partBonus(bill.getBonusList(), bill.getMoney());
}
}
return true;
});
return result != null && result;
}
}

View File

@ -1,16 +1,14 @@
package com.ruoyi.ss.user.domain.dto;
import com.ruoyi.common.utils.RegexpUtils;
import com.ruoyi.common.valid.EnumValid;
import com.ruoyi.ss.realName.domain.enums.RealNameType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import com.ruoyi.common.utils.RegexpUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author wjh
* 2024/8/26
@ -39,6 +37,14 @@ public class UserRealNameDTO {
@Pattern(regexp = RegexpUtils.MOBILE_PHONE_REGEXP, message = "手机号格式错误")
private String realPhone;
@ApiModelProperty("身份证正面")
@NotBlank(message = "身份证正面不允许为空")
private String idCardFront;
@ApiModelProperty("身份证背面")
@NotBlank(message = "身份证背面不允许为空")
private String idCardBack;
@ApiModelProperty("风控信息ID")
private Long riskInfoId;

View File

@ -228,6 +228,11 @@ public class VipOrderServiceImpl implements VipOrderService, AfterPay, AfterRefu
List<Bonus> bonusList = bonusConverter.toPoList(order, pay.getChannelId());
int insertBonus = bonusService.batchInsert(bonusList);
ServiceUtil.assertion(insertBonus != bonusList.size(), "创建分成失败");
// 分配金额
int part = bonusService.partBonus(bonusList, order.getAmount());
ServiceUtil.assertion(part != bonusList.size(), "分配分成失败");
}
return update;

View File

@ -1,9 +1,16 @@
package com.ruoyi.task.bill;
import com.ruoyi.common.utils.DateUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.iot.domain.IotDeviceInfo;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.suit.domain.enums.SuitFeeType;
@ -11,17 +18,12 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
import com.ruoyi.ss.transactionBill.service.TransactionAssembler;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.system.domain.enums.config.ConfigKey;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
/**
* @author wjh
@ -43,6 +45,15 @@ public class BillMonitorTask {
@Autowired
private DeviceService deviceService;
@Autowired
private TransactionAssembler transactionAssembler;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
@Autowired
private BonusService bonusService;
/**
* 关闭低功率的订单
*/
@ -96,22 +107,57 @@ public class BillMonitorTask {
*/
public void updateEleFinishTime(String startTime) {
// 查询指定时间后已结束的电量订单
// TransactionBillQuery query = new TransactionBillQuery();
// query.setType(TransactionBillType.RECHARGE.getType());
// query.setCreateTimeStart(DateUtils.toLocalDateTime(startTime));
// query.setIsFinished(true);
// query.setSuitFeeTypes(SuitFeeType.rechargeEleList());
// query.setIsNullSuitEndTime(true);
// List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(query);
// if (CollectionUtils.isEmptyElement(list)) {
// log.info("暂无结束的电量订单");
// return;
// }
// // 更新结束时间
// List<Long> billIds = list.stream().map(TransactionBillVO::getBillId).filter(Objects::nonNull).collect(Collectors.toList());
// int update = transactionBillService.batchUpdateSuitEndTime(billIds, LocalDateTime.now());
// log.info("更新结束时间: update= {}" , update);
log.info("已弃用 updateEleFinishTime, 与 monitor 合并");
}
/**
* TODO 监控订单
*/
public void monitor() {
// 查询已结束但未进行流程的订单
TransactionBillQuery query = new TransactionBillQuery();
query.setType(TransactionBillType.RECHARGE.getType());
query.setCreateTimeStart(DateUtils.toLocalDateTime(startTime));
query.setIsFinished(true);
query.setSuitFeeTypes(SuitFeeType.rechargeEleList());
query.setIsNullSuitEndTime(true);
query.setFinished(false);
query.setStatusList(TransactionBillStatus.payedOrder());
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(query);
if (CollectionUtils.isEmptyElement(list)) {
log.info("暂无结束的电量订单");
log.info("暂无未处理的已结束订单");
return;
}
// 更新结束时间
List<Long> billIds = list.stream().map(TransactionBillVO::getBillId).filter(Objects::nonNull).collect(Collectors.toList());
int update = transactionBillService.batchUpdateSuitEndTime(billIds, LocalDateTime.now());
log.info("更新结束时间: update= {}" , update);
// 拼接分成列表
transactionAssembler.assembleBonusList(list);
for (TransactionBillVO bill : list) {
try {
transactionBillService.handleFinished(bill);
} catch (Exception e) {
log.warn("处理已结束订单{}出错:{}", bill.getBillNo(), e.getMessage());
}
}
// 执行一次分成
bonusService.payBonusBeforeTime(LocalDateTime.now());
}
}

View File

@ -1,5 +1,11 @@
package com.ruoyi.web.controller.app;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
@ -7,12 +13,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.dto.SysNoticeQuery;
import com.ruoyi.system.domain.enums.NoticeStatus;
import com.ruoyi.system.service.ISysNoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author wjh
@ -28,9 +30,8 @@ public class AppNoticeController extends BaseController {
@ApiOperation("获取最新的公告")
@GetMapping("/new")
@Anonymous
public AjaxResult getNewNotice() {
public AjaxResult getNewNotice(SysNoticeQuery query) {
PageHelper.orderBy("create_time desc");
SysNoticeQuery query = new SysNoticeQuery();
query.setStatus(NoticeStatus.ENABLED.getStatus());
return success(noticeService.selectOne(query));
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.web.controller.app;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -7,6 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ss.storeType.domain.StoreTypeVO;
import com.ruoyi.ss.storeType.service.StoreTypeService;
import io.swagger.annotations.ApiOperation;
@ -21,7 +24,8 @@ public class AppStoreTypeController extends BaseController{
@ApiOperation("获取全部店铺类型")
@GetMapping("/listAll")
public AjaxResult listAll() {
return success(storeTypeService.selectListAllName());
List<StoreTypeVO> list = storeTypeService.selectListAllName();
return success(list);
}
}

View File

@ -1,32 +1,41 @@
package com.ruoyi.web.controller.common;
import static com.ruoyi.common.core.domain.AjaxResult.success;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.binarywang.wx.miniapp.api.WxMaService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.qiniu.QiNiuUtils;
import com.ruoyi.system.service.IVerificationCodeService;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import com.ruoyi.common.utils.idcard.IdCardVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.idcard.IDCardUtil;
import com.ruoyi.common.utils.qiniu.QiNiuUtils;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.system.service.IVerificationCodeService;
import static com.ruoyi.common.core.domain.AjaxResult.success;
import cn.binarywang.wx.miniapp.api.WxMaService;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
/**
* 通用请求处理
@ -191,4 +200,14 @@ public class CommonController
WxJsapiSignature jsapiSignature = wxMaService.getJsapiService().createJsapiSignature(url);
return success(jsapiSignature);
}
@ApiOperation("身份证OCR")
@PostMapping("/idcardOcr")
public AjaxResult idcardOcr(@RequestParam String url) {
IdCardVo vo = IDCardUtil.ocr(url);
if (vo == null ) {
return AjaxResult.error("识别失败");
}
return success(vo.getResult());
}
}

View File

@ -64,6 +64,9 @@ face:
appKey: 204590328
appCode: 32b6c6445b1a42ed862dd4202392c47d
appSecret: td0vlGZRy9GxlrpinlrxSXFXVW34JxDh
# 身份证OCR
idcardOcr:
appCode: 4b5c959b87ee43539cd745ba38458686
# 项目相关配置