xieb
2023-10-26 f6ec72eb97af8b98ec99230850d297075496e5c1
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
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.sm.sjztmd.entity.AttResBase;
import cn.gistack.sm.sjztmd.entity.TbRelResUser;
import cn.gistack.sm.sjztmd.excel.TbRelResUserExcel;
import cn.gistack.sm.sjztmd.mapper.TbRelResUserMapper;
import cn.gistack.sm.sjztmd.service.IAttResBaseService;
import cn.gistack.sm.sjztmd.service.ITbRelResUserService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @PROJECT_NAME: skjcmanager
 * @DESCRIPTION:
 * @USER: aix
 * @DATE: 2023/10/26 10:32
 */
@Service
@DS("zt")
public class TbRelResUserServiceImpl extends ServiceImpl<TbRelResUserMapper, TbRelResUser> implements ITbRelResUserService {
 
    @Autowired
    private IAttResBaseService attResBaseService;
 
    @Autowired
    private ITbRelResUserService tbRelResUserService;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importbRelResUser(List<TbRelResUserExcel> data) {
        if (data.size()>0) {
 
            List<TbRelResUser> list = new ArrayList<>();
            for (TbRelResUserExcel excelPo:data) {
                if (StringUtil.isBlank(excelPo.getResNo()) || StringUtil.isBlank(excelPo.getPhone()))
                    continue;
 
                TbRelResUser tbpo = new TbRelResUser();
 
                AttResBase attResBase = attResBaseService.getOne(Wrappers.<AttResBase>query().lambda().eq(AttResBase::getResRegCode,excelPo.getResNo()));
 
                if (null == attResBase)
                    continue;
 
                if (StringUtil.isBlank(attResBase.getGuid()) || StringUtil.isBlank(excelPo.getPhone()))
                    continue;
 
                tbpo.setResGuid(attResBase.getGuid());
                tbpo.setPhone(excelPo.getPhone());
 
                // 如果存在不保存
                long count = tbRelResUserService.count(Wrappers.<TbRelResUser>query().lambda().eq(TbRelResUser::getResGuid,attResBase.getGuid()).eq(TbRelResUser::getPhone,excelPo.getPhone()));
                if (count == 0)
                    list.add(tbpo);
            }
 
            if (list.size() > 0)
                saveBatch(list);//批量保存
        }
    }
}