|
@@ -1,54 +1,27 @@
|
|
|
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.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.entity.Student;
|
|
|
+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;
|
|
|
-import com.yonge.toolset.utils.easyexcel.ExcelException;
|
|
|
-import com.yonge.toolset.utils.easyexcel.ExcelUtils;
|
|
|
-import com.yonge.toolset.utils.excel.POIUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
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 org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@@ -62,179 +35,55 @@ public class TenantActivationCodeController extends BaseController {
|
|
|
private TenantActivationCodeService tenantActivationCodeService;
|
|
|
|
|
|
@Autowired
|
|
|
- private TenantAlbumPurchaseService tenantAlbumPurchaseService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
|
|
|
|
@Autowired
|
|
|
- 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)));
|
|
|
- }
|
|
|
+ private StudentService studentService;
|
|
|
|
|
|
@ApiOperation(value = "查询分页", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeQuery")
|
|
|
@PostMapping("/page")
|
|
|
public HttpResponseResult<PageInfo<TenantActivationCodeWrapper.TenantActivationCode>> page(
|
|
|
@RequestBody TenantActivationCodeWrapper.TenantActivationCodeQuery query) {
|
|
|
- TenantInfo tenantInfo = getTenantInfo();
|
|
|
- query.setTenantId(tenantInfo.getId());
|
|
|
+ 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());
|
|
|
// 查询数据
|
|
|
IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
|
|
|
tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);
|
|
|
- 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(pageInfo);
|
|
|
- }
|
|
|
-
|
|
|
- @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("激活码已经激活");
|
|
|
+ for (TenantActivationCodeWrapper.TenantActivationCode record : pages.getRecords()) {
|
|
|
+ String activationCode = record.getActivationCode();
|
|
|
+ String substring = activationCode.substring(3);
|
|
|
+ record.setActivationCode("***" + substring);
|
|
|
}
|
|
|
- return succeed();
|
|
|
+ return succeed(QueryInfo.pageInfo(pages, pages.getRecords()));
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/exportActiveCode")
|
|
|
- @ApiOperation(value = "导出模板")
|
|
|
- public void exportActiveCode(HttpServletResponse response) {
|
|
|
+ @ApiOperation(value = "激活激活码")
|
|
|
+ @PostMapping("/active")
|
|
|
+ public HttpResponseResult<Boolean> active(@RequestParam("activationCode") String activationCode) {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- if (sysUser == null) {
|
|
|
+ if (sysUser == null || null == sysUser.getId()) {
|
|
|
throw new BizException("请登录");
|
|
|
}
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/importActiveCode")
|
|
|
- @ApiOperation(value = "导入", notes = "传入file")
|
|
|
- public HttpResponseResult<List<ErrMsg>> importActiveCode(
|
|
|
- @RequestParam("file") MultipartFile file,
|
|
|
- @RequestParam("tenantAlbumPurchaseId") Long tenantAlbumPurchaseId) {
|
|
|
- if (null == file) {
|
|
|
- return HttpResponseResult.failed("请上传文件");
|
|
|
- }
|
|
|
- SysUser user = sysUserFeignService.queryUserInfo();
|
|
|
- if (user == null || null == user.getId()) {
|
|
|
- return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
- }
|
|
|
- TenantStaff tenantStaff = tenantStaffService.getByUserId(user.getId());
|
|
|
- if (tenantStaff == null) {
|
|
|
- return HttpResponseResult.failed("权限不足");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- ExcelDataReader<TenantActivationCodeWrapper.ImportTemplate> reader =
|
|
|
- ExcelUtils.getReader(TenantActivationCodeWrapper.ImportTemplate.class, file);
|
|
|
- tenantActivationCodeService.importActiveCode(reader.getDataList(), user.getTenantId(), user.getId(),
|
|
|
- tenantAlbumPurchaseId);
|
|
|
- return HttpResponseResult.succeed();
|
|
|
- } catch (ExcelException e) {
|
|
|
- return HttpResponseResult.failed(BizHttpStatus.IMPORT.getCode(), e.getErrMsgList(),
|
|
|
- BizHttpStatus.IMPORT.getMsg());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @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));
|
|
|
+ tenantActivationCodeService.active(activationCode, sysUser.getId());
|
|
|
+ return succeed();
|
|
|
}
|
|
|
|
|
|
- private TenantInfo getTenantInfo() {
|
|
|
+ @ApiOperation(value = "激活激活码")
|
|
|
+ @PostMapping("/activeById")
|
|
|
+ public HttpResponseResult<Boolean> activeById(@RequestParam("id") String id) {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
- TenantInfo tenantInfo = tenantInfoService.lambdaQuery().eq(TenantInfo::getUserId, sysUser.getId())
|
|
|
- .last("limit 1").one();
|
|
|
- if (tenantInfo == null) {
|
|
|
- throw new BizException("非法请求");
|
|
|
+ if (sysUser == null || null == sysUser.getId()) {
|
|
|
+ throw new BizException("请登录");
|
|
|
}
|
|
|
- return tenantInfo;
|
|
|
+ tenantActivationCodeService.activeById(id, sysUser.getId());
|
|
|
+ return succeed();
|
|
|
}
|
|
|
}
|