Browse Source

增加一个定时任务扫描机构付款信息
修改
修改人员信息手机号后对比机构手机号是否一样

hgw 3 years ago
parent
commit
528b1eb94a

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantInfo.java

@@ -81,6 +81,10 @@ public class TenantInfo implements Serializable {
     @ApiModelProperty(value = "状态0 草稿 1启动 2停用")
     private Integer state;
 
+    @TableField("user_id_")
+    @ApiModelProperty(value = "管理员账号id")
+    private Integer userId;
+
     @TableField("created_by_")
     @ApiModelProperty(value = "创建人")
     private Integer createdBy;
@@ -227,6 +231,14 @@ public class TenantInfo implements Serializable {
         this.state = state;
     }
 
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
     public Integer getCreatedBy() {
         return createdBy;
     }

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantOrderRecordService.java

@@ -19,5 +19,7 @@ public interface TenantOrderRecordService extends IService<TenantOrderRecord> {
 
     Map<String, Object> checkTenantOrder(String orderNo);
 
+    void checkTenantOrder();
+
 }
 

+ 16 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/EmployeeServiceImpl.java

@@ -11,20 +11,19 @@ import com.ym.mec.biz.dal.dto.SimpleUserDto;
 import com.ym.mec.biz.dal.entity.Employee;
 import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
+import com.ym.mec.biz.dal.entity.TenantInfo;
 import com.ym.mec.biz.dal.enums.EmployeeOperateEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.ParamEnum;
 import com.ym.mec.biz.dal.page.EmployeeQueryInfo;
-import com.ym.mec.biz.service.EmployeeService;
-import com.ym.mec.biz.service.ImGroupMemberService;
-import com.ym.mec.biz.service.ImUserFriendService;
-import com.ym.mec.biz.service.OaUserService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.ImGroupModel;
 import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.im.ImFeignService;
 import com.ym.mec.im.entity.GroupMember;
@@ -68,6 +67,8 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 	private CooperationOrganDao cooperationOrganDao;
 	@Autowired
 	private OaUserService oaUserService;
+    @Autowired
+    private TenantInfoService tenantInfoService;
 
 	@Override
 	public BaseDAO<Integer, Employee> getDAO() {
@@ -112,8 +113,8 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 			employee.setAvatar(user.getAvatar());
 		}
 
-		//todo 添加到OA 临时注释
-//		oaUserService.addOaUser(employee);
+		//添加到OA
+		oaUserService.addOaUser(employee);
 	}
 
 	@Override
@@ -144,6 +145,15 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 		imFeignService.update(new ImUserModel(employee.getUserId().toString(),employee.getRealName(),sysUser.getAvatar()));
 
 		employee.setAvatar(sysUser.getAvatar());
+        //更新机构信息
+        TenantInfo tenantInfo = tenantInfoService.getOne(new WrapperUtil<TenantInfo>()
+                .hasEq("user_id_",employee.getId()).queryWrapper());
+        if(Objects.nonNull(tenantInfo) && !Objects.equals(tenantInfo.getPhone(),employee.getPhone())){
+            tenantInfo.setPhone(employee.getPhone());
+            tenantInfo.setUpdatedTime(new Date());
+            tenantInfo.setUpdatedBy(sysUser.getId());
+            tenantInfoService.updateById(tenantInfo);
+        }
 
 		//更新OA信息
 		oaUserService.updateOaUser(employee);

+ 49 - 49
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -85,7 +85,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Override
     public void addTenantInfo(TenantInfoDto dto) {
         //校验手机号是否唯一
-        checkPhone(dto);
+        RBucket<Object> bucket = checkPhone(dto);
         //校验营业执照信息
         checkTsign(dto.getTsignCode());
 
@@ -106,6 +106,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                 tenantProductInfoService::addTenantProduct);
         //添加机构配置
         setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig);
