package com.jsh.erp.service.configSecurity.impl;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.github.pagehelper.PageHelper;
|
import com.jsh.erp.constants.BusinessConstants;
|
import com.jsh.erp.datasource.entities.ConfigSecurity;
|
import com.jsh.erp.datasource.entities.ConfigSecurityExample;
|
import com.jsh.erp.datasource.mappers.ConfigSecurityMapper;
|
import com.jsh.erp.dto.ConfigSecurityQuery;
|
import com.jsh.erp.exception.JshException;
|
import com.jsh.erp.service.account.AccountService;
|
import com.jsh.erp.service.configSecurity.ConfigSecurityService;
|
import com.jsh.erp.service.log.LogService;
|
import com.jsh.erp.utils.StringUtil;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
import javax.annotation.Resource;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Objects;
|
|
@Service
|
public class ConfigSecurityServiceImpl implements ConfigSecurityService {
|
|
private Logger logger = LoggerFactory.getLogger(AccountService.class);
|
|
@Resource
|
private ConfigSecurityMapper configSecurityMapper;
|
|
@Resource
|
private LogService logService;
|
|
@Override
|
public Long findListCount(ConfigSecurityQuery configSecurityQuery) {
|
ConfigSecurityExample example = new ConfigSecurityExample();
|
ConfigSecurityExample.Criteria criteria = example.createCriteria();
|
criteria.andDeleteFlagEqualTo(false);
|
if (StringUtils.isNotEmpty(configSecurityQuery.getKeyword())) {
|
criteria.andKeywordLike("%" + configSecurityQuery.getKeyword() + "%");
|
}
|
if (StringUtils.isNotEmpty(configSecurityQuery.getType())) {
|
criteria.andTypeEqualTo(configSecurityQuery.getType());
|
}
|
|
return configSecurityMapper.countByExample(example);
|
}
|
|
@Override
|
public List<ConfigSecurity> findList(ConfigSecurityQuery configSecurityQuery) {
|
// 设置分页参数
|
PageHelper.startPage(configSecurityQuery.getCurrentPage()-1, configSecurityQuery.getPageSize());
|
|
ConfigSecurityExample example = new ConfigSecurityExample();
|
ConfigSecurityExample.Criteria criteria = example.createCriteria();
|
criteria.andDeleteFlagEqualTo(false);
|
if (StringUtils.isNotEmpty(configSecurityQuery.getKeyword())) {
|
criteria.andKeywordLike("%" + configSecurityQuery.getKeyword() + "%");
|
}
|
if (StringUtils.isNotEmpty(configSecurityQuery.getType())) {
|
criteria.andTypeEqualTo(configSecurityQuery.getType());
|
}
|
|
example.setOrderByClause(" create_time desc ");
|
|
return configSecurityMapper.selectByExample(example);
|
}
|
|
@Transactional
|
@Override
|
public int add(ConfigSecurity configSecurity) {
|
configSecurity.setDeleteFlag(false);
|
|
extractedKeywordExists(configSecurity.getKeyword(),null);
|
|
return configSecurityMapper.insert(configSecurity);
|
}
|
|
private void extractedKeywordExists(String keyword, Long id) {
|
// 查看关键字是否已经存在
|
ConfigSecurityExample example = new ConfigSecurityExample();
|
ConfigSecurityExample.Criteria criteria = example.createCriteria();
|
criteria.andDeleteFlagEqualTo(false);
|
criteria.andKeywordEqualTo(keyword);
|
if(!Objects.isNull(id)){
|
criteria.andIdNotEqualTo(id);
|
}
|
long keywordExistedCnt = configSecurityMapper.countByExample(example);
|
if(keywordExistedCnt>0)
|
throw new RuntimeException("关键词已经存在");
|
}
|
|
@Transactional
|
@Override
|
public int update(ConfigSecurity configSecurity) {
|
extractedKeywordExists(configSecurity.getKeyword(),configSecurity.getId());
|
|
return configSecurityMapper.updateByPrimaryKeySelective(configSecurity);
|
}
|
|
@Transactional
|
@Override
|
public int deleteById(Long id) {
|
ConfigSecurity configSecurity = configSecurityMapper.selectByPrimaryKey(id);
|
configSecurity.setDeleteFlag(true);
|
return configSecurityMapper.updateByPrimaryKeySelective(configSecurity);
|
// return configSecurityMapper.deleteByPrimaryKey(id);
|
}
|
|
@Transactional
|
@Override
|
public int deleteBatch(String ids) {
|
|
ConfigSecurity configSecurity = new ConfigSecurity();
|
configSecurity.setDeleteFlag(true);
|
|
ConfigSecurityExample example=new ConfigSecurityExample();
|
ConfigSecurityExample.Criteria criteria=example.createCriteria();
|
List<Long> configSecurityIds = StringUtil.strToLongList(ids);
|
criteria.andIdIn(configSecurityIds);
|
int result=0;
|
try{
|
result = configSecurityMapper.updateByExampleSelective(configSecurity, example);
|
}catch(Exception e){
|
JshException.writeFail(logger, e);
|
}
|
return result;
|
}
|
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
@Override
|
public int batchSetStatus(Integer status, String ids) throws Exception {
|
|
logService.insertLog("账户",
|
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
|
ConfigSecurity configSecurity = new ConfigSecurity();
|
configSecurity.setStatus(status);
|
|
ConfigSecurityExample example=new ConfigSecurityExample();
|
ConfigSecurityExample.Criteria criteria=example.createCriteria();
|
List<Long> configSecurityIds = StringUtil.strToLongList(ids);
|
criteria.andIdIn(configSecurityIds);
|
int result=0;
|
try{
|
result = configSecurityMapper.updateByExampleSelective(configSecurity, example);
|
}catch(Exception e){
|
JshException.writeFail(logger, e);
|
}
|
return result;
|
}
|
|
|
}
|