Sfoglia il codice sorgente

Merge branch 'develop-new' of http://git.dayaedu.com/yonge/cooleshow into develop-new

liujc 1 anno fa
parent
commit
a8fda73ee7
23 ha cambiato i file con 397 aggiunte e 44 eliminazioni
  1. 26 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java
  2. 1 1
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java
  3. 61 13
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TenantActivationCodeController.java
  4. 84 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TenantGroupController.java
  5. 23 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/vo/TenantActivationCodeVo.java
  6. 4 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/TenantActivationCode.java
  7. 2 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/MessageTypeEnum.java
  8. 1 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/UserTenantBindRecordMapper.java
  9. 36 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java
  10. 38 6
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java
  11. 16 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java
  12. 42 3
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java
  13. 12 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantUnbindRecordServiceImpl.java
  14. 6 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantActivationCodeWrapper.java
  15. 0 3
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantAlbumPurchaseWrapper.java
  16. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantGroupWrapper.java
  17. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantInfoWrapper.java
  18. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserTenantBindRecordWrapper.java
  19. 4 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantActivationCodeMapper.xml
  20. 2 9
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantAlbumPurchaseMapper.xml
  21. 1 1
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantGroupMapper.xml
  22. 3 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml
  23. 26 7
      cooleshow-user/user-biz/src/main/resources/config/mybatis/UserTenantBindRecordMapper.xml

+ 26 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -7,10 +7,12 @@ import com.yonge.cooleshow.biz.dal.dto.VipSubmitReq;
 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
 import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
 import com.yonge.cooleshow.biz.dal.entity.TenantGroup;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
 import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
 import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
 import com.yonge.cooleshow.biz.dal.vo.StudentVo;
