yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package com.qianwen.smartman.modules.system.service.impl;
 
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.smartman.common.enums.StatusType;
import com.qianwen.smartman.common.utils.ExtraLambdaQueryWrapper;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.common.utils.ValidatorUtils;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import com.qianwen.smartman.modules.system.convert.PostConvert;
import com.qianwen.smartman.modules.system.entity.Post;
import com.qianwen.smartman.modules.system.excel.PostImport;
import com.qianwen.smartman.modules.system.mapper.PostMapper;
import com.qianwen.smartman.modules.system.service.IPostService;
import com.qianwen.smartman.modules.system.vo.PostDetailVO;
import com.qianwen.smartman.modules.system.vo.PostSelectVO;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/service/impl/PostServiceImpl.class */
public class PostServiceImpl extends BaseServiceImpl<PostMapper, Post> implements IPostService {
    @Autowired
    private OssBuilder ossBuilder;
    @Autowired
    @Lazy
    private IEmployeeService employeeService;
 
    @Override // org.springblade.modules.system.service.IPostService
    public IPage<PostDetailVO> selectPostPage(IPage<PostDetailVO> page, PostSelectVO postSelectVO) {
        return page.setRecords(((PostMapper) this.baseMapper).selectPostPage(page, postSelectVO));
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public String getPostIds(String tenantId, String postNames) {
        List<Post> postList = this.baseMapper.selectList(Wrappers.<Post>query().lambda().eq(Post::getTenantId, tenantId)
                .eq(Post::getStatus, CommonConstant.ENABLE)
                .in(Post::getPostName, Func.toStrList(postNames)));
        /*
        List<Post> postList = ((PostMapper) this.baseMapper).selectList((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId)).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE)).in((v0) -> {
            return v0.getPostName();
        }, Func.toStrList(postNames)));*/
        if (postList != null && postList.size() > 0) {
            return (String) postList.stream().map(post -> {
                return Func.toStr(post.getId());
            }).distinct().collect(Collectors.joining(","));
        }
        return null;
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public String getPostIdsByFuzzy(String tenantId, String postNames) {
        LambdaQueryWrapper<Post> wrapper = Wrappers.<Post>query().lambda().eq(Post::getTenantId, tenantId);
        /*
        Wrapper wrapper = (LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getTenantId();
        }, tenantId);*/
        wrapper.and(wrapper2 -> {
            List<String> names = Func.toStrList(postNames);
            names.forEach(name -> {
                LambdaQueryWrapper lambdaQueryWrapper =  wrapper2.like(Post::getPostName, name).or();
            });
        });
        List<Post> postList = this.baseMapper.selectList(wrapper);
        if (postList != null && postList.size() > 0) {
            return (String) postList.stream().map(post -> {
                return Func.toStr(post.getId());
            }).distinct().collect(Collectors.joining(","));
        }
        return null;
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public List<String> getPostNames(String postIds) {
        return ((PostMapper) this.baseMapper).getPostNames(Func.toLongArray(postIds));
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public void checkExistPostNameOrCode(Post post) {
        Post result = getOne(Lambda.<Post>create()
                .and(wrapper -> wrapper.eq(Post::getPostName, post.getPostName()).or().eq(Post::getPostCode, post.getPostCode()))
                
                .ne(Func.isNotEmpty(post.getId()), Post::getId, post.getId())
                .eq(Post::getStatus, CommonConstant.ENABLE)
                .limit());
        /*
        Post result = (Post) getOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().and(wrapper -> {
            ExtraLambdaQueryWrapper extraLambdaQueryWrapper = (ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) wrapper.eq((v0) -> {
                return v0.getPostName();
            }, post.getPostName())).or()).eq((v0) -> {
                return v0.getPostCode();
            }, post.getPostCode());
        })).ne(Func.isNotEmpty(post.getId()), (v0) -> {
            return v0.getId();
        }, post.getId()).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE)).limit());*/
        if (Func.isNotEmpty(result)) {
            throw new ServiceException(MessageUtils.message("cps.post.name.or.code.already.exists", new Object[0]));
        }
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public BladeFile importPost(List<PostImport> data) {
        if (Func.isEmpty(data)) {
            throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
        }
        if (data.size() > 200) {
            throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0]));
        }
        HashMap<String, Object> codeMap = new HashMap<>(16);
        HashMap<String, Object> nameMap = new HashMap<>(16);
        List<Post> postList = list(Wrappers.<Post>lambdaQuery().eq(Post::getStatus, CommonConstant.ENABLE));
        /*
        List<Post> postList = list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE));*/
        if (Func.isNotEmpty(postList)) {
            postList.forEach(x -> {
                codeMap.put(x.getPostCode(), null);
                nameMap.put(x.getPostName(), null);
            });
        }
        Boolean flag = Boolean.TRUE;
        for (PostImport datum : data) {
            checkImportPost(datum, codeMap, nameMap);
            if (Func.isNotEmpty(datum.getFailReason())) {
                flag = Boolean.FALSE;
            }
        }
        if (!flag.booleanValue()) {
            MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "postFailTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "岗位信息表", data.stream().filter(x2 -> {
                return Func.isNotEmpty(x2.getFailReason());
            }).collect(Collectors.toList()), (Object) null, (AbstractMergeStrategy) null);
            BladeFile bladeFile = this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
            return bladeFile;
        }
        List<Post> result = PostConvert.INSTANCE.convertExcelToEntity(data);
        saveBatch(result);
        return null;
    }
 
    private void checkImportPost(PostImport postImport, HashMap<String, Object> codeMap, HashMap<String, Object> nameMap) {
        String codeKey = postImport.getPostCode();
        String nameKey = postImport.getPostName();
        if (Func.isEmpty(codeKey)) {
            postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.can.not.be.null", new Object[0]));
        } else if (codeMap.containsKey(codeKey)) {
            postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.already.exists", new Object[0]));
        } else if (ValidatorUtils.checkContextLength(codeKey)) {
            postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.length.error", new Object[0]));
        } else {
            codeMap.put(codeKey, null);
            if (Func.isEmpty(nameKey)) {
                postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.can.not.be.null", new Object[0]));
            } else if (nameMap.containsKey(nameKey)) {
                postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.already.exists", new Object[0]));
            } else if (ValidatorUtils.checkContextLength(nameKey)) {
                postImport.setFailReason(MessageUtils.message("cps.post.name.or.code.length.error", new Object[0]));
            } else if (ValidatorUtils.stringFilter(nameKey)) {
                postImport.setFailReason(MessageUtils.message("cps.post.name.exist.special.symbols.error", new Object[0]));
            } else if (checkExistImportEnablePostNameOrCode(codeKey, nameKey)) {
                postImport.setFailReason(MessageUtils.message("cps.post.name.already.exist.stop.status", new Object[0]));
            } else {
                nameMap.put(nameKey, null);
            }
        }
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public void insertNewPost(Post post) {
        boolean result = (Func.isNotEmpty(post.getId()) ? Boolean.TRUE : Boolean.FALSE).booleanValue();
        if (!result) {
            checkExistEnablePostNameOrCode(post);
        }
        saveOrUpdate(post);
    }
 
    @Override // org.springblade.modules.system.service.IPostService
    public Boolean removePost(List<Long> ids, Integer type) {
        if (StatusType.REMOVE.getType().equals(type)) {
            Long postEmployeeNum = Long.valueOf(this.employeeService.count(Wrappers.<Employee>lambdaQuery().in(Employee::getPostId, ids)));
            /*
            Long postEmployeeNum = Long.valueOf(this.employeeService.count((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getPostId();
            }, ids)));*/
            if (postEmployeeNum.compareTo(Long.valueOf("0")) > 0) {
                throw new ServiceException(MessageUtils.message("cps.post.exist.employee", new Object[0]));
            }
            CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
            return Boolean.valueOf(deleteLogic(ids));
        }
        return Boolean.valueOf(changeStatus(ids, CommonConstant.DEACTIVATE));
    }
 
    private boolean checkExistImportEnablePostNameOrCode(String code, String name) {
        Post result = getOne(Lambda.<Post>create()
                .and(wrapper -> wrapper.eq(Post::getPostName, name).or().eq(Post::getPostCode, code))
                
                .eq(Post::getStatus, CommonConstant.DEACTIVATE)
                .limit());
        /*
        Post result = (Post) getOne(((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) Lambda.create().and(wrapper -> {
            ExtraLambdaQueryWrapper extraLambdaQueryWrapper = (ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) ((ExtraLambdaQueryWrapper) wrapper.eq((v0) -> {
                return v0.getPostName();
            }, name)).or()).eq((v0) -> {
                return v0.getPostCode();
            }, code);
        })).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.DEACTIVATE)).limit());*/
        if (result != null) {
            return Boolean.TRUE.booleanValue();
        }
        return Boolean.FALSE.booleanValue();
    }
 
    private void checkExistEnablePostNameOrCode(Post post) {
        Post result = getOne(Lambda.<Post>create().and(wrapper -> {
            ExtraLambdaQueryWrapper extraLambdaQueryWrapper = wrapper.eq(Post::getPostName, post.getPostName()).or().eq(Post::getPostCode, post.getPostCode());
        }).ne(Func.isNotEmpty(post.getId()), Post::getId, post.getId()).eq(Post::getStatus, CommonConstant.DEACTIVATE).limit());
        if (result != null) {
            throw new ServiceException(MessageUtils.message("cps.post.name.already.exist.stop.status", new Object[0]));
        }
    }
}