Explorar o código

1.机构端激活码接口合并错误

yuanliang %!s(int64=2) %!d(string=hai) anos
pai
achega
c049136e18

+ 140 - 32
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/TenantActivationCodeController.java

@@ -1,20 +1,30 @@
 package com.yonge.cooleshow.tenant.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.microsvc.toolkit.common.webportal.exception.BizException;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.entity.Student;
+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.entity.TenantStaff;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
 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.service.TenantStaffService;
 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.common.enums.BizHttpStatus;
+import com.yonge.cooleshow.common.enums.EActivationCode;
+import com.yonge.cooleshow.tenant.vo.TenantActivationCodeVo;
 import com.yonge.toolset.utils.date.DateUtil;
 import com.yonge.toolset.utils.easyexcel.ErrMsg;
 import com.yonge.toolset.utils.easyexcel.ExcelDataReader;
@@ -44,72 +54,132 @@ import java.util.List;
 @Api(tags = "机构激活码")
 public class TenantActivationCodeController extends BaseController {
 
+
     @Autowired
     private TenantActivationCodeService tenantActivationCodeService;
 
     @Autowired
+    private TenantAlbumPurchaseService tenantAlbumPurchaseService;
+
+    @Autowired
     private SysUserFeignService sysUserFeignService;
 
     @Autowired
-    private StudentService studentService;
+    private TenantInfoService tenantInfoService;
+
     @Autowired
     private TenantStaffService tenantStaffService;
 
+    @ApiOperation(value = "详情", notes = "机构激活码-根据详情ID查询单条, 传入id")
+//    @GetMapping("/detail/{id}")
+    public R<TenantActivationCodeVo.TenantActivationCode> detail(@PathVariable("id") Long id) {
+
+        TenantActivationCode wrapper = tenantActivationCodeService.detail(id);
+
+        return R.from(TenantActivationCodeVo.TenantActivationCode.from(JSON.toJSONString(wrapper)));
+    }
+
     @ApiOperation(value = "查询分页", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeQuery")
     @PostMapping("/page")
     public HttpResponseResult<PageInfo<TenantActivationCodeWrapper.TenantActivationCode>> page(
             @RequestBody TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
-        SysUser sysUser = sysUserFeignService.queryUserInfo();
-        if (sysUser == null || null == sysUser.getId()) {
-            throw new BizException("请登录");
-        }
-        Student student = studentService.getById(sysUser.getId());
-        if (student == null) {
-            throw new BizException("学生不存在");
-        }
-        query.setActivationPhone(sysUser.getPhone());
-        query.setTenantId(student.getTenantId());
+        TenantInfo tenantInfo = getTenantInfo();
+        query.setTenantId(tenantInfo.getId());
         // 查询数据
         IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
                 tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
-        for (TenantActivationCodeWrapper.TenantActivationCode record : pages.getRecords()) {
-            String activationCode = record.getActivationCode();
-            String substring = activationCode.substring(3);
-            record.setActivationCode("***" + substring);
+        PageInfo<TenantActivationCodeWrapper.TenantActivationCode> pageInfo = QueryInfo.pageInfo(pages,
+                pages.getRecords());
+
+        if (query.getTenantAlbumPurchaseId() != null) {
+            TenantActivationCodeWrapper.TenantActivationCode extra =
+                    new TenantActivationCodeWrapper.TenantActivationCode();
+            TenantAlbumPurchase purchase = tenantAlbumPurchaseService.getById(query.getTenantAlbumPurchaseId());
+            extra.setActiveQuantity(purchase.getActiveQuantity());
+            pageInfo.setExtra(extra);
         }
-        return succeed(QueryInfo.pageInfo(pages, pages.getRecords()));
+
+        return succeed(pageInfo);
     }
 
-    @ApiOperation(value = "激活激活码")
-    @PostMapping("/active")
-    public HttpResponseResult<Boolean> active(@RequestParam("activationCode") String activationCode) {
-        SysUser sysUser = sysUserFeignService.queryUserInfo();
-        if (sysUser == null || null == sysUser.getId()) {
-            throw new BizException("请登录");
+    @ApiOperation(value = "激活码发放", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeSend")
+    @PostMapping("/send")
+    public HttpResponseResult<Boolean> send(@Validated @RequestBody TenantActivationCodeVo.TenantActivationCodeSend send) {
+        TenantInfo tenantInfo = getTenantInfo();
+        tenantActivationCodeService.sendActivationCode(tenantInfo.getId(), send.getTenantAlbumPurchaseId(),
+                send.getActivationCodeList(),
+                send.getStudentIdList());
+        return succeed();
+    }
+
+    @ApiOperation(value = "激活码发放取消", notes = "传入 激活码的ID")
+    @PostMapping("/sendCancel")
+    public HttpResponseResult<Boolean> sendCancel(@RequestParam("id") Long id) {
+        TenantInfo tenantInfo = getTenantInfo();
+        TenantActivationCode activationCode = tenantActivationCodeService.getById(id);
+        if (activationCode == null || !tenantInfo.getId().equals(activationCode.getTenantId())) {
+            throw new BizException("激活码不存在");
+        }
+        boolean update = tenantActivationCodeService.lambdaUpdate()
+                .set(TenantActivationCode::getSendStatus, EActivationCode.WAIT)
+                .eq(TenantActivationCode::getTenantId, id)
+                .eq(TenantActivationCode::getActivationStatus, false)
+                .eq(TenantActivationCode::getSendStatus, EActivationCode.SEND)
+                .update();
+        if (!update) {
+            throw new BizException("激活码已经激活");
         }
-        tenantActivationCodeService.active(activationCode, sysUser.getId());
         return succeed();
     }
 
-    @ApiOperation(value = "激活激活码")
-    @PostMapping("/activeById")
-    public HttpResponseResult<Boolean> activeById(@RequestParam("id") String id) {
+    @GetMapping("/exportActiveCode")
+    @ApiOperation(value = "导出模板")
+    public void exportActiveCode(HttpServletResponse response) {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
-        if (sysUser == null || null == sysUser.getId()) {
+        if (sysUser == null) {
             throw new BizException("请登录");
         }
-        tenantActivationCodeService.activeById(id, sysUser.getId());
-        return succeed();
+        Long tenantId = sysUser.getTenantId();
+
+        TenantActivationCodeWrapper.TenantActivationCodeQuery query =
+                new TenantActivationCodeWrapper.TenantActivationCodeQuery();
+        query.setTenantId(tenantId);
+        query.setActivationStatus(false);
+        query.setPage(1);
+        query.setRows(9999);
+        IPage<TenantActivationCodeWrapper.TenantActivationCode> queryInfo =
+                tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
+        List<TenantActivationCodeWrapper.TenantActivationCode> rows = queryInfo.getRecords();
+        if (rows.isEmpty()) {
+            throw new BizException("没有可导出数据");
+        }
+
+        try (OutputStream outputStream = response.getOutputStream()) {
+            HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"激活码", "手机号"}, new String[]{
+                    "activationCode", "activationPhone"}, rows);
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-Disposition", "attac:wq" +
+                    "hment;filename=active_code-" + DateUtil.getDate(new Date()) + ".xls");
+            workbook.write(outputStream);
+            outputStream.flush();
+        } catch (Exception e) {
+            log.error("导出激活码异常", e);
+        }
     }
 
 
     @GetMapping("/exportOrderCode")
     @ApiOperation(value = "导出订单激活码模板")
-    public void exportOrderCode(HttpServletResponse response, String orderNo) {
-
+    public void exportOrderCode(HttpServletResponse response,String orderNo) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            throw new BizException("请登录");
+        }
+        Long tenantId = sysUser.getTenantId();
 
         TenantActivationCodeWrapper.TenantActivationCodeQuery query =
                 new TenantActivationCodeWrapper.TenantActivationCodeQuery();
+        query.setTenantId(tenantId);
         query.setActivationStatus(false);
         query.setOrderNo(orderNo);
         query.setPage(1);
@@ -118,7 +188,7 @@ public class TenantActivationCodeController extends BaseController {
                 tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
         List<TenantActivationCodeWrapper.TenantActivationCode> rows = queryInfo.getRecords();
         if (rows.isEmpty()) {
-            throw new com.microsvc.toolkit.common.webportal.exception.BizException("没有可导出数据");
+            throw new BizException("没有可导出数据");
         }
 
         try (OutputStream outputStream = response.getOutputStream()) {
@@ -163,4 +233,42 @@ public class TenantActivationCodeController extends BaseController {
         }
     }
 
+    @ApiOperation(value = "新增", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCode")
+//    @PostMapping("/save")
+    public R<JSONObject> add(@Validated @RequestBody TenantActivationCodeVo.TenantActivationCode tenantActivationCodeVo) {
+
+        // 新增数据
+        tenantActivationCodeService.save(JSON.parseObject(tenantActivationCodeVo.jsonString(),
+                TenantActivationCode.class));
+
+        return R.defaultR();
+    }
+
+    @ApiOperation(value = "修改", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCode")
+//    @PostMapping("/update")
+    public R<JSONObject> update(@Validated @RequestBody TenantActivationCodeVo.TenantActivationCode tenantActivationCodeVo) {
+
+        // 更新数据
+        tenantActivationCodeService.updateById(JSON.parseObject(tenantActivationCodeVo.jsonString(),
+                TenantActivationCode.class));
+
+        return R.defaultR();
+    }
+
+    @ApiOperation(value = "删除", notes = "机构激活码- 传入id")
+//    @PostMapping("/remove")
+    public R<Boolean> remove(@RequestParam Long id) {
+
+        return R.from(tenantActivationCodeService.removeById(id));
+    }
+
+    private TenantInfo getTenantInfo() {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        TenantInfo tenantInfo = tenantInfoService.lambdaQuery().eq(TenantInfo::getUserId, sysUser.getId())
+                .last("limit 1").one();
+        if (tenantInfo == null) {
+            throw new BizException("非法请求");
+        }
+        return tenantInfo;
+    }
 }