嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-service/src/main/java/com/hai/service/impl/BsCompanyServiceImpl.java

133 lines
4.1 KiB

package com.hai.service.impl;
import com.hai.dao.BsCompanyMapper;
import com.hai.dao.BsOrganizationMapper;
import com.hai.dao.SecUserMapper;
import com.hai.dao.SecUserRoleRelMapper;
import com.hai.entity.*;
import com.hai.service.BsCompanyService;
import com.hai.service.CommonService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service("bsCompanyService")
public class BsCompanyServiceImpl implements BsCompanyService {
@Resource
private BsCompanyMapper bsCompanyMapper;
@Resource
private BsOrganizationMapper bsOrganizationMapper;
@Resource
private SecUserMapper secUserMapper;
@Resource
private SecUserRoleRelMapper secUserRoleRelMapper;
@Resource
private CommonService commonService;
@Override
public List<BsCompany> findPage(Map<String, String> map) {
BsCompanyExample example = new BsCompanyExample();
BsCompanyExample.Criteria criteria = example.createCriteria();
criteria.andIdNotEqualTo(1L);
if(StringUtils.isNotBlank(map.get("name"))){
criteria.andNameLike("%" + map.get("name") + "%");
}
example.setOrderByClause("create_time desc");
List<BsCompany> companyList = bsCompanyMapper.selectByExample(example);
if (companyList != null && companyList.size() != 0) {
for (BsCompany company : companyList) {
company.setRegionName(commonService.getRegionName(Long.valueOf(company.getRegionId())));
}
}
return companyList;
}
@Override
@Transactional
public void addCompanyInfo(BsCompany secCompany, SecUser secUser, BsOrganization secOrganization) throws Exception {
// 保存公司
bsCompanyMapper.insert(secCompany);
// 保存公司对应顶级部门
secOrganization.setCompanyId(secCompany.getId());
bsOrganizationMapper.insert(secOrganization);
// 保存公司主角色
secUser.setCompanyId(secCompany.getId());
secUser.setObjectType(5);
secUser.setObjectId(secCompany.getId());
secUser.setOrganizationId(secOrganization.getId());
secUserMapper.insert(secUser);
// 修改部门管理员为公司主角色
secOrganization.setManagerId(secUser.getId());
secOrganization.setManagerName(secUser.getUserName());
secOrganization.setManagerPhone(secUser.getTelephone());
bsOrganizationMapper.updateByPrimaryKey(secOrganization);
// 保存用户角色
SecUserRoleRel userRole = new SecUserRoleRel();
userRole.setUserId(secUser.getId());
userRole.setRoleId(5L);
secUserRoleRelMapper.insert(userRole);
}
@Override
public int updateCompany(BsCompany secCompany) {
return bsCompanyMapper.updateByPrimaryKey(secCompany);
}
@Override
public BsCompany getCompanyById(Long id) {
BsCompany company =bsCompanyMapper.selectByPrimaryKey(id);
if (company.getRegionId() != null) {
company.setRegionName(commonService.getRegionName(Long.valueOf(company.getRegionId())));
}
return company;
}
@Override
public List<BsCompany> getCompany(Map<String, String> map) {
return null;
}
@Override
@Transactional
public void updateCompanyAndDept(BsCompany secCompany, SecUser secUser, BsOrganization secOrganization) {
bsCompanyMapper.updateByPrimaryKey(secCompany);
bsOrganizationMapper.updateByPrimaryKey(secOrganization);
secUserMapper.updateByPrimaryKey(secUser);
}
@Override
public BsCompany selectCompanyByName(String name) {
BsCompanyExample example = new BsCompanyExample();
BsCompanyExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(name);
criteria.andStatusEqualTo(1);
List<BsCompany> list = bsCompanyMapper.selectByExample(example);
if (list != null && list.size() != 0) {
return list.get(0);
}else {
return null;
}
}
@Override
public BsCompany selectCompanyByRegion(String regionId) {
BsCompanyExample example = new BsCompanyExample();
example.createCriteria().andStatusEqualTo(1).andRegionIdEqualTo(regionId);
List<BsCompany> companies = bsCompanyMapper.selectByExample(example);
if (companies != null && companies.size() != 0) {
return companies.get(0);
}
return null;
}
}