|
|
@@ -0,0 +1,98 @@
|
|
|
+package com.cyksj.web.controller.manage;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.manage.SysEmailMapper;
|
|
|
+import com.cyksj.model.entity.SysEmail;
|
|
|
+import com.cyksj.model.excel.ExcelMidJourneyData;
|
|
|
+import com.cyksj.service.mange.SysEmailService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+/*
|
|
|
+ *项目名: netflix
|
|
|
+ *文件名: MidJourneyEmailController
|
|
|
+ *创建者: JavaZou
|
|
|
+ *创建时间:2023/4/3 15:08
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/manage/midjourney")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class MidJourneyEmailController {
|
|
|
+ private final SysEmailMapper sysEmailMapper;
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ private final SysEmailService sysEmailService;
|
|
|
+
|
|
|
+ private final static String SECRET = "q1w2e3";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入Midjourney 邮件
|
|
|
+ */
|
|
|
+ @PostMapping("/import/email")
|
|
|
+ public void readMidJourneyEmail(MultipartFile file) throws Exception {
|
|
|
+ EasyExcel.read(file.getInputStream(), ExcelMidJourneyData.class, new AnalysisEventListener<ExcelMidJourneyData>() {
|
|
|
+ @Override
|
|
|
+ public void invoke(ExcelMidJourneyData data, AnalysisContext analysisContext) {
|
|
|
+ try {
|
|
|
+ SysEmail sysEmail = new SysEmail();
|
|
|
+ BeanUtil.copyProperties(data, sysEmail);
|
|
|
+ if (StrUtil.isEmpty(sysEmail.getSecret())) {
|
|
|
+ sysEmail.setSecret(SECRET);
|
|
|
+ }
|
|
|
+ sysEmail.setType(SysEmail.Type.Midjourney);
|
|
|
+ sysEmailMapper.insert(sysEmail);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ).sheet().doRead();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * midJourney邮件列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get/email")
|
|
|
+ public Result<SearchResult<SysEmail>> getEmail() {
|
|
|
+ SearchResult<SysEmail> search = beanSearcher.search(SysEmail.class, MapUtils.builder().field(SysEmail::getType, SysEmail.Type.Midjourney.name()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户登录midjourney账号 验证
|
|
|
+ */
|
|
|
+ @GetMapping("/verify/email")
|
|
|
+ public Result<String> verifyEmail() {
|
|
|
+ SysEmail sysEmail = beanSearcher.searchFirst(SysEmail.class, MapUtils.builder().field(SysEmail::getType, SysEmail.Type.Midjourney.name()).orderBy("rand()").build());
|
|
|
+
|
|
|
+ if (sysEmail == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("未配置Midjourney邮箱");
|
|
|
+ }
|
|
|
+ sysEmailService.verifyEmail(sysEmail);
|
|
|
+ }
|
|
|
+}
|