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 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 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> queryAllRepoType() { return repoMapper.queryAllRepoType(); } @Override public List queryRepoPull() { SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo(); List repoPullDownVos = repoMapper.queryRepoPull(userInfo.getCompanyId()); repoPullDownVos.forEach(rd -> { List repoUnitList = unitMapper.findList(new RepoUnit().setRepoId(rd.getRepoId())); rd.setRepoUnitList(repoUnitList); }); return repoPullDownVos; } @Override public List repoUnitPullDown(Repo repo) { return unitMapper.findList(new RepoUnit().setRepoId(repo.getRepoId())); } }