张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
package com.thhy.mobile.modules.biz.repo.service.impl;
 
import com.thhy.general.common.BasicStatus;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.DeepCopyUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.mobile.modules.biz.repo.entity.*;
import com.thhy.mobile.modules.biz.repo.mapper.RepoMapper;
import com.thhy.mobile.modules.biz.repo.mapper.RepoRecordMapper;
import com.thhy.mobile.modules.biz.repo.mapper.RepoUnitMapper;
import com.thhy.mobile.modules.biz.repo.service.RepoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
/**
 *  服务实现类
 * @author zhang_xiao_bo
 * @since 2023-05-15 11:13:39
 */
@Service
public class RepoServiceImpl implements RepoService {
 
 
 
    @Autowired
    private RepoMapper repoMapper;
 
    @Autowired
    private RepoRecordMapper recordMapper;
 
    @Autowired
    private RepoUnitMapper unitMapper;
 
    public Repo get(Serializable id){
        return repoMapper.queryById(id);
    }
 
    public List<RepoListVo> findList(Repo repo){
        SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
        return repoMapper.findList(repo.setCompanyId(sysUserInfo.getCompanyId()));
    }
 
    /**
     * 增加和修改
     * @param repoDto
     */
    @Transactional
    public void addRepo(RepoDto repoDto){
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        Repo repo = new Repo();
        List<RepoUnit> repoUnitList = repoDto.getRepoUnitList();
        DeepCopyUtils.copy(repoDto,repo);
        if(repo.getRepoId() == null){
            //增加操作
            repo.setCompanyId(userInfo.getCompanyId());
            repo.setCreateUser(userInfo.getUserId());
            repoMapper.insert(repo);
 
        }else{
            //修改操作
            repo.setUpdateUser(userInfo.getUserId());
            repo.setUpdateTime(new Date());
            repoMapper.update(repo);
 
            unitMapper.findList(new RepoUnit().setRepoId(repo.getRepoId()));
            //unitMapper.deleteByRepoId(repo.getRepoId());
        }
 
        repoUnitList.forEach(ru ->{
            if(ru.getUnitId()==null){
                ru.setRepoId(repo.getRepoId());
                unitMapper.insert(ru);
            }else{
                /*int count = recordMapper.countByUnitId(ru.getUnitId());
                if(count>0){
 
                }*/
                unitMapper.update(ru);
            }
 
        });
 
    }
 
    /**
     * 修改
     * @param repo
     */
    public void update(Repo repo){
        repoMapper.update(repo);
    }
 
    /**
     * 删除
     * @param repoId
     */
    @Transactional
    public void delete(String repoId){
        int count = recordMapper.countRecordByRepoId(repoId);
        if(count>0){
            throw new BasicException(BasicStatus.REPO_IS_ALREADY_USE);
        }
        repoMapper.deleteById(repoId);
    }
 
    @Override
    @Transactional
    public void deleteUnit(RepoUnit repoUnit) {
        int count = recordMapper.countByUnitId(repoUnit.getUnitId());
        if(count>0){
            throw new BasicException(BasicStatus.REPO_UNIT_IS_ALREADY_USE);
        }
        unitMapper.deleteById(repoUnit.getUnitId());
    }
 
    @Override
    public List<HashMap<String,Object>> queryAllRepoType() {
        return repoMapper.queryAllRepoType();
    }
 
    @Override
    public List<RepoPullDownVo> queryRepoPull() {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        List<RepoPullDownVo> repoPullDownVos = repoMapper.queryRepoPull(userInfo.getCompanyId());
        repoPullDownVos.forEach(rd -> {
            List<RepoUnit> repoUnitList = unitMapper.findList(new RepoUnit().setRepoId(rd.getRepoId()));
            rd.setRepoUnitList(repoUnitList);
        });
        return repoPullDownVos;
    }
 
    @Override
    public List<RepoUnit> repoUnitPullDown(Repo repo) {
        return unitMapper.findList(new RepoUnit().setRepoId(repo.getRepoId()));
    }
}