Quellcode durchsuchen

Merge branch 'master' into feat-wenwenreport-20220514

lixuesong vor 3 Jahren
Ursprung
Commit
6ccde489c1
24 geänderte Dateien mit 1444 neuen und 153 gelöschten Zeilen
  1. 29 0
      db/v2022/3upm_sequence.sql
  2. 5 5
      hnqz-common/hnqz-common-bom/pom.xml
  3. 1 1
      hnqz-common/pom.xml
  4. 1 1
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/CacheConstants.java
  5. 6 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/MqConstants.java
  6. 32 2
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/dto/OladingCommonRequest.java
  7. 4 0
      hnqz-upms/hnqz-upms-biz/pom.xml
  8. 35 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/config/SequenceConfig.java
  9. 5 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/config/UpmsConfig.java
  10. 2 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/GigThirdApiController.java
  11. 122 48
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmPayOffController.java
  12. 4 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java
  13. 12 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/input/WmScorePackageSettleInput.java
  14. 5 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/input/WmScorePackageSettleOutput.java
  15. 1 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/SubjectTypeEnum.java
  16. 8 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/SysUserMapper.java
  17. 31 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmPayOffService.java
  18. 11 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmScorePackageSettleNoteService.java
  19. 150 5
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/gig/impl/GigThirdApiServiceImpl.java
  20. 10 7
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/MonitoringIndicatorServiceImpl.java
  21. 546 51
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmPayOffServiceImpl.java
  22. 395 30
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageSettleNoteServiceImpl.java
  23. 26 0
      hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/SysUserMapper.xml
  24. 3 1
      hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmScorePackageMapper.xml

+ 29 - 0
db/v2022/3upm_sequence.sql

@@ -0,0 +1,29 @@
+USE `hnqzx`;
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for upms_sequence
+-- ----------------------------
+DROP TABLE IF EXISTS `upms_sequence`;
+CREATE TABLE `upms_sequence`
+(
+    `id`           BIGINT                            NOT NULL AUTO_INCREMENT,
+    `value`        BIGINT                            NOT NULL,
+    `name`         VARCHAR(32) CHARACTER SET utf8mb4 NOT NULL,
+    `gmt_create`   DATETIME                          NOT NULL,
+    `gmt_modified` DATETIME                          NOT NULL,
+    PRIMARY KEY (`id`) USING BTREE,
+    UNIQUE KEY `uk_name` (`name`) USING BTREE
+) ENGINE = InnoDB
+  DEFAULT CHARSET = utf8mb4
+  COLLATE = utf8mb4_general_ci;
+
+-- ----------------------------
+-- Records of upms_sequence
+-- ----------------------------
+BEGIN;
+COMMIT;
+
+SET FOREIGN_KEY_CHECKS = 1;

+ 5 - 5
hnqz-common/hnqz-common-bom/pom.xml

@@ -98,11 +98,11 @@
 				<artifactId>hnqz-common-feign</artifactId>
 				<version>${hnqz.version}</version>
 			</dependency>
-			<!--<dependency>-->
-			<!--	<groupId>com.qunzhixinxi</groupId>-->
-			<!--	<artifactId>hnqz-common-sequence</artifactId>-->
-			<!--	<version>${hnqz.version}</version>-->
-			<!--</dependency>-->
+			<dependency>
+				<groupId>com.qunzhixinxi</groupId>
+				<artifactId>hnqz-common-sequence</artifactId>
+				<version>${hnqz.version}</version>
+			</dependency>
 			<dependency>
 				<groupId>com.qunzhixinxi</groupId>
 				<artifactId>hnqz-common-swagger</artifactId>

+ 1 - 1
hnqz-common/pom.xml

@@ -45,7 +45,7 @@
 		<module>hnqz-common-oss</module>
 		<module>hnqz-common-security</module>
 		<module>hnqz-common-sentinel</module>
-		<!--<module>hnqz-common-sequence</module>-->
+		<module>hnqz-common-sequence</module>
 		<module>hnqz-common-swagger</module>
 		<!--<module>hnqz-common-transaction</module>-->
 		<module>hnqz-common-ding</module>

+ 1 - 1
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/CacheConstants.java

@@ -113,6 +113,6 @@ public interface CacheConstants {
 	/**
 	 * 自由职家签约结果回调key
 	 */
-	String OLADING_SIGN_UP_NOTIFY_KEY = "OLADING:SIGN_UP:NOTIFY:KEY:";
+	String OLADING_NOTIFY_KEY = "OLADING:NOTIFY:KEY:";
 
 }

+ 6 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/MqConstants.java

@@ -25,4 +25,10 @@ public interface MqConstants {
 	String DIRECT_MODE_GIG_SIGN_CERT_QUEUE = "direct_mode_gig_sign_cert_queue";
 	String DIRECT_MODE_GIG_SIGN_CERT_RES_QUEUE = "direct_mode_gig_sign_cert_res_queue";
 	String DIRECT_MODE_GIG_BANK_CARD_QUEUE = "direct_mode_gig_bank_card_queue";
+
+	/**
+	 * 订单服务队列
+	 */
+	String DIRECT_MODE_OMS_ORDER_BATCH_SUBMIT_QUEUE = "direct_mode_oms_order_batch_submit_queue";
+
 }

+ 32 - 2
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/dto/OladingCommonRequest.java

@@ -70,12 +70,14 @@ public class OladingCommonRequest implements Serializable {
 		// 接口名称
 		SIGN_UP("签约回调"),
 		UPLOAD_ID_CARD_IMAGE("证照上传回调"),
-		UPLOAD_TAXPAYER_AGREEMENT("上传企业纳税人协议回调");
+		UPLOAD_TAXPAYER_AGREEMENT("上传企业纳税人协议回调"),
+		CREATE_ORDER_V2("创建代付订单"),
+		CREATE_ORDER_DETAIL("阿拉钉内部打款订单回调");
 
 		/**
 		 * 描述
 		 */
-		private String desc;
+		private final String desc;
 	}
 
 	/**
@@ -129,4 +131,32 @@ public class OladingCommonRequest implements Serializable {
 
 		private final String message;
 	}
+
+	/**
+	 * 创建代付订单状态
+	 */
+	@Getter
+	@AllArgsConstructor
+	public enum CreateOrderV2Status {
+		ACCEPT("已受理"),
+		CLOSE("已关闭");
+
+		private final String status;
+
+	}
+
+
+	/**
+	 * 创建代付订单状态
+	 */
+	@Getter
+	@AllArgsConstructor
+	public enum RemitStatusStatus {
+		ACCEPT("出款中"),
+		REMIT("已成功"),
+		FAIL("已失败");
+
+		private final String status;
+
+	}
 }

+ 4 - 0
hnqz-upms/hnqz-upms-biz/pom.xml

@@ -33,6 +33,10 @@
 	<description>hnqz 通用用户权限管理系统业务处理模块</description>
 
 	<dependencies>
+		<dependency>
+			<groupId>com.qunzhixinxi</groupId>
+			<artifactId>hnqz-common-sequence</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>com.qunzhixinxi</groupId>
 			<artifactId>hnqz-common-mq</artifactId>

+ 35 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/config/SequenceConfig.java

@@ -0,0 +1,35 @@
+package com.qunzhixinxi.hnqz.admin.config;
+
+import cn.hutool.core.date.DateUtil;
+import com.qunzhixinxi.hnqz.common.data.tenant.TenantContextHolder;
+import com.qunzhixinxi.hnqz.common.sequence.builder.DbSeqBuilder;
+import com.qunzhixinxi.hnqz.common.sequence.properties.SequenceDbProperties;
+import com.qunzhixinxi.hnqz.common.sequence.sequence.Sequence;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.sql.DataSource;
+
+/**
+ * @author hnqz
+ * @date 2019-05-26
+ * <p>
+ * 设置发号器生成规则
+ */
+@Configuration
+public class SequenceConfig {
+
+	/**
+	 * 订单流水号发号器
+	 * @param dataSource
+	 * @param properties
+	 * @return
+	 */
+	@Bean
+	public Sequence paySequence(DataSource dataSource, SequenceDbProperties properties) {
+		return DbSeqBuilder.create()
+				.bizName(() -> String.format("payoff_%s_%s", TenantContextHolder.getTenantId(), DateUtil.today()))
+				.dataSource(dataSource).step(properties.getStep()).retryTimes(properties.getRetryTimes())
+				.tableName(properties.getTableName()).build();
+	}
+}

+ 5 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/config/UpmsConfig.java

@@ -36,5 +36,10 @@ public class UpmsConfig {
 	 */
 	private String wechatEnv;
 
+	/**
+	 * 零工服务地址
+	 */
+	private String gigServiceUrl;
+
 
 }

+ 2 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/GigThirdApiController.java

