|
|
|
@ -4,7 +4,6 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import com.baiye.constant.DefaultNumberConstants;
|
|
|
|
|
import com.baiye.exception.EntityExistException;
|
|
|
|
|
import com.baiye.model.enums.ResponseCode;
|
|
|
|
|
import com.baiye.modules.security.service.OnlineUserService;
|
|
|
|
|
import com.baiye.modules.system.domain.Company;
|
|
|
|
|
import com.baiye.modules.system.repository.CompanyRepository;
|
|
|
|
@ -18,6 +17,8 @@ import com.baiye.util.PageUtil;
|
|
|
|
|
import com.baiye.util.QueryHelp;
|
|
|
|
|
import com.baiye.util.SecurityUtils;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
@ -47,28 +48,26 @@ public class CompanyServiceImpl implements CompanyService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public CompanyDto userUpdateCompany(CompanyDto companyDto) throws Exception {
|
|
|
|
|
Long companyId = SecurityUtils.getCompanyId();
|
|
|
|
|
if (companyId != null) {
|
|
|
|
|
Company byUserId = companyRepository.findById(companyId).orElseGet(Company::new);
|
|
|
|
|
if (byUserId == null) {
|
|
|
|
|
throw new EntityExistException(Company.class, "companyName", companyDto.getCompanyName());
|
|
|
|
|
}
|
|
|
|
|
Integer invitationCode = companyDto.getInvitationCode();
|
|
|
|
|
if (invitationCode != null) {
|
|
|
|
|
agentService.updateAgentNums(invitationCode);
|
|
|
|
|
}
|
|
|
|
|
companyDto.setId(byUserId.getId());
|
|
|
|
|
companyDto.setUserId(SecurityUtils.getCurrentUserId());
|
|
|
|
|
companyDto.setStatus(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
BeanUtil.copyProperties(companyDto, byUserId);
|
|
|
|
|
byUserId.setApplicationTime(DateUtil.date());
|
|
|
|
|
userRepository.updateStatusById(Boolean.FALSE, SecurityUtils.getCurrentUserId());
|
|
|
|
|
onlineUserService.kickOutForUsername(SecurityUtils.getCurrentUsername());
|
|
|
|
|
return companyMapper.toDto(companyRepository.save(byUserId));
|
|
|
|
|
@CacheEvict(cacheNames = "companyCache", key = "#companyId")
|
|
|
|
|
public CompanyDto userUpdateCompany(CompanyDto companyDto, Long companyId) {
|
|
|
|
|
Company byUserId = companyRepository.findById(companyId).orElseGet(Company::new);
|
|
|
|
|
if (byUserId == null) {
|
|
|
|
|
throw new EntityExistException(Company.class, "companyName", companyDto.getCompanyName());
|
|
|
|
|
}
|
|
|
|
|
Integer invitationCode = companyDto.getInvitationCode();
|
|
|
|
|
if (invitationCode != null) {
|
|
|
|
|
agentService.updateAgentNums(invitationCode);
|
|
|
|
|
}
|
|
|
|
|
throw new EntityExistException(Long.class, "companyId", ResponseCode.USER_INFORMATION_ERROR.getDesc());
|
|
|
|
|
companyDto.setId(byUserId.getId());
|
|
|
|
|
companyDto.setUserId(SecurityUtils.getCurrentUserId());
|
|
|
|
|
companyDto.setStatus(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
BeanUtil.copyProperties(companyDto, byUserId);
|
|
|
|
|
byUserId.setApplicationTime(DateUtil.date());
|
|
|
|
|
userRepository.updateStatusById(Boolean.FALSE, SecurityUtils.getCurrentUserId());
|
|
|
|
|
onlineUserService.kickOutForUsername(SecurityUtils.getCurrentUsername());
|
|
|
|
|
return companyMapper.toDto(companyRepository.save(byUserId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|