+        //释放
+        bucket.delete();
     }
 
     /**
@@ -114,25 +116,25 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void updateTenantInfo(TenantInfoDto dto) {
-        //机构id
-        Integer tenantId = Optional.ofNullable(dto)
-                .map(TenantInfoDto::getId)
-                .orElseThrow(() -> new BizException("机构信息不能为空!"));
-
         //查询机构信息
-        TenantInfo tenantInfo = this.getById(tenantId);
-        if (Objects.isNull(tenantInfo)) {
-            throw new BizException("未找到该机构信息!");
-        }
+        TenantInfo tenantInfo = Optional.ofNullable(dto)
+                .map(TenantInfoDto::getId)
+                .map(this::getById)
+                .orElseThrow(() -> new BizException("未找到该机构信息,机构信息不能为空!"));
 
         //机构状态 1已缴费,并且 机构注册的手机号与本次修改后的手机号不同,就证明本次修改了手机号 则需要修改机构的账号信息
         if (1 == tenantInfo.getPayState() && !Objects.equals(tenantInfo.getPhone(), dto.getPhone())) {
             //校验修改后的手机号是否是唯一
-            checkPhone(dto);
-            //修改机构用户手机号(登录账号)信息
-            SysUser tenantUser = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone());
-            tenantUser.setPhone(dto.getPhone());
-            sysUserFeignService.updateSysUser(tenantUser);
+            RBucket<Object> bucket = checkPhone(dto);
+            //
+            if (Objects.nonNull(tenantInfo.getUserId())) {
+                //
+                SysUser tenantUser = sysUserFeignService.queryUserById(tenantInfo.getUserId());
+                tenantUser.setPhone(dto.getPhone());
+                sysUserFeignService.updateSysUser(tenantUser);
+            }
+            //释放锁
+            bucket.delete();
         }
 
         //机构状态 0未缴费
@@ -141,7 +143,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             checkTsign(dto.getTsignCode());
             //修改产品
             if (Objects.nonNull(dto.getProductInfo())) {
-                setIdByApply(tenantId, dto.getProductInfo(), dto.getProductInfo()::setTenantId,
+                setIdByApply(tenantInfo.getId(), dto.getProductInfo(), dto.getProductInfo()::setTenantId,
                         tenantProductInfoService::updateTenantProduct);
             }
         }
@@ -154,7 +156,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 
         //修改机构配置
         if (Objects.nonNull(dto.getConfig())) {
-            setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::updateConfig);
+            setIdByApply(tenantInfo.getId(), dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::updateConfig);
         }
     }
 
@@ -199,33 +201,33 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 第一个启用默认激活账号等信息
      *
      * @param id    机构id
-     * @param state 机构状态 0草稿 1启动 2停用
+     * @param state 机构状态1启动 2停用
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void opsTenantState(Integer id, Integer state) {
-        if (Objects.nonNull(state)) {
-            if (state == 1 || state == 2) {
-                TenantInfo tenantInfo = baseMapper.selectById(id);
-                if (Objects.isNull(tenantInfo)) {
-                    throw new BizException("该机构数据异常! ID : [" + id + "]");
+        if (Objects.nonNull(state) && state == 1 || state == 2) {
+            TenantInfo tenantInfo = baseMapper.selectById(id);
+            if (Objects.isNull(tenantInfo)) {
+                throw new BizException("该机构数据异常! ID : [" + id + "]");
+            }
+            Integer userId = getUserId();
+            tenantInfo.setUpdatedBy(userId);
+            tenantInfo.setUpdatedTime(new Date());
+            tenantInfo.setState(state);
+            //状态= 开通
+            if (state == 1) {
+                if (tenantInfo.getPayState() == 0) {
+                    throw new BizException("机构未缴费无法开通!");
                 }
-                Integer userId = getUserId();
-                tenantInfo.setUpdatedBy(userId);
-                tenantInfo.setUpdatedTime(new Date());
-                tenantInfo.setState(state);
-                //状态= 开通并且已支付完成
-                if (state == 1) {
-                    if (tenantInfo.getPayState() == 1) {
-                        //判断是否初次启用
-                        firstOpen(tenantInfo);
-                    } else {
-                        throw new BizException("机构未缴费无法开通!");
-                    }
+                //已支付完成 并且 没有创建用户信息
+                if (tenantInfo.getPayState() == 1 && Objects.nonNull(tenantInfo.getUserId())) {
+                    //初次开通
+                    checkFirstOpen(tenantInfo);
                 }
-                baseMapper.updateById(tenantInfo);
-                return;
             }
+            baseMapper.updateById(tenantInfo);
+            return;
         }
         throw new BizException("传入机构状态参数异常!");
     }
@@ -235,7 +237,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      *
      * @param tenantInfo 机构信息
      */
