AccountConfigController.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. package jnpf.message.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.annotation.SaMode;
  4. import com.alibaba.fastjson.JSONObject;
  5. import io.swagger.v3.oas.annotations.Operation;
  6. import io.swagger.v3.oas.annotations.Parameter;
  7. import io.swagger.v3.oas.annotations.Parameters;
  8. import io.swagger.v3.oas.annotations.tags.Tag;
  9. import jakarta.validation.Valid;
  10. import jnpf.base.ActionResult;
  11. import jnpf.base.UserInfo;
  12. import jnpf.base.controller.SuperController;
  13. import jnpf.base.entity.DictionaryDataEntity;
  14. import jnpf.base.service.BillRuleService;
  15. import jnpf.base.service.DictionaryDataService;
  16. import jnpf.base.vo.DownloadVO;
  17. import jnpf.base.vo.PageListVO;
  18. import jnpf.base.vo.PaginationVO;
  19. import jnpf.config.ConfigValueUtil;
  20. import jnpf.constant.FileTypeConstant;
  21. import jnpf.constant.MsgCode;
  22. import jnpf.emnus.ModuleTypeEnum;
  23. import jnpf.exception.DataException;
  24. import jnpf.message.entity.AccountConfigEntity;
  25. import jnpf.message.model.accountconfig.AccountConfigForm;
  26. import jnpf.message.model.accountconfig.AccountConfigInfoVO;
  27. import jnpf.message.model.accountconfig.AccountConfigListVO;
  28. import jnpf.message.model.accountconfig.AccountConfigPagination;
  29. import jnpf.message.model.message.EmailModel;
  30. import jnpf.message.service.AccountConfigService;
  31. import jnpf.message.service.SendConfigTemplateService;
  32. import jnpf.message.util.EmailUtil;
  33. import jnpf.message.util.QyWebChatUtil;
  34. import jnpf.permission.entity.UserEntity;
  35. import jnpf.permission.service.UserService;
  36. import jnpf.util.*;
  37. import jnpf.util.third.DingTalkUtil;
  38. import jnpf.util.wxutil.HttpUtil;
  39. import lombok.extern.slf4j.Slf4j;
  40. import org.springframework.beans.factory.annotation.Autowired;
  41. import org.springframework.http.MediaType;
  42. import org.springframework.transaction.annotation.Transactional;
  43. import org.springframework.web.bind.annotation.*;
  44. import org.springframework.web.multipart.MultipartFile;
  45. import java.io.IOException;
  46. import java.util.*;
  47. /**
  48. * 账号配置功能
  49. *
  50. * @版本: V3.2.0
  51. * @版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
  52. * @作者: JNPF开发平台组
  53. * @日期: 2022-08-18
  54. */
  55. @Slf4j
  56. @RestController
  57. @Tag(name = "账号配置功能", description = "message")
  58. @RequestMapping("/api/message/AccountConfig")
  59. public class AccountConfigController extends SuperController<AccountConfigService, AccountConfigEntity> {
  60. @Autowired
  61. private FileExport fileExport;
  62. @Autowired
  63. private BillRuleService billRuleService;
  64. @Autowired
  65. private ConfigValueUtil configValueUtil;
  66. @Autowired
  67. private UserService userApi;
  68. @Autowired
  69. private AccountConfigService accountConfigService;
  70. @Autowired
  71. private DictionaryDataService dictionaryDataApi;
  72. @Autowired
  73. private SendConfigTemplateService sendConfigTemplateService;
  74. /**
  75. * 列表
  76. *
  77. * @param accountConfigPagination 账号配置分页模型
  78. * @return
  79. */
  80. @Operation(summary = "列表")
  81. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  82. @GetMapping
  83. public ActionResult<PageListVO<AccountConfigListVO>> list(AccountConfigPagination accountConfigPagination) throws IOException {
  84. List<AccountConfigEntity> list = accountConfigService.getList(accountConfigPagination);
  85. List<DictionaryDataEntity> smsSendTypeList = dictionaryDataApi.getListByTypeDataCode("smsSendType");
  86. List<DictionaryDataEntity> webHookList = dictionaryDataApi.getListByTypeDataCode("msgWebHookSendType");
  87. //处理id字段转名称,若无需转或者为空可删除
  88. UserEntity userEntity;
  89. List<AccountConfigListVO> listVO = JsonUtil.getJsonToList(list, AccountConfigListVO.class);
  90. for (AccountConfigListVO accountConfigVO : listVO) {
  91. //渠道
  92. if (StringUtil.isNotEmpty(accountConfigVO.getChannel())) {
  93. smsSendTypeList.stream().filter(t -> accountConfigVO.getChannel().equals(t.getEnCode())).findFirst()
  94. .ifPresent(dataTypeEntity -> accountConfigVO.setChannel(dataTypeEntity.getFullName()));
  95. }
  96. //webhook类型
  97. if (accountConfigVO.getWebhookType() != null) {
  98. webHookList.stream().filter(t -> accountConfigVO.getWebhookType().equals(t.getEnCode())).findFirst()
  99. .ifPresent(dataTypeEntity -> accountConfigVO.setWebhookType(dataTypeEntity.getFullName()));
  100. }
  101. if (StringUtil.isNotEmpty(accountConfigVO.getCreatorUserId())) {
  102. userEntity = userApi.getInfo(accountConfigVO.getCreatorUserId());
  103. if (userEntity != null) {
  104. accountConfigVO.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
  105. }
  106. }
  107. }
  108. PageListVO vo = new PageListVO();
  109. vo.setList(listVO);
  110. PaginationVO page = JsonUtil.getJsonToBean(accountConfigPagination, PaginationVO.class);
  111. vo.setPagination(page);
  112. return ActionResult.success(vo);
  113. }
  114. /**
  115. * 创建
  116. *
  117. * @param accountConfigForm 新建账号配置模型
  118. * @return ignore
  119. */
  120. @Operation(summary = "新建")
  121. @Parameters({
  122. @Parameter(name = "accountConfigForm", description = "新建账号配置模型")
  123. })
  124. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  125. @PostMapping
  126. @Transactional
  127. public ActionResult create(@RequestBody @Valid AccountConfigForm accountConfigForm) throws DataException {
  128. boolean b = accountConfigService.checkForm(accountConfigForm, 0, accountConfigForm.getType(), "");
  129. if (b) {
  130. return ActionResult.fail(MsgCode.EXIST002.get());
  131. }
  132. boolean c = accountConfigService.checkGzhId(accountConfigForm.getAppKey(), 0, "7", "");
  133. if ("7".equals(accountConfigForm.getType())) {
  134. if (c) {
  135. return ActionResult.fail(MsgCode.FA048.get());
  136. }
  137. }
  138. String mainId = RandomUtil.uuId();
  139. UserInfo userInfo = UserProvider.getUser();
  140. AccountConfigEntity entity = JsonUtil.getJsonToBean(accountConfigForm, AccountConfigEntity.class);
  141. entity.setCreatorTime(DateUtil.getNowDate());
  142. entity.setCreatorUserId(userInfo.getUserId());
  143. entity.setId(mainId);
  144. accountConfigService.save(entity);
  145. return ActionResult.success(MsgCode.SU001.get());
  146. }
  147. /**
  148. * 信息
  149. *
  150. * @param id 主键
  151. * @return ignore
  152. */
  153. @Operation(summary = "信息")
  154. @GetMapping("/{id}")
  155. @Parameters({
  156. @Parameter(name = "id", description = "主键", required = true)
  157. })
  158. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  159. public ActionResult<AccountConfigInfoVO> info(@PathVariable("id") String id) {
  160. AccountConfigEntity entity = accountConfigService.getInfo(id);
  161. AccountConfigInfoVO vo = JsonUtil.getJsonToBean(entity, AccountConfigInfoVO.class);
  162. return ActionResult.success(vo);
  163. }
  164. /**
  165. * 表单信息(详情页)
  166. *
  167. * @param id 主键
  168. * @return ignore
  169. */
  170. @Operation(summary = "表单信息(详情页)")
  171. @Parameters({
  172. @Parameter(name = "id", description = "主键", required = true)
  173. })
  174. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  175. @GetMapping("/detail/{id}")
  176. public ActionResult<AccountConfigInfoVO> detailInfo(@PathVariable("id") String id) {
  177. return info(id);
  178. }
  179. /**
  180. * 更新
  181. *
  182. * @param id 主键
  183. * @param accountConfigForm 修改账号配置模型
  184. * @return ignore
  185. */
  186. @Operation(summary = "更新")
  187. @PutMapping("/{id}")
  188. @Parameters({
  189. @Parameter(name = "id", description = "主键", required = true),
  190. @Parameter(name = "accountConfigForm", description = "修改账号配置模型", required = true)
  191. })
  192. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  193. @Transactional
  194. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid AccountConfigForm accountConfigForm) throws DataException {
  195. boolean b = accountConfigService.checkForm(accountConfigForm, 0, accountConfigForm.getType(), accountConfigForm.getId());
  196. if (b) {
  197. return ActionResult.fail(MsgCode.EXIST002.get());
  198. }
  199. boolean c = accountConfigService.checkGzhId(accountConfigForm.getAppKey(), 0, "7", id);
  200. if ("7".equals(accountConfigForm.getType())) {
  201. if (c) {
  202. return ActionResult.fail(MsgCode.FA048.get());
  203. }
  204. }
  205. //判断配置是否被引用
  206. if (Objects.equals(0, accountConfigForm.getEnabledMark())) {
  207. if (sendConfigTemplateService.isUsedAccount(accountConfigForm.getId())) {
  208. return ActionResult.fail(MsgCode.FA049.get());
  209. }
  210. }
  211. UserInfo userInfo = UserProvider.getUser();
  212. AccountConfigEntity entity = accountConfigService.getInfo(id);
  213. if (entity != null) {
  214. AccountConfigEntity subentity = JsonUtil.getJsonToBean(accountConfigForm, AccountConfigEntity.class);
  215. subentity.setCreatorTime(entity.getCreatorTime());
  216. subentity.setCreatorUserId(entity.getCreatorUserId());
  217. subentity.setLastModifyTime(DateUtil.getNowDate());
  218. subentity.setLastModifyUserId(userInfo.getUserId());
  219. boolean b1 = accountConfigService.updateById(subentity);
  220. if (!b1) {
  221. return ActionResult.fail(MsgCode.VS405.get());
  222. }
  223. return ActionResult.success(MsgCode.SU004.get());
  224. } else {
  225. return ActionResult.fail(MsgCode.FA002.get());
  226. }
  227. }
  228. /**
  229. * 删除
  230. *
  231. * @param id 主键
  232. * @return ignore
  233. */
  234. @Operation(summary = "删除")
  235. @DeleteMapping("/{id}")
  236. @Parameters({
  237. @Parameter(name = "id", description = "主键", required = true)
  238. })
  239. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  240. @Transactional
  241. public ActionResult delete(@PathVariable("id") String id) {
  242. AccountConfigEntity entity = accountConfigService.getInfo(id);
  243. if (entity != null) {
  244. //判断是否与消息发送配置关联
  245. //判断配置是否被引用
  246. if (sendConfigTemplateService.isUsedAccount(entity.getId())) {
  247. return ActionResult.fail(MsgCode.FA050.get());
  248. }
  249. accountConfigService.delete(entity);
  250. }
  251. return ActionResult.success(MsgCode.SU003.get());
  252. }
  253. /**
  254. * 开启或禁用
  255. *
  256. * @param id 主键
  257. * @return ignore
  258. */
  259. @Operation(summary = "开启或禁用")
  260. @PostMapping("/unable/{id}")
  261. @Parameters({
  262. @Parameter(name = "id", description = "主键", required = true)
  263. })
  264. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  265. @Transactional
  266. public ActionResult unable(@PathVariable("id") String id) {
  267. AccountConfigEntity entity = accountConfigService.getInfo(id);
  268. if (entity != null) {
  269. if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
  270. entity.setEnabledMark(0);
  271. return ActionResult.success(MsgCode.WF027.get());
  272. } else {
  273. //判断是否被引用
  274. entity.setEnabledMark(1);
  275. return ActionResult.success(MsgCode.WF026.get());
  276. }
  277. } else {
  278. return ActionResult.fail(MsgCode.FA007.get());
  279. }
  280. }
  281. /**
  282. * 复制
  283. *
  284. * @param id 主键
  285. * @return
  286. */
  287. @Operation(summary = "复制")
  288. @Parameters({
  289. @Parameter(name = "id", description = "主键", required = true)
  290. })
  291. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  292. @PostMapping("/{id}/Actions/Copy")
  293. @Transactional
  294. public ActionResult copy(@PathVariable("id") String id) {
  295. UserInfo userInfo = UserProvider.getUser();
  296. AccountConfigEntity entity = accountConfigService.getInfo(id);
  297. if (entity != null) {
  298. entity.setEnabledMark(0);
  299. String copyNum = UUID.randomUUID().toString().substring(0, 5);
  300. entity.setFullName(entity.getFullName() + ".副本" + copyNum);
  301. entity.setEnCode(entity.getEnCode() + copyNum);
  302. entity.setCreatorTime(DateUtil.getNowDate());
  303. entity.setCreatorUserId(userInfo.getUserId());
  304. if ("7".equals(entity.getType())) {
  305. entity.setAppKey(entity.getAppKey() + "副本" + copyNum);
  306. }
  307. entity.setLastModifyTime(null);
  308. entity.setLastModifyUserId(null);
  309. entity.setId(RandomUtil.uuId());
  310. AccountConfigEntity copyEntity = JsonUtil.getJsonToBean(entity, AccountConfigEntity.class);
  311. if (copyEntity.getEnCode().length() > 50 || copyEntity.getFullName().length() > 50) {
  312. return ActionResult.fail(MsgCode.PRI006.get());
  313. }
  314. accountConfigService.create(copyEntity);
  315. return ActionResult.success(MsgCode.SU007.get());
  316. } else {
  317. return ActionResult.fail(MsgCode.FA004.get());
  318. }
  319. }
  320. /**
  321. * 导出账号配置
  322. *
  323. * @param id 账号配置id
  324. * @return ignore
  325. */
  326. @Operation(summary = "导出")
  327. @GetMapping("/{id}/Action/Export")
  328. public ActionResult export(@PathVariable String id) {
  329. AccountConfigEntity entity = accountConfigService.getInfo(id);
  330. //导出文件
  331. DownloadVO downloadVO = fileExport.exportFile(entity, FileTypeConstant.TEMPORARY, entity.getFullName(), ModuleTypeEnum.ACCOUNT_CONFIG.getTableName());
  332. return ActionResult.success(downloadVO);
  333. }
  334. /**
  335. * 导入账号配置
  336. *
  337. * @param multipartFile 备份json文件
  338. * @return 执行结果标识
  339. */
  340. @Operation(summary = "导入")
  341. @PostMapping(value = "/Action/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  342. public ActionResult importData(@RequestPart("file") MultipartFile multipartFile) throws DataException {
  343. UserInfo userInfo = UserProvider.getUser();
  344. //判断是否为.json结尾
  345. if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.ACCOUNT_CONFIG.getTableName())) {
  346. return ActionResult.fail(MsgCode.IMP002.get());
  347. }
  348. //获取文件内容
  349. String fileContent = FileUtil.getFileContent(multipartFile);
  350. AccountConfigEntity entity = JsonUtil.getJsonToBean(fileContent, AccountConfigEntity.class);
  351. entity.setCreatorUserId(userInfo.getUserId());
  352. entity.setCreatorTime(DateUtil.getNowDate());
  353. return accountConfigService.ImportData(entity);
  354. }
  355. /**
  356. * 测试发送邮件
  357. *
  358. * @param accountConfigForm 账号测试模型
  359. * @return
  360. */
  361. @Operation(summary = "测试发送邮箱")
  362. @Parameters({
  363. @Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
  364. })
  365. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  366. @PostMapping("/testSendMail")
  367. @Transactional
  368. public ActionResult testSendMail(@RequestBody @Valid AccountConfigForm accountConfigForm) {
  369. List<String> toMails = accountConfigForm.getTestSendEmail();
  370. // 获取邮箱配置
  371. Map<String, String> objModel = new HashMap<>();
  372. objModel.put("emailSmtpHost", accountConfigForm.getSmtpServer());
  373. objModel.put("emailSmtpPort", accountConfigForm.getSmtpPort().toString());
  374. objModel.put("emailSenderName", accountConfigForm.getAddressorName());
  375. objModel.put("emailAccount", accountConfigForm.getSmtpUser());
  376. objModel.put("emailPassword", accountConfigForm.getSmtpPassword());
  377. objModel.put("emailSsl", accountConfigForm.getSslLink() == 1 ? "true" : "false");
  378. EmailModel emailModel = JsonUtil.getJsonToBean(objModel, EmailModel.class);
  379. StringBuilder toUserMail = new StringBuilder();
  380. String userEmailAll = "";
  381. String userEmail = "";
  382. String userName = "";
  383. // 相关参数验证
  384. if (StringUtil.isEmpty(emailModel.getEmailSmtpHost())) {
  385. return ActionResult.fail(MsgCode.MSERR101.get());
  386. } else if (StringUtil.isEmpty(emailModel.getEmailSmtpPort())) {
  387. return ActionResult.fail(MsgCode.MSERR101.get());
  388. } else if (StringUtil.isEmpty(emailModel.getEmailAccount())) {
  389. return ActionResult.fail(MsgCode.MSERR102.get());
  390. } else if (StringUtil.isEmpty(emailModel.getEmailPassword())) {
  391. return ActionResult.fail(MsgCode.MSERR103.get());
  392. } else if (toMails == null || toMails.size() < 1) {
  393. return ActionResult.fail(MsgCode.MSERR104.get());
  394. } else {
  395. // 设置邮件标题
  396. emailModel.setEmailTitle(accountConfigForm.getTestEmailTitle());
  397. // 设置邮件内容
  398. String content = accountConfigForm.getTestEmailContent();
  399. emailModel.setEmailContent(content);
  400. // 获取收件人的邮箱地址、创建消息用户实体
  401. for (String userId : toMails) {
  402. UserEntity userEntity = userApi.getInfo(userId);
  403. if (userEntity != null) {
  404. userEmail = StringUtil.isEmpty(userEntity.getEmail()) ? "" : userEntity.getEmail();
  405. userName = userEntity.getRealName();
  406. }
  407. if (StringUtil.isNotBlank(userEmail) && !"null".equals(userEmail)) {
  408. //校验用户邮箱格式
  409. if (!isEmail(userEmail)) {
  410. return ActionResult.fail(MsgCode.MSERR105.get(userName));
  411. }
  412. toUserMail = toUserMail.append(",").append(userName).append("<").append(userEmail).append(">");
  413. } else {
  414. return ActionResult.fail(MsgCode.MSERR106.get(userName));
  415. }
  416. }
  417. // 处理接收人员的邮箱信息串并验证
  418. userEmailAll = toUserMail.toString();
  419. if (StringUtil.isNotEmpty(userEmailAll)) {
  420. userEmailAll = userEmailAll.substring(1);
  421. }
  422. if (StringUtil.isEmpty(userEmailAll)) {
  423. return ActionResult.fail(MsgCode.MSERR107.get());
  424. } else {
  425. // 设置接收人员
  426. emailModel.setEmailToUsers(userEmailAll);
  427. // 发送邮件
  428. JSONObject retJson = EmailUtil.sendMail(emailModel);
  429. if (!retJson.getBoolean("code")) {
  430. return ActionResult.fail(MsgCode.MSERR108.get(retJson.get("error")));
  431. }
  432. }
  433. }
  434. return ActionResult.success(MsgCode.MSERR111.get());
  435. }
  436. /**
  437. * 测试企业微信配置的连接功能
  438. *
  439. * @param accountConfigForm 账号测试模型
  440. * @return ignore
  441. */
  442. @Operation(summary = "测试企业微信配置的连接")
  443. @Parameters({
  444. @Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
  445. })
  446. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  447. @PostMapping("/testQyWebChatConnect")
  448. public ActionResult testQyWebChatConnect(@RequestBody @Valid AccountConfigForm accountConfigForm) {
  449. JSONObject retMsg;
  450. // 测试发送消息、组织同步的连接
  451. //企业微信企业id
  452. String corpId = accountConfigForm.getEnterpriseId();
  453. //企业微信应用secret
  454. String agentSecret = accountConfigForm.getAppSecret();
  455. // String corpSecret = testAccountConfigForm.getQyhCorpSecret();
  456. // 测试发送消息的连接
  457. retMsg = QyWebChatUtil.getAccessToken(corpId, agentSecret);
  458. if (HttpUtil.isWxError(retMsg)) {
  459. return ActionResult.fail(MsgCode.MSERR110.get(retMsg.getString("errmsg")));
  460. }
  461. return ActionResult.success(MsgCode.MSERR109.get());
  462. }
  463. /**
  464. * 测试钉钉配置的连接功能
  465. *
  466. * @param accountConfigForm 账号测试模型
  467. * @return ignore
  468. */
  469. @Operation(summary = "测试钉钉配置的连接")
  470. @Parameters({
  471. @Parameter(name = "accountConfigForm", description = "账号测试模型", required = true)
  472. })
  473. @SaCheckPermission(value = {"integrationCenter.sms", "integrationCenter.email", "integrationCenter.weChatMp", "integrationCenter.webhook"}, mode = SaMode.OR)
  474. @PostMapping("/testDingTalkConnect")
  475. public ActionResult testDingTalkConnect(@RequestBody @Valid AccountConfigForm accountConfigForm) {
  476. JSONObject retMsg;
  477. // 测试钉钉配置的连接
  478. String appKey = accountConfigForm.getAppId();
  479. String appSecret = accountConfigForm.getAppSecret();
  480. ///
  481. // String agentId = dingTalkModel.getDingAgentId();
  482. // 测试钉钉的连接
  483. retMsg = DingTalkUtil.getAccessToken(appKey, appSecret);
  484. if (!retMsg.getBoolean("code")) {
  485. return ActionResult.fail(MsgCode.MSERR110.get(retMsg.getString("error")));
  486. }
  487. return ActionResult.success(MsgCode.MSERR109.get());
  488. }
  489. public boolean isEmail(String email) {
  490. String EMAIL_REGEX = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
  491. Boolean b = email.matches(EMAIL_REGEX);
  492. return b;
  493. }
  494. }