|
@@ -18,6 +18,8 @@ package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -27,17 +29,21 @@ import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
|
|
|
import com.qunzhixinxi.hnqz.admin.config.TaxNotifyConfig;
|
|
|
+import com.qunzhixinxi.hnqz.admin.config.UpmsConfig;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.*;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.SettleAmountMonitorInput;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.SettleNoteStatusOutput;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.output.WmTaskSettleNoteOutput;
|
|
|
import com.qunzhixinxi.hnqz.admin.enums.ChannelEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.GigTypeEnum;
|
|
|
import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.SysUserSubMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.mapper.WmScorePackageMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.mapper.WmScorePackageSettleNoteMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.*;
|
|
|
import com.qunzhixinxi.hnqz.admin.util.SendSms;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.constant.CommonConstants;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
import com.qunzhixinxi.hnqz.common.ding.config.DingConfig;
|
|
|
import com.qunzhixinxi.hnqz.common.ding.entity.EmployPayResponse;
|
|
@@ -45,6 +51,7 @@ import com.qunzhixinxi.hnqz.common.ding.entity.EmployPayResultSuccessItem;
|
|
|
import com.qunzhixinxi.hnqz.common.ding.entity.EmployPayResultfailItem;
|
|
|
import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
|
|
|
import com.qunzhixinxi.hnqz.common.ding.service.DingService;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
|
import com.qunzhixinxi.hnqz.common.taxhelper.config.TaxHelperConfig;
|
|
|
import com.qunzhixinxi.hnqz.common.taxhelper.entity.model.TaxHelperSettlementModel;
|
|
@@ -55,9 +62,16 @@ import com.qunzhixinxi.hnqz.common.taxhelper.service.TaxHelperService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang.RandomStringUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -77,6 +91,7 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
|
|
|
private final WmScorePackageSettleNoteMapper noteMapper;
|
|
|
private final WmScorePackageMapper wmScorePackageMapper;
|
|
|
private final SysUserService sysUserService;
|
|
|
+ private final SysUserSubMapper sysUserSubMapper;
|
|
|
private final SysDeptService deptService;
|
|
|
private final SysDeptSubService sysDeptSubService;
|
|
|
private final RedisTemplate redisTemplate;
|
|
@@ -86,6 +101,7 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
|
|
|
private final TaxHelperService taxHelperService;
|
|
|
private final TaxNotifyConfig taxNotifyConfig;
|
|
|
private final MonitoringIndicatorService monitoringIndicatorService;
|
|
|
+ private final UpmsConfig upmsConfig;
|
|
|
|
|
|
@Override
|
|
|
public IPage<WmTaskSettleNoteOutput> getWmTaskSettleInfoPage(Page page, WmScorePackageSettleNote note) {
|
|
@@ -454,22 +470,39 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
|
|
|
}
|
|
|
|
|
|
SysUser sysUser = sysUserService.getById(note.getUserId());
|
|
|
+
|
|
|
+ // 获取结算零工
|
|
|
+ GigTypeEnum gigTypeEnum = GigTypeEnum.resolve(Integer.parseInt(input.getSubType()));
|
|
|
+
|
|
|
+ if (gigTypeEnum == null){
|
|
|
+ return R.failed(sysUser.getRealname() + "人员结算渠道不存在,不能结算");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, gigTypeEnum)
|
|
|
+ .eq(SysUserSub::getUserId, sysUser.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (userSub == null){
|
|
|
+ return R.failed(sysUser.getRealname() + "人员认证信息不存在,不能结算");
|
|
|
+ }
|
|
|
+
|
|
|
if (redisTemplate.hasKey(CacheConstants.SETTLE_PACKAGE_KEY + note.getId())) {
|
|
|
- return R.failed("结算对象-" + sysUser.getRealname() + ":");
|
|
|
+ return R.failed("结算对象-" + sysUser.getRealname() + ":正在结算,请勿重复结算");
|
|
|
}
|
|
|
- if (SubjectTypeEnum.TYPE_RENLIJIA.getCode().equals(note.getSubType())) {
|
|
|
- log.info("结算渠道 {}", SubjectTypeEnum.TYPE_RENLIJIA.getDesc());
|
|
|
- if (!DingEnum.CER_STATUS_1.getType().equals(sysUser.getRljCertStatus())) {
|
|
|
- //认证中
|
|
|
- log.info("结算对象- {} :未认证成功,不能结算", sysUser.getRealname());
|
|
|
- return R.failed("结算对象-" + sysUser.getRealname() + ":未认证成功,不能结算");
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("结算渠道 {}", SubjectTypeEnum.TYPE_SHUIBANGYUN.getDesc());
|
|
|
- if (!Objects.equals(sysUser.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
|
|
|
- log.info("结算对象- {} :人员未认证或未绑卡,不能结算", sysUser.getRealname());
|
|
|
- return R.failed("人员未认证或未绑卡,不能结算");
|
|
|
- }
|
|
|
+
|
|
|
+ switch (gigTypeEnum) {
|
|
|
+ case REN_LI_JIA:
|
|
|
+ case OLADING:
|
|
|
+ if (!Objects.equals(userSub.getCertStatus(), DingEnum.CER_STATUS_1.getType())) {
|
|
|
+ return R.failed(sysUser.getRealname() + "未认证,不能发起结算");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TAX_HELPOR:
|
|
|
+ if (!Objects.equals(userSub.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
|
|
|
+ return R.failed(sysUser.getRealname() + "人员未认证或未绑卡,不能结算");
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return R.failed(sysUser.getRealname() + "人员结算渠道不存在,不能结算");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -486,7 +519,14 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
|
|
|
String subjectName = sysDeptSub.getSubjectName();
|
|
|
return settleByRenLiJia(note, config, wmScorePackage, subjectName);
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ // 自由职家
|
|
|
+ else if (SubjectTypeEnum.TYPE_OLADING.getCode().equals(input.getSubType())) {
|
|
|
+ String taxCode = sysDept.getTaxCode();
|
|
|
+ return settleByOlading(input, wmScorePackage, sysUser, taxCode);
|
|
|
+ }
|
|
|
+ // 税邦云
|
|
|
+ else {
|
|
|
String taxCode = sysDept.getTaxCode();
|
|
|
if (StringUtils.isNotEmpty(taxCode)) {
|
|
|
log.info("税邦云结算开始-获取会员所属企业的统一社会信用代码:{} ", taxCode);
|
|
@@ -698,6 +738,113 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private R settleByOlading(WmScorePackageSettleNote note,
|
|
|
+ WmScorePackage wmScorePackage,
|
|
|
+ SysUser sysUser,
|
|
|
+ String taxCode) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加锁
|
|
|
+ */
|
|
|
+ redisTemplate.opsForValue().set(CacheConstants.SETTLE_PACKAGE_KEY + note.getId(),
|
|
|
+ note.getId(), CacheConstants.SETTLE_TIME, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始结算
|
|
|
+ */
|
|
|
+
|
|
|
+ HnqzUser operator = SecurityUtils.getUser();
|
|
|
+ String gigTokenUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/token?tenantId={tenantId}&action={action}&userId={userId}";
|
|
|
+ String gigSettleUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/settlement";
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取请求token
|
|
|
+ ResponseEntity<String> tokenResult = new RestTemplate().getForEntity(gigTokenUrl, String.class,
|
|
|
+ String.valueOf(operator.getDeptId()), "settle", String.valueOf(operator.getId()));
|
|
|
+ log.warn("获取结算token:{}", tokenResult.getBody());
|
|
|
+ if (!JSONUtil.isJson(tokenResult.getBody())){
|
|
|
+ return R.failed("获取结算token失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(tokenResult.getBody());
|
|
|
+
|
|
|
+ if (jsonObject.getInt("code") != 0 || StrUtil.isBlank(jsonObject.getStr("data"))){
|
|
|
+ return R.failed("获取结算token失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ String token = jsonObject.getStr("data");
|
|
|
+
|
|
|
+ // 间隔100毫秒
|
|
|
+ Thread.sleep(100);
|
|
|
+
|
|
|
+
|
|
|
+ // 封装结算参数
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("token", token);
|
|
|
+ params.put("tenantId", operator.getDeptId());
|
|
|
+ params.put("operatorId", operator.getId());
|
|
|
+ params.put("requestId", RandomStringUtils.randomAlphabetic(12));
|
|
|
+ params.put("taskName", wmScorePackage.getScorePackageName() + "_" + System.currentTimeMillis());
|
|
|
+ params.put("amount", String.valueOf(note.getSettleAmount().doubleValue()));
|
|
|
+ params.put("taskStartTime", wmScorePackage.getCreateTime().toLocalDate());
|
|
|
+ params.put("taskEndTime", wmScorePackage.getUpdateTime().toLocalDate());
|
|
|
+ params.put("taskLocation", "要易云");
|
|
|
+ params.put("username", sysUser.getUsername());
|
|
|
+ params.put("idCard", sysUser.getIdCardNumber());
|
|
|
+ params.put("realName", sysUser.getRealname());
|
|
|
+ params.put("bankCard", sysUser.getBankCardNumber());
|
|
|
+ params.put("tagId", note.getInvoiceType());
|
|
|
+ params.put("endType", "CSO");
|
|
|
+ params.put("enterpriseCode", taxCode);
|
|
|
+ params.put("subjectType", "OLADING");
|
|
|
+ params.put("channel", "DEFAULT");
|
|
|
+
|
|
|
+
|
|
|
+ // 发起结算
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ HttpEntity<String> result = new RestTemplate().exchange(gigSettleUrl, HttpMethod.POST, new HttpEntity<>(params, headers), String.class);
|
|
|
+ log.warn("阿拉丁结算: {}", result.getBody());
|
|
|
+ if (!JSONUtil.isJson(result.getBody())){
|
|
|
+ return R.failed("结算失败");
|
|
|
+ }
|
|
|
+ JSONObject settelObj = JSONUtil.parseObj(result.getBody());
|
|
|
+
|
|
|
+
|
|
|
+ if (Objects.equals(settelObj.getInt("code"), CommonConstants.SUCCESS)) {
|
|
|
+ log.info("自由职家结算提交成功: {}", note.getSettleNo());
|
|
|
+ //streamId 获取不到
|
|
|
+ if (StringUtils.isEmpty(settelObj.getStr("data"))) {
|
|
|
+ log.warn("自由职家结算提交成功 requestId 获取不到: {}", note.getSettleNo());
|
|
|
+ }
|
|
|
+ note.setUpdateTime(LocalDateTime.now());
|
|
|
+ note.setSettleNoteStatus(DingEnum.NOTE_STATUS_SUBMIT.getType());
|
|
|
+ // 新增字段streamId
|
|
|
+ note.setStreamId(settelObj.getStr("data"));
|
|
|
+ } else {
|
|
|
+ log.warn("自由职家结算提交失败: {}", note.getSettleNo());
|
|
|
+ note.setUpdateTime(LocalDateTime.now());
|
|
|
+ note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
|
|
|
+
|
|
|
+ log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
|
|
|
+ redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + note.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e){
|
|
|
+ log.warn("自由职家结算提交失败: {}", note.getSettleNo());
|
|
|
+ note.setUpdateTime(LocalDateTime.now());
|
|
|
+ note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
|
|
|
+
|
|
|
+ log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
|
|
|
+ redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + note.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ this.baseMapper.updateById(note);
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private R settleByShuiBangYun(){
|
|
|
return R.failed("因系统维护,暂时不能提起支付,有问题请联系客服");
|
|
|
}
|