tj
2025-03-20 87a0ccb7ed3f0c9bfd856169ef03de136cd1047d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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;
    }
 
 
}