|  |  | 
 |  |  | package com.doumee.service.business.impl; | 
 |  |  |  | 
 |  |  | import com.doumee.core.constants.ResponseStatus; | 
 |  |  | import com.doumee.core.exception.BusinessException; | 
 |  |  | import com.doumee.core.model.PageData; | 
 |  |  | import com.doumee.core.model.PageWrap; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.CompanyMapper; | 
 |  |  | import com.doumee.dao.business.CompanyPermissionMapper; | 
 |  |  | import com.doumee.dao.business.model.Company; | 
 |  |  | import com.doumee.dao.business.model.CompanyPermission; | 
 |  |  | import com.doumee.dao.system.SystemUserMapper; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.service.business.CompanyPermissionService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CompanyPermissionMapper companyPermissionMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private SystemUserMapper systemUserMapper; | 
 |  |  |     @Autowired | 
 |  |  |     private CompanyMapper companyMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(CompanyPermission companyPermission) { | 
 |  |  |         companyPermissionMapper.insert(companyPermission); | 
 |  |  |         if(companyPermission.getUserId() == null || companyPermission.getCompanyIdList() == null || companyPermission.getCompanyIdList().size()==0){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         SystemUser user =systemUserMapper.selectById(companyPermission.getUserId()); | 
 |  |  |         if(user == null || (user.getDeleted() !=null && user.getDeleted())){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,用户信息不存在,请尝试刷新页面重试!"); | 
 |  |  |         } | 
 |  |  |         List<Company> companieList = companyMapper.selectList(new QueryWrapper<Company>().lambda() | 
 |  |  |                 .in(Company::getId,companyPermission.getCompanyIdList()) | 
 |  |  |                 .eq(Company::getIsdeleted, Constants.ZERO)); | 
 |  |  |  | 
 |  |  |         if(companieList == null || companieList.size() == 0){ | 
 |  |  |             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择有效企业,请尝试刷新页面重试!"); | 
 |  |  |         } | 
 |  |  |         Date date = new Date(); | 
 |  |  |         List<CompanyPermission> list = new ArrayList<>(); | 
 |  |  |         for(Company c : companieList){ | 
 |  |  |             CompanyPermission model = new CompanyPermission(); | 
 |  |  |             model.setCompanyId(c.getId()); | 
 |  |  |             model.setIsdeleted(Constants.ZERO); | 
 |  |  |             model.setIsdeleted(Constants.ZERO); | 
 |  |  |             model.setCreator(user.getId()); | 
 |  |  |             model.setUserId(companyPermission.getUserId()); | 
 |  |  |             model.setCreateDate(date); | 
 |  |  |             list.add(model); | 
 |  |  |         } | 
 |  |  |         //刪除原有的,在批量插入新的 | 
 |  |  |         companyPermissionMapper.delete(new QueryWrapper<CompanyPermission>().lambda().eq(CompanyPermission::getUserId,companyPermission.getUserId())); | 
 |  |  |         companyPermissionMapper.insertBatchSomeColumn(list); | 
 |  |  |         return companyPermission.getId(); | 
 |  |  |     } | 
 |  |  |  |