@@ -48,6 +50,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -73,6 +76,9 @@ public class StudentController extends BaseController {
     @Autowired
     private TenantGroupService tenantGroupService;
 
+    @Autowired
+    private TenantActivationCodeService tenantActivationCodeService;
+
     @GetMapping("/detail/{id}")
     @ApiOperation(value = "详情", notes = "传入id")
     @ApiImplicitParams({
@@ -113,6 +119,25 @@ public class StudentController extends BaseController {
         IPage<StudentVo> pages = studentService.selectPage(PageUtil.getPage(query), query);
         List<StudentVo> rows = pages.getRecords();
 
+        //如果真实姓名字段为空 把真实姓名赋值给昵称
+        rows.forEach(r -> {
+            if (StringUtils.isEmpty(r.getRealName())) {
+                if (StringUtils.isNotEmpty(r.getUsername())) {
+                    r.setRealName(r.getUsername());
+                }
+            }
+        });
+
+        Map<String, List<TenantActivationCode>> groupByPhone = new HashMap<>();
+        if (!rows.isEmpty() && query.getTenantAlbumPurchaseId() != null) {
+            List<String> studentPhones =
+                    rows.stream().map(StudentVo::getPhone).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
+            groupByPhone = tenantActivationCodeService.lambdaQuery()
+                    .eq(TenantActivationCode::getTenantAlbumPurchaseId, query.getTenantAlbumPurchaseId())
+                    .in(TenantActivationCode::getActivationPhone, studentPhones)
+                    .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationPhone));
+        }
+
         List<Long> tenantGroupIds = rows.stream().map(Student::getTenantGroupId)
                 .filter(next -> next != null && next != -1L).distinct().collect(Collectors.toList());
         Map<Long, String> tenantGroupIdNameMap = new HashMap<>();
@@ -125,6 +150,7 @@ public class StudentController extends BaseController {
 
 
         for (StudentVo vo : rows) {
+            vo.setSendActiveCodeNum(groupByPhone.getOrDefault(vo.getPhone(), new ArrayList<>()).size());
             if (vo.getDelFlag() == YesOrNoEnum.YES) {
                 vo.setUserStatus(UserStatusEnum.CLOSED);
             } else {

+ 1 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java

@@ -163,7 +163,7 @@ public class TeacherController extends BaseController {
     }
 
     @PostMapping("/updateTenant")
-    @ApiOperation(value = "新增或修改", notes = "传入teacher")
+    @ApiOperation(value = "新增或修改机构", notes = "传入teacher")
     @PreAuthorize("@pcs.hasPermissions('teacher/updateTenant')")
     public HttpResponseResult<Boolean> updateTenant(@Valid @RequestBody TeacherWrapper.UpdateTenant updateTenant) {
         SysUser sysUser = sysUserFeignService.queryUserInfo();

+ 61 - 13
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TenantActivationCodeController.java

@@ -1,27 +1,38 @@
 package com.yonge.cooleshow.admin.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.microsvc.toolkit.common.response.paging.PageInfo;
 import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
 import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
+import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
 import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
 import com.yonge.cooleshow.biz.dal.service.TenantAlbumPurchaseService;
+import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.cooleshow.tenant.vo.TenantActivationCodeVo;
 import com.yonge.toolset.base.exception.BizException;
-import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
 
 @Slf4j
 @Validated
@@ -36,32 +47,69 @@ public class TenantActivationCodeController extends BaseController {
     @Autowired
     private TenantAlbumPurchaseService tenantAlbumPurchaseService;
 
+    @Autowired
+    private TenantInfoService tenantInfoService;
 
     @ApiOperation(value = "查询分页", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeQuery")
     @PostMapping("/page")
+    @PreAuthorize("@pcs.hasPermissions('tenantActivationCode/page')")
     public HttpResponseResult<PageInfo<TenantActivationCodeWrapper.TenantActivationCode>> page(
             @RequestBody TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
 
-        if (StringUtils.isBlank(query.getOrderNo())) {
-            throw new BizException("订单号不能为空");
+        String activationTime = query.getActivationTime();
+        if (StringUtils.isNotEmpty(activationTime)) {
+            Date parse = new SimpleDateFormat("yyyy-MM").parse(activationTime, new ParsePosition(0));
+            query.setActivationStartTime(parse);
+            Calendar instance = Calendar.getInstance();
+            instance.setTime(parse);
+            instance.add(Calendar.MONTH, 1);
+            instance.add(Calendar.DATE, -1);
+            instance.set(Calendar.HOUR_OF_DAY, 23);
+            instance.set(Calendar.MINUTE, 59);
+            instance.set(Calendar.MILLISECOND, 59);
+            query.setActivationEndTime(instance.getTime());
         }
-        // 查询订单购买的专辑
-        TenantAlbumPurchase albumPurchase = tenantAlbumPurchaseService.getByOrderNo(query.getOrderNo());
-        if (albumPurchase == null) {
-            return succeed(new PageInfo<>());
-        }
-        query.setActivationStatus(true);
-        query.setTenantAlbumPurchaseId(albumPurchase.getId());
-        // 查询数据
         IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
                 tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
-        PageInfo<TenantActivationCodeWrapper.TenantActivationCode> pageInfo = PageUtil.pageInfo(pages);
+        com.microsvc.toolkit.common.response.paging.PageInfo<TenantActivationCodeWrapper.TenantActivationCode> pageInfo = QueryInfo.pageInfo(pages,
+                pages.getRecords());
 
         if (query.getTenantAlbumPurchaseId() != null) {
-            pageInfo.setStatInfo(albumPurchase);
+            TenantActivationCodeWrapper.TenantActivationCode extra =
+                    new TenantActivationCodeWrapper.TenantActivationCode();
+            TenantAlbumPurchase purchase = tenantAlbumPurchaseService.getById(query.getTenantAlbumPurchaseId());
+            extra.setActiveQuantity(purchase.getActiveQuantity());
+            pageInfo.setExtra(extra);
         }
 
         return succeed(pageInfo);
     }
 
+    @ApiOperation(value = "激活码发放", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeSend")
+    @PostMapping("/send")
+    @PreAuthorize("@pcs.hasPermissions('tenantActivationCode/send')")
+    public HttpResponseResult<Boolean> send(@Validated @RequestBody TenantActivationCodeVo.TenantActivationCodeSend send) {
+        tenantActivationCodeService.sendActivationCode(send.getTenantId(), send.getTenantAlbumPurchaseId(),
+                send.getActivationCodeList(),
+                send.getStudentIdList());
+        return succeed();
+    }
+
+    @ApiOperation(value = "激活码重发", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeSend")
+    @PostMapping("/resend")
+    @PreAuthorize("@pcs.hasPermissions('tenantActivationCode/resend')")
+    public HttpResponseResult<Boolean> resend(@Validated @RequestBody TenantActivationCodeVo.TenantActivationCodeResend send) {
+        tenantActivationCodeService.resend(send.getCode(), send.getUserId(), send.getTenantId(), send.getTenantAlbumPurchaseId());
+        return succeed();
+    }
+
+    @ApiOperation(value = "激活码发放取消", notes = "传入 激活码的ID")
+    @PostMapping("/sendCancel")
+    @PreAuthorize("@pcs.hasPermissions('tenantActivationCode/sendCancel')")
+    public HttpResponseResult<Boolean> sendCancel(@Validated @RequestBody TenantActivationCodeVo.CodeSend codeSend) {
+        TenantActivationCode activationCode = tenantActivationCodeService.getById(codeSend.getId());
+        TenantInfo tenantInfo = tenantInfoService.getById(codeSend.getTenantId());
+        tenantActivationCodeService.sendCancel(tenantInfo, activationCode);
+        return succeed();
+    }
 }

+ 84 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TenantGroupController.java

@@ -1,21 +1,39 @@
 package com.yonge.cooleshow.admin.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.microsvc.toolkit.common.response.paging.PageInfo;
 import com.microsvc.toolkit.common.response.paging.QueryInfo;
 import com.microsvc.toolkit.common.response.template.R;
+import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+import com.yonge.cooleshow.biz.dal.entity.ImGroup;
+import com.yonge.cooleshow.biz.dal.entity.TenantGroup;
+import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantGroupWrapper;
+import com.yonge.cooleshow.tenant.vo.TenantGroupVo;
+import com.yonge.toolset.base.exception.BizException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
 @Slf4j
 @Validated
 @RestController
@@ -26,6 +44,12 @@ public class TenantGroupController {
     @Autowired
     private TenantGroupService tenantGroupService;
 
+    @Resource
+    private SysUserFeignService sysUserFeignService;
+
+    @Autowired
+    private ImGroupService imGroupService;
+
     @ApiOperation(value = "查询分页", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroupQuery")
     @PreAuthorize("@pcs.hasPermissions('tenantGroup/page', {'BACKEND'})")
     @PostMapping("/page")
@@ -40,4 +64,64 @@ public class TenantGroupController {
         return R.from(tenantGroupService.adjustTenantGroup(adjustTenantGroup));
     }
 
+    @ApiOperation(value = "详情", notes = "机构小组表-根据详情ID查询单条, 传入id")
+    @GetMapping("/detail/{id}")
+    @PreAuthorize("@pcs.hasPermissions('tenantGroup/detail')")
+    public R<TenantGroupWrapper.TenantGroup> detail(@PathVariable("id") Long id) {
+        TenantGroup wrapper = tenantGroupService.detail(id);
+        if (wrapper == null) {
+            return R.from(new TenantGroupWrapper.TenantGroup());
+        }
+        TenantGroupWrapper.TenantGroup group = TenantGroupWrapper.TenantGroup.from(JSON.toJSONString(wrapper));
+        group.setImGroupExist(false);
+        if (StringUtils.isNotEmpty(wrapper.getImGroupId())) {
+            ImGroup imGroup = imGroupService.getById(wrapper.getImGroupId());
+            if (imGroup != null) {
+                group.setImGroupExist(true);
+            }
+        }
+        List<TenantGroupWrapper.TenantGroupMember> members =
+                tenantGroupService.queryGroupMember(wrapper.getTenantId(), id);
+        List<Long> userIds = members.stream().map(TenantGroupWrapper.TenantGroupMember::getUserId)
+                .collect(Collectors.toList());
+        group.setUserIds(userIds);
+        group.setGroupUserCount(members.size());
+        group.setUserList(members);
+        return R.from(group);
+    }
+
+    @ApiOperation(value = "新增", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroup")
+    @PostMapping("/save")
+    @PreAuthorize("@pcs.hasPermissions('tenantGroup/save')")
+    public R<JSONObject> add(@Validated @RequestBody TenantGroupVo.TenantGroup tenantGroup) {
+        Long tenantId = tenantGroup.getTenantId();
+        if (tenantId == null) {
+            throw new BizException("机构ID不能为空");
+        }
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        TenantGroupWrapper.TenantGroup group = TenantGroupWrapper.TenantGroup.from(tenantGroup.jsonString());
+        group.setCreateBy(sysUser.getId());
+        // 新增数据
+        tenantGroupService.add(group, tenantGroup.getImGroupCreate());
+
+        return R.defaultR();
+    }
+
+    @ApiOperation(value = "修改", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroup")
+    @PostMapping("/update")
+    @PreAuthorize("@pcs.hasPermissions('tenantGroup/update')")
+    public R<JSONObject> update(@Validated @RequestBody TenantGroupVo.TenantGroup tenantGroup) {
+        // 更新数据
+        tenantGroupService.update(TenantGroupWrapper.TenantGroup.from(tenantGroup.jsonString()), tenantGroup.getImGroupCreate());
+
+        return R.defaultR();
+    }
+
+    @ApiOperation(value = "删除", notes = "机构小组表- 传入id")
+    @PostMapping("/remove")
+    @PreAuthorize("@pcs.hasPermissions('tenantGroup/remove')")
+    public R<Boolean> remove(@RequestParam Long id) {
+
+        return R.from(tenantGroupService.delete(id));
+    }
 }

+ 23 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/vo/TenantActivationCodeVo.java

@@ -27,6 +27,9 @@ public class TenantActivationCodeVo {
         @NotNull(message = "专辑购买记录的ID不能为空")
         private Long tenantAlbumPurchaseId;
 
+        @ApiModelProperty("机构ID")
+        private Long tenantId;
+
         @ApiModelProperty("激活码列表,批量发送时为空")
         private List<String> activationCodeList = new ArrayList<>();
 
@@ -45,6 +48,9 @@ public class TenantActivationCodeVo {
         @NotNull(message = "专辑购买记录的ID不能为空")
         private Long tenantAlbumPurchaseId;
 
+        @ApiModelProperty("结构ID")
+        private Long tenantId;
+
         @ApiModelProperty("激活码")
         @NotBlank(message = "激活码不能为空")
         private String code;
@@ -107,6 +113,9 @@ public class TenantActivationCodeVo {
         @ApiModelProperty("创建时间")
         private Date createTime;
 
+        @ApiModelProperty("发放时间")
+        private Date sendTime;
+
 
         public String jsonString() {
             return JSON.toJSONString(this);
@@ -117,4 +126,18 @@ public class TenantActivationCodeVo {
         }
     }
 
+    @Data
+    @ApiModel("激活码发放")
+    public static class CodeSend {
+
+        @ApiModelProperty("机构ID")
+        @NotNull
+        private Long tenantId;
+
+        @ApiModelProperty("激活码ID")
+        @NotNull
+        private Long id;
+
+    }
+
 }

+ 4 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/TenantActivationCode.java

@@ -72,4 +72,8 @@ public class TenantActivationCode implements Serializable {
 	@TableField(value = "create_time_")
     private Date createTime;
 
+    @ApiModelProperty("发放时间")
+	@TableField(value = "send_time_")
+    private Date sendTime;
+
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/enums/MessageTypeEnum.java

@@ -131,6 +131,8 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     TENANT_MUSIC_BUY("购买曲目"),
     TENANT_STUDENT_CHANGE("机构变更"),
     ADD_COOPERATE_TENANT("添加合作机构"),
+    TEACHER_BIND_TENANT("老师绑定机构"),
+    TEACHER_UNBIND_TENANT("老师解绑机构"),
     ;
 
     MessageTypeEnum(String msg) {

+ 1 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/UserTenantBindRecordMapper.java

@@ -25,4 +25,5 @@ public interface UserTenantBindRecordMapper extends BaseMapper<UserTenantBindRec
     List<UserTenantBindRecordWrapper.UserTenantBindRecord> selectPage(@Param("page") IPage<UserTenantBindRecordWrapper.UserTenantBindRecord> page,
                                                                       @Param("param") UserTenantBindRecordWrapper.UserTenantBindRecordQuery param);
 
+    void add(@Param("record") UserTenantBindRecord record);
 }

+ 36 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -25,6 +25,7 @@ import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumRefMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantGroupMapper;
+import com.yonge.cooleshow.biz.dal.mapper.UserTenantBindRecordMapper;
 import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.service.im.ImGroupCoreService;
 import com.yonge.cooleshow.biz.dal.vo.MyFollow;
@@ -125,6 +126,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
     @Autowired
     private TenantGroupMapper tenantGroupMapper;
 
+    @Autowired
+    private UserTenantBindRecordMapper userTenantBindRecordMapper;
     @Override
     public StudentVo detail(Long userId) {
         return baseMapper.detail(userId);
@@ -582,6 +585,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
 //             删除好友
             imUserFriendService.delTeacherFriendByTenantId(student.getTenantId(), student.getUserId(),
                     ClientEnum.STUDENT.getCode());
+            addBindUnBindRecord(student.getUserId(),student.getTenantId(),false);
         }
         if (toTenantId != null && toTenantId != -1L) {
             // 加好友
@@ -593,6 +597,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                 studentIds.add(student.getUserId());
                 imUserFriendService.saveUserFriend(teacher.getUserId(), studentIds);
             }
+            addBindUnBindRecord(student.getUserId(),student.getTenantId(),true);
         }
         this.lambdaUpdate().set(Student::getTenantId, toTenantId)
                 .set(Student::getTenantGroupId, -1L)
@@ -672,6 +677,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             imUserFriendService.delTeacherFriendByTenantId(student.getTenantId(), student.getUserId(),
                     ClientEnum.STUDENT.getCode());
 
+            addBindUnBindRecord(student.getUserId(),student.getTenantId(),false);
+
             // 加好友
             QueryWrapper<Teacher> query = new QueryWrapper<>();
             query.lambda().eq(Teacher::getTenantId, newTenantId);
@@ -682,6 +689,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                 imUserFriendService.saveUserFriend(teacher.getUserId(), studentIds);
             }
 
+            addBindUnBindRecord(student.getUserId(),studentInfo.getTenantId(),true);
             sendStudentTenantChange(student,newTenantId);
         }
 
@@ -700,6 +708,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                     .set(StringUtils.isNotEmpty(studentInfo.getAvatar()), Student::getAvatar, studentInfo.getAvatar())
                     .eq(Student::getUserId, studentInfo.getId())
                     .update();
+
+            userTenantBindRecordMapper.update(null, Wrappers.<UserTenantBindRecord>lambdaUpdate()
+                    .eq(UserTenantBindRecord::getUserId, studentInfo.getId())
+                    .eq(UserTenantBindRecord::getUserType, "STUDENT")
+                    .set(UserTenantBindRecord::getUserId, sysUser.getId()));
         } else {
             Student newStudent = new Student();
             newStudent.setUserId(studentInfo.getId());
@@ -837,6 +850,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             List<Teacher> teacherList = teacherDao.selectList(queryWrapper);
             teacherList.forEach(next -> imUserFriendService.saveUserFriend(next.getUserId(),
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
+
+            addBindUnBindRecord(student.getUserId(), student.getTenantId(), true);
         }
 
         //  与随机一个客服建立好友
@@ -938,4 +953,25 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         }
     }
 
+    private void addBindUnBindRecord(Long studentId, Long tenantId, Boolean bind) {
+        UserTenantBindRecord bindRecord = new UserTenantBindRecord();
+        bindRecord.setUserId(studentId);
+        bindRecord.setUserType("STUDENT");
+        bindRecord.setTenantId(tenantId);
+        bindRecord.setBindStatus(bind);
+        bindRecord.setBindTime(new Date());
+        userTenantBindRecordMapper.add(bindRecord);
+
+        SysUser sysUser = sysUserMapper.getByUserId(studentId);
+        sendBindUnBindSMS(studentId, sysUser.getPhone(), Boolean.TRUE.equals(bind) ? MessageTypeEnum.TEACHER_BIND_TENANT : MessageTypeEnum.TEACHER_UNBIND_TENANT, tenantId);
+    }
+
+    private void sendBindUnBindSMS(Long userId, String phone, MessageTypeEnum messageType, Long tenantId) {
+        TenantInfo tenantInfo = tenantInfoService.getById(tenantId);
+        Map<Long, String> receivers = new HashMap<>();
+        receivers.put(userId, phone);
+        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, messageType,
+                receivers, null, 0, null, ClientEnum.SYSTEM.getCode(), tenantInfo.getName());
+    }
+
 }

+ 38 - 6
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
+import com.microsvc.toolkit.middleware.rtc.enums.EDeviceMessageType;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
@@ -26,6 +27,7 @@ import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
 import com.yonge.cooleshow.biz.dal.enums.TeacherTagEnum;
 import com.yonge.cooleshow.biz.dal.enums.TeacherTypeEnum;
 import com.yonge.cooleshow.biz.dal.mapper.TenantGroupMapper;
+import com.yonge.cooleshow.biz.dal.mapper.UserTenantBindRecordMapper;
 import com.yonge.cooleshow.biz.dal.queryInfo.TeacherQueryInfo;
 import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
@@ -203,6 +205,9 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
     @Autowired
     private TenantGroupMapper tenantGroupMapper;
 
+    @Autowired
+    private UserTenantBindRecordMapper userTenantBindRecordMapper;
+
 
     @Override
     public TeacherDao getDao() {
@@ -500,6 +505,10 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                     .map(Student::getUserId).collect(Collectors.toSet());
 
             imUserFriendService.saveUserFriend(teacher.getUserId(), collect);
+
+            // 机构老师添加机构绑定记录
+            addBindUnBindRecord(teacher.getUserId(),teacher.getTenantId(),true);
+            sendBindUnBindSMS(teacher.getUserId(), teacherSubmitReq.getPhone(), MessageTypeEnum.TEACHER_BIND_TENANT, teacher.getTenantId());
         }
         //  与客服建立好友
         String customerService = customerServiceConfig.getCustomerService();
@@ -1095,21 +1104,23 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                 });
             }
             // 删除好友关系
-            imUserFriendService.delStudentFriendByTenantId(teacher.getTenantId(), teacher.getUserId(),ClientEnum.TEACHER.getCode());
+            imUserFriendService.delStudentFriendByTenantId(teacher.getTenantId(), teacher.getUserId(), ClientEnum.TEACHER.getCode());
+            addBindUnBindRecord(teacher.getUserId(), teacher.getTenantId(), false);
+            SysUser sysUser = sysUserMapper.getByUserId(teacher.getUserId());
+            sendBindUnBindSMS(teacher.getUserId(), sysUser.getPhone(), MessageTypeEnum.TEACHER_UNBIND_TENANT, teacher.getTenantId());
 
         }
 
-        if (updateTenant.getTenantId().equals(-1L)) {
+        long tenantId = Optional.ofNullable(updateTenant.getTenantId()).orElse(-1L);
+        if (tenantId == -1L) {
             // 平台老师处理流程
             if (ESettlementFrom.TENANT.equals(teacher.getSettlementFrom())) {
                 // 解绑后,结算方式如果是机构,默认调整为老师
                 teacher.setSettlementFrom(ESettlementFrom.TEACHER);
                 teacher.setIsSettlement(true);
             }
-        }
-
-        // 机构老师与学生互加好友关系
-        if (Optional.ofNullable(updateTenant.getTenantId()).orElse(-1L) > 0) {
+        }else {
+            // 机构老师与学生互加好友关系
             // 自动与机构学生成为好友
             Set<Long> collect = studentService.lambdaQuery()
                     .eq(Student::getTenantId, updateTenant.getTenantId()).list().stream()
@@ -1119,6 +1130,9 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
             if (!collect.isEmpty()) {
                 imUserFriendService.saveUserFriend(teacher.getUserId(), collect);
             }
+            addBindUnBindRecord(teacher.getUserId(),updateTenant.getTenantId(),true);
+            SysUser sysUser = sysUserMapper.getByUserId(teacher.getUserId());
+            sendBindUnBindSMS(teacher.getUserId(), sysUser.getPhone(), MessageTypeEnum.TEACHER_BIND_TENANT, updateTenant.getTenantId());
         }
 
         teacher.setTenantId(updateTenant.getTenantId());
@@ -1199,4 +1213,22 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 
         return teachers.stream().collect(Collectors.toMap(Teacher::getUserId, o -> o, (o, n) -> n));
     }
+
+    private void addBindUnBindRecord(Long teacherId, Long tenantId, Boolean bind) {
+        UserTenantBindRecord bindRecord = new UserTenantBindRecord();
+        bindRecord.setUserId(teacherId);
+        bindRecord.setUserType("TEACHER");
+        bindRecord.setTenantId(tenantId);
+        bindRecord.setBindStatus(bind);
+        bindRecord.setBindTime(new Date());
+        userTenantBindRecordMapper.add(bindRecord);
+    }
+
+    private void sendBindUnBindSMS(Long userId, String phone, MessageTypeEnum messageType, Long tenantId) {
+        TenantInfo tenantInfo = tenantInfoService.getById(tenantId);
+        Map<Long, String> receivers = new HashMap<>();
+        receivers.put(userId, phone);
+        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.AWSMS, messageType,
+                receivers, null, 0, null, ClientEnum.SYSTEM.getCode(), tenantInfo.getName());
+    }
 }

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

@@ -158,6 +158,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
             boolean update = this.lambdaUpdate()
                     .set(TenantActivationCode::getSendStatus, EActivationCode.SEND.getCode())
                     .set(TenantActivationCode::getActivationPhone, idPhoneMap.get(studentId))
+                    .set(TenantActivationCode::getSendTime, new Date())
                     .eq(TenantActivationCode::getActivationStatus, false)
                     .eq(TenantActivationCode::getId, tenantActivationCodes.get(i).getId())
                     .update();
@@ -301,6 +302,12 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
         TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
         tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
         tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
+
+        if (activeCodeNumber.equals(tenantAlbumPurchase.getPurchaseQuantity())) {
+            tenantAlbumPurchase.setActiveStatus("ALL");
+        } else {
+            tenantAlbumPurchase.setActiveStatus("PART");
+        }
         tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
 
     }
@@ -341,12 +348,19 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
         boolean update = this.lambdaUpdate()
                 .set(TenantActivationCode::getSendStatus, EActivationCode.WAIT)
                 .set(TenantActivationCode::getActivationPhone, "")
+                .set(TenantActivationCode::getSendTime, null)
                 .eq(TenantActivationCode::getId, activationCode.getId())
                 .eq(TenantActivationCode::getActivationStatus, false)
                 .eq(TenantActivationCode::getSendStatus, EActivationCode.SEND)
                 .update();
         if (!update) {
-            throw new BizException("激活码已经激活");
+            TenantActivationCode code = this.getById(activationCode.getId());
+            if (EActivationCode.WAIT.equals(code.getSendStatus())) {
+                throw new BizException("激活码已撤回");
+            }
+            if (Boolean.TRUE.equals(code.getActivationStatus())) {
+                throw new BizException("激活码已经激活");
+            }
         }
         com.yonge.cooleshow.auth.api.entity.SysUser sysUser = sysUserService.findUserByPhone(activationCode.getActivationPhone());
         if (sysUser != null) {
@@ -406,6 +420,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
         for (int i = 0; i < studentIdList.size(); i++) {
             TenantActivationCode tenantActivationCode = activationCodes.get(i);
             tenantActivationCode.setSendStatus(EActivationCode.SEND);
+            tenantActivationCode.setSendTime(new Date());
             tenantActivationCode.setActivationPhone(mapPhoneById.getOrDefault(studentIdList.get(i), ""));
             updates.add(tenantActivationCode);
         }

+ 42 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java

@@ -109,10 +109,15 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                         .list().stream().map(ImGroup::getId).collect(Collectors.toList());
                 existImgGroupIds.addAll(imgGroupIds);
             }
+            List<Long> adminIdList = records.stream().map(TenantGroupWrapper.TenantGroup::getAdminId).distinct().collect(Collectors.toList());
+            Map<Long, com.yonge.cooleshow.biz.dal.entity.SysUser> mapByIds = sysUserService.getMapByIds(adminIdList);
 
             for (TenantGroupWrapper.TenantGroup record : records) {
                 record.setGroupUserCount(groupBy.getOrDefault(record.getId(), 0));
                 record.setImGroupExist(existImgGroupIds.contains(record.getImGroupId()));
+                if (mapByIds.containsKey(record.getAdminId())) {
+                    record.setAdminName(mapByIds.get(record.getAdminId()).getUsername());
+                }
             }
         }
         return iPage;
@@ -135,8 +140,15 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         if (count > 0) {
             throw new BizException("小组名称已存在");
         }
-        this.save(entity);
         Long adminId = tenantGroup.getAdminId();
+        Teacher teacher = teacherDao.selectById(adminId);
+        if (!tenantGroup.getTenantId().equals(teacher.getTenantId())) {
+            throw new BizException("负责人机构已经变更,请重新选择");
+        }
+        List<Long> userIds = tenantGroup.getUserIds();
+        checkStudent(tenantGroup.getTenantId(), userIds,null);
+
+        this.save(entity);
         if (adminId != null && Boolean.TRUE.equals(imGroupCreate)) {
             // 建群
             try {
@@ -153,7 +165,6 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 throw new BizException("创建机构小组群失败");
             }
             // 加群成员
-            List<Long> userIds = tenantGroup.getUserIds();
             if (CollectionUtils.isNotEmpty(userIds)) {
                 try {
                     imGroupService.addGroupMember(entity.getImGroupId(), new HashSet<>(userIds));
@@ -164,7 +175,6 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             }
         }
         // 加群成员
-        List<Long> userIds = tenantGroup.getUserIds();
         if (CollectionUtils.isNotEmpty(userIds)) {
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, userIds)
@@ -194,6 +204,13 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             throw new BizException("小组名称已经存在");
         }
 
+        Long adminId = tenantGroup.getAdminId();
+        Teacher teacher = teacherDao.selectById(adminId);
+        if (!tenantGroup.getTenantId().equals(teacher.getTenantId())) {
+            throw new BizException("负责人机构已经变更,请重新选择");
+        }
+        checkStudent(tenantGroup.getTenantId(), tenantGroup.getUserIds(),tenantGroup.getId());
+
         TenantGroup entity = JSON.parseObject(tenantGroup.jsonString(), TenantGroup.class);
         entity.setImGroupId(oldGroup.getImGroupId());
         // 是否建群
@@ -523,4 +540,26 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 .eq(Student::getTenantGroupId, tenantGroupId);
         return studentDao.selectList(queryWrapper);
     }
+
+    private void checkStudent(Long tenantId, List<Long> userIds,Long tenantGroupId) {
+        if (CollectionUtils.isEmpty(userIds)) {
+            return;
+        }
+        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .in(Student::getUserId, userIds);
+        List<Student> students = studentDao.selectList(queryWrapper);
+        if (userIds.size() != students.size()) {
+            throw new BizException("参数错误");
+        }
+        for (Student student : students) {
+            if (!tenantId.equals(student.getTenantId())) {
+                throw new BizException("学生已经在其他机构");
+            }
+            Long groupId = student.getTenantGroupId();
+            if (groupId != -1L && !groupId.equals(tenantGroupId)) {
+                throw new BizException("学生已经在其他小组");
+            }
+        }
+    }
 }

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

