134 lines
5.0 KiB
Java
134 lines
5.0 KiB
Java
package net.gepafin.tendermanagement.service.impl;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import net.gepafin.tendermanagement.dao.CompanyDao;
|
|
import net.gepafin.tendermanagement.dao.DelegationDao;
|
|
import net.gepafin.tendermanagement.dao.VatCheckDao;
|
|
import net.gepafin.tendermanagement.entities.CompanyEntity;
|
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
|
import net.gepafin.tendermanagement.entities.UserWithCompanyEntity;
|
|
import net.gepafin.tendermanagement.model.request.CompanyDelegationRequest;
|
|
import net.gepafin.tendermanagement.model.request.CompanyRequest;
|
|
import net.gepafin.tendermanagement.model.response.CompanyDelegationResponse;
|
|
import net.gepafin.tendermanagement.model.response.CompanyResponse;
|
|
import net.gepafin.tendermanagement.service.CompanyService;
|
|
import net.gepafin.tendermanagement.util.Validator;
|
|
|
|
@Service
|
|
public class CompanyServiceImpl implements CompanyService {
|
|
|
|
@Autowired
|
|
private Validator validator;
|
|
|
|
@Autowired
|
|
private CompanyDao companyDao;
|
|
|
|
@Autowired
|
|
private VatCheckDao vatCheckDao;
|
|
|
|
@Autowired
|
|
private DelegationDao delegationDao;
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public CompanyResponse createCompany(HttpServletRequest request, CompanyRequest companyRequest) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
return companyDao.createCompany(userEntity, companyRequest);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public CompanyResponse updateCompany(HttpServletRequest request, Long companyId, CompanyRequest companyRequest) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
validator.validateUserWithCompany(request, companyId);
|
|
return companyDao.updateCompany(userEntity, companyId, companyRequest);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(readOnly = true)
|
|
public CompanyResponse getCompany(HttpServletRequest request, Long companyId) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
validator.validateUserWithCompany(request, companyId);
|
|
return companyDao.getCompany(userEntity, companyId);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void deleteCompany(HttpServletRequest request, Long companyId) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
validator.validateUserWithCompany(request, companyId);
|
|
companyDao.deleteCompany(userEntity, companyId);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(readOnly = true)
|
|
public List<CompanyResponse> getCompanyByUserId(HttpServletRequest request, Long userId) {
|
|
validator.validateUserId(request, userId);
|
|
return companyDao.getCompanyByUserId(userId);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(readOnly = true)
|
|
public Map<String, Object> checkVatNumber(HttpServletRequest request, String vatNumber) {
|
|
return vatCheckDao.checkVatNumber(vatNumber);
|
|
}
|
|
@Override
|
|
public CompanyEntity validateCompany(Long companyId) {
|
|
return companyDao.validateCompany(companyId);
|
|
}
|
|
|
|
@Override
|
|
public UserWithCompanyEntity validateUserWithCompny(Long userId, Long companyId) {
|
|
return companyDao.validateUserWithCompny(userId, companyId);
|
|
}
|
|
@Override
|
|
public UserWithCompanyEntity getUserWithCompany(Long userId, Long companyId) {
|
|
return companyDao.getUserWithCompany(userId, companyId);
|
|
}
|
|
@Override
|
|
@Transactional(readOnly = true)
|
|
public ByteArrayOutputStream downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
|
return delegationDao.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public CompanyDelegationResponse uploadCompanyDelegation(HttpServletRequest request, Long companyId, MultipartFile file) {
|
|
UserEntity userEntity = validator.validateUser(request);
|
|
validator.validateUserWithCompany(request, companyId);
|
|
return delegationDao.uploadCompanyDelegation(userEntity, companyId, file);
|
|
}
|
|
|
|
@Override
|
|
@Transactional
|
|
public CompanyDelegationResponse getCompanyDelegation(HttpServletRequest request, Long companyId) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
return delegationDao.getCompanyDelegation(userEntity, companyId);
|
|
}
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void deleteCompanyDelegation(HttpServletRequest request, Long companyId) {
|
|
|
|
UserEntity userEntity = validator.validateUser(request);
|
|
delegationDao.deleteCompanyDelegation(userEntity, companyId);
|
|
}
|
|
public UserWithCompanyEntity getUserWithCompanyEntity(Long userId,Long companyId){
|
|
return companyDao.getUserWithCompany(userId,companyId);
|
|
}
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void removeCompanyFromList(HttpServletRequest request, Long companyId) {
|
|
UserEntity userEntity =validator.validateUser(request);
|
|
companyDao.removeCompanyFromList(userEntity, companyId);
|
|
}
|
|
}
|