Browse Source

Merge remote-tracking branch 'origin/saas' into saas

yanite 3 năm trước cách đây
mục cha
commit
949c628059

+ 9 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/TenantInfoSendMsgService.java

@@ -2,5 +2,13 @@ package com.ym.mec.biz.service;
 
 public interface TenantInfoSendMsgService {
 
-    void platformSendToAll(String email, String phone, Object[] objs);
+    /**
+     * 以平台的名义发送邮件及短信
+     *
+     * @param receiveUserId 接收者userId
+     * @param email         接收email的地址
+     * @param phone         接收短信的电话
+     * @param objs          发送的信息
+     */
+    void platformSendToAll(Integer receiveUserId, String email, String phone, Object[] objs);
 }

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

@@ -37,7 +37,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.util.*;
-import java.util.concurrent.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
 
 @Service
@@ -115,11 +117,11 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 				throw new BizException("员工已存在");
 			}
 		}
-		// 修改 gym + 联系人手机后4位
-		int phoneStrLen = employee.getPhone().length();
-		employee.setPassword(new BCryptPasswordEncoder().encode("gym" + employee.getPhone().substring(phoneStrLen - 4, phoneStrLen)));
-		// employee.setPassword(new BCryptPasswordEncoder().encode(ParamEnum.INIT_PASSWORD.getCode().toString()));
-		employee.setUserType("SYSTEM");
+        if (StringUtils.isBlank(employee.getPassword())) {
+            int phoneStrLen = employee.getPhone().length();
+            employee.setPassword(new BCryptPasswordEncoder().encode("gym" + employee.getPhone().substring(phoneStrLen - 4, phoneStrLen)));
+        }
+        employee.setUserType("SYSTEM");
 		teacherDao.addSysUser(employee);
 		employee.setUserId(employee.getId());
         employeeDao.insert(employee);

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -153,7 +153,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
                 //当前余额大于300 并且 本次扣除后剩余额度小于300 就发信息提醒
                 if (balance.compareTo(new BigDecimal(300)) > -1 && balance.compareTo(after) < 0) {
                     TenantInfo t = tenantInfoService.getById(course.getTenantId());
-                    tenantInfoSendMsgService.platformSendToAll(t.getEmail(), t.getPhone(), new Object[]{t.getName()});
+                    tenantInfoSendMsgService.platformSendToAll(t.getUserId(), t.getEmail(), t.getPhone(), new Object[]{t.getName()});
                 }
             }
         });

+ 12 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoSendMsgServiceImpl.java

@@ -41,29 +41,31 @@ public class TenantInfoSendMsgServiceImpl implements TenantInfoSendMsgService {
     /**
      * 以平台的名义发送邮件及短信
      *
-     * @param email 发送的地址 电话或者邮件
-     * @param objs  发送的信息
+     * @param receiveUserId 接收者userId
+     * @param email         接收email的地址
+     * @param phone         接收短信的电话
+     * @param objs          发送的信息
      */
     @Override
-    public void platformSendToAll(String email, String phone, Object[] objs) {
+    public void platformSendToAll(Integer receiveUserId, String email, String phone, Object[] objs) {
         Map<Integer, String> sendPar = new HashMap<>();
-        Integer userId = tenantInfoDao.queryUserByTenantId(-1);
-        if (Objects.isNull(userId)) {
+        if (Objects.isNull(receiveUserId)) {
             return;
         }
-        log.info("platformSendToAll>>> email {} phone {} objs {} sendPar {}", email, phone, objs, sendPar);
 
         if (StringUtils.isNotBlank(email)) {
-            sendPar.put(userId, email);
-            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL,
+            sendPar.put(receiveUserId, email);
+            log.info("platformSendToAll>>> receiveUserId {} email {} objs {} sendPar {}", receiveUserId, email, objs, sendPar);
+            sysMessageService.batchSendMessage(-1, MessageSenderPluginContext.MessageSender.EMAIL,
                     PLATFORM_ALL_MSG_ENUM.get(MessageSenderPluginContext.MessageSender.EMAIL),
                     sendPar, null, 0, null,
                     "SYSTEM", objs);
         }
 
         if (StringUtils.isNotBlank(phone)) {
-            sendPar.put(userId, phone);
-            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS,
+            sendPar.put(receiveUserId, phone);
+            log.info("platformSendToAll>>> receiveUserId {} phone {} objs {} sendPar {}", receiveUserId, phone, objs, sendPar);
+            sysMessageService.batchSendMessage(-1, MessageSenderPluginContext.MessageSender.AWSMS,
                     PLATFORM_ALL_MSG_ENUM.get(MessageSenderPluginContext.MessageSender.AWSMS),
                     sendPar, null, 0, null,
                     "SYSTEM", objs);

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

@@ -9,7 +9,6 @@ import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.SysUserType;
 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.dto.TenantConfigDto;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
@@ -38,6 +37,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.dao.DuplicateKeyException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -81,8 +81,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Autowired
     private IdGeneratorService idGenerator;
     @Autowired
-    private SysConfigDao sysConfigDao;
-    @Autowired
     private TenantOrderRecordService tenantOrderRecordService;
     @Autowired
     private TenantAssetsInfoService assetsInfoService;
@@ -94,6 +92,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     private TenantInfoSendMsgService tenantInfoSendMsgService;
     @Autowired
     private SysConfigService sysConfigService;
+    @Autowired
+    private ContractService contractService;
 
     /**
      * 新增机构
@@ -267,6 +267,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
             tenantInfo.setUpdatedBy(userId);
             tenantInfo.setUpdatedTime(new Date());
             tenantInfo.setState(state);
+            String pw = null;
             //状态= 开通
             if (state == 1) {
                 if (tenantInfo.getPayState() == 0) {
@@ -274,11 +275,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                 }
                 //已支付完成 并且 没有创建用户信息
                 if (tenantInfo.getPayState() == 1 && Objects.isNull(tenantInfo.getUserId())) {
-                    //初次开通
-                    checkFirstOpen(tenantInfo);
+                    //初次开通 返回密码
+                    pw = checkFirstOpen(tenantInfo);
                 }
             }
             baseMapper.updateById(tenantInfo);
+            //在执行了修改机构信息之后,并且有返回密码(第一次开通机构会生成登录密码并返回)就发送邮件及短信提醒
+            if (StringUtils.isNotBlank(pw)) {
+                Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), pw, "https://online.dayaedu.com"};
+                tenantInfoSendMsgService.platformSendToAll(tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
+            }
             return;
         }
         throw new BizException("传入机构状态参数异常!");
@@ -288,13 +294,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
      * 第一次开通服务
      *
      * @param tenantInfo 机构信息
+     * @return 初次开通机构返回机构密码
      */
-    private void checkFirstOpen(TenantInfo tenantInfo) {
+    private String checkFirstOpen(TenantInfo tenantInfo) {
         Integer tenantId = tenantInfo.getId();
         SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone());
         if (Objects.nonNull(user)) {
             if (user.getUserType().contains(SysUserType.SYSTEM.getCode())) {
-                return;
+                return null;
             }
         }
 
@@ -322,11 +329,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Integer orgId = createOrg(tenantInfo);
         //建立角色
         Integer roleId = createRole(tenantInfo);
+        //密码规则 gym + 随机6位数字
+        String pw = new BCryptPasswordEncoder().encode("gym" + (int) ((Math.random() * 9 + 1) * 100000));
         // 创建账号、用户信息、用户和角色关系
-        createUser(tenantInfo, orgId, Lists.newArrayList(roleId));
+        createUser(tenantInfo, orgId, Lists.newArrayList(roleId), pw);
         //建立角色和菜单关系数据
         Lists.partition(collectMenuId, 50)
                 .forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId));
+        //添加签章信息
+        contractService.addTsign(tenantInfo.getTsignCode(), tenantInfo.getTsignName());
 
         Date now = new Date();
 
@@ -341,11 +352,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now);
         productInfo.setExpiryDate(expiryDate);
         tenantProductInfoService.updateById(productInfo);
-        //发送邮件及短信提醒
-        Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), "123456", "https://online.dayaedu.com"};
-        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
         //释放锁
         bucket.delete();
+
+        return pw;
     }
 
     //计算过期时间