@@ -76,7 +76,7 @@ public class GigThirdApiController {
 		if (StrUtil.isBlank(requestId)) {
 			requestId = (String) data.get("request_id");
 		}
-		String redisKey = String.format("%s_%s_%s", CacheConstants.OLADING_SIGN_UP_NOTIFY_KEY, interfaceName, requestId);
+		String redisKey = String.format("%s_%s_%s", CacheConstants.OLADING_NOTIFY_KEY, interfaceName, requestId);
 		Boolean absent = redisTemplate.opsForValue().setIfAbsent(redisKey, reqStr, 30, TimeUnit.MINUTES);
 		if (!absent) {
 			log.error("存在在途操作requestId={}", requestId);
@@ -112,6 +112,7 @@ public class GigThirdApiController {
 		} catch (Exception e) {
 			log.error("自由职家统一请求异常", e);
 		} finally {
+			redisTemplate.delete(redisKey);
 			try {
 				response.getWriter().write("SUCCESS");
 				response.getWriter().flush();

+ 122 - 48
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmPayOffController.java

@@ -18,22 +18,30 @@ import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
 import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.script.DefaultRedisScript;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.validation.Valid;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * 结算表
@@ -41,56 +49,102 @@ import java.util.Map;
  * @author Liujh
  * @date 2020-12-1
  */
+@Slf4j
 @RestController
 @AllArgsConstructor
-@RequestMapping("/settle" )
+@RequestMapping("/settle")
 @Api(value = "settle", tags = "结算管理")
 public class WmPayOffController {
 
 	private final WmPayOffService wmPayOffService;
 	private final WmScorePackageService wmScorePackageService;
+	private final RedisTemplate<String, Object> redisTemplate;
 
-
+	/**
+	 * 财务回退操作
+	 * @param input 操作参数
+	 * @return 回退结果
+	 */
 	@ApiOperation(value = "结算回退", notes = "提交结算")
-	@SysLog("提交结算" )
+	@SysLog("提交结算")
 	@PostMapping("/settleBack")
 	public R settleBack(@RequestBody WmScorePackageSettleInput input) {
-		if(StringUtils.isEmpty(input.getId())){
+		if (StringUtils.isEmpty(input.getId())) {
 			return R.failed("数据异常");
 		}
 		return wmPayOffService.settleBack(input);
 	}
 
-	@ApiOperation(value = "提交结算", notes = "提交结算")
-	@SysLog("提交结算" )
-	@PostMapping("/settleSubmit")
-	public R settleSubmit(@RequestBody WmScorePackageSettleInput input) {
-		if(CollectionUtils.isEmpty(input.getNotes())){
-			return R.failed("数据异常");
-		}
 
-		if(StringUtils.isEmpty(input.getId())){
-			return R.failed("数据异常");
+	/**
+	 * 获取批量结算token,三分钟有效
+	 * token格式:[租户i]d:order_batch:[用户id]:token:
+	 *
+	 * @return 结算token
+	 */
+	@GetMapping(value = "/token")
+	public String getOrderBatchToken() {
+
+		String randomStr;
+
+		// 获取操作员
+		HnqzUser finaAdmin = SecurityUtils.getUser();
+		final String token = String.format("%d:order_batch:%d:token", finaAdmin.getTenantId(), finaAdmin.getId());
+
+		// 返回缓存生成好的
+		if (Boolean.TRUE.equals(redisTemplate.hasKey(token))) {
+			return (String) redisTemplate.opsForValue().get(token);
 		}
-		if(null == input.getInvoiceCategory()){
-			return R.failed("数据异常");
+
+		// 生成缓存key,将token缓存到redis
+		do {
+			randomStr = RandomStringUtils.randomNumeric(6);
+		} while (Boolean.FALSE.equals(redisTemplate.opsForValue().setIfAbsent(token, randomStr, 3, TimeUnit.MINUTES)));
+
+		return randomStr;
+
+	}
+
+	/**
+	 * 业务提交结算信息到财务
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
+	@ApiOperation(value = "提交结算", notes = "提交结算")
+	@SysLog("提交结算")
+	@PostMapping("/settleSubmit")
+	public R settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
+
+		//1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
+		HnqzUser finaAdmin = SecurityUtils.getUser();
+		final String REDIS_DEL_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
+		Long execute = redisTemplate.execute(new DefaultRedisScript<>(REDIS_DEL_SCRIPT, Long.class),
+				Collections.singletonList(String.format("%d:order_batch:%d:token", finaAdmin.getTenantId(), finaAdmin.getId())), input.getToken());
+		// 通过EVAL脚本原子验证令牌和删除令牌
+		boolean oops = (execute != null && execute == 0);
+
+		// 令牌验证失败
+		if (oops) {
+			log.error(String.format("提交 TOKEN 不正确:%s", input.getToken()));
+			return R.failed("提交 TOKEN 不正确,请刷新页面重试");
 		}
 
 		return wmPayOffService.settleSubmit(input);
 	}
 
 	@ApiOperation(value = "保存结算", notes = "保存结算")
-	@SysLog("保存结算" )
+	@SysLog("保存结算")
 	@PostMapping("/settleSave")
 	public R settleSave(@RequestBody WmScorePackageSettleInput input) {
-		if(CollectionUtils.isEmpty(input.getNotes())){
+		if (CollectionUtils.isEmpty(input.getNotes())) {
 			return R.failed("数据异常");
 		}
 
-		if(StringUtils.isEmpty(input.getId())){
+		if (StringUtils.isEmpty(input.getId())) {
 			return R.failed("数据异常");
 		}
-		if(null == input.getInvoiceCategory()){
+		if (null == input.getInvoiceCategory()) {
 			return R.failed("数据异常");
 		}
 
@@ -99,25 +153,27 @@ public class WmPayOffController {
 
 	/**
 	 * 弃用
+	 *
 	 * @Modify: start
 	 * @Version: v2021.4.16
 	 * @Author: ryz
 	 * @Date: 2021/4/28
-	*/
+	 */
+	@Deprecated
 	@ApiOperation(value = "结算", notes = "结算")
-	@SysLog("结算" )
+	@SysLog("结算")
 	@PostMapping("/settleIssue")
 	public R settleIssue(@RequestBody WmScorePackageSettleInput input) {
-		if(StringUtils.isEmpty(input.getId())){
+		if (StringUtils.isEmpty(input.getId())) {
 			return R.failed("数据异常");
 		}
-		if(CollectionUtils.isEmpty(input.getNotes())){
+		if (CollectionUtils.isEmpty(input.getNotes())) {
 			return R.failed("数据异常");
 		}
-		if(null == input.getInvoiceCategory()){
+		if (null == input.getInvoiceCategory()) {
 			return R.failed("数据异常");
 		}
-		if(StringUtils.isEmpty(input.getScorePackageName())){
+		if (StringUtils.isEmpty(input.getScorePackageName())) {
 			return R.failed("数据异常");
 		}
 
@@ -125,10 +181,10 @@ public class WmPayOffController {
 	}
 
 	@ApiOperation(value = "重新结算", notes = "重新结算")
-	@SysLog("重新结算" )
+	@SysLog("重新结算")
 	@PostMapping("/settleReIssue")
 	public R settleReIssue(@RequestBody WmScorePackageSettleInput input) {
-		if(StringUtils.isEmpty(input.getId())){
+		if (StringUtils.isEmpty(input.getId())) {
 			return R.failed("数据异常");
 		}
 
@@ -136,8 +192,14 @@ public class WmPayOffController {
 		return wmPayOffService.settleReIssueBySubType(input);
 	}
 
+	/**
+	 * 发起结算
+	 *
+	 * @param input 提交参数
+	 * @return 提交结果
+	 */
 	@ApiOperation(value = "结算", notes = "结算")
-	@SysLog("结算" )
+	@SysLog("结算")
 	@PostMapping("/settleById")
 	public R settleById(@RequestBody WmScorePackageSettleInput input) {
 
@@ -145,12 +207,19 @@ public class WmPayOffController {
 	}
 
 
+	/**
+	 * 财务审核页面
+	 *
+	 * @param page  分页信息
+	 * @param input 参数
+	 * @return
+	 */
 	@ApiOperation(value = "分页查询结算", notes = "分页查询结算")
-	@SysLog("分页查询结算" )
+	@SysLog("分页查询结算")
 	@GetMapping("/listPackageSettleList")
 	public R listPackageSettleList(Page page, WmScorePackageSettleInput input) {
 
-		input.setSendPackageDeptId(SecurityUtils.getUser().getDeptId() +"");
+		input.setSendPackageDeptId(SecurityUtils.getUser().getDeptId() + "");
 		input.setPackageFinishStatus("1");
 		input.setTypeid("4");
 		input.setSettleFlag("1");
@@ -166,10 +235,10 @@ public class WmPayOffController {
 	 */
 	@ApiOperation(value = "积分包结算导出", notes = "积分包结算导出")
 	@ResponseExcel(name = "exportPackageSettle", sheet = "积分包结算数据")
-	@SysLog("积分包结算导出" )
+	@SysLog("积分包结算导出")
 	@GetMapping("/exportPackageSettle")
 	public List<WmScorePackageSettleExcelModel> exportPackageSettle(WmScorePackageSettleInput input) {
-		input.setSendPackageDeptId(SecurityUtils.getUser().getDeptId() +"");
+		input.setSendPackageDeptId(SecurityUtils.getUser().getDeptId() + "");
 		input.setPackageFinishStatus("1");
 		input.setTypeid("4");
 		input.setSettleFlag("1");
@@ -192,7 +261,7 @@ public class WmPayOffController {
 
 			SubjectTypeEnum subjectTypeEnum = SubjectTypeEnum.resolve(settleOutput.getSubType());
 			export.setSubType(subjectTypeEnum.getDesc());
-			switch (subjectTypeEnum){
+			switch (subjectTypeEnum) {
 				case TYPE_RENLIJIA:
 					export.setInvoiceCategory(WmScorePackageSettleExcelModel.DingCategoryEnum.resolve(settleOutput.getInvoiceCategory()).getDesc());
 					break;
@@ -214,15 +283,15 @@ public class WmPayOffController {
 	}
 
 	@ApiOperation(value = "结算", notes = "结算")
-	@SysLog("结算" )
+	@SysLog("结算")
 	@PostMapping("/saveSettleInfo")
-	public R saveSettleInfo(@RequestBody List<WmScorePackage> wsList){
-		if(CollectionUtils.isEmpty(wsList)) {
+	public R saveSettleInfo(@RequestBody List<WmScorePackage> wsList) {
+		if (CollectionUtils.isEmpty(wsList)) {
 			return R.failed("请选择数据");
-		}else {
+		} else {
 			for (WmScorePackage wmScorePackage : wsList) {
-				if(StringUtils.isEmpty(wmScorePackage.getId())){
-					return R.failed("数据异常,请联系管理员:"+wmScorePackage.getScoreName());
+				if (StringUtils.isEmpty(wmScorePackage.getId())) {
+					return R.failed("数据异常,请联系管理员:" + wmScorePackage.getScoreName());
 				}
 			}
 		}
@@ -234,24 +303,29 @@ public class WmPayOffController {
 		}
 	}
 
+	/**
+	 * 结算
+	 * @param input
+	 * @return
+	 */
 	@ApiOperation(value = "结算-自由选择渠道", notes = "结算-自由选择渠道")
-	@SysLog("结算-自由选择渠道" )
+	@SysLog("结算-自由选择渠道")
 	@PostMapping("/settleIssueBySubType")
 	public R settleIssueBySubType(@RequestBody WmScorePackageSettleInput input) {
-		if(StringUtils.isEmpty(input.getId())){
+		if (StringUtils.isEmpty(input.getId())) {
 			return R.failed("数据异常");
 		}
-		if(StringUtils.isEmpty(input.getSubType())){
+		if (StringUtils.isEmpty(input.getSubType())) {
 			return R.failed("数据异常");
 		}
-		if(CollectionUtils.isEmpty(input.getNotes())){
+		if (CollectionUtils.isEmpty(input.getNotes())) {
 			return R.failed("数据异常");
 		}
-		if(null == input.getInvoiceCategory()){
+		if (null == input.getInvoiceCategory()) {
 			return R.failed("数据异常");
 		}
 
-		if(StringUtils.isEmpty(input.getScorePackageName())){
+		if (StringUtils.isEmpty(input.getScorePackageName())) {
 			return R.failed("数据异常");
 		}
 
@@ -264,7 +338,7 @@ public class WmPayOffController {
 	 * @param inputList
 	 * @return
 	 */
-	@SysLog("批量财务结算" )
+	@SysLog("批量财务结算")
 	@PostMapping("/batch-financial-settle")
 	public R<?> batchFinancialSettle(@RequestBody List<WmScorePackageSettleInput> inputList) {
 		if (CollectionUtil.isEmpty(inputList)) {
@@ -272,8 +346,8 @@ public class WmPayOffController {
 		}
 		List<Map<String, String>> msgList = new ArrayList<>();
 		for (WmScorePackageSettleInput input : inputList) {
-			if(StringUtils.isEmpty(input.getId()) || StringUtils.isEmpty(input.getSubType())
-				|| null == input.getInvoiceCategory() || StringUtils.isEmpty(input.getScorePackageName())) {
+			if (StringUtils.isEmpty(input.getId()) || StringUtils.isEmpty(input.getSubType())
+					|| null == input.getInvoiceCategory() || StringUtils.isEmpty(input.getScorePackageName())) {
 				return R.failed("数据异常");
 			}
 			// 查询结算详情(用于拼接notes数据)

+ 4 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java

@@ -319,6 +319,10 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	 */
 	private Integer invoiceCategory;
 
+	/**
+	 * 支付中心订单号
+	 */
+	private String omsOrderSn;
 
 	/**
 	 * 1:任务包

+ 12 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/input/WmScorePackageSettleInput.java

@@ -5,6 +5,9 @@ import com.qunzhixinxi.hnqz.admin.enums.CategoryEnum;
 import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
 import lombok.Data;
 
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -17,10 +20,18 @@ public class WmScorePackageSettleInput {
 	/**
 	 * packageId
 	 */
+	@NotBlank(message = "积分包信息必填")
 	private String id;
 
+	/**
+	 * 发票类目
+	 */
+	@NotNull(message = "发票类目必填")
 	private Integer invoiceCategory;
 
+	@NotBlank(message = "结算token必填")
+	private String token;
+
 	private String categoryName;
 
 	private String status;
@@ -54,6 +65,7 @@ public class WmScorePackageSettleInput {
 	private Integer ysh;
 	private Integer dsh;
 
+	@NotEmpty(message = "结算信息必填")
 	private List<WmScorePackageSettleNote> notes;
 
 	/**

+ 5 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/input/WmScorePackageSettleOutput.java

@@ -62,4 +62,9 @@ public class WmScorePackageSettleOutput {
 
 	private String settleNoteNumber;
 
+	/**
+	 * 订单编号
+	 */
+	private String omsOrderSn;
+
 }

+ 1 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/SubjectTypeEnum.java

@@ -12,6 +12,7 @@ public enum SubjectTypeEnum {
 
 	TYPE_RENLIJIA("0", "人力家"),
 	TYPE_SHUIBANGYUN("1", "税邦云"),
+	TYPE_OLADING("2", "自由职家"),
 
 	ENABLE_FLAG_FALSE("0", "无效"),
 	ENABLE_FLAG_TRUE("1", "有效"),

+ 8 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/mapper/SysUserMapper.java

@@ -107,4 +107,12 @@ public interface SysUserMapper extends DataScopeMapper<SysUser> {
 	 */
 	List<SysUser> selectByDeptIdAndRoleId(@Param("deptId") Integer deptId, @Param("realNameOrPhone") String realNameOrPhone,
 										  @Param("roleList") List<Integer> roleList);
+
+	/**
+	 * 获取用户信息
+	 *
+	 * @param userIds 用户id列表
+	 * @return 用户信息集合
+	 */
+	List<SysUser> listUserDetails(@Param(value = "userIds") List<Integer> userIds);
 }

+ 31 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmPayOffService.java

@@ -17,20 +17,50 @@ import java.util.List;
  */
 public interface WmPayOffService extends IService<WmPayOff> {
 
-	public R saveSettleInfo(List<WmScorePackage> wsList) throws Exception;
+	R saveSettleInfo(List<WmScorePackage> wsList) throws Exception;
 
+	/**
+	 * 获取结算信息
+	 *
+	 * @param input 参数
+	 * @return 结算信息
+	 */
 	R settleById(WmScorePackageSettleInput input);
 
 	R settleIssue(WmScorePackageSettleInput input);
 
+	/**
+	 * 业务保存操作
+	 *
+	 * @param input 提交信息
+	 * @return 保存结果
+	 */
 	R settleSave(WmScorePackageSettleInput input);
 
 	R settleReIssue(WmScorePackageSettleInput input);
 
+	/**
+	 * 业务提交结算信息到财务
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
 	R settleSubmit(WmScorePackageSettleInput input);
 
+	/**
+	 * 财务回退操作
+	 *
+	 * @param input 提交参数
+	 * @return 操作结果
+	 */
 	R settleBack(WmScorePackageSettleInput input);
 
+	/**
+	 * 提交结算
+	 *
+	 * @param input 提交结算信息
+	 * @return 提交结果
+	 */
 	R settleIssueBySubType(WmScorePackageSettleInput input);
 
 	R settleReIssueBySubType(WmScorePackageSettleInput input);

+ 11 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmScorePackageSettleNoteService.java

@@ -62,8 +62,19 @@ public interface WmScorePackageSettleNoteService extends IService<WmScorePackage
 
 	R revokeSettle(WmScorePackageSettleNote note);
 
+	/**
+	 * 按任务量单一结算
+	 * @param note 结算信息
+	 * @return 结算结果
+	 */
 	R singletSettle(WmScorePackageSettleNote note);
 
+	/**
+	 * 提交结算申请
+	 *
+	 * @param note
+	 * @return R
+	 */
 	R batchSettle(WmScorePackageSettleNote note);
 
 	/**

+ 150 - 5
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/gig/impl/GigThirdApiServiceImpl.java

@@ -7,16 +7,21 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.dto.OladingCommonRequest;
 import com.qunzhixinxi.hnqz.admin.entity.SysUserSub;
+import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
+import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageSettleNote;
 import com.qunzhixinxi.hnqz.admin.entity.dto.UserSignCertDTO;
 import com.qunzhixinxi.hnqz.admin.enums.GigCallBackStatus;
 import com.qunzhixinxi.hnqz.admin.enums.GigTypeEnum;
 import com.qunzhixinxi.hnqz.admin.enums.OladingCertStatus;
 import com.qunzhixinxi.hnqz.admin.service.SysUserSubService;
+import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
+import com.qunzhixinxi.hnqz.admin.service.WmScorePackageSettleNoteService;
 import com.qunzhixinxi.hnqz.admin.service.gig.GigThirdApiService;
 import com.qunzhixinxi.hnqz.admin.service.gig.SysUserSignCertService;
 import com.qunzhixinxi.hnqz.common.core.exception.ValidateCodeException;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,8 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
 import java.time.LocalDateTime;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * @author lixuesong
@@ -36,15 +43,16 @@ import java.util.concurrent.TimeUnit;
 @AllArgsConstructor
 public class GigThirdApiServiceImpl implements GigThirdApiService {
 
+	private final RedisTemplate redisTemplate;
 	private final SysUserSubService sysUserSubService;
-
 	private final SysUserSignCertService sysUserSignCertService;
-
-	private final RedisTemplate redisTemplate;
+	private final WmScorePackageSettleNoteService scorePackageSettleNoteService;
+	private final WmScorePackageService scorePackageService;
 
 	/**
 	 * 自由职家回调业务处理
-	 *  @param interfaceName
+	 *
+	 * @param interfaceName
 	 * @param requestId
 	 * @param data
 	 */
@@ -53,7 +61,7 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 		// 接口名称
 		OladingCommonRequest.InterfaceName interfaceNameEnum = Enum.valueOf(OladingCommonRequest.InterfaceName.class, interfaceName);
 		// 状态
-		String status = (String) data.get("status");
+		String status = "CREATE_ORDER_DETAIL".equals(interfaceName) ? (String) data.get("remit_status")  : (String) data.get("status");
 		// 截取前缀部分,从而获取到系统内部的requestId
 		String requestIdPrefix = StrUtil.split(requestId, StrUtil.UNDERLINE).get(0);
 
@@ -81,11 +89,148 @@ public class GigThirdApiServiceImpl implements GigThirdApiService {
 						Enum.valueOf(OladingCommonRequest.UploadTaxpayerAgreementStatus.class, status);
 				this.oladingUploadTaxpayerAgreement(requestIdPrefix, agreementStatus);
 				break;
+			case CREATE_ORDER_V2:
+				// 创建代付订单结果
+				this.oladingCreateOrderV2(requestId, Enum.valueOf(OladingCommonRequest.CreateOrderV2Status.class, status), data);
+				break;
+			case CREATE_ORDER_DETAIL:
+				this.oladingCreateOrderDetail(requestId, Enum.valueOf(OladingCommonRequest.RemitStatusStatus.class, status));
+				// 打款订单
+				break;
+			default:
+				throw new ValidateCodeException("回调方法处理不存在");
+		}
+	}
+
+	/**
+	 * 创建代付订单回调处理
+	 *
+	 * @param requestId 流水号
+	 * @param status    受理状态
+	 */
+	@Transactional(rollbackFor = Exception.class)
+	public void oladingCreateOrderDetail(String requestId, OladingCommonRequest.RemitStatusStatus status) {
+
+		int yaoyiStatus;
+		switch (status){
+			case REMIT:
+				yaoyiStatus = 1;
+				break;
+			case FAIL:
+				yaoyiStatus = 2;
+				break;
 			default:
+				log.error("订单状态错误:{}", status);
+				return;
+		}
+
+		List<WmScorePackageSettleNote> noteList = scorePackageSettleNoteService.list(Wrappers.<WmScorePackageSettleNote>lambdaQuery().eq(WmScorePackageSettleNote::getStreamId, requestId));
+
+		if (CollectionUtils.isNotEmpty(noteList)) {
+
+			log.warn("阿拉钉内部打款:{}", requestId);
+
+			List<WmScorePackageSettleNote> updateList = noteList.stream().map(note -> {
+				WmScorePackageSettleNote updateEntity = new WmScorePackageSettleNote();
+				updateEntity.setId(note.getId());
+				updateEntity.setSettleNoteStatus(yaoyiStatus);
+				if (yaoyiStatus == 1){
+					updateEntity.setNotifyTime(LocalDateTime.now());
+				}
+				updateEntity.setUpdateTime(LocalDateTime.now());
+				return updateEntity;
+			}).collect(Collectors.toList());
 
+			scorePackageSettleNoteService.updateBatchById(updateList);
+
+			WmScorePackageSettleNote tmp = noteList.get(0);
+			WmScorePackage scorePackage = scorePackageService.getById(tmp.getPackageId());
+
+			// 遥领不修改
+			if (!"1611890566".equals(scorePackage.getSendPackageDeptId())) {
+				// 更新积分包状态
+				log.info("更新积分包状态:{}", tmp);
+				WmScorePackage wmScorePackage = new WmScorePackage();
+				wmScorePackage.setId(tmp.getPackageId());
+				wmScorePackage.setSettleStatus(yaoyiStatus);
+				wmScorePackage.setUpdateTime(LocalDateTime.now());
+				scorePackageService.updateById(wmScorePackage);
+			}
+			redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + tmp.getId());
+		}
+	}
+
+	/**
+	 * 创建代付订单回调处理
+	 *
+	 * @param requestId 流水号
+	 * @param status    受理状态
+	 */
+	@SuppressWarnings("unchecked")
+	@Transactional(rollbackFor = Exception.class)
+	public void oladingCreateOrderV2(String requestId, OladingCommonRequest.CreateOrderV2Status status, Map<String, Object> data) {
+
+		boolean accept = OladingCommonRequest.CreateOrderV2Status.ACCEPT.equals(status);
+
+		int yaoyiStatus;
+		if (!accept) {
+			yaoyiStatus = 2;
+		} else {
+			List<Map<String, Object>> orderList = (List<Map<String, Object>>) data.get("remit_order_list");
+			Map<String, Object> o = orderList.get(0);
+			String remitStatue = (String) o.get("remit_status");
+			OladingCommonRequest.RemitStatusStatus remitStatusStatus = Enum.valueOf(OladingCommonRequest.RemitStatusStatus.class, remitStatue);
+			switch (remitStatusStatus){
+				case REMIT:
+					yaoyiStatus = 1;
+					break;
+				case FAIL:
+					yaoyiStatus = 2;
+					break;
+				default:
+					return;
+			}
+		}
+
+
+		List<WmScorePackageSettleNote> noteList = scorePackageSettleNoteService.list(Wrappers.<WmScorePackageSettleNote>lambdaQuery().eq(WmScorePackageSettleNote::getStreamId, requestId));
+
+		if (CollectionUtils.isNotEmpty(noteList)) {
+
+			log.warn("阿拉丁创建代付订单:{}", requestId);
+
+			List<WmScorePackageSettleNote> updateList = noteList.stream().map(note -> {
+				WmScorePackageSettleNote updateEntity = new WmScorePackageSettleNote();
+				updateEntity.setId(note.getId());
+				updateEntity.setSettleNoteStatus(yaoyiStatus);
+				if (yaoyiStatus == 1){
+					updateEntity.setNotifyTime(LocalDateTime.now());
+				}
+				updateEntity.setUpdateTime(LocalDateTime.now());
+				return updateEntity;
+			}).collect(Collectors.toList());
+
+			scorePackageSettleNoteService.updateBatchById(updateList);
+
+			WmScorePackageSettleNote tmp = noteList.get(0);
+			WmScorePackage scorePackage = scorePackageService.getById(tmp.getPackageId());
+
+			// 遥领不修改
+			if (!"1611890566".equals(scorePackage.getSendPackageDeptId())) {
+				// 更新积分包状态
+				log.info("更新积分包状态:{}", tmp);
+				WmScorePackage wmScorePackage = new WmScorePackage();
+				wmScorePackage.setId(tmp.getPackageId());
+				wmScorePackage.setSettleStatus(yaoyiStatus);
+				wmScorePackage.setUpdateTime(LocalDateTime.now());
+				scorePackageService.updateById(wmScorePackage);
+			}
+
+			redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + tmp.getId());
 		}
 	}
 
+
 	/**
 	 * 自由职家签约结果回调
 	 *

+ 10 - 7
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/MonitoringIndicatorServiceImpl.java

@@ -16,6 +16,7 @@
  */
 package com.qunzhixinxi.hnqz.admin.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qunzhixinxi.hnqz.admin.entity.MonitoringIndicator;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
@@ -35,14 +36,16 @@ import static com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants.MONITORING_
 @Service
 public class MonitoringIndicatorServiceImpl extends ServiceImpl<MonitoringIndicatorMapper, MonitoringIndicator> implements MonitoringIndicatorService {
 
-	@Cacheable(value = MONITORING_INDICATOR)
+	// @Cacheable(value = MONITORING_INDICATOR)
 	@Override
 	public MonitoringIndicator getBySubType(String subType) {
-		if(SubjectTypeEnum.TYPE_RENLIJIA.getCode().equals(subType)){
-			return baseMapper.selectById(1);
-		}else if(SubjectTypeEnum.TYPE_SHUIBANGYUN.getCode().equals(subType)){
-			return baseMapper.selectById(2);
-		}
-		return null;
+
+		return this.getOne(Wrappers.<MonitoringIndicator>lambdaQuery().eq(MonitoringIndicator::getSubType, subType));
+		// if(SubjectTypeEnum.TYPE_RENLIJIA.getCode().equals(subType)){
+		// 	return baseMapper.selectById(1);
+		// }else if(SubjectTypeEnum.TYPE_SHUIBANGYUN.getCode().equals(subType)){
+		// 	return baseMapper.selectById(2);
+		// }
+		// return null;
 	}
 }

+ 546 - 51
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmPayOffServiceImpl.java

@@ -1,28 +1,37 @@
 package com.qunzhixinxi.hnqz.admin.service.impl;
 
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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.input.WmScorePackageSettleInput;
 import com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput;
+import com.qunzhixinxi.hnqz.admin.enums.GigTypeEnum;
 import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
 import com.qunzhixinxi.hnqz.admin.mapper.SysUserMapper;
+import com.qunzhixinxi.hnqz.admin.mapper.SysUserSubMapper;
 import com.qunzhixinxi.hnqz.admin.mapper.WmPayOffMapper;
 import com.qunzhixinxi.hnqz.admin.service.*;
+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.*;
 import com.qunzhixinxi.hnqz.common.ding.enums.DingEnum;
 import com.qunzhixinxi.hnqz.common.ding.service.DingService;
+import com.qunzhixinxi.hnqz.common.rabbitmq.client.RabbitMqClient;
 import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
+import com.qunzhixinxi.hnqz.common.sequence.sequence.Sequence;
 import com.qunzhixinxi.hnqz.common.taxhelper.config.TaxHelperConfig;
 import com.qunzhixinxi.hnqz.common.taxhelper.entity.model.TaxHelperSettlementModel;
 import com.qunzhixinxi.hnqz.common.taxhelper.entity.request.TaxHelperSettlementRequest;
@@ -32,10 +41,17 @@ 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.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -54,8 +70,10 @@ import java.util.stream.Collectors;
 @AllArgsConstructor
 public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> implements WmPayOffService {
 
+	private final UpmsConfig upmsConfig;
 	private final WmPayOffMapper wmPayOffMapper;
 	private final SysUserMapper sysUserMapper;
+	private final SysUserSubMapper sysUserSubMapper;
 	private final DingService dingService;
 	private final WmScorePackageService wmScorePackageService;
 	private final WmTaskService wmTaskService;
@@ -70,7 +88,15 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 	private final WmDaDrugEntService wmDaDrugEntService;
 	private final TaxHelperService taxHelperService;
 	private final TaxNotifyConfig taxNotifyConfig;
+	private final RabbitMqClient rabbitMqClient;
+	private final Sequence paySequence;
 
+	/**
+	 * 财务回退操作
+	 *
+	 * @param input 提交参数
+	 * @return 操作结果
+	 */
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public R settleBack(WmScorePackageSettleInput input) {
@@ -160,7 +186,7 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 //			noteService.saveBatch(notes);
 		} else {
 //			notes.forEach(item -> item.setRealName(sysUserMapper.selectById(item.getUserId()).getRealname()));
-			notes.forEach(item->{
+			notes.forEach(item -> {
 				SysUser user = sysUserMapper.selectById(item.getUserId());
 				item.setRealName(user.getRealname());
 				item.setIdCardNumber(user.getIdCardNumber());
@@ -240,48 +266,71 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		return R.ok(resultMap);
 	}
 
+	/**
+	 * 业务提交结算信息到财务
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
 	@Override
 	public R settleSubmit(WmScorePackageSettleInput input) {
 		WmScorePackage wmScorePackage = wmScorePackageService.getById(input.getId());
+
 		if (!"0".equals(wmScorePackage.getSettleFlag())) {
 			return R.failed("结算状态异常,请勿重复结算");
 		}
+
 		List<WmScorePackageSettleNote> notes = input.getNotes();
 
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser user = sysUserMapper.selectById(note.getUserId());
-			if(StringUtils.isEmpty(user.getIdCardNumber())){
-				return R.failed(user.getRealname()+"未认证,不能发起结算");
+			if (StringUtils.isEmpty(user.getIdCardNumber())) {
+				return R.failed(user.getRealname() + "未认证,不能发起结算");
 			}
-			if("0".equals(input.getSubType())){
-				if (!Objects.equals(user.getRljCertStatus(), DingEnum.CER_STATUS_1.getType())) {
-					return R.failed(user.getRealname()+"未认证,不能发起结算");
-				}
+
+			// 获取结算零工
+			GigTypeEnum gigTypeEnum = GigTypeEnum.resolve(Integer.parseInt(input.getSubType()));
+			if (gigTypeEnum == null){
+				return R.failed(user.getRealname() + "人员结算渠道不存在,不能结算");
 			}
-			if("1".equals(input.getSubType())){
-				// return R.failed("因系统维护,暂时不能提起支付,有问题请联系客服");
-				if (!Objects.equals(user.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
-					return R.failed(user.getRealname()+"人员未认证或未绑卡,不能结算");
-				}
+
+			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, gigTypeEnum)
+					.eq(SysUserSub::getUserId, user.getUserId())
+			);
+
+			if (userSub == null){
+				return R.failed(user.getRealname() + "人员认证信息不存在,不能结算");
+			}
+
+			switch (gigTypeEnum) {
+				case REN_LI_JIA:
+				case OLADING:
+					if (!Objects.equals(userSub.getCertStatus(), DingEnum.CER_STATUS_1.getType())) {
+						return R.failed(user.getRealname() + "未认证,不能发起结算");
+					}
+					break;
+				case TAX_HELPOR:
+					if (!Objects.equals(userSub.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
+						return R.failed(user.getRealname() + "人员未认证或未绑卡,不能结算");
+					}
+					break;
+				default:
+					return R.failed(user.getRealname() + "人员结算渠道不存在,不能结算");
 			}
 		}
 
-		/**
-		 * @Modify: start 校验当月结算额度
-		 * @Version: 2021.4.16
-		 * @Author: ryz
-		 * @Date: 2021/4/22
-		 */
+		// 校验当月结算额度
 		List<String> idCard = notes.stream().map(WmScorePackageSettleNote::getIdCardNumber).collect(Collectors.toList());
-		List<Integer> ids = notes.stream().filter(item->null != item.getId()).map(WmScorePackageSettleNote::getId).collect(Collectors.toList());
+		List<Integer> ids = notes.stream().filter(item -> null != item.getId()).map(WmScorePackageSettleNote::getId).collect(Collectors.toList());
 		List<String> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).collect(Collectors.toList());
 
-		SettleAmountMonitorInput monitorInput = SettleAmountMonitorInput.fromIdCard(idCard, ids,input.getSubType());
+		SettleAmountMonitorInput monitorInput = SettleAmountMonitorInput.fromIdCard(idCard, ids, input.getSubType());
 		List<SettleAmountMonitorOutput> monitorOutputList = sysDeptSubService.getSettleAmountMonitor(monitorInput);
 
-		SettleAmountMonitorInput deptMonitorInput = SettleAmountMonitorInput.fromUserId(userIds, ids,input.getSubType());
+		SettleAmountMonitorInput deptMonitorInput = SettleAmountMonitorInput.fromUserId(userIds, ids, input.getSubType());
 		List<SettleAmountMonitorOutput> deptAmountMonitor = sysDeptSubService.getDeptAmountMonitor(deptMonitorInput);
 
+		// 结算渠道
 		SysDeptSub condition = new SysDeptSub();
 		condition.setDeptId(SecurityUtils.getUser().getDeptId());
 		condition.setSubjectType(input.getSubType());
@@ -291,6 +340,7 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			return R.failed("人员所在机构未配置结算信息");
 		}
 
+		// 限额
 		MonitoringIndicator monitoringIndicator = monitoringIndicatorService.getBySubType(input.getSubType());
 
 		BigDecimal deptLimit = sysDeptSub.getLimitAmount();
@@ -330,7 +380,7 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			note.setSubType(input.getSubType());
 			note.setInvoiceType(input.getInvoiceCategory());
 			note.setCategoryName(input.toCategoryName());
-			if(null == note.getId()){
+			if (null == note.getId()) {
 				note.setCreateTime(LocalDateTime.now());
 			}
 		}
@@ -356,36 +406,58 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		return R.ok();
 	}
 
+	/**
+	 * 业务保存操作
+	 *
+	 * @param input 提交信息
+	 * @return 保存结果
+	 */
 	@Override
 	public R settleSave(WmScorePackageSettleInput input) {
-//		WmScorePackage wmScorePackage = wmScorePackageService.getById(input.getId());
 
 		List<WmScorePackageSettleNote> notes = input.getNotes();
 
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser user = sysUserMapper.selectById(note.getUserId());
-			if(StringUtils.isEmpty(user.getIdCardNumber())){
-				return R.failed(user.getRealname()+"未认证,不能发起结算");
+			if (StringUtils.isEmpty(user.getIdCardNumber())) {
+				return R.failed(user.getRealname() + "未认证,不能发起结算");
 			}
-			if("0".equals(input.getSubType())){
-				if (!Objects.equals(user.getRljCertStatus(), DingEnum.CER_STATUS_1.getType())) {
-					return R.failed(user.getRealname()+"未认证,不能发起结算");
-				}
+
+			// 获取结算零工
+			GigTypeEnum gigTypeEnum = GigTypeEnum.resolve(Integer.parseInt(input.getSubType()));
+
+			if (gigTypeEnum == null){
+				return R.failed(user.getRealname() + "人员结算渠道不存在,不能结算");
 			}
-			if("1".equals(input.getSubType())){
-				if (!Objects.equals(user.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
-					return R.failed(user.getRealname()+"人员未认证或未绑卡,不能结算");
-				}
+
+			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, gigTypeEnum)
+					.eq(SysUserSub::getUserId, user.getUserId())
+			);
+
+			if (userSub == null){
+				return R.failed(user.getRealname() + "人员认证信息不存在,不能结算");
+			}
+
+			switch (gigTypeEnum) {
+				case REN_LI_JIA:
+				case OLADING:
+					if (!Objects.equals(userSub.getCertStatus(), DingEnum.CER_STATUS_1.getType())) {
+						return R.failed(user.getRealname() + "未认证,不能发起结算");
+					}
+					break;
+				case TAX_HELPOR:
+					if (!Objects.equals(userSub.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
+						return R.failed(user.getRealname() + "人员未认证或未绑卡,不能结算");
+					}
+					break;
+				default:
+					return R.failed(user.getRealname() + "人员结算渠道不存在,不能结算");
 			}
 		}
-		/**
-		 * @Modify: start 校验当月结算额度
-		 * @Version: 2021.4.16
-		 * @Author: ryz
-		 * @Date: 2021/4/22
-		 */
+
+		// 校验当月结算额度
 		List<String> idCard = notes.stream().map(WmScorePackageSettleNote::getIdCardNumber).collect(Collectors.toList());
-		List<Integer> ids = notes.stream().filter(item->null != item.getId()).map(WmScorePackageSettleNote::getId).collect(Collectors.toList());
+		List<Integer> ids = notes.stream().filter(item -> null != item.getId()).map(WmScorePackageSettleNote::getId).collect(Collectors.toList());
 		List<String> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).collect(Collectors.toList());
 
 		SettleAmountMonitorInput monitorInput = SettleAmountMonitorInput.fromIdCard(idCard, ids, input.getSubType());
@@ -442,7 +514,7 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			note.setSubType(input.getSubType());
 			note.setInvoiceType(input.getInvoiceCategory());
 			note.setCategoryName(input.toCategoryName());
-			if(null == note.getId()){
+			if (null == note.getId()) {
 				note.setCreateTime(LocalDateTime.now());
 			}
 
@@ -504,12 +576,18 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			} else {
 				return R.failed("未配置企业的统一社会信用代码");
 			}
-			return settleByShuiBangYun(input, sysDeptSub, wmScorePackage,taxCode);
+			return settleByShuiBangYun(input, sysDeptSub, wmScorePackage, taxCode);
 			// return settleByShuiBangYun();
 		}
 
 	}
 
+	/**
+	 * 提交结算
+	 *
+	 * @param input 提交结算信息
+	 * @return 提交结果
+	 */
 	@Override
 	public R settleIssueBySubType(WmScorePackageSettleInput input) {
 
@@ -532,27 +610,420 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			return R.failed("机构appId未维护");
 		}
 
+		SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
+
+		String taxCode = sysDept.getTaxCode();
+
+		// 人力家
 		if (SubjectTypeEnum.TYPE_RENLIJIA.getCode().equals(input.getSubType())) {
 			return settleByRenLiJia(input, sysDeptSub, wmScorePackage);
-		} else {
-			SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
-
-			String taxCode = sysDept.getTaxCode();
+		}
+		// 自由职家
+		else if (SubjectTypeEnum.TYPE_OLADING.getCode().equals(input.getSubType())) {
+			return settleByOlading(input, sysDeptSub, wmScorePackage, taxCode);
+		}
+		// 税邦云
+		else {
 			if (StringUtils.isNotEmpty(taxCode)) {
 				log.info("税邦云结算开始-获取会员所属企业的统一社会信用代码:{} ", taxCode);
 			} else {
 				return R.failed("未配置企业的统一社会信用代码");
 			}
-			return settleByShuiBangYun(input, sysDeptSub, wmScorePackage,taxCode);
+			return settleByShuiBangYun(input, sysDeptSub, wmScorePackage, taxCode);
 			// return settleByShuiBangYun();
 		}
 
 	}
 
-	private R settleByShuiBangYun(){
+
+	/**
+	 * 阿拉丁结算操作
+	 *
+	 * @param input          结算数据
+	 * @param sysDeptSub     结算配置
+	 * @param wmScorePackage 积分包
+	 * @return 结果
+	 */
+	private R settleByOlading(WmScorePackageSettleInput input,
+							  SysDeptSub sysDeptSub,
+							  WmScorePackage wmScorePackage,
+							  String taxCode) {
+
+		List<WmScorePackageSettleNote> notes = input.getNotes();
+		StringBuilder noticeInfo = new StringBuilder();
+
+		/**
+		 * WmScorePackageSettleNote
+		 */
+		for (WmScorePackageSettleNote note : notes) {
+			note.setInvoiceType(input.getInvoiceCategory());
+			note.setCategoryName(input.toCategoryName());
+			note.setSubToGigTime(LocalDateTime.now());
+		}
+		noteService.updateBatchById(notes);
+
+
+		for (int i = 0; i < notes.size(); i++) {
+			WmScorePackageSettleNote note = notes.get(i);
+			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
+
+			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, GigTypeEnum.OLADING)
+					.eq(SysUserSub::getUserId, sysUser.getUserId())
+			);
+
+			if (userSub == null) {
+				log.info("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+				return R.failed("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+			}
+
+			if (!Objects.equals(userSub.getCertStatus(), DingEnum.CER_STATUS_1.getType())) {
+				return R.failed(sysUser.getRealname() + "人员未认证或未绑卡,不能结算");
+			}
+
+			if (redisTemplate.hasKey(CacheConstants.SETTLE_PACKAGE_KEY + note.getId())) {
+				return R.failed("结算对象-" + sysUser.getRealname() + ":正在结算,请勿重复结算");
+			}
+
+			if (DingEnum.NOTE_STATUS_SUCCESS.getType().equals(note.getSettleNoteStatus())) {
+				log.info("结算对象-" + sysUser.getRealname() + ":已结算,请勿重复结算");
+				return R.failed("结算对象-" + sysUser.getRealname() + ":已结算,请勿重复结算");
+			}
+			if (DingEnum.NOTE_STATUS_SUBMIT.getType().equals(note.getSettleNoteStatus())) {
+				log.info("结算对象-" + sysUser.getRealname() + ":已提交,请等待耐心结算结果");
+				return R.failed("结算对象-" + sysUser.getRealname() + ":已提交,请等待耐心结算结果");
+			}
+			sysUser.setBankCardNumber(userSub.getBankCardNumber());
+		}
+		HnqzUser operator = SecurityUtils.getUser();
+		String gigTokenUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/token?tenantId={tenantId}&action={action}&userId={userId}";
+		String gigSettleUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/settlement";
+
+		for (int i = 0; i < notes.size(); i++) {
+			WmScorePackageSettleNote note = notes.get(i);
+
+			/**
+			 * 加锁
+			 */
+			redisTemplate.opsForValue().set(CacheConstants.SETTLE_PACKAGE_KEY + note.getId(),
+					note.getId(), CacheConstants.SETTLE_TIME, TimeUnit.DAYS);
+
+			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
+			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");
+				params.put("taskDescription", "根据要求,执行、并完成学术推广活动,并以在线平台工具采集、记录活动内容");
+				params.put("acceptanceStandard", "完成不同任务获得不同任务积分,根据不同任务给与0~30000积分,每个积分兑换0.8~1.2元,按次数结算");
+
+
+				// 发起结算
+				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());
+						noticeInfo.append(sysUser.getRealname() + ":提交结算成功,业务流水号获取不到,请联系管理员;");
+					}
+					note.setUpdateTime(LocalDateTime.now());
+					note.setSettleNoteStatus(DingEnum.NOTE_STATUS_SUBMIT.getType());
+					// 新增字段streamId
+					note.setStreamId(settelObj.getStr("data"));
+					noticeInfo.append(sysUser.getRealname() + ":提交结算成功;");
+				} else {
+					log.warn("自由职家结算提交失败: {}", note.getSettleNo());
+					note.setUpdateTime(LocalDateTime.now());
+					note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
+					noticeInfo.append(sysUser.getRealname() + ":结算提交失败-" + settelObj.getStr("msg") + ";");
+
+					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());
+				noticeInfo.append(sysUser.getRealname() + ":结算提交失败;");
+
+				log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
+				redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + note.getId());
+			}
+		}
+
+		noteService.updateBatchById(notes);
+
+		/**
+		 * 更新结算结果
+		 */
+		SettleNoteStatusOutput output = noteService.selectSettleNoteStatus(input.getId());
+		WmScorePackage updateEntity = new WmScorePackage();
+		updateEntity.setId(input.getId());
+		updateEntity.setSettleStatus(output.toSettleStatus());
+		wmScorePackageService.updateById(updateEntity);
+
+		return R.ok(null, noticeInfo.toString());
+	}
+
+	// /**
+	//  * 自由职家结算
+	//  *
+	//  * @param input
+	//  * @param sysDeptSub
+	//  * @param wmScorePackage
+	//  * @param taxCode
+	//  * @return 提交结果
+	//  */
+	// private R settleByOlading(WmScorePackageSettleInput input,
+	// 						  SysDeptSub sysDeptSub,
+	// 						  WmScorePackage wmScorePackage,
+	// 						  String taxCode) {
+	//
+	// 	// 获取发票类型和名称
+	// 	int invoiceCategory = input.getInvoiceCategory();
+	// 	String categoryName = input.toCategoryName();
+	//
+	// 	// 获取结算记录
+	// 	List<WmScorePackageSettleNote> notes = input.getNotes();
+	//
+	// 	// 结算锁
+	// 	List<String> lockKey = new ArrayList<>(notes.size());
+	//
+	// 	// 校验,循环设置结算记录的发票信息
+	// 	notes.forEach(note -> {
+	// 		if (Boolean.TRUE.equals(redisTemplate.hasKey(String.format("%s:%d", CacheConstants.SETTLE_PACKAGE_KEY, note.getId())))
+	// 				|| DingEnum.NOTE_STATUS_SUCCESS.getType().equals(note.getSettleNoteStatus())
+	// 				|| DingEnum.NOTE_STATUS_SUBMIT.getType().equals(note.getSettleNoteStatus())) {
+	// 			String errMsg = String.format("结算记录-%d,存在历史或在途操作,请勿重复结算。", note.getId());
+	// 			log.error(errMsg);
+	// 			throw new RuntimeException(errMsg);
+	// 		}
+	//
+	// 		note.setInvoiceType(invoiceCategory);
+	// 		note.setCategoryName(categoryName);
+	// 		note.setSubToGigTime(LocalDateTime.now());
+	//
+	// 		lockKey.add(String.format("%s:%d",CacheConstants.SETTLE_PACKAGE_KEY, note.getId()));
+	//
+	// 	});
+	//
+	// 	noteService.updateBatchById(notes);
+	//
+	//
+	// 	// 校验信息
+	// 	List<String> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).distinct().collect(Collectors.toList());
+	// 	List<SysUser> sysUsers = sysUserMapper.selectList(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds));
+	// 	List<SysUserSub> userSubs = sysUserSubMapper.selectList(Wrappers.<SysUserSub>lambdaQuery().in(SysUserSub::getUserId, userIds)
+	// 			.eq(SysUserSub::getGigType, GigTypeEnum.OLADING.getCode())
+	// 			.eq(SysUserSub::getGigChannel, GigChannelEnum.DEFAULT.getCode())
+	// 			.eq(SysUserSub::getCertStatus, OladingCertStatus.CERT.getCode())
+	// 	);
+	//
+	// 	if (CollUtil.isEmpty(sysUsers) || CollUtil.isEmpty(userSubs)){
+	// 		log.error("用户或用户认证记录缺失不能发起结算");
+	// 		throw new RuntimeException("用户或用户认证记录缺失不能发起结算");
+	// 	}
+	//
+	// 	Map<Integer, SysUser> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, Function.identity()));
+	// 	Map<Integer, SysUserSub> userSubMap = userSubs.stream().collect(Collectors.toMap(SysUserSub::getUserId, Function.identity()));
+	//
+	// 	if (!userMap.keySet().containsAll(userMap.keySet())){
+	// 		log.error("用户尚未认证不能发起结算");
+	// 		throw new RuntimeException("用户尚未认证不能发起结算");
+	// 	}
+	//
+	//
+	//
+	// 	// ~================================================================================================= 发起结算
+	//
+	// 	try {
+	// 		// 1 结算纪录锁定
+	// 		Map<String, String> keyMap = lockKey.stream().collect(Collectors.toMap(Function.identity(), Function.identity()));
+	// 		if (Boolean.FALSE.equals(redisTemplate.opsForValue().multiSetIfAbsent(keyMap))){
+	// 			log.error("存在在途的操作");
+	// 			throw new RuntimeException("存在在途的操作");
+	// 		}
+	//
+	// 		// 3 封装批量订单
+	// 		OmsOrderRequest.OrderBatchSubmitParams orderBatchSubmitParams = new OmsOrderRequest.OrderBatchSubmitParams();
+	// 		orderBatchSubmitParams.setBatchNo(paySequence.nextNo());
+	// 		orderBatchSubmitParams.setPayeeQuantity((long)sysUsers.size());
+	// 		orderBatchSubmitParams.setOrderToken(RandomStringUtils.randomNumeric(6));
+	// 		orderBatchSubmitParams.setRemarks("正常结算");
+	// 		orderBatchSubmitParams.setEndType(CheckoutType.SubmitEndType.CSO);
+	//
+	//
+	//
+	//
+	// 		orderBatchSubmitParams.setOrderQuantity();
+	// 		orderBatchSubmitParams.setOrderSubmits();
+	// 		orderBatchSubmitParams.setBatchAmountPayable();
+	//
+	//
+	// 		// 4 发送消息
+	//
+	// 		// 5 修改积分包
+	//
+	// 	} catch (Exception e){
+	// 		log.error("提交结算失败",e);
+	// 		redisTemplate.delete(lockKey);
+	// 	}
+	//
+	//
+	//
+	//
+	//
+	//
+	//
+	//
+	//
+	// 	for (int i = 0; i < notes.size(); i++) {
+	// 		WmScorePackageSettleNote note = notes.get(i);
+	//
+	// 		/**
+	// 		 * 加锁
+	// 		 */
+	// 		redisTemplate.opsForValue().set(CacheConstants.SETTLE_PACKAGE_KEY + note.getId(),
+	// 				note.getId(), CacheConstants.SETTLE_TIME, TimeUnit.DAYS);
+	//
+	// 		SysUser sysUser = sysUserMapper.selectById(note.getUserId());
+	//
+	// 		TaxHelperConfig config = new TaxHelperConfig();
+	// 		config.setAppId(sysDeptSub.getAppId());
+	// 		config.setAppSecrete(sysDeptSub.getAppSecret());
+	// 		config.setQueryUrl(sysDeptSub.getQueryUrl());
+	//
+	// 		/**
+	// 		 * 开始结算
+	// 		 */
+	// 		TaxHelperSettlementModel taxHelperSettlementModel = new TaxHelperSettlementModel(config);
+	// 		taxHelperSettlementModel.setEnterpriseCode(taxCode);
+	//
+	// 		taxHelperSettlementModel.setExtendFieldNames(Arrays.asList("报告下载地址"));
+	// 		taxHelperSettlementModel.setCount(1);
+	//
+	// 		taxHelperSettlementModel.setNotifyUrl(taxNotifyConfig.getNotifyUrl() + "/admin/taxhelper/" + sysUser.getUserId() + "/settlementNotify");
+	// 		TaxHelperSettlementModel.DetailedArr detailedArr = new TaxHelperSettlementModel.DetailedArr();
+	// 		detailedArr.setIdCard(sysUser.getIdCardNumber());
+	// 		detailedArr.setInputAmount(note.getSettleAmount().doubleValue());
+	// 		detailedArr.setCategoryName(note.getCategoryName());
+	// 		taxHelperSettlementModel.setDetailedArr(Arrays.asList(detailedArr));
+	//
+	// 		TaxHelperSettlementModel.AbstractArr abstractArr = new TaxHelperSettlementModel.AbstractArr();
+	//
+	// 		abstractArr.setIdCard(sysUser.getIdCardNumber());
+	// 		abstractArr.setNumber(1);
+	// 		abstractArr.setPrice(note.getSettleAmount().doubleValue());
+	// 		abstractArr.setAmount(note.getSettleAmount().doubleValue());
+	//
+	// 		// abstractArr.setExtendField1(taxNotifyConfig.getTaskUrl() + "/admin/api/h5PackagePage?current=1&size=20&id=" + wmScorePackage.getScorePackageName());
+	// 		abstractArr.setExtendField1(taxNotifyConfig.getTaskUrl() + "/#/h5/indexTask?id=" + note.getPackageId() + "&userId=" + note.getUserId());
+	//
+	// 		taxHelperSettlementModel.setAbstractArr(Arrays.asList(abstractArr));
+	//
+	// 		TaxHelperSettlementRequest taxHelperSettlementRequest = new TaxHelperSettlementRequest(taxHelperSettlementModel);
+	//
+	// 		TaxHelperResponse response = taxHelperService.settlement(taxHelperSettlementRequest);
+	//
+	// 		log.info("税邦云结算: {}", response);
+	//
+	//
+	// 		if (response.success()) {
+	// 			log.info("税邦云结算提交成功: {}", note.getSettleNo());
+	// 			//streamId 获取不到
+	// 			if (StringUtils.isEmpty(response.getMessage())) {
+	// 				log.info("税邦云结算提交成功 streamId 获取不到: {}", note.getSettleNo());
+	// 				noticeInfo.append(sysUser.getRealname() + ":提交结算成功,业务流水号获取不到,请联系管理员;");
+	// 			}
+	// 			note.setUpdateTime(LocalDateTime.now());
+	// 			note.setSettleNoteStatus(DingEnum.NOTE_STATUS_SUBMIT.getType());
+	// 			// 新增字段streamId
+	// 			note.setStreamId(response.getMessage());
+	// 			noticeInfo.append(sysUser.getRealname() + ":提交结算成功;");
+	// 		} else {
+	// 			log.info("税邦云结算提交失败: {}", note.getSettleNo());
+	// 			note.setUpdateTime(LocalDateTime.now());
+	// 			note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
+	// 			noticeInfo.append(sysUser.getRealname() + ":结算提交失败-" + response.getMessage() + ";");
+	//
+	// 			log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
+	// 			redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + note.getId());
+	//
+	// 		}
+	// 	}
+	//
+	// 	noteService.updateBatchById(notes);
+	//
+	// 	/**
+	// 	 * 更新结算结果
+	// 	 */
+	// 	SettleNoteStatusOutput output = noteService.selectSettleNoteStatus(input.getId());
+	// 	WmScorePackage updateEntity = new WmScorePackage();
+	// 	updateEntity.setId(input.getId());
+	// 	updateEntity.setSettleStatus(output.toSettleStatus());
+	// 	wmScorePackageService.updateById(updateEntity);
+	//
+	// 	return R.ok(null, noticeInfo.toString());
+	// }
+
+	private R settleByShuiBangYun() {
 		return R.failed("因系统维护,暂时不能提起支付,有问题请联系客服");
 	}
 
+	/**
+	 * 税邦云
+	 *
+	 * @param input          结算数据
+	 * @param sysDeptSub     结算配置
+	 * @param wmScorePackage 积分包
+	 * @return 结果
+	 */
 	private R settleByShuiBangYun(WmScorePackageSettleInput input,
 								  SysDeptSub sysDeptSub,
 								  WmScorePackage wmScorePackage,
@@ -572,12 +1043,20 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		noteService.updateBatchById(notes);
 
 
-
 		for (int i = 0; i < notes.size(); i++) {
 			WmScorePackageSettleNote note = notes.get(i);
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			if (!Objects.equals(sysUser.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
+			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, GigTypeEnum.REN_LI_JIA)
+					.eq(SysUserSub::getUserId, sysUser.getUserId())
+			);
+
+			if (userSub == null){
+				log.info("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+				return R.failed("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+			}
+
+			if (!Objects.equals(userSub.getCertStatus(), TaxHelperCertStatus.CERT.getCode())) {
 				return R.failed(sysUser.getRealname() + "人员未认证或未绑卡,不能结算");
 			}
 
@@ -685,6 +1164,14 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		return R.ok(null, noticeInfo.toString());
 	}
 
+	/**
+	 * 人力家结算
+	 *
+	 * @param input          结算数据
+	 * @param sysDeptSub     结算配置
+	 * @param wmScorePackage 积分包
+	 * @return 结果
+	 */
 	private R settleByRenLiJia(WmScorePackageSettleInput input, SysDeptSub sysDeptSub, WmScorePackage wmScorePackage) {
 		List<WmScorePackageSettleNote> notes = input.getNotes();
 
@@ -712,6 +1199,14 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 			WmScorePackageSettleNote note = notes.get(i);
 
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
+			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery().eq(SysUserSub::getGigType, GigTypeEnum.REN_LI_JIA)
+					.eq(SysUserSub::getUserId, sysUser.getUserId())
+			);
+
+			if (userSub == null){
+				log.info("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+				return R.failed("结算对象-" + sysUser.getRealname() + ":认证信息不存在,不能结算");
+			}
 
 			if (StringUtils.isEmpty(sysUser.getIdCardNumber())) {
 				log.info("任务包众包代表-" + sysUser.getRealname() + ":身份证号未补录");
@@ -720,7 +1215,7 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 				return R.failed("任务包众包代表-" + sysUser.getRealname() + ":身份证号未补录");
 			}
 
-			if (!DingEnum.CER_STATUS_1.getType().equals(sysUser.getRljCertStatus())) {
+			if (!DingEnum.CER_STATUS_1.getType().equals(userSub.getCertStatus())) {
 				//认证中
 				log.info("结算对象-" + sysUser.getRealname() + ":未认证成功,不能结算");
 				return R.failed("结算对象-" + sysUser.getRealname() + ":未认证成功,不能结算");

+ 395 - 30
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageSettleNoteServiceImpl.java

@@ -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,11 +62,19 @@ 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.LocalDate;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -77,6 +92,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 +102,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 +471,40 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 		}
 
 		SysUser sysUser = sysUserService.getById(note.getUserId());
+
+		// 获取结算零工
+		GigTypeEnum gigTypeEnum = GigTypeEnum.resolve(Integer.parseInt(note.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() + "人员未认证或未绑卡,不能结算");
+				}
+				break;
+			default:
+				return R.failed(sysUser.getRealname() + "人员结算渠道不存在,不能结算");
 		}
 
 		/**
@@ -486,7 +521,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(note.getSubType())) {
+			String taxCode = sysDept.getTaxCode();
+			return settleByOlading(note, wmScorePackage, sysUser, taxCode);
+		}
+		// 税邦云
+		else {
 			String taxCode = sysDept.getTaxCode();
 			if (StringUtils.isNotEmpty(taxCode)) {
 				log.info("税邦云结算开始-获取会员所属企业的统一社会信用代码:{} ", taxCode);
@@ -519,6 +561,7 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 
 		String[] ids = input.getIdStr().split(",");
 		List<WmScorePackageSettleNote> noteList = new ArrayList<>(ids.length);
+		List<WmScorePackageSettleNote> oladingNoteList = new ArrayList<>(ids.length);
 		for (int i = 0; i < ids.length; i++) {
 			String id = ids[i];
 			WmScorePackageSettleNote note = this.baseMapper.selectById(id);
@@ -541,22 +584,40 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 			}
 
 			SysUser sysUser = sysUserService.getById(note.getUserId());
+
+			// 获取结算零工
+			GigTypeEnum gigTypeEnum = GigTypeEnum.resolve(Integer.parseInt(note.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() + ":正在结算,请勿重复结算");
 			}
-			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() + "人员未认证或未绑卡,不能结算");
+					}
+					break;
+				default:
+					return R.failed(sysUser.getRealname() + "人员结算渠道不存在,不能结算");
 			}
 
 			/**
@@ -573,14 +634,20 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 				String subjectName = sysDeptSub.getSubjectName();
 				settleByRenLiJia(note, config, wmScorePackage, subjectName);
 
-			} else {
+			}
+			// 自由职家
+			else if (SubjectTypeEnum.TYPE_OLADING.getCode().equals(note.getSubType())){
+				oladingNoteList.add(note);
+			}
+			// 税邦云
+			else {
 				noteList.add(note);
 			}
 		}
 
 		// 税邦云结算
+		String taxCode = sysDept.getTaxCode();
 		if (CollectionUtils.isNotEmpty(noteList)) {
-			String taxCode = sysDept.getTaxCode();
 			if (StringUtils.isNotEmpty(taxCode)) {
 				log.info("税邦云结算开始-获取会员所属企业的统一社会信用代码:{} ", taxCode);
 			} else {
@@ -594,6 +661,18 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 			return settleByTaxHelper(noteList, config, taxCode);
 			// return settleByTaxHelper();
 		}
+
+		// 自由职家结算
+		if (CollectionUtils.isNotEmpty(oladingNoteList)) {
+			if (StringUtils.isNotEmpty(taxCode)) {
+				log.info("自由职家结算开始-获取会员所属企业的统一社会信用代码:{} ", taxCode);
+			} else {
+				return R.failed("未配置企业的统一社会信用代码");
+			}
+			return batchSettleByOlading(oladingNoteList,taxCode);
+			// return settleByTaxHelper();
+		}
+
 		return R.ok();
 	}
 
@@ -602,6 +681,183 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 		return R.failed("因系统维护,暂时不能提起支付,有问题请联系客服");
 	}
 
+	/**
+	 * 税帮云结算
+	 *
+	 * @param noteList 结算记录
+	 * @param taxCode  企业三合一码
+	 * @return 结果
+	 */
+	private R batchSettleByOlading(List<WmScorePackageSettleNote> noteList, String taxCode) {
+
+		// 加锁
+		List<Integer> noteIdList = noteList.stream().filter(note ->
+						redisTemplate.opsForValue().setIfAbsent(
+								CacheConstants.SETTLE_PACKAGE_KEY + ":note_id_" + note.getId(),
+								noteList, CacheConstants.SETTLE_TIME, TimeUnit.DAYS))
+				.mapToInt(WmScorePackageSettleNote::getId).boxed().collect(Collectors.toList());
+
+		// 加锁记录数不等于提交记录数,说明存在在途交易
+		if (CollectionUtils.isEmpty(noteIdList)) {
+			log.error("当前用户存在其他结算请求");
+			return R.failed("当前用户存在其他结算请求");
+		} else {
+			if (!Objects.equals(noteList.size(), noteIdList.size())) {
+				// 删除锁
+				noteIdList.forEach(id -> redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + ":note_id_" + id));
+				log.error("当前用户存在其他结算请求");
+				return R.failed("当前用户存在其他结算请求");
+			}
+		}
+
+		HnqzUser operator = SecurityUtils.getUser();
+		String gigTokenUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/token?tenantId={tenantId}&action={action}&userId={userId}";
+		String gigSettleUrl = upmsConfig.getGigServiceUrl() + "/gig/operation/settlement";
+
+		List<Map<String, Object>> settleParamsMapper = new ArrayList<>();
+		Map<String, Map<String, Object>> detailMap = new HashMap<>();
+		noteList.forEach(note -> {
+			WmScorePackage wmScorePackage = wmScorePackageMapper.selectById(note.getPackageId());
+			// 封装结算参数
+			Map<String, Object> params;
+			if (detailMap.containsKey(note.getIdCardNumber())) {
+				params = detailMap.get(note.getIdCardNumber());
+				params.put("amount", String.valueOf(new BigDecimal((String) params.get("amount")).add(note.getSettleAmount()).doubleValue()));
+
+
+				LocalDate startTime = (LocalDate) params.get("taskStartTime");
+				LocalDate endTime = (LocalDate) params.get("taskEndTime");
+				LocalDate noteCreateTime = wmScorePackage.getCreateTime().toLocalDate();
+				LocalDate noteUpdateTime = wmScorePackage.getUpdateTime().toLocalDate();
+
+				if (noteCreateTime.isBefore(startTime)) {
+					params.put("taskStartTime", wmScorePackage.getCreateTime().toLocalDate());
+				}
+				if (noteUpdateTime.isAfter(endTime)) {
+					params.put("taskEndTime", wmScorePackage.getUpdateTime().toLocalDate());
+				}
+
+				Set<Integer> ids = (Set<Integer>) params.get("noteIds");
+				ids.add(note.getId());
+				params.put("noteIds", ids);
+			} else {
+				SysUser sysUser = sysUserService.getById(note.getUserId());
+				params = new HashMap<>(19);
+				params.put("tenantId", operator.getDeptId());
+				params.put("operatorId", operator.getId());
+				params.put("requestId", RandomStringUtils.randomAlphabetic(12));
+				params.put("taskName", String.format("%s(%s)_%s", sysUser.getRealname(), sysUser.getUsername(), 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", note.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");
+				params.put("taskDescription", "根据要求,执行、并完成学术推广活动,并以在线平台工具采集、记录活动内容");
+				params.put("acceptanceStandard", "完成不同任务获得不同任务积分,根据不同任务给与0~30000积分,每个积分兑换0.8~1.2元,按次数结算");
+
+				Set<Integer> noteIds = new HashSet<>();
+				noteIds.add(note.getId());
+				params.put("noteIds", noteIds);
+				detailMap.put(note.getIdCardNumber(), params);
+			}
+		});
+
+		detailMap.forEach((key, value) -> settleParamsMapper.add(value));
+
+
+		// 开始结算
+		for (Map<String, Object> params : settleParamsMapper) {
+
+			Set<Integer> noteIds = (Set<Integer>) params.get("noteIds");
+			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);
+
+				params.put("token", token);
+
+				// 发起结算
+				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)) {
+					noteIds.forEach(id -> {
+						log.info("自由职家结算提交成功");
+						//streamId 获取不到
+						if (StringUtils.isEmpty(settelObj.getStr("data"))) {
+							log.info("自由职家提交成功 streamId 获取不到");
+						}
+						WmScorePackageSettleNote note = new WmScorePackageSettleNote();
+						note.setId(id);
+						note.setUpdateTime(LocalDateTime.now());
+						note.setSettleNoteStatus(DingEnum.NOTE_STATUS_SUBMIT.getType());
+						// 新增字段streamId
+						note.setStreamId(settelObj.getStr("data"));
+						this.baseMapper.updateById(note);
+					});
+
+				} else {
+					noteIds.forEach(id -> {
+						WmScorePackageSettleNote note = new WmScorePackageSettleNote();
+						note.setId(id);
+						log.info("自由职家结算提交失败: {}", note.getSettleNo());
+						note.setUpdateTime(LocalDateTime.now());
+						note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
+						this.baseMapper.updateById(note);
+						log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
+						redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + ":note_id_" + note.getId());
+					});
+
+					return R.ok("结算失败");
+				}
+
+			} catch (Exception e) {
+				noteIds.forEach(id -> {
+					WmScorePackageSettleNote note = new WmScorePackageSettleNote();
+					note.setId(id);
+					log.info("自由职家结算提交失败: {}", note.getSettleNo());
+					note.setUpdateTime(LocalDateTime.now());
+					note.setSettleNoteStatus(DingEnum.NOTE_STATUS_FAIL.getType());
+					this.baseMapper.updateById(note);
+					log.info("认证状态异常,结算解锁settleNoteId:{}", note.getId());
+					redisTemplate.delete(CacheConstants.SETTLE_PACKAGE_KEY + ":note_id_" + note.getId());
+				});
+				return R.ok("结算失败");
+			}
+		}
+
+		return R.ok("提交结算成功");
+	}
+
 	/**
 	 * 税帮云结算
 	 *
@@ -698,6 +954,115 @@ 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");
+			params.put("taskDescription", "根据要求,执行、并完成学术推广活动,并以在线平台工具采集、记录活动内容");
+			params.put("acceptanceStandard", "完成不同任务获得不同任务积分,根据不同任务给与0~30000积分,每个积分兑换0.8~1.2元,按次数结算");
+
+
+			// 发起结算
+			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("因系统维护,暂时不能提起支付,有问题请联系客服");
 	}

+ 26 - 0
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/SysUserMapper.xml

@@ -58,6 +58,7 @@
 		<result column="city_code" property="cityCode"/>
 		<result column="user_type" property="userType"/>
 		<result column="bank_card_number" property="bankCardNumber"/>
+		<result column="bank_phone" property="bankPhone"/>
 		<result column="tax_helper_agreement_signature" property="taxHelperAgreementSignature"/>
 	</resultMap>
 
@@ -99,6 +100,7 @@
 		<result column="province_code" property="provinceCode"/>
 		<result column="city_code" property="cityCode"/>
 		<result column="user_type" property="userType"/>
+		<result column="bank_phone" property="bankPhone"/>
 		<result column="bank_card_number" property="bankCardNumber"/>
 		<collection property="roleList" ofType="com.qunzhixinxi.hnqz.admin.api.entity.SysRole"
 					select="com.qunzhixinxi.hnqz.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
@@ -142,6 +144,7 @@
 		<result column="province_code" property="provinceCode"/>
 		<result column="city_code" property="cityCode"/>
 		<result column="user_type" property="userType"/>
+		<result column="bank_phone" property="bankPhone"/>
 		<result column="bank_card_number" property="bankCardNumber"/>
 		<collection property="roleList" ofType="com.qunzhixinxi.hnqz.admin.api.entity.SysRole">
 			<id column="role_id" property="roleId"/>
@@ -698,4 +701,27 @@
 		</set>
 		where user_id = #{userId,jdbcType=BIGINT}
 	</update>
+
+
+	<select id="listUserDetails" resultMap="baseResultMap">
+		SELECT u.user_id,
+			   u.realname,
+			   u.username,
+			   u.id_card_number,
+			   u.tenant_id,
+			   u.dept_id,
+			   u.bank_phone,
+		       us.bank_card_number,
+			   us.gig_type,
+			   us.cert_status
+		FROM sys_user u
+				 LEFT JOIN sys_user_sub us on us.user_id = u.user_id
+		<where>
+			u.user_id in
+			<foreach collection="userIds" index="idx" item="userId" open="(" close=")" separator=",">
+				#{userId}
+			</foreach>
+		</where>
+
+	</select>
 </mapper>

+ 3 - 1
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmScorePackageMapper.xml

@@ -92,6 +92,7 @@
 		<result property="scorePackageStatus" column="score_package_status"/>
 		<result property="subType" column="sub_type"/>
 		<result property="drugProducerList" column="drug_producer"/>
+		<result property="omsOrderSn" column="oms_order_sn"/>
 
 	</resultMap>
 
@@ -1393,7 +1394,8 @@
 		       p.score,
 		       p.package_type2,
 		       p.sub_type,
-		       p.source_type
+		       p.source_type,
+		       p.oms_order_sn
 		FROM wm_score_package p, sys_dept d
 		WHERE
 		p.send_package_dept_id = d.dept_id