-    private void firstOpen(TenantInfo tenantInfo) {
+    private void checkFirstOpen(TenantInfo tenantInfo) {
         Integer tenantId = tenantInfo.getId();
         SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone());
         if (Objects.nonNull(user)) {
@@ -280,6 +282,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         assetsInfo.setFrozenAmount(BigDecimal.ZERO);
         assetsInfo.setCreatedTime(new Date());
         assetsInfoService.save(assetsInfo);
+        //释放锁
+        bucket.delete();
     }
 
     //拆分菜单获取菜单ID
@@ -314,6 +318,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         e.setEntryDate(LocalDate.now().toDate());
         e.setRoles(roles);
         e.setRoleIds(roles);
+        e.setUserType(SysUserType.SYSTEM.getCode());
         e.setOrganIdList(String.valueOf(orgId));
         try {
             log.info("createUser >>>> {}", e);
@@ -465,9 +470,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     /**
      * 校验手机号
      */
-    private void checkPhone(TenantInfoDto dto) {
+    private RBucket<Object> checkPhone(TenantInfoDto dto) {
         //防止重复点击 加锁
-        String key = "Tenant_First_Add:" + dto.getPhone();
+        String key = "Tenant_Check_Phone:" + dto.getPhone();
         RBucket<Object> bucket = redissonClient.getBucket(key);
         //原子操作 抢锁成功为true
         if (!bucket.trySet(dto.getPhone(), 1L, TimeUnit.MINUTES)) {
@@ -479,9 +484,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                 .orElse(null);
         if (Objects.nonNull(sysUser)) {
             if (sysUser.getUserType().contains(SysUserType.SYSTEM.getCode())) {
+                bucket.delete();
                 throw new BizException("该手机号已被注册!");
             }
         }
+        return bucket;
     }
 
     /**
@@ -493,15 +500,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * @param action    需要执行的操作
      */
     private <T> void setIdByApply(Integer tenantId, T clazz, Consumer<Integer> setOption, Consumer<T> action) {
-        Optional.ofNullable(clazz)
-                .filter(c -> Objects.nonNull(setOption))
-                .filter(c -> Objects.nonNull(action))
-                .filter(c -> Objects.nonNull(tenantId))
-                .map(c -> {
-                    setOption.accept(tenantId);
-                    return c;
-                })
-                .ifPresent(action);
+        setOption.accept(tenantId);
+        action.accept(clazz);
     }
 
     /**

+ 74 - 24
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -14,6 +14,7 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.thirdparty.adapay.Payment;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.joda.time.LocalDateTime;
 import org.slf4j.Logger;
@@ -21,10 +22,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表服务实现类
@@ -45,6 +43,9 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
     @Autowired
     private TenantInfoService tenantInfoService;
 
+    //订单不存在
+    public static final String PAYMENT_ID_NOT_EXISTS = "payment_id_not_exists";
+
     @Override
     public PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto) {
         Page<TenantOrderRecord> pageInfo = PageUtil.getPage(dto.getPage(), dto.getRows());
@@ -54,12 +55,75 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
         return PageUtil.pageInfo(baseMapper.queryPage(pageInfo, dto));
     }
 
-    public static final String PAYMENT_ID_NOT_EXISTS = "payment_id_not_exists";
-
+    /**
+     * 校验订单状态
+     *
+     * @param orderNo 我方订单编号
+     */
     @Override
     public Map<String, Object> checkTenantOrder(String orderNo) {
         TenantOrderRecord orderRecord = this.getOne(new WrapperUtil<TenantOrderRecord>()
                 .hasEq("order_no_", orderNo).queryWrapper());
+
+        //主动去第三方查询订单状态
+        checkTransOrderState(orderRecord);
+
+        //返回
+        Map<String, Object> result = new HashMap<>();
+        result.put("groupType", orderRecord.getOrderType());
+        //订单信息
+        Map<String, Object> order = new HashMap<>();
+        result.put("order", order);
+        order.put("orderNo", orderRecord.getOrderNo());
+        order.put("expectAmount", orderRecord.getExpectAmount());
+        order.put("type", orderRecord.getOrderType());
+        //购买的信息
+        Map<String, Object> detail = new HashMap<>();
+        result.put("detail", detail);
+
+        log.info("checkTenantOrder  getOrderState>>>>> {}", JSON.toJSONString(orderRecord));
+        getOrderState(orderRecord, result);
+        log.info("checkTenantOrder  result >>>>> {}", result);
+        return result;
+    }
+
+    @Override
+    public void checkTenantOrder() {
+        List<TenantOrderRecord> list = this.list(new WrapperUtil<TenantOrderRecord>().queryWrapper()
+                .isNotNull("trans_no_")
+                .eq("order_state_", 0));
+        if (CollectionUtils.isNotEmpty(list)) {
+            list.forEach(record -> {
+                checkTransOrderState(record);
+                if (record.getOrderState() == 1) {
+                    //开通缴费
+                    if (TenantOrderRecordEnum.TENANT_OPEN.getCode().equals(record.getOrderType())) {
+                        //机构产品信息
+                        TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
+                                .hasEq("tenant_id_", record.getTenantId()).queryWrapper());
+                        //修改机构信息
+                        TenantInfo tenantInfo = new TenantInfo();
+                        tenantInfo.setId(record.getTenantId());
+                        tenantInfo.setPayState(1);
+                        tenantInfoService.updateById(tenantInfo);
+                        //修改机构产品信息
+                        productInfo.setPayDate(new Date());
+                        productInfo.setTenantId(record.getTenantId());
+                        tenantProductInfoService.updateById(productInfo);
+                    }
+                    //修改流水
+                    LocalDateTime now = LocalDateTime.now();
+                    record.setPayDate(now.toLocalDate().toDate());
+                    record.setPayTime(now.toDate());
+                    baseMapper.updateById(record);
+                }
+            });
+        }
+
+    }
+
+    //主动去第三方查询订单状态
+    private void checkTransOrderState(TenantOrderRecord orderRecord) {
         if (StringUtils.equals(orderRecord.getPaymentChannel(), PaymentChannelEnum.ADAPAY.getCode())) {
             Map<String, Object> payment;
             try {
@@ -90,24 +154,6 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
                 log.error("checkTenantOrder  payment error>>>>> {}", JSON.toJSONString(orderRecord));
             }
         }
-
-        //返回
-        Map<String, Object> result = new HashMap<>();
-        result.put("groupType", orderRecord.getOrderType());
-        //订单信息
-        Map<String, Object> order = new HashMap<>();
-        result.put("order", order);
-        order.put("orderNo", orderRecord.getOrderNo());
-        order.put("expectAmount", orderRecord.getExpectAmount());
-        order.put("type", orderRecord.getOrderType());
-        //购买的信息
-        Map<String, Object> detail = new HashMap<>();
-        result.put("detail", detail);
-
-        log.info("checkTenantOrder  getOrderState>>>>> {}", JSON.toJSONString(orderRecord));
-        getOrderState(orderRecord, result);
-        log.info("checkTenantOrder  result >>>>> {}", result);
-        return result;
     }
 
     private void getOrderState(TenantOrderRecord orderRecord, Map<String, Object> result) {
@@ -152,6 +198,10 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
         detail.put("mode", serveDetail.getMode());
         detail.put("num", productInfo.getExpiryCount());
 
+        orderSuccessOps(orderRecord, productInfo);
+    }
+
+    private void orderSuccessOps(TenantOrderRecord orderRecord, TenantProductInfo productInfo) {
         TenantInfo tenantInfo = new TenantInfo();
         tenantInfo.setId(orderRecord.getTenantId());
         tenantInfo.setPayState(1);

+ 5 - 4
mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -12,24 +12,25 @@
         <result column="logo_" jdbcType="VARCHAR" property="logo"/>
         <result column="customer_service_phone_" jdbcType="VARCHAR" property="customerServicePhone"/>
         <result column="remark_" jdbcType="VARCHAR" property="remark"/>
+        <result column="tsign_code_" jdbcType="VARCHAR" property="tsignCode"/>
+        <result column="tsign_name_" jdbcType="VARCHAR" property="tsignName"/>
+        <result column="area_id_" jdbcType="INTEGER" property="areaId"/>
         <result column="domain_name_" jdbcType="VARCHAR" property="domainName"/>
         <result column="data_source_" jdbcType="VARCHAR" property="dataSource"/>
         <result column="pay_state_" jdbcType="INTEGER" property="payState"/>
         <result column="state_" jdbcType="INTEGER" property="state"/>
+        <result column="user_id_" jdbcType="INTEGER" property="userId"/>
         <result column="created_by_" jdbcType="INTEGER" property="createdBy"/>
         <result column="created_time_" jdbcType="TIMESTAMP" property="createdTime"/>
         <result column="updated_by_" jdbcType="INTEGER" property="updatedBy"/>
         <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
-        <result column="tsign_code_" jdbcType="VARCHAR" property="tsignCode"/>
-        <result column="tsign_name_" jdbcType="VARCHAR" property="tsignName"/>
-        <result column="area_id_" jdbcType="INTEGER" property="areaId"/>
     </resultMap>
 
     <sql id="Base_Column_List">
         id_
         , name_, contacts_, phone_, address_, email_, logo_, customer_service_phone_, remark_, domain_name_,
         data_source_, pay_state_, state_, created_by_, created_time_, updated_by_, updated_time_, tsign_code_, tsign_name_,
-        area_id_
+        area_id_,user_id_
     </sql>
 
     <resultMap id="TenantInfoInfoResult" type="com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo">

+ 6 - 0
mec-client-api/src/main/java/com/ym/mec/task/TaskRemoteService.java

@@ -223,4 +223,10 @@ public interface TaskRemoteService {
 	 */
 	@GetMapping("task/remarkCountFlag")
     void remarkCountFlag();
+
+    /**
+     * 定时校验-机构订单状态
+     */
+	@GetMapping("task/checkTenantOrder")
+    void checkTenantOrder();
 }

+ 24 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/CheckTenantOrder.java

@@ -0,0 +1,24 @@
+package com.ym.mec.task.jobs;
+
+import com.ym.mec.task.TaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author hgw
+ * Created by 2021-12-24
+ */
+@Service
+public class CheckTenantOrder extends BaseTask {
+
+    @Autowired
+    private TaskRemoteService taskRemoteService;
+
+    @Override
+    public void execute() throws TaskException {
+        taskRemoteService.checkTenantOrder();
+    }
+
+}

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TaskController.java

@@ -106,6 +106,8 @@ public class TaskController extends BaseController {
 	private SysMusicCompareRecordService sysMusicCompareRecordService;
 	@Autowired
 	private TenantInfoService tenantInfoService;
+    @Autowired
+    private TenantOrderRecordService tenantOrderRecordService;
 
 	@GetMapping(value = "/syncImHistoryMessageTask")
 	// 同步即时通讯聊天记录
@@ -509,4 +511,10 @@ public class TaskController extends BaseController {
 	public void remarkCountFlag(){
 //		studentService.remarkCountFlag();
 	}
+
+    @ApiOperation("定时校验-机构订单状态")
+    @GetMapping(value = "/checkTenantOrder")
+    public void checkTenantOrder(){
+        tenantOrderRecordService.checkTenantOrder();
+    }
 }