SnRemarkService.java
2.04 KB
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
package com.huaheng.pc.config.sn.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.sn.domain.SnPartDetailHistory;
import com.huaheng.pc.config.sn.domain.SnRemark;
import com.huaheng.pc.config.sn.mapper.SnPartDetailHistoryMapper;
import com.huaheng.pc.config.sn.mapper.SnRemarkMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class SnRemarkService extends ServiceImpl<SnRemarkMapper, SnRemark> {
@Resource
private SnService snService;
public AjaxResult createdSnReamrk(String snCode,String remark,String operation){
SnRemark snRemark=new SnRemark();
if(StringUtils.isEmpty(snCode)){
return AjaxResult.error("SN为空");
}
if(StringUtils.isEmpty(remark)){
return AjaxResult.error("备注为空");
}
snRemark.setCreated(new Date());
snRemark.setCreatedBy(ShiroUtils.getUserName());
snRemark.setLoginName(ShiroUtils.getLoginName());
snRemark.setSnCode(snCode);
snRemark.setRemark(remark);
String[] array=snCode.split(",");
// 使用Stream API去除重复数据
Set<String> set = Arrays.stream(array)
.distinct()
.collect(Collectors.toSet());
// 将Set转换回数组
String[] uniqueArray = set.toArray(new String[0]);
StringBuilder sb = new StringBuilder();
for (String item : set) {
if(snService.getSn(item)==null){
return AjaxResult.error("sn号"+item+"不存在");
}
sb.append(item).append(",");
}
if(!this.save(snRemark)){
return AjaxResult.error("操作失败");
}
return AjaxResult.success("操作成功");
}
}