liujc 2 years ago
parent
commit
18588045a0

+ 41 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/TenantActivationCodeController.java

@@ -7,20 +7,29 @@ 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.TenantStaff;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
 import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
+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.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.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.OutputStream;
@@ -43,6 +52,8 @@ public class TenantActivationCodeController extends BaseController {
 
     @Autowired
     private StudentService studentService;
+    @Autowired
+    private TenantStaffService tenantStaffService;
 
     @ApiOperation(value = "查询分页", notes = "机构激活码- 传入 TenantActivationCodeVo.TenantActivationCodeQuery")
     @PostMapping("/page")
@@ -122,4 +133,34 @@ public class TenantActivationCodeController extends BaseController {
             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());
+        }
+    }
+
 }