Explorar o código

Merge branch 'feature/0721-tenant' of http://git.dayaedu.com/yonge/cooleshow into feature/0721-tenant

liujc hai 1 ano
pai
achega
6469974a4f

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantActivationCodeService.java

@@ -74,4 +74,6 @@ public interface TenantActivationCodeService extends IService<TenantActivationCo
      */
     void importActiveCode(List<ExcelDataReaderProperty<TenantActivationCodeWrapper.ImportTemplate>> dataList,
                           Long tenantId, Long userId, Long tenantAlbumPurchaseId);
+
+    void activeById(String id, Long userId);
 }

+ 58 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java

@@ -184,11 +184,12 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
         if (code == null) {
             throw new BizException("激活码不存在");
         }
-        if (Boolean.TRUE.equals(code.getActivationStatus()) || EActivationCode.SEND.equals(code.getSendStatus())) {
+        SysUser sysUser = sysUserMapper.selectById(studentId);
+        if (Boolean.TRUE.equals(code.getActivationStatus()) || (EActivationCode.SEND.equals(code.getSendStatus()) &&
+                !sysUser.getPhone().equals(code.getActivationPhone()))) {
             throw new BizException("激活码已经被使用");
         }
 
-        SysUser sysUser = sysUserMapper.selectById(studentId);
         // 通过状态和ID同时判断更新是否存在竞争
         boolean update = this.lambdaUpdate()
                 .set(TenantActivationCode::getActivationStatus, true)
@@ -219,6 +220,61 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
     }
 
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void activeById(String id, Long userId) {
+        Student student = studentDao.selectById(userId);
+        if (student == null) {
+            throw new BizException("学生不存在");
+        }
+        Long tenantId = -1L;
+        if (student.getTenantId() != null) {
+            tenantId = student.getTenantId();
+        }
+        TenantActivationCode code = baseMapper.selectById(id);
+        if(code == null || !code.getTenantId().equals(tenantId)) {
+            throw new BizException("激活码不存在");
+        }
+        SysUser sysUser = sysUserMapper.selectById(student.getUserId());
+        if(!sysUser.getPhone().equals(code.getActivationPhone())) {
+            // 该激活码未指定为当前学生使用
+            throw new BizException("激活码不存在");
+        }
+        if (Boolean.TRUE.equals(code.getActivationStatus())) {
+            throw new BizException("激活码已经被使用");
+        }
+
+        // 通过状态和ID同时判断更新是否存在竞争
+        boolean update = this.lambdaUpdate()
+                .set(TenantActivationCode::getActivationStatus, true)
+                .set(TenantActivationCode::getActivationUserId, student.getUserId())
+                .set(TenantActivationCode::getActivationTime, new Date())
+                .set(TenantActivationCode::getActivationPhone, sysUser.getPhone())
+                .eq(TenantActivationCode::getId, code.getId())
+                .eq(TenantActivationCode::getActivationStatus, false)
+                .update();
+        if (!update) {
+            throw new BizException("激活码已经被使用");
+        }
+        Long tenantAlbumPurchaseId = code.getTenantAlbumPurchaseId();
+        TenantAlbumPurchase purchase = tenantAlbumPurchaseMapper.selectById(tenantAlbumPurchaseId);
+
+        addUserTenantAlbumRecord(student.getUserId(), purchase, null);
+
+        // 更新购买记录中激活码使用统计数量值
+        Integer activeCodeNumber = this.lambdaQuery()
+                .eq(TenantActivationCode::getTenantId, tenantId)
+                .eq(TenantActivationCode::getTenantAlbumPurchaseId, code.getTenantAlbumPurchaseId())
+                .eq(TenantActivationCode::getActivationStatus, true).count();
+
+        TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
+        tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
+        tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
+        tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
+
+    }
+
+
     /**
      * 添加用户机构专辑激活记录
      *

+ 12 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserTenantAlbumRecordServiceImpl.java

@@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
 import com.yonge.cooleshow.biz.dal.wrapper.UserTenantAlbumRecordWrapper;
 import com.yonge.cooleshow.biz.dal.mapper.UserTenantAlbumRecordMapper;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -276,12 +277,22 @@ public class UserTenantAlbumRecordServiceImpl extends ServiceImpl<UserTenantAlbu
         String describe = tenantAlbum.getDescribe();
         //声部
         String subjectTypes = tenantAlbum.getSubjectTypes();
-
+        //原价
+        BigDecimal costPrice = tenantAlbum.getCostPrice();
+        //售价
+        BigDecimal salePrice = tenantAlbum.getSalePrice();
+        //周期
+        Integer purchaseCycle = tenantAlbum.getPurchaseCycle();
+
+        album.setId(String.valueOf(tenantAlbum.getId()));
         album.setName(name);
         album.setCoverImg(coverImg);
         album.setMusicNum(size);
         album.setDescribe(describe);
         album.setSubjectTypes(subjectTypes);
+        album.setCostPrice(costPrice);
+        album.setPurchaseCycle(purchaseCycle);
+        album.setSalePrice(salePrice);
         return album;
     }
 }

+ 11 - 0
cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/controller/TenantActivationCodeController.java

@@ -77,4 +77,15 @@ public class TenantActivationCodeController extends BaseController {
         tenantActivationCodeService.active(activationCode, sysUser.getId());
         return succeed();
     }
+
+    @ApiOperation(value = "激活激活码")
+    @PostMapping("/activeById")
+    public HttpResponseResult<Boolean> activeById(@RequestParam("id") String id) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null || null == sysUser.getId()) {
+            throw new BizException("请登录");
+        }
+        tenantActivationCodeService.activeById(id, sysUser.getId());
+        return succeed();
+    }
 }

+ 46 - 21
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/TenantInfoController.java

@@ -18,6 +18,7 @@ import com.yonge.cooleshow.common.security.SecurityConstants;
 import com.yonge.cooleshow.tenant.io.request.SysUserWrapper;
 import com.yonge.cooleshow.tenant.io.request.TenantInfoVo;
 import com.yonge.toolset.base.exception.BizException;
+import com.yonge.toolset.utils.obj.ObjectUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -148,28 +149,34 @@ public class TenantInfoController extends BaseController {
         String code = sysUser.getCode();
         String phone = sysUser.getPhone();
 
-        boolean re = smsCodeService.verifyValidCode(phone, code, "PHONE");
-
         com.yonge.cooleshow.biz.dal.entity.SysUser sysUser1 = JSON.parseObject(sysUser.jsonString(), com.yonge.cooleshow.biz.dal.entity.SysUser.class);
 
-        if (re) {
-            SysUser user = sysUserFeignService.queryUserInfo();
-            tenantInfoService.updateSysUser(sysUser1, user.getId());
+        //如果传手机号
+        if (StringUtils.isNotBlank(phone)){
+            boolean re = smsCodeService.verifyValidCode(phone, code, "PHONE");
+            if (re){
+                SysUser user = sysUserFeignService.queryUserInfo();
+                tenantInfoService.updateSysUser(sysUser1, user.getId());
+
+                //设置默认头像
+                if (sysUser.getAvatar().isEmpty()) {
+                    sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
+                }
+
+                //判断更改的手机所属的机构信息
+
+                String oldPhone = user.getPhone();
+                //查看原机构信息
+                List<TenantInfo> list = tenantInfoService.lambdaQuery().eq(TenantInfo::getPhone, oldPhone).list();
+                if (CollectionUtils.isNotEmpty(list)){
+                    TenantInfo info = list.get(0);
+                    if (ObjectUtil.isEmpty(info)) {
+                        //更新tennatInfo
+                        info.setPhone(phone);
+                        tenantInfoService.updateById(info);
+                    }
+                }
 
-        //设置默认头像
-        if (sysUser.getAvatar().isEmpty()) {
-            sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
-        }
-        //判断更改的手机所属的机构信息
-            List<TenantInfo> list = tenantInfoService.lambdaQuery().eq(TenantInfo::getPhone, phone).list();
-        if (CollectionUtils.isNotEmpty(list)){
-            TenantInfo info = list.get(0);
-            if (info != null) {
-                //更新tennatInfo
-                info.setPhone(phone);
-                tenantInfoService.updateById(info);
-            }
-        }
                 //更新员工表
                 Long id = user.getId();
                 TenantStaff staff = tenantStaffService.getByUserId(id);
@@ -178,8 +185,26 @@ public class TenantInfoController extends BaseController {
                     staff.setAvatar(sysUser.getAvatar());
                     tenantStaffService.updateById(staff);
                 }
-    } else {
-            throw new BizException("手机号校验有误");
+            } else {
+                throw new BizException("手机号校验有误");
+            }
+        }  else {
+            SysUser user = sysUserFeignService.queryUserInfo();
+            tenantInfoService.updateSysUser(sysUser1, user.getId());
+
+            //设置默认头像
+            if (sysUser.getAvatar().isEmpty()) {
+                sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
+            }
+
+            //更新员工表
+            Long id = user.getId();
+            TenantStaff staff = tenantStaffService.getByUserId(id);
+            if (staff != null){
+                staff.setNickname(sysUser.getUsername());
+                staff.setAvatar(sysUser.getAvatar());
+                tenantStaffService.updateById(staff);
+            }
         }
             return HttpResponseResult.succeed(true);
         }