| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- package jnpf.message.service.impl;
- import jnpf.base.service.SuperServiceImpl;
- import jnpf.base.ActionResult;
- import jnpf.constant.MsgCode;
- import jnpf.exception.DataException;
- import jnpf.message.entity.AccountConfigEntity;
- import jnpf.message.mapper.AccountConfigMapper;
- import jnpf.message.model.accountconfig.*;
- import jnpf.message.service.AccountConfigService;
- import cn.hutool.core.util.ObjectUtil;
- import jnpf.permission.service.AuthorizeService;
- import java.lang.reflect.Field;
- import com.baomidou.mybatisplus.annotation.TableField;
- import org.springframework.stereotype.Service;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import org.springframework.beans.factory.annotation.Autowired;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import jnpf.util.*;
- import java.util.*;
- /**
- * 账号配置功能
- * 版本: V3.2.0
- * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
- * 作者: JNPF开发平台组
- * 日期: 2022-08-18
- */
- @Service
- public class AccountConfigServiceImpl extends SuperServiceImpl<AccountConfigMapper, AccountConfigEntity> implements AccountConfigService {
- @Override
- public List<AccountConfigEntity> getList(AccountConfigPagination accountConfigPagination) {
- return getTypeList(accountConfigPagination, accountConfigPagination.getDataType());
- }
- @Override
- public List<AccountConfigEntity> getTypeList(AccountConfigPagination accountConfigPagination, String dataType) {
- String userId = UserProvider.getUser().getUserId();
- int total = 0;
- int accountConfigNum = 0;
- QueryWrapper<AccountConfigEntity> accountConfigQueryWrapper = new QueryWrapper<>();
- //关键字
- if (StringUtil.isNotBlank(accountConfigPagination.getKeyword()) && !"null".equals(accountConfigPagination.getKeyword())) {
- accountConfigNum++;
- accountConfigQueryWrapper.lambda().and(t -> t.like(AccountConfigEntity::getEnCode, accountConfigPagination.getKeyword())
- .or().like(AccountConfigEntity::getFullName, accountConfigPagination.getKeyword()).or().like(AccountConfigEntity::getAddressorName,accountConfigPagination.getKeyword())
- .or().like(AccountConfigEntity::getSmtpUser,accountConfigPagination.getKeyword()).or().like(AccountConfigEntity::getSmsSignature,accountConfigPagination.getKeyword()));
- }
- //webhook类型
- if (ObjectUtil.isNotEmpty(accountConfigPagination.getWebhookType())) {
- accountConfigNum++;
- accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getWebhookType, accountConfigPagination.getWebhookType());
- }
- //渠道
- if (ObjectUtil.isNotEmpty(accountConfigPagination.getChannel())) {
- accountConfigNum++;
- accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getChannel, accountConfigPagination.getChannel());
- }
- //状态
- if(ObjectUtil.isNotEmpty(accountConfigPagination.getEnabledMark())){
- accountConfigNum++;
- int enabledMark = Integer.parseInt(accountConfigPagination.getEnabledMark());
- accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark, enabledMark);
- }
- //配置类型
- if (ObjectUtil.isNotEmpty(accountConfigPagination.getType())) {
- accountConfigNum++;
- accountConfigQueryWrapper.lambda().eq(AccountConfigEntity::getType, accountConfigPagination.getType());
- }
- //排序
- if (StringUtil.isEmpty(accountConfigPagination.getSidx())) {
- accountConfigQueryWrapper.lambda().orderByAsc(AccountConfigEntity::getSortCode).orderByDesc(AccountConfigEntity::getCreatorTime).orderByDesc(AccountConfigEntity::getLastModifyTime);
- } else {
- try {
- String sidx = accountConfigPagination.getSidx();
- AccountConfigEntity accountConfigEntity = new AccountConfigEntity();
- Field declaredField = accountConfigEntity.getClass().getDeclaredField(sidx);
- declaredField.setAccessible(true);
- String value = declaredField.getAnnotation(TableField.class).value();
- accountConfigQueryWrapper = "asc".equals(accountConfigPagination.getSort().toLowerCase()) ? accountConfigQueryWrapper.orderByAsc(value) : accountConfigQueryWrapper.orderByDesc(value);
- } catch (NoSuchFieldException e) {
- e.printStackTrace();
- }
- }
- if (!"1".equals(dataType)) {
- if (total > 0 || total == 0) {
- Page<AccountConfigEntity> page = new Page<>(accountConfigPagination.getCurrentPage(), accountConfigPagination.getPageSize());
- IPage<AccountConfigEntity> userIPage = this.page(page, accountConfigQueryWrapper);
- return accountConfigPagination.setData(userIPage.getRecords(), userIPage.getTotal());
- } else {
- List<AccountConfigEntity> list = new ArrayList();
- return accountConfigPagination.setData(list, list.size());
- }
- } else {
- return this.list(accountConfigQueryWrapper);
- }
- }
- @Override
- public AccountConfigEntity getInfo(String id) {
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getId, id);
- return this.getOne(queryWrapper);
- }
- @Override
- public void create(AccountConfigEntity entity) {
- this.save(entity);
- }
- @Override
- public boolean update(String id, AccountConfigEntity entity) {
- entity.setId(id);
- return this.updateById(entity);
- }
- @Override
- public void delete(AccountConfigEntity entity) {
- if (entity != null) {
- this.removeById(entity.getId());
- }
- }
- //子表方法
- //列表子表数据方法
- //验证表单唯一字段
- @Override
- public boolean checkForm(AccountConfigForm form, int i,String type,String id) {
- int total = 0;
- if (ObjectUtil.isNotEmpty(form.getEnCode())) {
- QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
- codeWrapper.lambda().eq(AccountConfigEntity::getEnCode, form.getEnCode());
- codeWrapper.lambda().eq(AccountConfigEntity::getType,type);
- if(StringUtil.isNotBlank(id) && !"null".equals(id)) {
- codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
- }
- total += (int) this.count(codeWrapper);
- }
- int c = 0;
- if (total > i + c) {
- return true;
- }
- return false;
- }
- @Override
- public boolean checkGzhId(String gzhId, int i,String type,String id) {
- int total = 0;
- if (StringUtil.isNotEmpty(gzhId) && !"null".equals(gzhId)) {
- QueryWrapper<AccountConfigEntity> codeWrapper = new QueryWrapper<>();
- codeWrapper.lambda().eq(AccountConfigEntity::getAppId, gzhId);
- codeWrapper.lambda().eq(AccountConfigEntity::getType,type);
- if(StringUtil.isNotBlank(id) && !"null".equals(id)) {
- codeWrapper.lambda().ne(AccountConfigEntity::getId, id);
- }
- total += (int) this.count(codeWrapper);
- }
- int c = 0;
- if (total > i + c) {
- return true;
- }
- return false;
- }
- @Override
- public AccountConfigEntity getInfoByType(String appKey, String type) {
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
- queryWrapper.lambda().eq(AccountConfigEntity::getAppKey,appKey);
- return this.getOne(queryWrapper);
- }
- @Override
- public AccountConfigEntity getInfoByEnCode(String enCode, String type){
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getType, type);
- queryWrapper.lambda().eq(AccountConfigEntity::getEnCode,enCode);
- return this.getOne(queryWrapper);
- }
- @Override
- public List<AccountConfigEntity> getListByType(String type){
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getType,type);
- queryWrapper.lambda().eq(AccountConfigEntity::getEnabledMark,1);
- return this.list(queryWrapper);
- }
- @Override
- public boolean isExistByFullName(String fullName, String id) {
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getFullName, fullName);
- if (!StringUtil.isEmpty(id)) {
- queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
- }
- return this.count(queryWrapper) > 0 ? true : false;
- }
- @Override
- public boolean isExistByEnCode(String enCode, String id,String type) {
- QueryWrapper<AccountConfigEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(AccountConfigEntity::getEnCode, enCode);
- queryWrapper.lambda().eq(AccountConfigEntity::getType,type);
- if (!StringUtil.isEmpty(id)) {
- queryWrapper.lambda().ne(AccountConfigEntity::getId, id);
- }
- return this.count(queryWrapper) > 0 ? true : false;
- }
- @Override
- public ActionResult ImportData(AccountConfigEntity entity) throws DataException {
- if (entity != null) {
- // if (isExistByFullName(entity.getFullName(), entity.getId())) {
- // return ActionResult.fail(MsgCode.EXIST001.get());
- // }
- if (isExistByEnCode(entity.getEnCode(), entity.getId(),entity.getType())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- try {
- this.save(entity);
- } catch (Exception e) {
- throw new DataException(MsgCode.IMP003.get());
- }
- return ActionResult.success(MsgCode.IMP001.get());
- }
- return ActionResult.fail(MsgCode.IMP006.get());
- }
- }
|