根据银行流水批量创建到款认领并根据角色查询所有员工ID并发送CRM消息通知

/**
 * @author 翘楚
 * @codeName 根据银行流水批量创建到款认领
 * @description 是否生成到款认款:否【true、false】
 */
def retSel = Fx.object.find("BankStatementObj",
        FQLAttribute.builder()
                .columns(["_id", "name", "arrival_date", "amount_received", "owner"])
                .queryTemplate(QueryTemplate.AND(["is_related_received_payment": QueryOperator.EQ("false")]))
                .build(),
        SelectAttribute.builder().build()).result() as QueryResult
List dataList = retSel['dataList'] as List
/**
 * @codeName 根据角色查询所有员工ID并发送CRM消息通知
 * @description 根据角色查询所有员工ID并发送CRM消息通知
 * @note 排除合伙人
 * @函数需求编号
 */
List roleCodes = ["00000000000000000000000000000015"]
// 调用方法获取用户信息
def (boolean errorR, List dataR, String messageR) = Fx.auth.user.getUsersByRoleCodes(roleCodes)
if (errorR) {
    // 如果有错误信息,记录日志
    log.info("error: " + messageR)
} else {
    // 记录成功获取的数据
    log.info(dataR)
}
boolean isBj = false
// 定义正则表达式模式 需要过滤的 userId 列表
def bJPattern = ~/^(1186|1187|1188|1189|1050|1075)$/
List userIdList = [];
dataR.each { itemR ->
    String userId = itemR['userId'] as String;
    isBj = bJPattern.matcher(userId).matches();
    if (!isBj) {
        userIdList.add(userId);
    }
}
log.info(userIdList)
List partitionList = Fx.utils.listPartition(dataList, 100)
partitionList.each { item ->
    List formattedList
    formattedList = item.collect { data ->
        def dataMap = data as Map // 将data转换为Map类型
        Date arrDate = dataMap['arrival_date'] as Date;
        Map masterData = [
                "bank_statement_id": dataMap['_id'] as String,
                "name"             : dataMap['name'] as String,
                "arrival_date"     : arrDate.toTimestamp(),
                "amount_received"  : dataMap['amount_received'] as String,
                "owner"            : dataMap['owner'] as List,
        ]
        def (Boolean error2, Map result2, String errorMessage2) = Fx.object.create("ReceivedPaymentObj", masterData, null, true)
        if (error2) {
            log.info(errorMessage2)
        } else {
            String id = result2.data['_id'] as String;
            //自定义接收用户ID
            //def userTest = ["1331", "1332"]
            //List partitionListR = Fx.utils.listPartition(userTest, 1)
            List partitionListR = Fx.utils.listPartition(userIdList, 50)
            partitionListR.each { itemR2 ->
                //根据id分批组装数据
                List userIds = itemR2 as List
                Fx.log.info("当前id分批组装数据条数:" + userIds.size())
                log.info(userIds)
                //Fx.log.info("实际发送的数据条数:" + userIdList.size())
                Notice objectNotify = Notice.objectNotice("ReceivedPaymentObj", id)
                def (Boolean dataErrorR, String dataNoticeR, String errorMessageR) = Fx.message.sendNotice("到款认领", "请确认到款认领", userIds, objectNotify)
                if (dataErrorR) {
                    log.info(errorMessageR)
                } else {
                    log.info(dataNoticeR)
                }
            }
        }
    }
}

参考:
1、Fx.auth.user.getRolesByUsers
Fx.auth | 纷享销客 | 帮助中心
2、Fx.message.sendNotice
Fx.message | 纷享销客 | 帮助中心
3、Fx.object.find
Fx.object | 纷享销客 | 帮助中心 
4、Fx.object.create
Fx.object | 纷享销客 | 帮助中心

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值