后台进件迁移,消息列表,大小机构详情更改

This commit is contained in:
liuyingfang 2023-09-27 10:28:09 +08:00
parent 14e9548e89
commit e27fa5a8e1
21 changed files with 918 additions and 91 deletions

View File

@ -23,6 +23,10 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author admin
@ -61,4 +65,13 @@ public class Shell {
RestTemplate restTemplate(){
return new RestTemplate();
}
@Bean
public ThreadPoolExecutor threadPoolExecutor() {
return new ThreadPoolExecutor(10,
20,
60L,
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(10));
}
}

View File

@ -7,6 +7,8 @@ import com.chaozhanggui.admin.system.service.AgencyService;
import com.chaozhanggui.admin.system.util.MD5Util;
import com.chaozhanggui.admin.system.util.SignUtils;
import com.chaozhanggui.common.system.config.RespBody;
import com.chaozhanggui.dao.system.entity.TbPlussUserApp;
import com.chaozhanggui.dao.system.entity.TbPlussUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
@ -55,11 +57,11 @@ public class AgencyController {
}
return new RespBody("999997");
}
// @OpLog(opName = "更改机构", opDetail = "更改机构", opCode = "AGENCY_UPDATE")
// @GetMapping("updateAgency")
// public RespBody updateAgencyInfo(){
// agencyService.updateAgency()
// }
@OpLog(opName = "更改机构", opDetail = "更改机构", opCode = "AGENCY_UPDATE")
@PostMapping("updateAgency")
public RespBody updateAgencyInfo(@RequestBody TbPlussUserInfo userInfo){
return agencyService.updateAgency(userInfo);
}
@GetMapping("AgencyInfo")

View File

@ -0,0 +1,33 @@
package com.chaozhanggui.admin.system.controller;
import cn.hutool.db.Page;
import com.chaozhanggui.admin.system.service.NotificationService;
import com.chaozhanggui.common.system.config.RespBody;
import com.chaozhanggui.dao.system.dao.TbPlussNoticeMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 消息通知
*/
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/notification")
@Slf4j
public class NotificationController {
@Resource
private NotificationService notificationService;
@GetMapping("/page")
@ResponseBody
public RespBody notificationQuery(@RequestParam("currPage") Integer currPage, @RequestParam("size")Integer size){
return notificationService.notificationQuery(currPage,size);
}
}

View File

@ -14,6 +14,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
@ -76,10 +77,30 @@ public class PromotionImageController {
return new RespBody("999994");
}
/**
* 邝工需求
* @return
*/
@PostMapping("/testRequest")
public RespBody testRequest(){
int randomNumber = new Random().nextInt(6);
List<Object> objects = new ArrayList<>();
return new RespBody(String.valueOf(randomNumber),objects);
}
/**
* 邝工需求
* @return
*/
@PostMapping("/testRequestBoolean")
public RespBody testRequestBoolean(){
Random random = new Random();
int value = random.nextInt(2);
if (value == 0) {
return new RespBody("000000","success");
} else {
return new RespBody("000000","fail");
}
}
}

View File

@ -22,6 +22,6 @@ public class AdminWebConfig implements WebMvcConfigurer {
registry.addInterceptor(new LoginInterceptor(redisUtil))
.addPathPatterns()
// 如果有静态资源的时候可以在这个地方放行
.excludePathPatterns("/","/user/doLogin","/agency/mytest","/agency/queryAgency","/promotion/testRequest","/agency/sendmessage");
.excludePathPatterns("/","/user/doLogin","/agency/mytest","/agency/queryAgency","/promotion/testRequest","/promotion/testRequestBoolean","/agency/sendmessage");
}
}

View File

