AccountConfigServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package jnpf.message.service.impl;
  2. import jnpf.base.service.SuperServiceImpl;
  3. import jnpf.base.ActionResult;
  4. import jnpf.constant.MsgCode;
  5. import jnpf.exception.DataException;
  6. import jnpf.message.entity.AccountConfigEntity;
  7. import jnpf.message.mapper.AccountConfigMapper;
  8. import jnpf.message.model.accountconfig.*;
  9. import jnpf.message.service.AccountConfigService;
  10. import cn.hutool.core.util.ObjectUtil;
  11. import jnpf.permission.service.AuthorizeService;
  12. import java.lang.reflect.Field;
  13. import com.baomidou.mybatisplus.annotation.TableField;
  14. import org.springframework.stereotype.Service;
  15. import com.baomidou.mybatisplus.core.metadata.IPage;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import jnpf.util.*;
  20. import java.util.*;
  21. /**
  22. * 账号配置功能
  23. * 版本: V3.2.0
  24. * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
  25. * 作者: JNPF开发平台组
  26. * 日期: 2022-08-18
  27. */
  28. @Service
  29. public class AccountConfigServiceImpl extends SuperServiceImpl<AccountConfigMapper, AccountConfigEntity> implements AccountConfigService {
  30. @Override
  31. public List<AccountConfigEntity> getList(AccountConfigPagination accountConfigPagination) {
  32. return getTypeList(accountConfigPagination, accountConfigPagination.getDataType());
  33. }
  34. @Override
  35. public List<AccountConfigEntity> getTypeList(AccountConfigPagination accountConfigPagination, String dataType) {
  36. String userId = UserProvider.getUser().getUserId();
  37. int total = 0;
  38. int accountConfigNum = 0;
  39. QueryWrapper<AccountConfigEntity> accountConfigQueryWrapper = new QueryWrapper<>();
  40. //关键字
  41. if (StringUtil.isNotBlank(accountConfigPagination.getKeyword()) && !"null".equals(accountConfigPagination.getKeyword())) {
  42. accountConfigNum++;
  43. accountConfigQueryWrapper.lambda().and(t -> t.like(AccountConfigEntity::getEnCode, accountConfigPagination.getKeyword())
  44. .or().like(AccountConfigEntity::getFullName, accountConfigPagination.getKeyword()).or().like(AccountConfigEntity::getAddressorName,accountConfigPagination.getKeyword())
  45. .or().like(AccountConfigEntity::getSmtpUser,accountConfigPagination.getKeyword()).or().like(AccountConfigEntity::getSmsSignature,accountConfigPagination.getKeyword()));
  46. }
  47. //webhook类型
  48. if (ObjectUtil.isNotEmpty(accountConfigPagination.getWebhookType())) {
  49. accountConfigNum++;
  50. accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getWebhookType, accountConfigPagination.getWebhookType());
  51. }
  52. //渠道
  53. if (ObjectUtil.isNotEmpty(accountConfigPagination.getChannel())) {
  54. accountConfigNum++;
  55. accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getChannel, accountConfigPagination.getChannel());
  56. }
  57. //状态
  58. if(ObjectUtil.isNotEmpty(accountConfigPagination.getEnabledMark())){
  59. accountConfigNum++;
  60. int enabledMark = Integer.parseInt(accountConfigPagination.getEnabledMark());
  61. accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark, enabledMark);
  62. }
  63. //配置类型
  64. if (ObjectUtil.isNotEmpty(accountConfigPagination.getType())) {
  65. accountConfigNum++;
  66. accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getType, accountConfigPagination.getType());
  67. }
  68. //排序
  69. if (StringUtil.isEmpty(accountConfigPagination.getSidx())) {
  70. accountConfigQueryWrapper.lambda().orderByAsc(AccountConfigEntity::getSortCode).orderByDesc(AccountConfigEntity::getCreatorTime).orderByDesc(AccountConfigEntity::getLastModifyTime);
  71. } else {
  72. try {
  73. String sidx = accountConfigPagination.getSidx();
  74. AccountConfigEntity accountConfigEntity = new AccountConfigEntity();
  75. Field declaredField = accountConfigEntity.getClass().getDeclaredField(sidx);
  76. declaredField.setAccessible(true);
  77. String value = declaredField.getAnnotation(TableField.class).value();
  78. accountConfigQueryWrapper = "asc".equals(accountConfigPagination.getSort().toLowerCase()) ? accountConfigQueryWrapper.orderByAsc(value) : accountConfigQueryWrapper.orderByDesc(value);
  79. } catch (NoSuchFieldException e) {
  80. e.printStackTrace();
  81. }
  82. }
  83. if (!"1".equals(dataType)) {
  84. if (total > 0 || total == 0) {
  85. Page<AccountConfigEntity> page = new Page<>(accountConfigPagination.getCurrentPage(), accountConfigPagination.getPageSize());
  86. IPage<AccountConfigEntity> userIPage = this.page(page, accountConfigQueryWrapper);
  87. return accountConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
  88. } else {
  89. List<AccountConfigEntity> list = new ArrayList();
  90. return accountConfigPagination.setData(list, list.size());
  91. }
  92. } else {
  93. return this.list(accountConfigQueryWrapper);
  94. }
  95. }
  96. @Override
  97. public AccountConfigEntity getInfo(String id) {
  98. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  99. queryWrapper.lambda().eq(AccountConfigEntity::getId, id);
  100. return this.getOne(queryWrapper);
  101. }
  102. @Override
  103. public void create(AccountConfigEntity entity) {
  104. this.save(entity);
  105. }
  106. @Override
  107. public boolean update(String id, AccountConfigEntity entity) {
  108. entity.setId(id);
  109. return this.updateById(entity);
  110. }
  111. @Override
  112. public void delete(AccountConfigEntity entity) {
  113. if (entity != null) {
  114. this.removeById(entity.getId());
  115. }
  116. }
  117. //子表方法
  118. //列表子表数据方法
  119. //验证表单唯一字段
  120. @Override
  121. public boolean checkForm(AccountConfigForm form, int i,String type,String id) {
  122. int total = 0;
  123. if (ObjectUtil.isNotEmpty(form.getEnCode())) {
  124. QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
  125. codeWrapper.lambda().eq(AccountConfigEntity::getEnCode, form.getEnCode());
  126. codeWrapper.lambda().eq(AccountConfigEntity::getType,type);
  127. if(StringUtil.isNotBlank(id) && !"null".equals(id)) {
  128. codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
  129. }
  130. total += (int) this.count(codeWrapper);
  131. }
  132. int c = 0;
  133. if (total > i + c) {
  134. return true;
  135. }
  136. return false;
  137. }
  138. @Override
  139. public boolean checkGzhId(String gzhId, int i,String type,String id) {
  140. int total = 0;
  141. if (StringUtil.isNotEmpty(gzhId) && !"null".equals(gzhId)) {
  142. QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
  143. codeWrapper.lambda().eq(AccountConfigEntity::getAppId, gzhId);
  144. codeWrapper.lambda().eq(AccountConfigEntity::getType,type);
  145. if(StringUtil.isNotBlank(id) && !"null".equals(id)) {
  146. codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
  147. }
  148. total += (int) this.count(codeWrapper);
  149. }
  150. int c = 0;
  151. if (total > i + c) {
  152. return true;
  153. }
  154. return false;
  155. }
  156. @Override
  157. public AccountConfigEntity getInfoByType(String appKey, String type) {
  158. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  159. queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
  160. queryWrapper.lambda().eq(AccountConfigEntity::getAppKey,appKey);
  161. return this.getOne(queryWrapper);
  162. }
  163. @Override
  164. public AccountConfigEntity getInfoByEnCode(String enCode, String type){
  165. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  166. queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
  167. queryWrapper.lambda().eq(AccountConfigEntity::getEnCode,enCode);
  168. return this.getOne(queryWrapper);
  169. }
  170. @Override
  171. public List<AccountConfigEntity> getListByType(String type){
  172. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  173. queryWrapper.lambda().eq(AccountConfigEntity::getType,type);
  174. queryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark,1);
  175. return this.list(queryWrapper);
  176. }
  177. @Override
  178. public boolean isExistByFullName(String fullName, String id) {
  179. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  180. queryWrapper.lambda().eq(AccountConfigEntity::getFullName, fullName);
  181. if (!StringUtil.isEmpty(id)) {
  182. queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
  183. }
  184. return this.count(queryWrapper) > 0 ? true : false;
  185. }
  186. @Override
  187. public boolean isExistByEnCode(String enCode, String id,String type) {
  188. QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
  189. queryWrapper.lambda().eq(AccountConfigEntity::getEnCode, enCode);
  190. queryWrapper.lambda().eq(AccountConfigEntity::getType,type);
  191. if (!StringUtil.isEmpty(id)) {
  192. queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
  193. }
  194. return this.count(queryWrapper) > 0 ? true : false;
  195. }
  196. @Override
  197. public ActionResult ImportData(AccountConfigEntity entity) throws DataException {
  198. if (entity != null) {
  199. // if (isExistByFullName(entity.getFullName(), entity.getId())) {
  200. // return ActionResult.fail(MsgCode.EXIST001.get());
  201. // }
  202. if (isExistByEnCode(entity.getEnCode(), entity.getId(),entity.getType())) {
  203. return ActionResult.fail(MsgCode.EXIST002.get());
  204. }
  205. try {
  206. this.save(entity);
  207. } catch (Exception e) {
  208. throw new DataException(MsgCode.IMP003.get());
  209. }
  210. return ActionResult.success(MsgCode.IMP001.get());
  211. }
  212. return ActionResult.fail(MsgCode.IMP006.get());
  213. }
  214. }