SysConfigController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package jnpf.base.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.annotation.SaMode;
  4. import cn.hutool.core.collection.CollectionUtil;
  5. import cn.hutool.core.util.ObjectUtil;
  6. import com.alibaba.fastjson.JSONObject;
  7. import io.swagger.v3.oas.annotations.Operation;
  8. import io.swagger.v3.oas.annotations.Parameter;
  9. import io.swagger.v3.oas.annotations.Parameters;
  10. import io.swagger.v3.oas.annotations.tags.Tag;
  11. import jakarta.validation.Valid;
  12. import jnpf.base.ActionResult;
  13. import jnpf.base.entity.EmailConfigEntity;
  14. import jnpf.base.entity.SysConfigEntity;
  15. import jnpf.base.model.systemconfig.EmailTestForm;
  16. import jnpf.base.model.systemconfig.SocialsSysVo;
  17. import jnpf.base.model.systemconfig.SysConfigModel;
  18. import jnpf.base.service.SysconfigService;
  19. import jnpf.base.service.SystemConfigApi;
  20. import jnpf.constant.MsgCode;
  21. import jnpf.message.entity.QyWebChatModel;
  22. import jnpf.message.entity.SynThirdInfoEntity;
  23. import jnpf.message.model.message.DingTalkModel;
  24. import jnpf.message.service.SynThirdInfoService;
  25. import jnpf.message.util.QyWebChatUtil;
  26. import jnpf.message.util.SynThirdConsts;
  27. import jnpf.model.SocialsSysConfig;
  28. import jnpf.permission.model.user.form.UserUpAdminForm;
  29. import jnpf.permission.model.user.vo.UserAdminVO;
  30. import jnpf.permission.service.UserService;
  31. import jnpf.util.JsonUtil;
  32. import jnpf.util.RandomUtil;
  33. import jnpf.util.third.DingTalkUtil;
  34. import jnpf.util.wxutil.HttpUtil;
  35. import jnpf.workflow.service.TaskApi;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.web.bind.annotation.*;
  38. import java.util.*;
  39. /**
  40. * 系统配置
  41. *
  42. * @author JNPF开发平台组
  43. * @version V3.1.0
  44. * @copyright 引迈信息技术有限公司
  45. * @date 2019年9月27日 上午9:18
  46. */
  47. @Tag(name = "系统配置", description = "SysConfig")
  48. @RestController
  49. @RequestMapping("/api/system/SysConfig")
  50. public class SysConfigController extends SuperController<SysconfigService, SysConfigEntity> implements SystemConfigApi {
  51. @Autowired
  52. private SysconfigService sysconfigService;
  53. @Autowired
  54. private UserService userService;
  55. @Autowired
  56. private TaskApi taskApi;
  57. @Autowired
  58. private SynThirdInfoService synThirdInfoService;
  59. /**
  60. * 列表
  61. *
  62. * @return ignore
  63. */
  64. @Operation(summary = "列表")
  65. @GetMapping
  66. @SaCheckPermission(value = {"sysConfig.parameter", "sysConfig.strategy"}, mode = SaMode.OR)
  67. public ActionResult<SysConfigModel> list() {
  68. List<SysConfigEntity> list = sysconfigService.getList("SysConfig");
  69. HashMap<String, String> map = new HashMap<>(16);
  70. for (SysConfigEntity sys : list) {
  71. map.put(sys.getFkey(), sys.getValue());
  72. }
  73. SysConfigModel sysConfigModel = JsonUtil.getJsonToBean(map, SysConfigModel.class);
  74. return ActionResult.success(sysConfigModel);
  75. }
  76. /**
  77. * 保存设置
  78. *
  79. * @param sysConfigModel 系统配置模型
  80. * @return ignore
  81. */
  82. @Operation(summary = "更新系统配置")
  83. @Parameter(name = "sysConfigModel", description = "系统模型", required = true)
  84. @SaCheckPermission(value = {"sysConfig.parameter", "sysConfig.strategy"}, mode = SaMode.OR)
  85. @PutMapping
  86. public ActionResult save(@RequestBody SysConfigModel sysConfigModel) {
  87. if (Objects.nonNull(sysConfigModel.getVerificationCodeNumber())) {
  88. if (sysConfigModel.getVerificationCodeNumber() > 6) {
  89. return ActionResult.fail(MsgCode.SYS029.get());
  90. }
  91. if (sysConfigModel.getVerificationCodeNumber() < 3) {
  92. return ActionResult.fail(MsgCode.SYS030.get());
  93. }
  94. }
  95. String flowTodo = sysconfigService.getValueByKey("flowTodo");
  96. if (ObjectUtil.equals(flowTodo, "1") && ObjectUtil.equals(sysConfigModel.getFlowTodo(), 0)) {
  97. if (taskApi.checkTodo()) {
  98. return ActionResult.fail(MsgCode.WF141.get());
  99. }
  100. }
  101. String flowSign = sysconfigService.getValueByKey("flowSign");
  102. if (ObjectUtil.equals(flowSign, "1") && ObjectUtil.equals(sysConfigModel.getFlowSign(), 0)) {
  103. if (taskApi.checkSign()) {
  104. return ActionResult.fail(MsgCode.WF138.get());
  105. }
  106. }
  107. if (sysConfigModel.getAddSignLevel() > 6 || sysConfigModel.getAddSignLevel() < 1) {
  108. return ActionResult.fail("加签层级的范围不在1-6之间");
  109. }
  110. List<SysConfigEntity> entitys = new ArrayList<>();
  111. Map<String, Object> map = JsonUtil.entityToMap(sysConfigModel);
  112. map.put("isLog", "1");
  113. map.put("sysTheme", "1");
  114. map.put("pageSize", "30");
  115. map.put("lastLoginTime", 1);
  116. for (Map.Entry<String, Object> entry : map.entrySet()) {
  117. SysConfigEntity entity = new SysConfigEntity();
  118. entity.setId(RandomUtil.uuId());
  119. entity.setFkey(entry.getKey());
  120. entity.setValue(String.valueOf(entry.getValue()));
  121. entitys.add(entity);
  122. }
  123. sysconfigService.save(entitys);
  124. return ActionResult.success(MsgCode.SU005.get());
  125. }
  126. @Operation(summary = "获取第三方配置")
  127. @SaCheckPermission(value = {"sysConfig.parameter", "integrationCenter.dingTalk"}, mode = SaMode.OR)
  128. @GetMapping("/socials")
  129. public ActionResult<SocialsSysVo> getSocials() {
  130. SocialsSysConfig socialsConfig = sysconfigService.getSocialsConfig();
  131. SocialsSysVo vo = JsonUtil.getJsonToBean(socialsConfig, SocialsSysVo.class);
  132. List<SynThirdInfoEntity> qySynList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_ORG);
  133. List<SynThirdInfoEntity> dingSynList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_ORG);
  134. if (CollectionUtil.isNotEmpty(qySynList)) {
  135. vo.setQyhDisabled(true);
  136. }
  137. if (CollectionUtil.isNotEmpty(dingSynList)) {
  138. vo.setDingDisabled(true);
  139. }
  140. return ActionResult.success(vo);
  141. }
  142. @Operation(summary = "更新第三方配置")
  143. @Parameter(name = "SocialsSysConfig", description = "第三方参数模型", required = true)
  144. @SaCheckPermission(value = {"sysConfig.parameter", "integrationCenter.dingTalk"}, mode = SaMode.OR)
  145. @PutMapping("/socials")
  146. public ActionResult saveSocials(@RequestBody SocialsSysConfig sysConfigModel) {
  147. List<SysConfigEntity> entitys = new ArrayList<>();
  148. Map<String, Object> map = JsonUtil.entityToMap(sysConfigModel);
  149. for (Map.Entry<String, Object> entry : map.entrySet()) {
  150. SysConfigEntity entity = new SysConfigEntity();
  151. entity.setId(RandomUtil.uuId());
  152. entity.setFkey(entry.getKey());
  153. entity.setValue(String.valueOf(entry.getValue()));
  154. entity.setCategory("SocialsConfig");
  155. entitys.add(entity);
  156. }
  157. sysconfigService.saveSocials(entitys);
  158. return ActionResult.success(MsgCode.SU005.get());
  159. }
  160. /**
  161. * 邮箱账户密码验证
  162. *
  163. * @param emailTestForm 邮箱测试模型
  164. * @return ignore
  165. */
  166. @Operation(summary = "邮箱连接测试")
  167. @Parameter(name = "emailTestForm", description = "邮箱测试模型", required = true)
  168. @SaCheckPermission(value = {"sysConfig.parameter", "sysConfig.strategy"}, mode = SaMode.OR)
  169. @PostMapping("/Email/Test")
  170. public ActionResult checkLogin(@RequestBody EmailTestForm emailTestForm) {
  171. EmailConfigEntity entity = JsonUtil.getJsonToBean(emailTestForm, EmailConfigEntity.class);
  172. entity.setEmailSsl(Integer.valueOf(emailTestForm.getSsl()));
  173. String result = sysconfigService.checkLogin(entity);
  174. if ("true".equals(result)) {
  175. return ActionResult.success(MsgCode.SU017.get());
  176. } else {
  177. return ActionResult.fail(result);
  178. }
  179. }
  180. //=====================================测试企业微信、钉钉的连接=====================================
  181. /**
  182. * 测试企业微信配置的连接功能
  183. *
  184. * @param type 0-发送消息,1-同步组织
  185. * @param qyWebChatModel 企业微信模型
  186. * @return ignore
  187. */
  188. @Operation(summary = "测试企业微信配置的连接")
  189. @Parameters({
  190. @Parameter(name = "type", description = "0-发送消息,1-同步组织", required = true),
  191. @Parameter(name = "qyWebChatModel", description = "企业微信模型", required = true)
  192. })
  193. @SaCheckPermission("sysConfig.parameter")
  194. @PostMapping("{type}/testQyWebChatConnect")
  195. public ActionResult testQyWebChatConnect(@PathVariable("type") String type, @RequestBody @Valid QyWebChatModel qyWebChatModel) {
  196. JSONObject retMsg = new JSONObject();
  197. // 测试发送消息、组织同步的连接
  198. String corpId = qyWebChatModel.getQyhCorpId();
  199. String agentSecret = qyWebChatModel.getQyhAgentSecret();
  200. String corpSecret = qyWebChatModel.getQyhCorpSecret();
  201. // 测试发送消息的连接
  202. if ("0".equals(type)) {
  203. retMsg = QyWebChatUtil.getAccessToken(corpId, agentSecret);
  204. if (HttpUtil.isWxError(retMsg)) {
  205. return ActionResult.fail(MsgCode.SYS031.get(retMsg.getString("errmsg")));
  206. }
  207. return ActionResult.success(MsgCode.SYS032.get());
  208. } else if ("1".equals(type)) {
  209. retMsg = QyWebChatUtil.getAccessToken(corpId, corpSecret);
  210. if (HttpUtil.isWxError(retMsg)) {
  211. return ActionResult.fail(MsgCode.SYS033.get(retMsg.getString("errmsg")));
  212. }
  213. return ActionResult.success(MsgCode.SYS034.get());
  214. }
  215. return ActionResult.fail(MsgCode.SYS035.get());
  216. }
  217. /**
  218. * 测试钉钉配置的连接功能
  219. *
  220. * @param dingTalkModel 钉钉模板
  221. * @return ignore
  222. */
  223. @Operation(summary = "测试钉钉配置的连接")
  224. @Parameters({
  225. @Parameter(name = "dingTalkModel", description = "钉钉模型", required = true)
  226. })
  227. @SaCheckPermission("sysConfig.parameter")
  228. @PostMapping("/testDingTalkConnect")
  229. public ActionResult testDingTalkConnect(@RequestBody @Valid DingTalkModel dingTalkModel) {
  230. JSONObject retMsg = new JSONObject();
  231. // 测试钉钉配置的连接
  232. String appKey = dingTalkModel.getDingSynAppKey();
  233. String appSecret = dingTalkModel.getDingSynAppSecret();
  234. ///
  235. // String agentId = dingTalkModel.getDingAgentId();
  236. // 测试钉钉的连接
  237. retMsg = DingTalkUtil.getAccessToken(appKey, appSecret);
  238. if (!retMsg.getBoolean("code")) {
  239. return ActionResult.fail(MsgCode.SYS036.get(retMsg.getString("error")));
  240. }
  241. return ActionResult.success(MsgCode.SYS037.get());
  242. }
  243. /**
  244. * 获取管理员集合
  245. *
  246. * @return
  247. */
  248. @Operation(summary = "获取管理员集合")
  249. @SaCheckPermission("sysConfig.parameter")
  250. @GetMapping("/getAdminList")
  251. public ActionResult<List<UserAdminVO>> getAdminList() {
  252. List<UserAdminVO> admins = JsonUtil.getJsonToList(userService.getAdminList(), UserAdminVO.class);
  253. return ActionResult.success(admins);
  254. }
  255. /**
  256. * 获取管理员集合
  257. *
  258. * @param userUpAdminForm 超级管理员设置表单参数
  259. * @return
  260. */
  261. @Operation(summary = "获取管理员集合")
  262. @Parameters({
  263. @Parameter(name = "userUpAdminForm", description = "超级管理员设置表单参数", required = true)
  264. })
  265. @SaCheckPermission("sysConfig.parameter")
  266. @PutMapping("/setAdminList")
  267. public ActionResult<String> setAdminList(@RequestBody UserUpAdminForm userUpAdminForm) {
  268. userService.setAdminListByIds(userUpAdminForm.getAdminIds());
  269. return ActionResult.success(MsgCode.SU004.get());
  270. }
  271. }