@ -161,25 +161,54 @@ public class AgencyService {
}
@Transactional(rollbackFor = Exception.class)
public RespBody updateAgency(TbPlussUserInfo userInfo){
if (userInfo.getPhone() != null){
TbPlussUserApp userApp = new TbPlussUserApp();
userApp.setLoginname(userInfo.getPhone());
userApp.setUserid(Math.toIntExact(userInfo.getId()));
userInfoMapper.updateByPrimaryKey(userInfo);
userAppMapper.updateByPrimaryKeySelective(userApp);
}
//如有不存在的情况则添加数据
if (userInfo.getIdCard() != null){
idCardMapper.updateByPrimaryKeySelective(userInfo.getIdCard());
}else {
idCardMapper.insertSelective(userInfo.getIdCard());
}
if (userInfo.getCashAccount() != null){
cashAccountMapper.updateByPrimaryKeySelective(userInfo.getCashAccount());
}else {
cashAccountMapper.insertSelective(userInfo.getCashAccount());
}
return new RespBody("000000");
}
public RespBody getAgencyInfo(Integer userId){
//首先判断是不是大小机构
TbPlussUserPromotion userPromotion = userPromotionMapper.selectByPrimaryKey(userId);
if (userPromotion == null ||"FO".equals(userPromotion.getTypeCode()) || "SO".equals(userPromotion.getTypeCode())){
if (userPromotion == null){
return new RespBody("000086");
}
//查找大小机构的详情信息
//支付宝
TbPlussCashAccount tbPlussCashAccount = cashAccountMapper.selectByUserId(String.valueOf(userId));
//实名信息
TbPlussIdCard tbPlussIdCard = idCardMapper.selectCertByUserId(userId, TbPlussIdCard.TYPE_CERT);
//登录手机号
TbPlussUserApp tbPlussUserApp = userAppMapper.selectByUserId(userId);
if ("FO".equals(userPromotion.getTypeCode()) || "SO".equals(userPromotion.getTypeCode())){
//查找大小机构的详情信息
//支付宝
TbPlussCashAccount tbPlussCashAccount = cashAccountMapper.selectByUserId(String.valueOf(userId));
//实名信息
TbPlussIdCard tbPlussIdCard = idCardMapper.selectCertByUserId(userId, TbPlussIdCard.TYPE_CERT);
//登录手机号
TbPlussUserInfo tbPlussUserInfo = userInfoMapper.selectByPrimaryKey(Long.valueOf(userId));
HashMap<Object, Object> map = new HashMap<>();
map.put("zfb", tbPlussCashAccount);
map.put("idCard", tbPlussIdCard);
map.put("phone", tbPlussUserApp == null? null:tbPlussUserApp.getLoginname());
return new RespBody(map);
HashMap<Object, Object> map = new HashMap<>();
map.put("cashAccount", tbPlussCashAccount == null? new TbPlussCashAccount() : tbPlussCashAccount);
map.put("idCard", tbPlussIdCard == null? new TbPlussIdCard() : tbPlussIdCard);
map.put("phone", tbPlussUserInfo == null? null:tbPlussUserInfo.getPhone());
map.put("userId", tbPlussUserInfo == null? null:tbPlussUserInfo.getId());
return new RespBody(map);
}
return new RespBody("000086");
}

View File

@ -0,0 +1,30 @@
package com.chaozhanggui.admin.system.service;
import com.chaozhanggui.common.system.config.RespBody;
import com.chaozhanggui.dao.system.dao.TbPlussNoticeMapper;
import com.chaozhanggui.dao.system.entity.TbPlussNotice;
import com.chaozhanggui.dao.system.entity.TbPlussNotification;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class NotificationService {
@Resource
private TbPlussNoticeMapper tbPlussNoticeMapper;
public RespBody notificationQuery(Integer currPage, Integer size){
PageHelper.startPage(currPage, size);
List<TbPlussNotice> notificationList = tbPlussNoticeMapper.queryNotification();
PageInfo pageInfo=new PageInfo(notificationList);
return new RespBody(pageInfo);
}
}

View File

@ -54,6 +54,12 @@
<version>4.38.37.ALL</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.14</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -0,0 +1,57 @@
package com.chaozhanggui.common.system.util;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Base64;
@Slf4j
public class Base64Util {
private static final Integer KB = 1024;
/**
*
* @param origPicContent
* @param desFileSize 期望文件大小单位KB
* @return
*/
public static String compressPic(String origPicContent, Integer desFileSize) {
ByteArrayInputStream in = null;
ByteArrayOutputStream out = null;
try {
byte[] bytes = Base64.getDecoder().decode(origPicContent);
while (bytes.length > desFileSize * KB) {
in = new ByteArrayInputStream(bytes);
out = new ByteArrayOutputStream();
Thumbnails.of(in)
.scale(0.9f)
.outputQuality(1)
.toOutputStream(out);
bytes = out.toByteArray();
}
return Base64.getEncoder().encodeToString(bytes).replaceAll("[\r\n]","");
} catch (IOException e) {
log.error ("decode buffer fail, message:{}", e.getMessage (), e);
} finally {
if (in != null) {
try {
in.close ();
} catch (IOException e) {
log.error ("ByteArrayInputStream close fail, message:{}", e.getMessage (), e);
}
}
if (out != null) {
try {
out.close ();
} catch (IOException e) {
log.error ("ByteArrayOutputStream close fail, message:{}", e.getMessage (), e);
}
}
}
return origPicContent;
}
}

View File

@ -1,5 +1,7 @@
package com.chaozhanggui.common.system.util;
import org.apache.commons.codec.binary.Base64;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -10,6 +12,37 @@ import java.net.URL;
* @author lyf
*/
public class FileUtil {
public static String getBase64FromInputStream(InputStream in) {
// 将图片文件转化为字节数组字符串并对其进行Base64编码处理
byte[] data = null;
// 读取图片字节数组
try {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = in.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
data = swapStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (data == null) {
return null;
} else {
return new String(Base64.encodeBase64(data));
}
}
public static byte[] url2Bytes(String url) throws IOException {
URL urlConet = new URL(url);
HttpURLConnection con = (HttpURLConnection) urlConet.openConnection();
@ -26,4 +59,19 @@ public class FileUtil {
byte[] data = outStream.toByteArray();
return data;
}
public static String getBase64FromUrl(String url) {
try {
URL urlConn = new URL(url);
HttpURLConnection con = (HttpURLConnection) urlConn.openConnection();
con.setRequestMethod("GET");
con.setConnectTimeout(4 * 1000);
InputStream inStream = con.getInputStream();
return FileUtil.getBase64FromInputStream(inStream);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,26 @@
package com.chaozhanggui.common.system.util;
import lombok.val;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.Map;
public class MapUtils {
/**
* map转MultiValueMap
* @param map 原map
* @return
*/
public static MultiValueMap<String, Object> map2MultiValueMap(Map<String, Object> map) {
val result = new LinkedMultiValueMap<String, Object>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (entry.getValue() != null) {
result.add(entry.getKey(), entry.getValue());
}
}
return result;
}
}

View File

@ -2,9 +2,12 @@ package com.chaozhanggui.dao.system.dao;
import com.chaozhanggui.dao.system.entity.TbPlussNotice;
import com.chaozhanggui.dao.system.entity.TbPlussNotification;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Mapper
public interface TbPlussNoticeMapper {
@ -21,4 +24,6 @@ public interface TbPlussNoticeMapper {
int updateByPrimaryKeyWithBLOBs(TbPlussNotice record);
int updateByPrimaryKey(TbPlussNotice record);
List<TbPlussNotice> queryNotification();
}

View File

@ -1,9 +1,68 @@
package com.chaozhanggui.dao.system.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
@NoArgsConstructor
public class TbPlussNotice implements Serializable {
/**
* 系统通知 - 身份证认证
*/
public static final int TYPE_ID_CARD_AUTH = 0;
/**
* 系统通知 - 商户认证
*/
public static final int TYPE_MERCHANT_AUTH = 1;
/**
* 系统通知 - 员工退款申请
*/
public static final int TYPE_STAFF_REFUND = 2;
/**
* 系统通知 - 银行卡认证
*/
public static final int TYPE_BANK_AUTH = 5;
/**
* 系统通知 - 商户资料修改
*/
public static final int TYPE_MER_DATA_CHANGE = 8;
/**
* 系统通知 - 结算卡修改
*/
public static final int TYPE_MER_BANK_CHANGE = 9;
/**
* 系统通知 - 商户违规
*/
public static final int TYPE_MER_OUT_LINE = 10;
/**
* 系统通知 - 商户异常
*/
public static final int TYPE_MER_EXCEPTION = 11;
/**
* 系统通知 - 商户冻结
*/
public static final int TYPE_MER_FREEZE = 12;
/**
* 分润通知 - 商户分润
*/
public static final int TYPE_MER_PROFIT = 6;
/**
* 分润通知 - 商户升级分润
*/
public static final int TYPE_MER_UPDATE_PROFIT = 7;
private Integer id;
private String userid;
@ -33,6 +92,52 @@ public class TbPlussNotice implements Serializable {
private String uniquekey;
private String conrtent;
/**
* @description:指定推送的ids
* @date: 2021/8/27 14:51
*/
@TableField(exist = false)
private String userIds;
@TableField(exist = false)
private String aliass;
@TableField(exist = false)
private String parentIds;
@TableField(exist = false)
private String parentName;
@TableField(exist = false)
private String scheduleFlag;
public TbPlussNotice(Integer firstType, Integer secondType, TbPlussUserApp userApp) {
this.setUserid(userApp.getUserid().toString());
this.setNoticecode(UUID.randomUUID().toString().replace("-", ""));
this.setCreatedt(new Date());
this.setUsername(userApp.getUsername());
this.setTypefirst(firstType);
this.setTypesecond(secondType);
this.setIsdeal(0);
}
public TbPlussNotice(Integer firstType, Integer secondType, String userId) {
this.setUserid(userId);
this.setNoticecode(UUID.randomUUID().toString().replace("-", ""));
this.setCreatedt(new Date());
this.setTypefirst(firstType);
this.setTypesecond(secondType);
this.setIsdeal(0);
}
public TbPlussNotice(Integer firstType, Integer secondType, String userId, String userName) {
this.setUserid(userId);
this.setNoticecode(UUID.randomUUID().toString().replace("-", ""));
this.setCreatedt(new Date());
this.setUsername(userName);
this.setTypefirst(firstType);
this.setTypesecond(secondType);
this.setIsdeal(0);
}
private static final long serialVersionUID = 1L;

View File

@ -136,7 +136,6 @@ public class TbPlussUserApp implements Serializable {
@TableField(exist = false)
private TbPlussIdCard idCard;
public TbPlussIdCard getIdCard() {
return idCard;
}

View File

@ -1,5 +1,7 @@
package com.chaozhanggui.dao.system.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.util.Date;
@ -55,6 +57,33 @@ public class TbPlussUserInfo implements Serializable {
private String openid;
private String channelcode;
/**
* 结算支付宝信息
*/
@TableField(exist = false)
private TbPlussCashAccount cashAccount;
public TbPlussCashAccount getCashAccount() {
return cashAccount;
}
public void setCashAccount(TbPlussCashAccount cashAccount) {
this.cashAccount = cashAccount;
}
/**
* 实名信息
*/
@TableField(exist = false)
private TbPlussIdCard idCard;
public TbPlussIdCard getIdCard() {
return idCard;
}
public void setIdCard(TbPlussIdCard idCard) {
this.idCard = idCard;
}
private static final long serialVersionUID = 1L;

View File

@ -110,9 +110,6 @@
<if test="imgnegative != null">
imgNegative,
</if>
<if test="virtypeflag != null">
virTypeFlag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -154,9 +151,6 @@
<if test="imgnegative != null">
#{imgnegative,jdbcType=VARCHAR},
</if>
<if test="virtypeflag != null">
#{virtypeflag,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.dao.system.entity.TbPlussIdCard">
@ -198,9 +192,6 @@
<if test="imgnegative != null">
imgNegative = #{imgnegative,jdbcType=VARCHAR},
</if>
<if test="virtypeflag != null and virtypeflag != ''">
virTypeFlag = #{virtypeflag,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>

View File

@ -35,7 +35,12 @@
from tb_pluss_notice
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<select id="queryNotification" resultType="com.chaozhanggui.dao.system.entity.TbPlussNotice">
select * from tb_pluss_notice
where typeFirst = 1
ORDER BY id DESC
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tb_pluss_notice
where id = #{id,jdbcType=INTEGER}
</delete>

View File

@ -0,0 +1,76 @@
package com.chaozhanggui.merchant.entity.ys;
/**
*图片以及文件相关实体类
*/
public class Meta {
/**
* 图片类别,A001-营业执照 A002-法人身份证正面(头像面) A003-法人身份证反面(国徽面) A004-结算账户正面(卡号面)
* A005-结算账户反面 A006-商户门头照片 A007-内景照片 A008-收银台照片 A009-手持身份证合影照片
* A010-收单协议盖章页 A011-开户许可证 A012-收单协议首页 A013-非法人身份证头像面 A014-非法人身份证国徽面
* B001-租赁合同 第一页 B002-租赁合同 第二页 B003-租赁合同 第三页 B004-法人/非法人手持授权书
* B005-法人/非法人结算授权书 B006-租赁面积图片 B007-经营业务图片 B008-其他1 B009-其他2
*/
private String picType;
/**
* 文件名
*/
private String picNm;
/**
* 入网申请流水号,调用商户入网申请接口成功会返回入网申请流水号
*/
private String sysFlowId;
/**
* 入网申请流水号,调用商户入网申请接口成功会返回入网申请流水号
*/
private String changeFlowId;
/**
* 文件摘要,图片文件的文件摘要即对图片文件的二进制内容进行sha256计算得到的值 示例值hjkahkjsjkfsjk78687dhjahdajhk
*/
private String sha256;
public String getPicType() {
return picType;
}
public void setPicType(String picType) {
this.picType = picType;
}
public String getPicNm() {
return picNm;
}
public void setPicNm(String picNm) {
this.picNm = picNm;
}
public String getSysFlowId() {
return sysFlowId;
}
public void setSysFlowId(String sysFlowId) {
this.sysFlowId = sysFlowId;
}
public String getChangeFlowId() {
return changeFlowId;
}
public void setChangeFlowId(String changeFlowId) {
this.changeFlowId = changeFlowId;
}
public String getSha256() {
return sha256;
}
public void setSha256(String sha256) {
this.sha256 = sha256;
}
}

View File

@ -41,7 +41,7 @@ public class MerchantImageService {
* @param channelType 通道类型
* @return 进件图片资料
*/
List<TbPlussMerchantImage> getListOfMerch(String userId, String channelType){
public List<TbPlussMerchantImage> getListOfMerch(String userId, String channelType){
TbPlussMerchantBaseInfo merchantBaseInfo = merchantBaseInfoMapper.selectByUserId(userId);
//查询图片
List<TbPlussMerchantImage> miList = merchantImageMapper.getListOfMerch(merchantBaseInfo.getMerchantcode());

View File

@ -0,0 +1,56 @@
package com.chaozhanggui.merchant.service.ys;
import cn.hutool.core.util.RandomUtil;
import com.chaozhanggui.dao.system.dao.TbPlussMerchantBaseInfoMapper;
import com.chaozhanggui.dao.system.dao.TbPlussNoticeMapper;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantBaseInfo;
import com.chaozhanggui.dao.system.entity.TbPlussMerchantChannelStatus;
import com.chaozhanggui.dao.system.entity.TbPlussNotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Objects;
import static com.chaozhanggui.dao.system.entity.TbPlussNotice.TYPE_MERCHANT_AUTH;
/**
* @author lyf
*/
@Service
public class MercAuditListener {
@Resource
private TbPlussMerchantBaseInfoMapper mbiMapper;
@Resource
private TbPlussNoticeMapper noticeMapper;
/**
* 进件失败后
* @param userId
* @param mcs
* @param msg
*/
public void onFail(String userId, TbPlussMerchantChannelStatus mcs, String msg) {
TbPlussMerchantBaseInfo mbi = mbiMapper.selectByMerchantcode(mcs.getMerchantcode());
String title2 = "银收客审核通知";
String msg2;
if (Objects.equals(mcs.getChannel(), 4)) {
msg2 = "商户D0进件驳回" + msg;
} else {
msg2 = "商户进件驳回," + msg;
}
String.valueOf(mbi.getUserid());
TbPlussNotice notice2 = new TbPlussNotice(1, 1, mbi.getUserid().toString());
notice2.setNoticecode("SHSH_" + System.currentTimeMillis() + RandomUtil.randomString(2));
notice2.setConrtent(msg2);
notice2.setTypefirst(1);
notice2.setTypesecond(TYPE_MERCHANT_AUTH);
noticeMapper.insertSelective(notice2);
//TODO 发送消息推送暂时没有
//generalPushUtil.sendAllPlatByAlias(Collections.singletonList(mbi.getUserId() + ""), title2, msg2, "1");
}
}

View File

@ -2,12 +2,14 @@ package com.chaozhanggui.merchant.service.ys;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.crypto.asymmetric.Sign;
import cn.hutool.crypto.asymmetric.SignAlgorithm;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.symmetric.AES;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
@ -16,15 +18,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chaozhanggui.common.system.config.MsgException;
import com.chaozhanggui.common.system.util.Base64Util;
import com.chaozhanggui.common.system.util.FileUtil;
import com.chaozhanggui.common.system.util.MapUtils;
import com.chaozhanggui.common.system.util.SignUtils;
import com.chaozhanggui.dao.system.dao.*;
import com.chaozhanggui.dao.system.entity.*;
import com.chaozhanggui.dao.system.entity.DTO.AccountDTO;
import com.chaozhanggui.merchant.entity.ys.*;
import com.chaozhanggui.merchant.service.sxf.MerchantImageService;
import com.chaozhanggui.merchant.service.sxf.RegionReflectService;
import com.chaozhanggui.merchant.service.sxf.SxfMerchantAuditService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@ -34,15 +41,21 @@ import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import static com.chaozhanggui.dao.system.entity.TbPlussMerchantBaseInfo.MERCH_TYPE_MICRO;
@ -103,69 +116,78 @@ public class YSAuditServiceV3 {
private TbPlussMerchantChannelStatusMapper merchantChannelStatusMapper;
@Resource
private TbPlussAccountMapper accountMapper;
@Resource
private MerchantImageService merchantImageService;
@Resource
private MercAuditListener mercAuditListener;
@Resource
private ExecutorService executorService;
@Resource
private TransactionTemplate transactionTemplate;
/**
* 银盛进件3.0
* @param userId 用户id
*/
// public void merchantAuditV3(String userId, boolean isFailCheck, Integer channel) {
// try {
// self.step1(userId,channel);
// executorService.execute(() -> {
// try {
// self.step2(userId,channel);
// Thread.sleep(10000);
// self.step3(userId, channel);
// } catch (Exception e) {
// e.printStackTrace();
//
// MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByUserId(userId);
// MerchantChannelStatus mcs = mcsService.getByMerchantCode(mbi.getMerchantCode(), channel);
//
// if (e instanceof MsgException) {
// Serializable obj = ((MsgException) e).getObj();
// if (obj instanceof RespEntity) {
// mcs.getExtra().putAll((JSONObject) JSON.toJSON(obj));
// }
// }
//
// if (mcs != null && mcs.getChannel().equals(channel)) {
// mcs.setStatus(MerchantChannelStatus.AUDIT_STATUS_EXAMINING);
// mcs.setThirdStatus(MerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING);
// mcs.setRemark("银盛审核失败: " + e.getMessage());
// mcs.setUpdateTime(new Date());
// transactionTemplate.execute(new TransactionCallbackWithoutResult() {
// @Override
// protected void doInTransactionWithoutResult(TransactionStatus status) {
// mcsService.updateById(mcs);
// }
// });
// }
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
//
// MerchantBaseInfo mbi = mbiService.getMerchantBaseInfoByUserId(userId);
// MerchantChannelStatus mcs = mcsService.getByMerchantCode(mbi.getMerchantCode(), channel);
//
// if (mcs != null && Objects.equals(mcs.getChannel(), channel)) {
// mcs.setStatus(MerchantChannelStatus.AUDIT_STATUS_EXAMINING);
// mcs.setThirdStatus(MerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING);
// mcs.setRemark("银盛审核失败: " + e.getMessage());
// mcs.setUpdateTime(new Date());
//
// // 这里将驳回的信息放入新的事务中防止被回滚
// transactionTemplate.execute(new TransactionCallbackWithoutResult() {
// @Override
// protected void doInTransactionWithoutResult(TransactionStatus status) {
// mcsService.updateById(mcs);
// }
// });
// }
//
// throw e;
// }
// }
public void merchantAuditV3(String userId, boolean isFailCheck, Integer channel) {
try {
step1(userId,channel);
executorService.execute(() -> {
try {
step2(userId,channel);
Thread.sleep(10000);
step3(userId, channel);
} catch (Exception e) {
e.printStackTrace();
TbPlussMerchantBaseInfo mbi = merchantBaseInfoMapper.selectByUserId(userId);
TbPlussMerchantChannelStatus mcs = merchantChannelStatusMapper.getByMerchantCode(mbi.getMerchantcode(), String.valueOf(channel));
if (e instanceof MsgException) {
Serializable obj = ((MsgException) e).getObj();
if (obj instanceof RespEntity) {
JSONObject extra = JSONObject.parseObject(mcs.getExtra());
extra.putAll((JSONObject) JSON.toJSON(obj));
}
}
if (mcs != null && mcs.getChannel().equals(channel)) {
mcs.setStatus(TbPlussMerchantChannelStatus.AUDIT_STATUS_EXAMINING);
mcs.setThirdstatus(TbPlussMerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING);
mcs.setRemark("银盛审核失败: " + e.getMessage());
mcs.setUpdatetime(new Date());
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
merchantChannelStatusMapper.updateByPrimaryKeySelective(mcs);
}
});
}
}
});
} catch (Exception e) {
e.printStackTrace();
TbPlussMerchantBaseInfo mbi = merchantBaseInfoMapper.selectByUserId(userId);
TbPlussMerchantChannelStatus mcs = merchantChannelStatusMapper.getByMerchantCode(mbi.getMerchantcode(), String.valueOf(channel));
if (mcs != null && Objects.equals(mcs.getChannel(), channel)) {
mcs.setStatus(TbPlussMerchantChannelStatus.AUDIT_STATUS_EXAMINING);
mcs.setThirdstatus(TbPlussMerchantChannelStatus.AUDIT_THIRD_STATUS_WAITING);
mcs.setRemark("银盛审核失败: " + e.getMessage());
mcs.setUpdatetime(new Date());
// 这里将驳回的信息放入新的事务中防止被回滚
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
merchantChannelStatusMapper.updateByPrimaryKeySelective(mcs);
}
});
}
throw e;
}
}
/**
* 组装进件基本信息
@ -317,6 +339,163 @@ public class YSAuditServiceV3 {
mcs.setChannel(channel);
}
JSONObject extra = ObjectUtil.isEmpty(mcs.getExtra())?new JSONObject():JSONObject.parseObject(mcs.getExtra());
extra.putAll(JSON.parseObject(req.getBusinessData()));
mcs.setApplicationid(extra.getString("sysFlowId"));
mcs.setThirdstatus(TbPlussMerchantChannelStatus.AUDIT_THIRD_STATUS_AUDITING);
mcs.setInterfaceversion(INTERFACE_VERSION);
merchantChannelStatusMapper.updateByPrimaryKey(mcs);
//mcsService.saveOrUpdate(mcs);
AccountDTO accountDTO = sxfMerchantAuditService.getRealAccount(userId, TbPlussAccount.CHANNEL_TYPE_D1);
idCardMapper.getLegalIdCard(userId);
}
/**
* 上传进件图片信息保存图片信息
* @param userId
* @param channel
*/
public void step2(String userId, Integer channel) {
TbPlussMerchantBaseInfo mbi = merchantBaseInfoMapper.selectByUserId(userId);
//筛选
List<TbPlussMerchantImage> miList = merchantImageService.getListOfMerch(userId, TbPlussAccount.CHANNEL_TYPE_D0);
TbPlussMerchantChannelStatus mcs = new TbPlussMerchantChannelStatus();
mcs = merchantChannelStatusMapper.selectByMerchantCode(mbi.getMerchantcode(),channel);
if (mcs == null) {
throw new MsgException("无法上传图片,无法确认进件信息");
}
for (TbPlussMerchantImage mi : miList) {
imageUpload(mi.getPhotoType(), mi.getPicurl(), mcs.getApplicationid());
}
}
/**
* 银盛进件最后一步:开通D0
* @param userId
* @param channel
*/
public void step3(String userId, Integer channel) {
TbPlussMerchantBaseInfo mbi = merchantBaseInfoMapper.selectByUserId(userId);
TbPlussMerchantChannelStatus mcs = merchantChannelStatusMapper.getByMerchantCode(mbi.getMerchantcode(), String.valueOf(channel));
if (mcs == null) {
throw new MsgException("无法确认进件信息");
}
JSONObject param = new JSONObject();
param.put("auditFlag", "Y");
param.put("sysFlowId", mcs.getApplicationid());
RespEntity respEntity = req(ReqMethod.auditCustInfoApply, param, channel);
JSONObject bizContent = JSON.parseObject(respEntity.getBusinessData());
JSONObject jsonExtra = JSONObject.parseObject(mcs.getExtra());
jsonExtra.putAll(bizContent);
String status = bizContent.getString("status");
if (status == null) {
log.error("银盛云商服3.0进件异常, {}", respEntity.getSubMsg());
return;
}
mcs.setThirdstatus(status);
switch (status) {
case STATUS_SUCCESS:
// 这里不做任何处理交给回调操作防止数据错乱
break;
case STATUS_REFUSE:
mcs.setRemark(respEntity.getSubMsg());
mcs.setStatus(TbPlussMerchantChannelStatus.AUDIT_STATUS_REJECT);
merchantChannelStatusMapper.updateByPrimaryKeySelective(mcs);
mercAuditListener.onFail(mbi.getUserid().toString(), mcs, respEntity.getSubMsg());
break;
case STATUS_TO_MANUAL:
mcs.setRemark(respEntity.getSubMsg());
mcs.setStatus(TbPlussMerchantChannelStatus.AUDIT_STATUS_ARTIFICIAL_EXAMINING);
merchantChannelStatusMapper.updateByPrimaryKeySelective(mcs);
break;
}
merchantChannelStatusMapper.updateByPrimaryKeySelective(mcs);
}
/**
* 图片上传方法
* @param photoType
* @param imgUrl
* @param flowId
*/
private void imageUpload(String photoType, String imgUrl, String flowId) {
int count = 0;
while (count < 3) {
count++;
String relPhotoType = imgTypeTransform(photoType);
if (photoType == null) {
throw new MsgException("缺少图片类型");
}
RespEntity respEntity = reqUpload(ReqMethod.upload, relPhotoType, imgUrl, flowId);
if (!Objects.equals(respEntity.getSubCode(), BIZ_SUCCESS)) {
log.info("第{}次上传失败:{}", count, respEntity.getSubMsg());
} else {
if (photoType.equals(TbPlussMerchantImage.BANK_CARD_FRONT)) {
imageUpload(TbPlussMerchantImage.BANK_CARD_BACK, imgUrl, flowId);
}
return;
}
}
throw new MsgException("图片多次上传失败");
}
/**
* 图片映射
* @param imageType
* @return
*/
public String imgTypeTransform(String imageType) {
if (imageType == null) {
throw new MsgException("图片类型不能为空");
}
switch (imageType) {
case TbPlussMerchantImage.SHOP_FRONT_DOOR:
return "A006";
case TbPlussMerchantImage.STORE_INTERIOR_PHOTO:
return "A007";
case TbPlussMerchantImage.CASH_DESK_PHOTO:
return "A008";
case TbPlussMerchantImage.ACCOUNT_PERMITS:
return "A011";
case TbPlussMerchantImage.BUSINESS_LICENSE:
return "A001";
case TbPlussMerchantImage.IDCARD_FRONT:
return "A003";
case TbPlussMerchantImage.IDCARD_BACK:
return "A002";
case TbPlussMerchantImage.BANK_CARD_FRONT:
return "A004";
case TbPlussMerchantImage.BANK_CARD_BACK:
return "A005";
case TbPlussMerchantImage.SETTLE_IDCARD_FRONT:
return "A013";
case TbPlussMerchantImage.SETTLE_IDCARD_BACK:
return "A014";
case TbPlussMerchantImage.NON_LEG_SETTLE_AUTH:
return "B005";
case TbPlussMerchantImage.CHANGE_FORM:
return "B008";
case TbPlussMerchantImage.CASH_DESK_WITH_PERSON:
return "B009";
}
return null;
}
/**
@ -444,6 +623,123 @@ public class YSAuditServiceV3 {
}
}
/**
* 进件上传图片
* @param reqMethod
* @param picType
* @param fileUrl
* @param sysFlowId
* @return
*/
public RespEntity reqUpload(ReqMethod reqMethod, String picType, String fileUrl, String sysFlowId) {
Calendar calendar = Calendar.getInstance();
int i = calendar.get(Calendar.HOUR_OF_DAY);
if (i < 8 || i >= 21) {
throw new MsgException("当前时段暂不支持入网请于8:00-21:00提交");
}
Meta meta = new Meta();
meta.setPicType(picType);
meta.setSysFlowId(sysFlowId);
meta.setChangeFlowId(sysFlowId);
try {
ReqEntity request = ReqEntity.get(ReqMethod.upload);
request.setCertId(ysConfig.getSrcMerchantNo());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.add("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
MultiValueMap<String, Object> reqMap = new LinkedMultiValueMap<>();
try {
String imgBase64Data = FileUtil.getBase64FromUrl(fileUrl);
String compressPic = Base64Util.compressPic(imgBase64Data, 1024);
byte[] byteArray = Base64.decode(compressPic);
ByteArrayResource file = new ByteArrayResource(byteArray) {
@Override
public String getFilename() {
return "test.jpg";
}
};
reqMap.add("file", file);
String sha256 = DigestUtil.sha256Hex(file.getInputStream());
meta.setSha256(sha256);
meta.setPicNm("test.jpg");
} catch (IOException e) {
e.printStackTrace();
}
JSONObject reqData = new JSONObject();
reqData.put("meta", meta);
request.setBizContent(reqData.toString());
log.info("业务参数==============>" + reqData);
String key = RandomUtil.randomString(RandomUtil.BASE_NUMBER + "ABCDEF",16);
log.info("key = " + key);
AES aes = new AES(key.getBytes(StandardCharsets.UTF_8));
String s = aes.encryptBase64(request.getBizContent());
request.setBizContent(s);
RSA rsa = SecureUtil.rsa(ysConfig.getPriKey(), ysConfig.getOldPubKey());
request.setCheck(rsa.encryptBase64(key, KeyType.PublicKey));
String encryptOriginData = SignUtils.getSignContent((JSONObject) JSON.toJSON(request));
Sign sign = SecureUtil.sign(SignAlgorithm.SHA256withRSA, ysConfig.getPriKey(), ysConfig.getOldPubKey());
log.info("加签源数据==============>" + encryptOriginData);
request.setSign(Base64.encode(sign.sign(encryptOriginData.getBytes())));
reqMap.addAll(MapUtils.map2MultiValueMap((JSONObject) JSON.toJSON(request)));
HttpEntity<MultiValueMap<String, Object>> reqEntity = new HttpEntity<>(reqMap, headers);
String respStr = restTemplate.postForObject(reqMethod.getUrl(), reqEntity, String.class);
log.info("返回信息base64{}", respStr);
byte[] decode = Base64.decode(respStr);
respStr = new String(decode, StandardCharsets.UTF_8);
log.info("返回信息:{}", respStr);
JSONObject param = JSON.parseObject(respStr);
String signContent = SignUtils.getSignContent(param);
System.out.println("加签原参数:" + signContent);
boolean checkSign;
try {
checkSign = sign.verify(signContent.getBytes(StandardCharsets.UTF_8), Base64.decode(param.getString("sign")));
} catch (Exception e) {
log.error("银盛云商服3.0图片上传接口验签失败: {}", e.getMessage());
e.printStackTrace();
checkSign = true;
}
if (!checkSign) {
throw new MsgException("银盛云商服3.0接口验签不通过");
}
RespEntity respEntity = JSON.parseObject(respStr, RespEntity.class);
// 检查网关code码
if (!Objects.equals(respEntity.getCode(), REQ_SUCCESS)) {
throw new MsgException(respEntity.getMsg());
}
// 业务响应码这里不做判断交给具体接口业务逻辑去判断
if (respEntity.getBusinessData() != null) {
byte[] bizBytes = Base64.decode(respEntity.getBusinessData());
String decryptBizData = aes.decryptStr(bizBytes);
respEntity.setBusinessData(decryptBizData);
}
log.info("业务返回参数: {}", respEntity.getBusinessData());
return respEntity;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 再次检测
* @param userId