@@ -19,6 +19,7 @@ import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
 import com.yonge.cooleshow.biz.dal.mapper.SysAreaMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantGroupMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantUnbindRecordMapper;
+import com.yonge.cooleshow.biz.dal.mapper.UserTenantBindRecordMapper;
 import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantUnbindRecordWrapper;
 import com.yonge.cooleshow.common.constant.SysConfigConstant;
@@ -93,6 +94,9 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
     @Autowired
     private ImGroupMemberService imGroupMemberService;
 
+    @Autowired
+    private UserTenantBindRecordMapper userTenantBindRecordMapper;
+
     /**
      * @param id 详情ID
      * @return TenantUnbindRecord
@@ -270,6 +274,14 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
                     .set(ESettlementFrom.TENANT.equals(teacher.getSettlementFrom()), Teacher::getSettlementFrom,
                             ESettlementFrom.TEACHER)
                     .set(Teacher::getTenantId, -1L));
+
+            UserTenantBindRecord bindRecord = new UserTenantBindRecord();
+            bindRecord.setUserId(unbindRecord.getUserId());
+            bindRecord.setUserType("TEACHER");
+            bindRecord.setTenantId(tenantId);
+            bindRecord.setBindStatus(false);
+            bindRecord.setBindTime(new Date());
+            userTenantBindRecordMapper.add(bindRecord);
         }
 
         // 添加历史记录

+ 6 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantActivationCodeWrapper.java

@@ -76,6 +76,9 @@ public class TenantActivationCodeWrapper {
         @ApiModelProperty("订单号 订单详情专用")
         private String orderNo;
 
+        @ApiModelProperty("激活码")
+        private String activationCode;
+
         public String getKeyword() {
             return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
         }
@@ -148,6 +151,9 @@ public class TenantActivationCodeWrapper {
         @ApiModelProperty("购买数量")
         private Integer  purchaseQuantity;
 
+        @ApiModelProperty("发放时间")
+        private Date sendTime;
+
         public String jsonString() {
             return JSON.toJSONString(this);
         }

+ 0 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantAlbumPurchaseWrapper.java

@@ -41,9 +41,6 @@ public class TenantAlbumPurchaseWrapper {
         @ApiModelProperty("机构ID")
         private Long tenantId;
 
-        @ApiModelProperty(value = "排序规则,激活数排序:升序:active_quantity_ asc,逆序:active_quantity_ desc")
-        private String orderBy;
-
 
         @ApiModelProperty("采购状态 WAIT_PAY 待支付   PAID 已付款 CLOSE 已关闭")
         private String purchaseStatus;

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantGroupWrapper.java

@@ -78,6 +78,9 @@ public class TenantGroupWrapper {
         @ApiModelProperty("管理员ID")
         private Long adminId;
 
+        @ApiModelProperty("管理员名称")
+        private String adminName;
+
         @ApiModelProperty("IM群聊ID")
         private String imGroupId;
 

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantInfoWrapper.java

@@ -49,6 +49,9 @@ public class TenantInfoWrapper {
         @ApiModelProperty("地区街道编码")
         private Integer regionCode;
 
+        @ApiModelProperty("启用/停用")
+        private Boolean enableFlag;
+
         public String getKeyword() {
             return Optional.ofNullable(keyword).filter(StringUtils::isNotBlank).orElse(null);
         }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/UserTenantBindRecordWrapper.java

@@ -112,6 +112,9 @@ public class UserTenantBindRecordWrapper {
         @ApiModelProperty("手机号")
         private String phone;
 
+        @ApiModelProperty("性别")
+        private Integer gender;
+
         @ApiModelProperty("小组名称")
         private String tenantGroupName;
 

+ 4 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantActivationCodeMapper.xml

@@ -15,6 +15,7 @@
         , t.activation_user_id_ AS activationUserId
         , t.update_time_ AS updateTime
         , t.create_time_ AS createTime
+        , t.send_time_ AS sendTime
     </sql>
 
     <select id="selectPage"
@@ -66,6 +67,9 @@
             <if test="param.tenantGroupId != null">
                 and st.tenant_group_id_ = #{param.tenantGroupId}
             </if>
+            <if test="param.activationCode != null and param.activationCode.trim() != ''">
+                AND t.activation_code_ like concat('%',#{param.activationCode},'%')
+            </if>
         </where>
         order by t.activation_status_ asc, t.id_ desc
     </select>

+ 2 - 9
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantAlbumPurchaseMapper.xml

@@ -31,7 +31,7 @@
         <where>
             <if test="param.keyword != null and param.keyword.trim() != ''">
                 AND (ta.name_ like concat('%',#{param.keyword},'%')
-                or t.purchase_quantity_ = #{param.keyword}
+                or t.purchase_quantity_ like concat('%',#{param.keyword},'%')
                 )
             </if>
             <if test="param.tenantId != null">
@@ -58,14 +58,7 @@
                 AND #{param.purchaseEndTime} >= t.create_time_
             </if>
         </where>
-        <choose>
-            <when test="param.orderBy != null and param.orderBy.trim() != ''">
-                order by #{param.orderBy}
-            </when>
-            <otherwise>
-                order by t.id_ desc
-            </otherwise>
-        </choose>
+        order by t.create_time_ desc
     </select>
     
 </mapper>

+ 1 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantGroupMapper.xml

@@ -30,7 +30,7 @@
                 AND t.admin_id_ = #{param.adminId}
             </if>
         </where>
-        ORDER BY t.id_ ASC
+        ORDER BY t.id_ DESC
     </select>
 
 </mapper>

+ 3 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -105,6 +105,9 @@
             <if test="param.regionCode != null">
                 and t.region_code_ = #{param.regionCode}
             </if>
+            <if test="param.enableFlag != null">
+                and t.enable_flag_ = #{param.enableFlag}
+            </if>
         </where>
         order by t.create_time_ desc
 	</select>

+ 26 - 7
cooleshow-user/user-biz/src/main/resources/config/mybatis/UserTenantBindRecordMapper.xml

@@ -20,26 +20,34 @@
         ,su.username_ userName
         ,su.phone_ phone
         ,su.gender_ gender
-        ,su.lock_flag_ lockFlag
+<!--        ,su.lock_flag_ lockFlag-->
         <if test="param.userType == 'TEACHER'">
+            ,if(su.lock_flag_ = 0 and tc.lock_flag_= 0,0,1) as lockFlag
             ,tc.settlement_from_ settlementFrom
             ,group_concat(tg.name_) tenantGroupName
-            ,tg.id_ tenantGroupId
+            ,group_concat(tg.id_) tenantGroupId
         </if>
         <if test="param.userType == 'STUDENT'">
             ,tg.name_ tenantGroupName
             ,tg.id_ tenantGroupId
             ,st.subject_id_ subjectId
+            ,if(su.lock_flag_ = 0 and st.lock_flag_= 0,0,1) as lockFlag
         </if>
         FROM user_tenant_bind_record t
         LEFT JOIN sys_user su ON t.user_id_ = su.id_
         <if test="param.userType == 'TEACHER'">
             LEFT JOIN teacher tc on t.user_id_ = tc.user_id_
             LEFT JOIN tenant_group tg on t.user_id_ = tg.admin_id_
+            <if test="param.tenantId != null">
+                and tg.tenant_id_ = #{param.tenantId}
+            </if>
         </if>
         <if test="param.userType == 'STUDENT'">
             LEFT JOIN student st on t.user_id_ = st.user_id_
             LEFT JOIN tenant_group tg on st.tenant_group_id_ = tg.id_
+            <if test="param.tenantId != null">
+                and tg.tenant_id_ = #{param.tenantId}
+            </if>
         </if>
         <where>
             <if test="param.keyword != null and param.keyword.trim() != ''">
@@ -55,9 +63,9 @@
                 AND t.user_type_ = #{param.userType}
             </if>
             <if test="param.tenantGroupId != null">
-                <if test="param.userType == 'TEACHER'">
-                    AND tg.id_ =#{param.tenantGroupId}
-                </if>
+<!--                <if test="param.userType == 'TEACHER'">-->
+<!--                    AND tg.id_ =#{param.tenantGroupId}-->
+<!--                </if>-->
                 <if test="param.userType == 'STUDENT'">
                     AND st.tenant_group_id_ = #{param.tenantGroupId}
                 </if>
@@ -81,8 +89,19 @@
                 AND st.subject_id_ = #{param.subjectId}
             </if>
         </where>
-        group by t.user_id_
-        order by t.bind_time_ desc
+        <if test="param.userType == 'TEACHER'">
+            group by t.user_id_
+        </if>
+        <if test="param.tenantGroupId != null and param.userType == 'TEACHER'">
+            HAVING find_in_set(#{param.tenantGroupId},tenantGroupId)
+        </if>
+        order by field(t.bind_status_,1,0) ,t.bind_time_ desc
     </select>
 
+    <insert id="add">
+        INSERT INTO user_tenant_bind_record(user_id_, user_type_, tenant_id_, bind_status_, bind_time_)
+        VALUES (#{record.userId}, #{record.userType}, #{record.tenantId}, #{record.bindStatus}, #{record.bindTime})
+        ON DUPLICATE KEY UPDATE bind_status_ = VALUES(bind_status_),
+                                bind_time_   = VALUES(bind_time_)
+    </insert>
 </mapper>