| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.PhoneUtil; |
| | | import com.xiaopeng.api.model.account.SysUser; |
| | | import com.xiaopeng.api.model.operation.XpWhitelist; |
| | | import com.xiaopeng.api.model.operation.XpWhitelistOperlog; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.exception.ServiceException; |
| | | import com.xiaopeng.common.core.utils.ip.IpUtils; |
| | | import com.xiaopeng.common.core.web.domain.AjaxResult; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.constant.I18nKeyConstant; |
| | | import com.xiaopeng.operation.dto.WhitelistAddDto; |
| | | import com.xiaopeng.operation.mapper.XpWhitelistMapper; |
| | | import com.xiaopeng.operation.mapper.XpWhitelistOperlogMapper; |
| | |
| | | } |
| | | List<XpWhitelist> addList = new ArrayList<>(); |
| | | List<String> accounts = Arrays.asList(dto.getAccount().split(",")); |
| | | StringBuilder operationContent = new StringBuilder("新增账号:"); |
| | | StringBuilder accountBuilder = new StringBuilder(); |
| | | for (String account : accounts) { |
| | | XpWhitelist xpWhitelist = new XpWhitelist(); |
| | | xpWhitelist.setAccount(account); |
| | | xpWhitelist.setStatus(true); |
| | | xpWhitelist.setIsPriorityDispatch(dto.getIsPriorityDispatch()); |
| | | xpWhitelist.setWhitelistSource(1); |
| | | xpWhitelist.setCreateBy(sysUser.getCreateBy()); |
| | | addList.add(xpWhitelist); |
| | | accountBuilder.append("\"").append(account).append("\"").append(","); |
| | | if (CollUtil.isNotEmpty(accounts)) { |
| | | String notValidPhoneNumber = accounts.stream().filter(item -> !PhoneUtil.isPhone(item)).collect(Collectors.joining(",")); |
| | | if (org.apache.commons.lang3.StringUtils.isNotBlank(notValidPhoneNumber)) { |
| | | throw new ServiceException("以下帐号格式不正确:" + notValidPhoneNumber, I18nKeyConstant.ACCOUNT_FORMAT_ERROR, new Object[]{notValidPhoneNumber}); |
| | | } |
| | | StringBuilder operationContent = new StringBuilder("新增账号:"); |
| | | StringBuilder accountBuilder = new StringBuilder(); |
| | | for (String account : accounts) { |
| | | XpWhitelist xpWhitelist = new XpWhitelist(); |
| | | xpWhitelist.setAccount(account); |
| | | xpWhitelist.setStatus(true); |
| | | xpWhitelist.setIsPriorityDispatch(dto.getIsPriorityDispatch()); |
| | | xpWhitelist.setWhitelistSource(1); |
| | | xpWhitelist.setCreateBy(sysUser.getCreateBy()); |
| | | addList.add(xpWhitelist); |
| | | accountBuilder.append("\"").append(account).append("\"").append(","); |
| | | } |
| | | XpWhitelistOperlog xpWhitelistOperlog = new XpWhitelistOperlog(); |
| | | xpWhitelistOperlog.setOperationName(sysUser.getNickName()); |
| | | xpWhitelistOperlog.setOperationAccount(sysUser.getPhoneNumber()); |
| | | xpWhitelistOperlog.setOperationType(1); |
| | | xpWhitelistOperlog.setOperationIp(IpUtils.getIpAddr()); |
| | | xpWhitelistOperlog.setOperationAccountId(sysUser.getId()); |
| | | StringBuilder content = operationContent.append(accountBuilder.substring(0, accountBuilder.length() - 1)); |
| | | xpWhitelistOperlog.setOperationContent(content.toString()); |
| | | xpWhitelistOperlogMapper.insert(xpWhitelistOperlog); |
| | | this.saveBatch(addList); |
| | | } |
| | | XpWhitelistOperlog xpWhitelistOperlog = new XpWhitelistOperlog(); |
| | | xpWhitelistOperlog.setOperationName(sysUser.getNickName()); |
| | | xpWhitelistOperlog.setOperationAccount(sysUser.getPhoneNumber()); |
| | | xpWhitelistOperlog.setOperationType(1); |
| | | xpWhitelistOperlog.setOperationIp(IpUtils.getIpAddr()); |
| | | xpWhitelistOperlog.setOperationAccountId(sysUser.getId()); |
| | | StringBuilder content = operationContent.append(accountBuilder.substring(0, accountBuilder.length() - 1)); |
| | | xpWhitelistOperlog.setOperationContent(content.toString()); |
| | | xpWhitelistOperlogMapper.insert(xpWhitelistOperlog); |
| | | this.saveBatch(addList); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R editWhitelist(XpWhitelist dto, SysUser sysUser) { |
| | | if (!PhoneUtil.isPhone(dto.getAccount())) { |
| | | throw new ServiceException("以下帐号格式不正确:", I18nKeyConstant.ACCOUNT_FORMAT_ERROR, new Object[]{dto.getAccount()}); |
| | | } |
| | | XpWhitelist whitelist = this.getById(dto.getId()); |
| | | |
| | | StringBuilder operationContent = new StringBuilder("编辑账号:"); |