|  | @@ -1,5 +1,6 @@
 | 
											
												
													
														|  |  package com.ym.mec.biz.service.impl;
 |  |  package com.ym.mec.biz.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import com.alibaba.fastjson.JSON;
 | 
											
												
													
														|  |  import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 |  |  import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 | 
											
												
													
														|  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 |  |  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
											
												
													
														|  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
											
										
											
												
													
														|  | @@ -7,26 +8,34 @@ import com.google.common.collect.Lists;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.client.SysUserFeignService;
 |  |  import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.entity.SysRole;
 |  |  import com.ym.mec.auth.api.entity.SysRole;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.entity.SysUser;
 |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.biz.dal.dao.OrganizationDao;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dao.TenantInfoDao;
 |  |  import com.ym.mec.biz.dal.dao.TenantInfoDao;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.TenantConfigDto;
 |  |  import com.ym.mec.biz.dal.dto.TenantConfigDto;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.TenantInfoDto;
 |  |  import com.ym.mec.biz.dal.dto.TenantInfoDto;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.TenantProductInfoDto;
 |  |  import com.ym.mec.biz.dal.dto.TenantProductInfoDto;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.entity.*;
 |  |  import com.ym.mec.biz.dal.entity.*;
 | 
											
												
													
														|  | -import com.ym.mec.biz.dal.enums.JobNatureEnum;
 |  | 
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.biz.dal.enums.*;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
 |  |  import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
 | 
											
												
													
														|  |  import com.ym.mec.biz.service.*;
 |  |  import com.ym.mec.biz.service.*;
 | 
											
												
													
														|  |  import com.ym.mec.common.exception.BizException;
 |  |  import com.ym.mec.common.exception.BizException;
 | 
											
												
													
														|  |  import com.ym.mec.common.page.PageInfo;
 |  |  import com.ym.mec.common.page.PageInfo;
 | 
											
												
													
														|  |  import com.ym.mec.common.page.PageUtil;
 |  |  import com.ym.mec.common.page.PageUtil;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.common.service.IdGeneratorService;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.thirdparty.yqpay.Msg;
 | 
											
												
													
														|  |  import org.apache.commons.collections.CollectionUtils;
 |  |  import org.apache.commons.collections.CollectionUtils;
 | 
											
												
													
														|  |  import org.joda.time.LocalDate;
 |  |  import org.joda.time.LocalDate;
 | 
											
												
													
														|  | 
 |  | +import org.joda.time.LocalDateTime;
 | 
											
												
													
														|  |  import org.redisson.api.RBucket;
 |  |  import org.redisson.api.RBucket;
 | 
											
												
													
														|  |  import org.redisson.api.RedissonClient;
 |  |  import org.redisson.api.RedissonClient;
 | 
											
												
													
														|  | 
 |  | +import org.slf4j.Logger;
 | 
											
												
													
														|  | 
 |  | +import org.slf4j.LoggerFactory;
 | 
											
												
													
														|  |  import org.springframework.beans.BeanUtils;
 |  |  import org.springframework.beans.BeanUtils;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
												
													
														|  |  import org.springframework.transaction.annotation.Transactional;
 |  |  import org.springframework.transaction.annotation.Transactional;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import java.math.BigDecimal;
 | 
											
												
													
														|  |  import java.util.*;
 |  |  import java.util.*;
 | 
											
												
													
														|  |  import java.util.concurrent.TimeUnit;
 |  |  import java.util.concurrent.TimeUnit;
 | 
											
												
													
														|  |  import java.util.function.Consumer;
 |  |  import java.util.function.Consumer;
 | 
											
										
											
												
													
														|  | @@ -34,6 +43,7 @@ import java.util.stream.Collectors;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  @Service
 |  |  @Service
 | 
											
												
													
														|  |  public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService {
 |  |  public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService {
 | 
											
												
													
														|  | 
 |  | +    private static final Logger log = LoggerFactory.getLogger(TenantInfoServiceImpl.class);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private SysUserFeignService sysUserFeignService;
 |  |      private SysUserFeignService sysUserFeignService;
 | 
											
										
											
												
													
														|  | @@ -49,6 +59,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 | 
											
												
													
														|  |      private RedissonClient redissonClient;
 |  |      private RedissonClient redissonClient;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private SysUserTsignService sysUserTsignService;
 |  |      private SysUserTsignService sysUserTsignService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private OrganizationDao organizationDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private PayService payService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private IdGeneratorService idGenerator;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private SysConfigDao sysConfigDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private TenantOrderRecordService tenantOrderRecordService;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 新增机构
 |  |       * 新增机构
 | 
											
										
											
												
													
														|  | @@ -78,6 +98,18 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 | 
											
												
													
														|  |                  tenantProductInfoService::addTenantProduct);
 |  |                  tenantProductInfoService::addTenantProduct);
 | 
											
												
													
														|  |          //添加机构配置
 |  |          //添加机构配置
 | 
											
												
													
														|  |          setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
 |  |          setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
 | 
											
												
													
														|  | 
 |  | +        //创建一个和机构同名称的“分部”
 | 
											
												
													
														|  | 
 |  | +        createOrg(tenantInfo);
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    //创建一个和机构同名称的“分部”
 | 
											
												
													
														|  | 
 |  | +    private void createOrg(TenantInfo tenantInfo) {
 | 
											
												
													
														|  | 
 |  | +        Organization organization = new Organization();
 | 
											
												
													
														|  | 
 |  | +        organization.setName(tenantInfo.getName());
 | 
											
												
													
														|  | 
 |  | +        organization.setDelFlag(YesOrNoEnum.NO);
 | 
											
												
													
														|  | 
 |  | +        organization.setGradeType(GradeTypeEnum.SIX_PLUS);
 | 
											
												
													
														|  | 
 |  | +        organization.setCreateTime(new Date());
 | 
											
												
													
														|  | 
 |  | +        organizationDao.insert(organization);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
										
											
												
													
														|  | @@ -283,10 +315,96 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 机构缴费
 |  |       * 机构缴费
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  | -    public void pay(){
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public Map<String, Object> pay(Integer tenantId) throws Exception {
 | 
											
												
													
														|  | 
 |  | +        TenantInfo tenantInfo = Optional.ofNullable(tenantId)
 | 
											
												
													
														|  | 
 |  | +                .map(baseMapper::selectById)
 | 
											
												
													
														|  | 
 |  | +                .orElseThrow(() -> new BizException("未查询到机构信息!"));
 | 
											
												
													
														|  | 
 |  | +        //机构产品信息
 | 
											
												
													
														|  | 
 |  | +        TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
 | 
											
												
													
														|  | 
 |  | +                .eq("tenant_id_", tenantId));
 | 
											
												
													
														|  | 
 |  | +        //生成订单编号
 | 
											
												
													
														|  | 
 |  | +        String orderNo = idGenerator.generatorId("payment") + "";
 | 
											
												
													
														|  | 
 |  | +        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 | 
											
												
													
														|  | 
 |  | +        TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_OPEN;
 | 
											
												
													
														|  | 
 |  | +        //获取分部信息
 | 
											
												
													
														|  | 
 |  | +        Organization organization = organizationDao.getByName(tenantInfo.getName(), tenantId);
 | 
											
												
													
														|  | 
 |  | +        if (Objects.isNull(organization)) {
 | 
											
												
													
														|  | 
 |  | +            throw new BizException("未查询到机构分部信息!");
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        Map<String, Object> payMap = new HashMap<>();
 | 
											
												
													
														|  | 
 |  | +        int orderState = 0;
 | 
											
												
													
														|  | 
 |  | +        //消费大于0元则拉起支付
 | 
											
												
													
														|  | 
 |  | +        if (productInfo.getPayAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
											
												
													
														|  | 
 |  | +            payMap = payService.getPayMap(
 | 
											
												
													
														|  | 
 |  | +                    productInfo.getPayAmount(),
 | 
											
												
													
														|  | 
 |  | +                    BigDecimal.ZERO,
 | 
											
												
													
														|  | 
 |  | +                    orderNo,
 | 
											
												
													
														|  | 
 |  | +                    baseApiUrl + "/WEB-SERVER/tenantInfo/notify",
 | 
											
												
													
														|  | 
 |  | +                    baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
 | 
											
												
													
														|  | 
 |  | +                    tenantEnum.getMsg(),
 | 
											
												
													
														|  | 
 |  | +                    tenantEnum.getMsg(),
 | 
											
												
													
														|  | 
 |  | +                    1,//临时写死
 | 
											
												
													
														|  | 
 |  | +                    tenantEnum.getCode()
 | 
											
												
													
														|  | 
 |  | +            );
 | 
											
												
													
														|  | 
 |  | +        } else {
 | 
											
												
													
														|  | 
 |  | +            //已支付
 | 
											
												
													
														|  | 
 |  | +            orderState = 1;
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        createOrderRecord(tenantId, productInfo.getPayAmount(), orderNo, tenantEnum, orderState);
 | 
											
												
													
														|  | 
 |  | +        log.info("tenant pay >>>>> " + JSON.toJSONString(payMap));
 | 
											
												
													
														|  | 
 |  | +        return payMap;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    //生成订单
 | 
											
												
													
														|  | 
 |  | +    private void createOrderRecord(Integer tenantId, BigDecimal payAmount, String orderNo, TenantOrderRecordEnum tenantEnum, Integer orderState) {
 | 
											
												
													
														|  | 
 |  | +        LocalDateTime now = LocalDateTime.now();
 | 
											
												
													
														|  | 
 |  | +        TenantOrderRecord record = new TenantOrderRecord();
 | 
											
												
													
														|  | 
 |  | +        record.setTenantId(tenantId);
 | 
											
												
													
														|  | 
 |  | +        record.setOrderNo(orderNo);
 | 
											
												
													
														|  | 
 |  | +        record.setOrderType(tenantEnum.getCode());
 | 
											
												
													
														|  | 
 |  | +        record.setPaymentChannel(PaymentChannelEnum.ADAPAY.getCode());
 | 
											
												
													
														|  | 
 |  | +        record.setExpectAmount(payAmount);
 | 
											
												
													
														|  | 
 |  | +        record.setActualAmount(payAmount);
 | 
											
												
													
														|  | 
 |  | +        record.setOrderState(orderState);
 | 
											
												
													
														|  | 
 |  | +        record.setPayDate(now.toLocalDate().toDate());
 | 
											
												
													
														|  | 
 |  | +        record.setPayTime(now.toDate());
 | 
											
												
													
														|  | 
 |  | +        record.setCreatedTime(now.toDate());
 | 
											
												
													
														|  | 
 |  | +        tenantOrderRecordService.save(record);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * 支付消息回调
 | 
											
												
													
														|  | 
 |  | +     *
 | 
											
												
													
														|  | 
 |  | +     * @param msg
 | 
											
												
													
														|  | 
 |  | +     * @return
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    @Override
 | 
											
												
													
														|  | 
 |  | +    public Msg orderNotify(Msg msg) {
 | 
											
												
													
														|  | 
 |  | +        log.info("tenant orderNotify >>>>> " +msg.toString());
 | 
											
												
													
														|  | 
 |  | +        msg.setMsg("fail");
 | 
											
												
													
														|  | 
 |  | +        Map<String, String> notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
 | 
											
												
													
														|  | 
 |  | +        TenantOrderRecord record = new TenantOrderRecord();
 | 
											
												
													
														|  | 
 |  | +        record.setOrderNo(notifyMap.get("merMerOrderNo"));
 | 
											
												
													
														|  | 
 |  | +        record.setTransNo(notifyMap.get("orderNo"));
 | 
											
												
													
														|  | 
 |  | +        String channelType = notifyMap.get("channelType").equals("1") ? "WXPay" : (notifyMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
 | 
											
												
													
														|  | 
 |  | +        record.setPayChannel(channelType);
 | 
											
												
													
														|  | 
 |  | +        //支付中订单存在,更新状态
 | 
											
												
													
														|  | 
 |  | +        if (msg.getResponseType().equals("1") && notifyMap.size() > 0 && msg.getCode().equals("88")) {
 | 
											
												
													
														|  | 
 |  | +            //tradeState 88就是正确的 其他错误的
 | 
											
												
													
														|  | 
 |  | +//            DealStatusEnum
 | 
											
												
													
														|  | 
 |  | +//            notifyMap.put("totalMoney", notifyMap.get("payAmount"));
 | 
											
												
													
														|  | 
 |  | +            record.setOrderState(1);
 | 
											
												
													
														|  | 
 |  | +            msg.setCode("000000");
 | 
											
												
													
														|  | 
 |  | +            msg.setMsg("success");
 | 
											
												
													
														|  | 
 |  | +        } else {
 | 
											
												
													
														|  | 
 |  | +            //支付失败
 | 
											
												
													
														|  | 
 |  | +            record.setOrderState(2);
 | 
											
												
													
														|  | 
 |  | +        }
 | 
											
												
													
														|  | 
 |  | +        tenantOrderRecordService.update(record, new QueryWrapper<TenantOrderRecord>()
 | 
											
												
													
														|  | 
 |  | +                .eq("order_no_", record.getOrderNo()));
 | 
											
												
													
														|  | 
 |  | +        log.info("tenant orderNotify return>>>>> " + msg.toString());
 | 
											
												
													
														|  | 
 |  | +        return msg;
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 校验手机号
 |  |       * 校验手机号
 |