This commit is contained in:
韩鹏辉 2023-09-14 14:49:08 +08:00
parent 95952a234a
commit c844e9ef38
19 changed files with 851 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
@ -90,7 +91,7 @@ public class OpLogAspect {
sb.append("请求参数:");
if(ObjectUtil.isNotEmpty(args)||args.length>0){
Arrays.stream(args).forEach(it->{
if(it instanceof String||it instanceof Integer||it instanceof Long){
if(it instanceof String|| it instanceof Float|| it instanceof Double||it instanceof Boolean ||it instanceof Integer||it instanceof Long|| it instanceof BigDecimal){
sb.append(it);
sb.append("&");
}else if(it instanceof Object){

View File

@ -2,7 +2,6 @@ package com.chaozhanggui.admin.system.service;
import com.chaozhanggui.common.system.config.RespBody;
import com.chaozhanggui.dao.system.dao.TbPlussAppMenuMapper;
import com.chaozhanggui.dao.system.entity.TbPlussAppGuide;
import com.chaozhanggui.dao.system.entity.TbPlussAppMenu;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

View File

@ -0,0 +1,35 @@
package com.chaozhanggui.admin.system.util;
import java.math.BigDecimal;
public class RedEnvelope {
private String id;
private double amount;
private int lastDigit;
private String targetUser;
public RedEnvelope(String id, double amount, int lastDigit, String targetUser) {
this.id = id;
this.amount = amount;
this.lastDigit = lastDigit;
this.targetUser = targetUser;
}
public String getId() {
return id;
}
public double getAmount() {
return amount;
}
public int getLastDigit() {
return lastDigit;
}
public String getTargetUser() {
return targetUser;
}
}

View File

@ -0,0 +1,80 @@
package com.chaozhanggui.admin.system.util;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class RedEnvelopeGame {
private List<RedEnvelope> redEnvelopes;
private double totalAmount;
private String id;
public RedEnvelopeGame(double totalAmount) {
this.totalAmount = totalAmount;
redEnvelopes = new ArrayList<>();
id="Red".concat(System.currentTimeMillis()+"");
}
public void createRedEnvelopes(int numberOfEnvelopes, int desiredLastDigit, String targetUser, String excludeUser) {
Random random = new Random();
for (int i = 0; i < numberOfEnvelopes; i++) {
double randomAmount = random.nextDouble() * totalAmount;
int lastDigit = (int) (randomAmount * 100) % 10; // 获取金额的个位数字作为尾数
boolean isBomb = lastDigit == desiredLastDigit && targetUser.equals(targetUser) && !excludeUser.equals("");
RedEnvelope envelope = new RedEnvelope(id,randomAmount, lastDigit, isBomb ? targetUser : excludeUser);
redEnvelopes.add(envelope);
System.out.println("::::");
}
}
public double grabRedEnvelope(String currentUser) {
if (redEnvelopes.isEmpty()) {
return 0.0; // 没有红包可抢
}
int randomIndex = new Random().nextInt(redEnvelopes.size());
RedEnvelope envelope = redEnvelopes.remove(randomIndex);
if (envelope.getLastDigit() == 0) {
System.out.println("玩家 " + currentUser + " 抢到了尾数为0的红包金额为 " + envelope.getAmount());
} else if (envelope.getTargetUser().equals(currentUser)) {
System.out.println("玩家 " + currentUser + " 抢到了尾数雷点红包,金额为 " + envelope.getAmount() + " 元,尾数为 " + envelope.getLastDigit());
// 处理中雷用户的逻辑例如扣除分数或执行其他操作
} else {
System.out.println("玩家 " + currentUser + " 抢到了 " + envelope.getAmount() + " 元红包,尾数为 " + envelope.getLastDigit());
}
return envelope.getAmount();
}
public double getTotalAmount() {
return totalAmount;
}
public static void main(String[] args) {
double totalAmount = 100.0; // 设置总金额
RedEnvelopeGame game = new RedEnvelopeGame(totalAmount);
int numberOfEnvelopes = 10; // 创建10个红包
int desiredLastDigit = 3; // 期望的尾数为3
String targetUserA = "Alice"; // 指定A用户中雷
String excludeUserB = "Bob"; // 指定B用户不中雷
game.createRedEnvelopes(numberOfEnvelopes, desiredLastDigit, targetUserA, excludeUserB);
// 假设有多个玩家每个玩家有一个名字用循环模拟玩家抢红包的过程
String[] players = {"A", "B", "C","D","E","F","G","H","I","K"};
for (String player : players) {
double amount = game.grabRedEnvelope(player);
if (amount > 0) {
System.out.println("玩家 " + player + " 抢到了 " + amount + " 元红包");
} else {
System.out.println("玩家 " + player + " 没有红包");
}
}
}
}

View File

@ -10,9 +10,9 @@ spring:
maxWait: 60000
redis:
# redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突
database: 0
database: 3
# redis服务器地址默认为localhost
host: 127.0.0.1
host: 101.37.12.135
# redis端口默认为6379
port: 6379
# redis访问密码默认为空

View File

@ -11,4 +11,7 @@ public interface TbPlussBankBranchLklMapper {
int insert(TbPlussBankBranchLkl record);
int insertSelective(TbPlussBankBranchLkl record);
TbPlussBankBranchLkl selectByBankNo(String bankNo);
}

View File

@ -11,4 +11,6 @@ public interface TbPlussBankRegionLklMapper {
int insert(TbPlussBankRegionLkl record);
int insertSelective(TbPlussBankRegionLkl record);
TbPlussBankRegionLkl selectByCode(String code);
}

View File

@ -3,6 +3,7 @@ package com.chaozhanggui.dao.system.dao;
import com.chaozhanggui.dao.system.entity.TbPlussMccReflect;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
@Component
@ -19,4 +20,6 @@ public interface TbPlussMccReflectMapper {
int updateByPrimaryKeySelective(TbPlussMccReflect record);
int updateByPrimaryKey(TbPlussMccReflect record);
TbPlussMccReflect selectByMccCodeAndChannel(@Param("mcc") String mcc, @Param("channel") String channel);
}

View File

@ -11,4 +11,7 @@ public interface TbPlussRegionLklMapper {
int insert(TbPlussRegionLkl record);
int insertSelective(TbPlussRegionLkl record);
TbPlussRegionLkl selectByName(String name);
}

View File

@ -83,4 +83,8 @@
</if>
</trim>
</insert>
<select id="selectByBankNo" resultMap="BaseResultMap">
select * from tb_pluss_bank_branch_lkl where branch_bank_no=#{bankNo} limit 1
</select>
</mapper>

View File

@ -67,4 +67,8 @@
</if>
</trim>
</insert>
<select id="selectByCode" resultMap="BaseResultMap">
select * from tb_pluss_bank_region_lkl where code=#{code}
</select>
</mapper>

View File

@ -103,4 +103,8 @@
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByMccCodeAndChannel" resultMap="BaseResultMap">
select * from tb_pluss_mcc_reflect where standard_mcc_code=#{mcc} and channel_id=#{channel}
</select>
</mapper>

View File

@ -67,4 +67,9 @@
</if>
</trim>
</insert>
<select id="selectByName" resultMap="BaseResultMap">
select * from tb_pluss_region_lkl where `name` like '%${name,jdbcType=VARCHAR}%'
limit 1
</select>
</mapper>

View File

@ -28,6 +28,21 @@
<artifactId>dao-api</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,444 @@
package com.chaozhanggui.merchant.service;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.common.system.util.DateUtils;
import com.chaozhanggui.dao.system.dao.*;
import com.chaozhanggui.dao.system.entity.*;
import com.chaozhanggui.merchant.util.HtmlUtil;
import com.chaozhanggui.merchant.vo.AttchmentsVo;
import com.chaozhanggui.merchant.vo.FeesSetVo;
import freemarker.template.TemplateException;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Component
@Slf4j
public class LklAuditService {
public static final String userNo = "22265868";
private static final String client_id = "chaozhanggui";
private static final String client_secret = "Y54Gqy6aLpxld3dp";
private static final String grant_type = "client_credentials";
/**
* 商户进件
*/
private static final String tuoKeMerchat = "https://htkactvi.lakala.com/registration/merchant";
/**
* 获取地区信息
*/
private static final String organparentCode = "https://htkactvi.lakala.com/registration/organization/";
/**
* 获取银行地区信息
*/
private static final String organizationBank = "https://htkactvi.lakala.com/registration/organization/bank/";
/**
* 文件上传
*/
private static final String fileUpload = "https://htkactvi.lakala.com/registration/file/upload";
private static final String tuoKeToken = "https://tkapi.lakala.com/auth/oauth/token";
@Autowired
TbPlussRegionLklMapper tbPlussRegionLklMapper;
@Autowired
TbPlussAccountMapper tbPlussAccountMapper;
@Autowired
TbPlussMerchantImageMapper tbPlussMerchantImageMapper;
@Autowired
TbPlussBankCardMapper tbPlussBankCardMapper;
@Autowired
TbPlussIdCardMapper tbPlussIdCardMapper;
@Autowired
TbPlussMccReflectMapper tbPlussMccReflectMapper;
@Autowired
TbPlussBankBranchLklMapper tbPlussBankBranchLklMapper;
@Autowired
TbPlussBankRegionLklMapper tbPlussBankRegionLklMapper;
public Map merchantAudit(TbPlussMerchantBaseInfo baseInfo, TbPlussMerchantChannelStatus channelStatus) {
JSONObject object1 = new JSONObject();
JSONObject object2 = new JSONObject();
object1.put("userNo", userNo); //合作机构信息 由拓客SAAS提供
object1.put("email", "chaozhanggui2023@163.com"); //商户邮箱
object1.put("busiCode", "WECHAT_PAY");//业务类型 BPOS:传统POS, ZPOS:电签,ZPOS4G4G电签,SUPER_POS:智能pos,B_WIZARD:蓝精灵,PAPER_CODE:码牌,WECHAT_PAY:专业化扫码,KLYX:云音箱,QRCODE:收款王,MONEY_BOX:收钱宝盒根据业务开放取值
object1.put("merRegName", baseInfo.getAlias()); //商户注册名称 不能少于七个中文
object1.put("merType", (baseInfo.getMerchanttype().equals(1) || baseInfo.getMerchanttype().equals("2")) ? "TP_PERSONAL" : "TP_MERCHANT"); //商户注册类型 TP_MERCHANT:企业 TP_PERSONAL:微个
object1.put("merName", baseInfo.getAlias()); //商户名称(经营名称) 不能少于七个中文
object1.put("merAddr", baseInfo.getAddress()); //去掉省市区后的详细地址
object1.put("provinceCode", tbPlussRegionLklMapper.selectByName(baseInfo.getProvince())); //省代码 通过地区信息获取地区查询接口获取 对应 code字段
object1.put("cityCode", tbPlussRegionLklMapper.selectByName(baseInfo.getCity())); // 市代码 通过地区信息获取地区查询接口获取 对应 code字段
object1.put("countyCode",tbPlussRegionLklMapper.selectByName(baseInfo.getDistrict())); // 区县代码 通过地区信息获取地区查询接口获取 对应 code字段
TbPlussAccount account= tbPlussAccountMapper.selectByUser(baseInfo.getUserid(),"D1");
MsgException.checkNull(account,"结算信息未提交");
TbPlussBankCard bankCard= tbPlussBankCardMapper.selectByPrimaryKey(Integer.valueOf(account.getBankcardid()));
MsgException.checkNull(bankCard, "结算卡信息未提交");
TbPlussIdCard idCard=tbPlussIdCardMapper.getLegalIdCard(baseInfo.getUserid().toString());
MsgException.checkNull(idCard, "商户基本信息不完整");
TbPlussMccReflect mccReflect=tbPlussMccReflectMapper.selectByMccCodeAndChannel(baseInfo.getMcc(),"5");
Set<Object> attchmentsVoSet = new HashSet<>();
if (baseInfo.getMerchanttype().equals("3")) {
object1.put("merRegName", baseInfo.getMerchantname());
object1.put("merName", baseInfo.getMerchantname());
object1.put("licenseName", baseInfo.getBussauthname()); //营业执照名称
object1.put("licenseNo", baseInfo.getBussauthnum()); //营业执照号码 微商户可不传 其他必传
StringBuffer startSb = new StringBuffer();
StringBuffer endSb = new StringBuffer();
if (baseInfo.getBussauthstarttime().contains("")) {
startSb.append(baseInfo.getBussauthstarttime(), 0, 4);
startSb.append("-");
startSb.append(baseInfo.getBussauthstarttime(), 5, 7);
startSb.append("-");
startSb.append(baseInfo.getBussauthstarttime(), 8, 10);
} else {
startSb.append(baseInfo.getBussauthstarttime());
}
if (ObjectUtil.isEmpty(baseInfo.getBussauthendtime()) || "长期".equals(baseInfo.getBuslictype())) {
endSb.append("2099-12-31");
} else {
if (baseInfo.getBussauthendtime().contains("")) {
endSb.append(baseInfo.getBussauthendtime(), 0, 4);
endSb.append("-");
endSb.append(baseInfo.getBussauthendtime(), 5, 7);
endSb.append("-");
endSb.append(baseInfo.getBussauthendtime(), 8, 10);
} else {
endSb.append(baseInfo.getBussauthendtime());
}
}
object1.put("licenseDtStart", startSb); //营业执照开始时间微商户可不传 其他必传格式yyyy-MM-dd
object1.put("licenseDtEnd", endSb); //微商户可不传 其他必传格式yyyy-MM-dd
TbPlussMerchantImage image= tbPlussMerchantImageMapper.selectByMerchantCodeType(baseInfo.getMerchantcode(),"03");
MsgException.checkNull(image, "营业执照不存在");
AttchmentsVo business_licence = new AttchmentsVo(); //图片set
business_licence.setId(laKaLaFileUpload(image.getPicUrl1(), "BUSINESS_LICENCE"));//营业执照
business_licence.setType("BUSINESS_LICENCE");//营业执照
attchmentsVoSet.add(business_licence);
//开户许可证
AttchmentsVo opening_permit = new AttchmentsVo(); //图片set
opening_permit.setId(laKaLaFileUpload(bankCard.getLicenseurl(), "OPENING_PERMIT"));//开户许可证
opening_permit.setType("OPENING_PERMIT");//开户许可证
attchmentsVoSet.add(opening_permit);
Map<String, Object> data = new HashMap<>();
data.put("customerName", baseInfo.getMerchantname());
data.put("licenseNo", baseInfo.getBussauthnum());
data.put("legalName", idCard.getCertname());
data.put("licenseName", baseInfo.getMerchantname());
data.put("identityNo", idCard.getCertno());
data.put("address", baseInfo.getProvince().concat(baseInfo.getCity()).concat(baseInfo.getDistrict()));
data.put("receiveDetail", baseInfo.getProvince().concat(baseInfo.getCity()).concat(baseInfo.getDistrict()).concat(baseInfo.getAddress()));
data.put("identityNoExpire", endSb);
data.put("accountName", bankCard.getBankholder());
data.put("accountIdCard", idCard.getCertno());
data.put("accountNo", bankCard.getBankcardno());
data.put("accountIdDtEnd", idCard.getCreatetime().equals("长期") ? "2099-12-31" : DateUtils.convertString(idCard.getCertendtime()));
data.put("bankName", bankCard.getBankname());
data.put("mail", "chaozhanggui2023@163.com");
data.put("contactManName", bankCard.getPhone());
data.put("channelType", ObjectUtils.isEmpty(mccReflect) ? "7399" : mccReflect.getMccCode());
data.put("phone", bankCard.getPhone());
data.put("agencyName", baseInfo.getMerchantname());
// //协议
AttchmentsVo agree_ment = new AttchmentsVo(); //图片set
try {
agree_ment.setId(laKaLaFileUpload(HtmlUtil.createAgreementPicture(HtmlUtil.writeHtml(data)), "AGREE_MENT"));//协议
agree_ment.setType("AGREE_MENT");//协议
attchmentsVoSet.add(agree_ment);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (TemplateException e) {
throw new RuntimeException(e);
}
}
object1.put("latitude", "108.94647"); //经度 进件所在地址经度error
object1.put("longtude", "34.34727"); //纬度 进件所在地址纬度 error
object1.put("source", "APP"); //进件来源 APP: app H5: h5
object1.put("businessContent", baseInfo.getMccname()); //商户经营内容
object1.put("larName", idCard.getCertname()); //姓名
object1.put("larIdType", "01"); //证件类型 01 身份证 暂时只支持身份证
object1.put("larIdCard", idCard.getCertno()); //证件号码
object1.put("larIdCardStart", birthdayDate(idCard.getCertstarttime())); //证件开始 格式yyyy-MM-dd
object1.put("larIdCardEnd", birthdayDate(idCard.getCertendtime())); //证件过期时间 格式yyyy-MM-dd
object1.put("contactMobile", baseInfo.getContactmobile()); //商户联系⼿机号码
object1.put("contactName", baseInfo.getContactname()); //商户联系姓名
TbPlussBankBranchLkl lakalaBranchInfo = tbPlussBankBranchLklMapper.selectByBankNo(bankCard.getContactline());
MsgException.checkNull(lakalaBranchInfo, "结算卡对应的分行支行信息不存在");
object1.put("openningBankCode", lakalaBranchInfo.getBranchBankNo()); //结算账户开户 通过银行列表查询接口获取 对应 branchBankNo字段
object1.put("openningBankName", lakalaBranchInfo.getBranchBankName()); //结算账户开户名称 通过银行列表查询接口获取 对应 branchBankName字段
object1.put("clearingBankCode", lakalaBranchInfo.getClearNo()); //结算账户清算 通过银行列表查询接口获取 对应 clearNo字段
TbPlussBankRegionLkl bankParentCode = tbPlussBankRegionLklMapper.selectByCode(lakalaBranchInfo.getAreaCode()); //市code name
MsgException.checkNull(bankParentCode, "结算卡对应的省份信息不存在");
TbPlussBankRegionLkl parentCode = tbPlussBankRegionLklMapper.selectByCode(bankParentCode.getParentCode()); //省code 名称
MsgException.checkNull(bankParentCode, "结算卡对应的城市信息不存在");
object1.put("settleProvinceCode", parentCode.getCode()); //结算信息省份名称 通过地区信息获取银行地区查询接口获取 对应 code字段
object1.put("settleProvinceName", parentCode.getName()); //结算信息省份代码 通过地区信息获取银行地区查询接口获取 对应 name字段
object1.put("settleCityCode", bankParentCode.getCode()); //结算信息城市名称 通过地区信息获取银行地区查询接口获取 对应 code字段
object1.put("settleCityName", bankParentCode.getName()); //结算信息城市代码 通过地区信息获取银行地区查询接口获取 对应 name字段
if ("02".equals(account.getSettletype())) {
AttchmentsVo opening_permit = new AttchmentsVo(); //图片set
opening_permit.setId(laKaLaFileUpload(account.getCertificateurl(), "LETTER_OF_AUTHORIZATION"));//对私非法人授权函
opening_permit.setType("LETTER_OF_AUTHORIZATION");//对私非法人授权函
attchmentsVoSet.add(opening_permit);
}
object1.put("accountNo", bankCard.getBankcardno()); //结算人银行卡号
object1.put("accountName", bankCard.getBankholder()); //结算人账户名称
object1.put("accountType", bankCard.getAccounttype().equals("01") ? "58" : "57"); //结算账户类型 57 对公 58 对私
// object1.put("accountIdType",tuoKeVo.getUserNo()); //结算证件类型 为空同法
object1.put("accountIdCard", idCard.getCertno()); //结算证件号码
if (bankCard.getAccounttype().equals("2")) {
//对公收银台照片
AttchmentsVo checkstand_img = new AttchmentsVo();
checkstand_img.setId(laKaLaFileUpload(idCard.getImgnegative(), "CHECKSTAND_IMG")); //收银台照片
checkstand_img.setType("CHECKSTAND_IMG");//收银台照片
attchmentsVoSet.add(checkstand_img);
TbPlussMerchantImage image =tbPlussMerchantImageMapper.selectByMerchantCodeType(baseInfo.getMerchantcode(),"06");
MsgException.checkNull(image, "门头照片不存在");
//门头照片
AttchmentsVo shop_outside_img = new AttchmentsVo();
shop_outside_img.setId(laKaLaFileUpload(image.getPicurl(), "SHOP_OUTSIDE_IMG"));//门头照片
shop_outside_img.setType("SHOP_OUTSIDE_IMG");
attchmentsVoSet.add(shop_outside_img);
image =tbPlussMerchantImageMapper.selectByMerchantCodeType(baseInfo.getMerchantcode(),"09");
MsgException.checkNull(image, "商铺内部照片不存在");
//商铺内部照片
AttchmentsVo shop_inside_img = new AttchmentsVo();
shop_inside_img.setId(laKaLaFileUpload(image.getPicurl(), "SHOP_INSIDE_IMG"));//商铺内部照片
shop_inside_img.setType("SHOP_INSIDE_IMG");
attchmentsVoSet.add(shop_inside_img);
}
JSONArray array = new JSONArray();
Set<FeesSetVo> feesSet = new HashSet<>();
FeesSetVo w = new FeesSetVo();
w.setFeeCode("WECHAT");
w.setFeeValue(0.38d);
array.add(w);
FeesSetVo a = new FeesSetVo();
a.setFeeCode("ALIPAY");
a.setFeeValue(0.38d);
array.add(a);
FeesSetVo u = new FeesSetVo();
u.setFeeCode("SCAN_PAY_SECOND");
u.setFeeValue(0.38d);
array.add(u);
feesSet.add(w);
feesSet.add(a);
feesSet.add(u);
object2.put("termNum", "1"); //终端数量 1-5 5个终端
object2.put("fees", feesSet); //费率集合
// object2.put("mcc","12007");
object2.put("mcc", ObjectUtils.isEmpty(mccReflect) ? "7399" : mccReflect.getMccCode()); //商户MCC编号 通过 商户类别查询查询小类接口获取 对应 code字段
object2.put("activityId", "13"); //归属活动信息 由拓客SAAS分配 云音响 14 专业化扫码 13 B2B收银台 25 码牌 12 智能pos 10 智能posPro 21
object1.put("bizContent", object2); //业务扩展信息 业务扩展信息
AttchmentsVo frontLegalPerson = new AttchmentsVo(); //图片set
frontLegalPerson.setId(laKaLaFileUpload(idCard.getImgpositive(), "ID_CARD_FRONT"));//法人身份证图片地址
frontLegalPerson.setType("ID_CARD_FRONT");//身份证正
attchmentsVoSet.add(frontLegalPerson);
AttchmentsVo reverseLegalPerson = new AttchmentsVo();
reverseLegalPerson.setId(laKaLaFileUpload(idCard.getImgnegative(), "ID_CARD_BEHIND")); //法人身份证图片地址
reverseLegalPerson.setType("ID_CARD_BEHIND");//身份证反
attchmentsVoSet.add(reverseLegalPerson);
object1.put("attchments", attchmentsVoSet); //附件信息集合 附件信息
object1.put("settleType", "D1"); //结算类型 D0秒到 D1次日结算
System.out.println("请求报文: " + object1);
/**获取拓客accessToken**/
Map map = getToken();
String result = "";
result = cn.hutool.http.HttpRequest.post(tuoKeMerchat)
.header("Authorization", "bearer " + map.get("access_token")).header("content-type", "application/json")
.body(object1.toString()).execute().body();
System.out.println("返回结果:" + result);
Map arry = (Map) JSONArray.parse(result);
return arry;
}
public String birthdayDate(String date) {
String str = date;
String s1 = "";
s1 = str.substring(0, 4) + "-" + str.substring(4, 6) + "-" + str.substring(6);
return s1;
}
public static Map getToken() {
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
// 表单提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.set("Authorization", "Basic " + getBase64());
// 封装参数
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", grant_type);
params.add("client_id", client_id);
params.add("client_secret", client_secret);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, headers);
// 执行HTTP请求
ResponseEntity<String> response = client.exchange(tuoKeToken, HttpMethod.POST, requestEntity, String.class);
Map map = (Map) JSONArray.parse(response.getBody());
return map;
}
@SneakyThrows
public static String laKaLaFileUpload(File file, String type) {
RestTemplate restTemplate = new RestTemplate();
String url = fileUpload;
Map<String, Object> params = new HashMap<>();
params.put("file", file);
params.put("imgType", type);
params.put("sourcechnl", "0");
params.put("isOcr", "false");
Map token = getToken();
String result = HttpRequest.post(url)
.header("Authorization", "bearer " + token.get("access_token"))
.form(params).execute().body();
Map parse = (Map) JSONArray.parse(result);
log.info("拉卡拉图片上传返回信息:{}", result);
return parse.get("url").toString();
}
@SneakyThrows
public static String laKaLaFileUpload(String url1, String type) {
String url = fileUpload;
Map<String, Object> params = new HashMap<>();
// String url1 = "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/images/9b42a8f68e2b4682bdb72490abe131fe.png?Expires=1994642722&OSSAccessKeyId=LTAI5tPdEfYSZcqHbjCrtPRD&Signature=cTcS0ey%2F6NYWQnyvVCMQsO6rZMU%3D";
URI uri = null;
try {
uri = new URI(url1);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
RestTemplate restTemplate1 = new RestTemplate();
ResponseEntity<byte[]> exchange = restTemplate1.exchange(uri, HttpMethod.GET, null, byte[].class);
MultipartFile file1 = new MockMultipartFile("file", exchange.getBody());
File file = convert(file1);
params.put("file", file);
params.put("imgType", type);
params.put("sourcechnl", "0");
params.put("isOcr", "false");
Map token = getToken();
String result = HttpRequest.post(url)
.header("Authorization", "bearer " + token.get("access_token"))
.form(params).execute().body();
Map parse = (Map) JSONArray.parse(result);
log.info("拉卡拉图片上传返回信息:{}", result);
return parse.get("url").toString();
}
public static File convert(MultipartFile multipartFile) throws IOException {
InputStream inputStream = multipartFile.getInputStream();
File file = File.createTempFile(ObjectUtil.isEmpty(multipartFile.getOriginalFilename()) ? String.valueOf(System.currentTimeMillis()) : multipartFile.getOriginalFilename(), ".png");
FileOutputStream outputStream = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
file.deleteOnExit();
return file;
}
public static String getBase64() {
String encodeBase64String = org.apache.commons.codec.binary.Base64.encodeBase64String((client_id + ":" + client_secret).getBytes());
return encodeBase64String;
}
}

View File

@ -1,26 +1,120 @@
package com.chaozhanggui.merchant.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantBaseInfoMapper;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantChannelMapper;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantChannelStatusMapper;
import com.chaozhanggui.dao.system.dao.TbPlussUserInfoMapper;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantBaseInfo;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantChannel;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantChannelStatus;
import com.chaozhanggui.dao.system.entity.TbPlussUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class MerchantService {
@Autowired
private TbPlussMerchantChannelMapper tbPlussMerchantChannelMapper;
public void merchantAudit(JSONObject jsonObject, String channelId){
@Autowired
private TbPlussUserInfoMapper tbPlussUserInfoMapper;
@Autowired
private TbPlussMerchantBaseInfoMapper tbPlussMerchantBaseInfoMapper;
@Autowired
private TbPlussMerchantChannelStatusMapper tbPlussMerchantChannelStatusMapper;
@Autowired
private LklAuditService lklAuditService;
public void merchantAudit(String userId, String channelId){
MsgException.checkBlank(channelId, "请选择进件通道");
MsgException.checkNull(userId,"请选择用户");
//获取用户信息
TbPlussUserInfo userInfo= tbPlussUserInfoMapper.selectByPrimaryKey(Long.valueOf(userId));
MsgException.checkNull(userInfo,"用户信息不存在");
//判断进件信息是否存在
TbPlussMerchantBaseInfo baseInfo= tbPlussMerchantBaseInfoMapper.selectByUserId(userId);
MsgException.checkNull(baseInfo,"请完善进件信息");
//判断是否存在审核的进件信息
TbPlussMerchantChannelStatus channelStatus= tbPlussMerchantChannelStatusMapper.getByMerchantCode(baseInfo.getMerchantcode(),channelId);
if(ObjectUtil.isEmpty(channelStatus)){
channelStatus=tbPlussMerchantChannelStatusMapper.getByMerchantCode(baseInfo.getMerchantcode(),null);
}
MsgException.checkNull(channelStatus,"商户未提交审核");
//判断是否存在正在审核中的数据
if ("1".equals(channelStatus.getStatus()) && !"-100".equals(channelStatus.getThirdstatus())) {
MsgException.throwException("进件审核中,请等待审核结果");
}
if ("2".equals(channelStatus.getStatus())||!"1".equals(channelStatus.getStatus()) || !"-100".equals(channelStatus.getThirdstatus())) {
MsgException.throwException("不符合商户审核条件");
}
//判断进件是否成功
if (ObjectUtil.isNotEmpty(channelStatus.getChannel())&&channelId.equals(channelStatus.getChannel().toString())&&isAudited(channelStatus)) {
MsgException.throwException("当前通道下已进件,请选择别的进件通道");
}
//获取进件通道
TbPlussMerchantChannel channel= tbPlussMerchantChannelMapper.selectByPrimaryKey(Integer.valueOf(channelId));
MsgException.checkNull(channel, "不存在的进件通道,或所选通道暂不支持进件");
switch (channelId){
case "1":
break;
case "2":
break;
case "3":
break;
case "4":
break;
case "5":
Map map= lklAuditService.merchantAudit(baseInfo,channelStatus);
if (ObjectUtil.isNotEmpty(map)&&String.valueOf(map.get("status")).equals("WAIT_AUDI")) {
}
break;
case "6":
break;
default:
MsgException.throwException("未知的进件通道");
}
}
public static boolean isAudited(TbPlussMerchantChannelStatus mcs) {
if (mcs == null) {
return false;
}
return "3".equals(mcs.getStatus()) ||
"6 ".equals(mcs.getStatus()) ||
"4".equals(mcs.getStatus());
}
}

View File

@ -0,0 +1,131 @@
package com.chaozhanggui.merchant.util;
import cn.hutool.core.io.FileUtil;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Component
@Slf4j
public class HtmlUtil {
@Autowired
FreeMarkerConfigurer freeMarkerConfigurer;
static Template template =null;
public void initHtml(){
try {
template = freeMarkerConfigurer.getConfiguration().getTemplate("indexHTKWECHAT_PAY.html");
System.out.println(template.getName());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//html 替换占位符
public static File writeHtml(Map<String, Object> data) throws IOException, TemplateException {
String fileName = UUID.randomUUID().toString();
File htmlFile = new File(FileUtil.getTmpDir(), fileName + ".html");
FileWriter sw = new FileWriter(htmlFile);
log.info("生成协议html, 地址:{}, 参数:{} ", htmlFile.getAbsolutePath(), data);
template.process(data, sw);
return htmlFile;
}
//html 转png 示例代码
public static File createAgreementPicture(File htmlFile) throws IOException {
File outputFile = new File(FileUtil.getTmpDir(), htmlFile.getName() + ".jpg");
log.info("生成图片开始, HTML地址 {}, 图片地址:{}", htmlFile.getAbsolutePath(), outputFile.getAbsolutePath());
String commandProcess = "wkhtmltoimage --width 400 --quality 94 " + htmlFile.getPath() + " " + outputFile.getPath();
log.info("协议执行procommand:{}", commandProcess);
long startTime = System.currentTimeMillis(); //获取开始时间
Process process = Runtime.getRuntime().exec(commandProcess);
try {
int exitVal = process.waitFor();
log.info("协议html转换png结果:{}", exitVal);
} catch (InterruptedException e) {
e.printStackTrace();
log.info("协议html转换png错误:{}", e.getMessage());
throw new IOException(e);
}
long endTime = System.currentTimeMillis(); //获取结束时间
log.info("程序运行时间: " + (endTime - startTime) + "ms");
log.info("生成图片结束,地址: {}", outputFile.getPath());
Thumbnails.of(outputFile).scale(1).outputQuality(0.9).toFile(outputFile);
return outputFile;
}
// 合并两张图片示例代码
public BufferedImage mergeImage(BufferedImage img1, BufferedImage img2, boolean isHorizontal) throws IOException {
int w1 = img1.getWidth();
int h1 = img1.getHeight();
int w2 = img2.getWidth();
int h2 = img2.getHeight();
// 从图片中读取RGB
int[] ImageArrayOne = new int[w1 * h1];
ImageArrayOne = img1.getRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 逐行扫描图像中各个像素的RGB到数组中
int[] ImageArrayTwo = new int[w2 * h2];
ImageArrayTwo = img2.getRGB(0, 0, w2, h2, ImageArrayTwo, 0, w2);
// 生成新图片
BufferedImage DestImage = null;
if (isHorizontal) { // 水平方向合并
// DestImage = new BufferedImage(w1+w2, h1, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = null;
if (h1 >= h2) {
DestImage = new BufferedImage(w1 + w2, h1, BufferedImage.TYPE_INT_RGB);
g2d = DestImage.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, w1 + w2, h1);
g2d.dispose();
} else {
DestImage = new BufferedImage(w2, h1, BufferedImage.TYPE_INT_RGB);// TYPE_INT_RGB
g2d = DestImage.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, w2 + w1, h1);
g2d.dispose();
}
DestImage.setRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 设置上半部分或左半部分的RGB
DestImage.setRGB(w1, 0, w2, h2, ImageArrayTwo, 0, w2);
} else { // 垂直方向合并
Graphics2D g2d = null;
if (w1 >= w2) {
DestImage = new BufferedImage(w1, h1 + h2, BufferedImage.TYPE_INT_RGB);// TYPE_INT_RGB
g2d = DestImage.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, w1 + w2, h1 + h2);
g2d.dispose();
} else {
DestImage = new BufferedImage(w2, h1 + h2, BufferedImage.TYPE_INT_RGB);// TYPE_INT_RGB
g2d = DestImage.createGraphics();
g2d.setPaint(Color.WHITE);
g2d.fillRect(0, 0, w2 + w1, h1 + h2);
g2d.dispose();
}
DestImage.setRGB(0, 0, w1, h1, ImageArrayOne, 0, w1); // 设置上半部分或左半部分的RGB
DestImage.setRGB(0, h1, w2, h2, ImageArrayTwo, 0, w2); // 设置下半部分的RGB
}
return DestImage;
}
}

View File

@ -0,0 +1,9 @@
package com.chaozhanggui.merchant.vo;
import lombok.Data;
@Data
public class AttchmentsVo {
private String id;
private String type;
}

View File

@ -0,0 +1,10 @@
package com.chaozhanggui.merchant.vo;
import lombok.Data;
@Data
public class FeesSetVo {
private String feeCode;
private Double feeValue;
private Double topFee;
}