@@ -383,8 +393,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         return sysRole.getId();
     }
 
-    //创建账号、用户信息、用户和角色关系
-    private void createUser(TenantInfo tenantInfo, Integer orgId, List<Integer> roles) {
+    //创建账号、用户信息、用户和角色关系 返回密码
+    private void createUser(TenantInfo tenantInfo, Integer orgId, List<Integer> roles, String pw) {
         Employee e = new Employee();
         e.setTenantId(tenantInfo.getId());
         e.setPhone(tenantInfo.getPhone());
@@ -395,6 +405,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         e.setRoleIds(roles);
         e.setUserType(SysUserType.SYSTEM.getCode());
         e.setOrganIdList(String.valueOf(orgId));
+        e.setPassword(pw);
         try {
             log.info("createUser >>>> {}", e);
             employeeService.add(e);
@@ -563,7 +574,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         TenantInfo tenantInfo = this.getById(tenantId);
         //发送邮件及短信提醒
         Object[] msg = {tenantInfo.getName()};
-        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
+        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
         //释放锁
         bucket.delete();
     }
@@ -831,7 +842,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     private void send(List<TenantInfo> infoList, String dateStr) {
         infoList.forEach(t -> {
             Object[] objects = {t.getName(), dateStr};
-            tenantInfoSendMsgService.platformSendToAll(t.getEmail(), t.getPhone(), objects);
+            tenantInfoSendMsgService.platformSendToAll(t.getUserId(), t.getEmail(), t.getPhone(), objects);
         });
     }
 

+ 4 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -131,7 +131,10 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
             list.forEach(record -> {
                 checkTransOrderState(record);
                 if (record.getOrderState() == 1) {
-                    checkOrder.get(record.getOrderType()).accept(record);
+                    Consumer<TenantOrderRecord> consumer = checkOrder.get(record.getOrderType());
+                    if (Objects.nonNull(consumer)) {
+                        consumer.accept(record);
+                    }
                     //修改流水
                     LocalDateTime now = LocalDateTime.now();
                     record.setPayDate(now.toLocalDate().toDate());

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/ClassGroupMapper.xml

@@ -1036,7 +1036,7 @@
         LEFT JOIN class_group cg ON cg.music_group_id_ = mg.id_
         LEFT JOIN class_group_student_mapper cgsm ON cgsm.class_group_id_ = cg.id_
         WHERE FIND_IN_SET(mg.id_,#{musicGroupIds}) AND cg.group_type_ = 'MUSIC' AND cgsm.user_id_ = #{userId}
-        GROUP BY mg.id_,mgsf.payment_status_
+        GROUP BY mg.id_
     </select>
 
     <select id="queryStudentPracticeCourses" resultMap="CourseListDto">

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/SysCouponMapper.xml

@@ -120,7 +120,7 @@
         WHERE id_ = #{param.id}
         and tenant_id_ = #{param.tenantId}
         <if test="param.checkStock != null">
-           and stock_count_ > (consume_num_ + #{param.exchangeNum})
+           and stock_count_ >= (consume_num_ + #{param.exchangeNum})
         </if>
     </update>