nidapeng
2024-05-06 b70bbce994e573e58d4ee79a53ea60e9338b2516
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CompanyServiceImpl.java
@@ -25,6 +25,7 @@
import com.doumee.dao.admin.request.UpdateCompanySortDTO;
import com.doumee.dao.admin.response.CompanyDTO;
import com.doumee.dao.business.CompanyMapper;
import com.doumee.dao.business.MemberMapper;
import com.doumee.dao.business.join.CompanyJoinMapper;
import com.doumee.dao.business.model.Category;
import com.doumee.dao.business.model.Company;
@@ -54,6 +55,8 @@
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private DataSyncConfig dataSyncConfig;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
@@ -79,6 +82,7 @@
            user = company.getLoginUserInfo();
        }
        String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
        company.setCompanyPath(company.getName());//名称路径
        company.setHkParentId(rootOrgId);
        if(company.getParentId() !=null){
            Company parent = findById(company.getParentId());
@@ -89,7 +93,9 @@
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息尚未同步下发成功~");
            }
            company.setHkParentId(parent.getHkId());
            company.setCompanyPath(parent.getCompanyPath()+"/"+company.getName());
        }
        company.setHkCompanyPath(company.getCompanyPath());
        company.setCreateDate(new Date());
        company.setCreator(user.getId());
        company.setIsdeleted(Constants.ZERO);
@@ -97,7 +103,6 @@
        company.setStatus(Constants.ZERO);
        company.setHkDate(company.getHkDate());
        company.setHkId(UUID.randomUUID().toString().replace("-",""));
        companyMapper.insert(company);
        //下发海康安防平台
        if(!addHkOrg(company)){
@@ -109,7 +114,6 @@
    private boolean addHkOrg(Company company) {
        List<OrgAddRequest> addList = new ArrayList<>();
        addList.add(getOrgAddModel(company));
        BaseResponse<OrgOrUserAddResponse> result =  HKService.addBatchOrg(addList);
        if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
            OrgOrUserAddResponse data = result.getData();
@@ -161,6 +165,7 @@
        return  model;
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer createLaborServices(Company company) {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(loginUserInfo ==null){
@@ -189,19 +194,25 @@
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void deleteById(Integer id,    LoginUserInfo user ) {
        if(id== null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        Company model = findById(id);
        if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,组织信息不存在~");
        }
        if(StringUtils.isBlank(model.getHkId())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,组织信息尚未同步下发成功,暂不支持修改,请尝试删除后重新添加~");
        if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
                .eq(Company::getParentId,model.getId())
                .eq(Company::getIsdeleted,Constants.ZERO)) >0){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该部门存在下级部门,不能进行删除操作!");
        }
        if(memberMapper.selectCount(new QueryWrapper<Member>().lambda()
                .eq(Member::getCompanyId,model.getId())
                .eq(Member::getIsdeleted,Constants.ZERO)) >0){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,该部门下存在人员信息,不能进行删除操作!");
        }
        Company company = new Company();
        company.setId(id);
        company.setEditDate(new Date());
@@ -211,7 +222,7 @@
        company.setHkDate(company.getHkDate());
        companyMapper.updateById(company);
        //下发海康安防平台
        if(!delHkOrg(model)){
        if(StringUtils.isBlank(model.getHkId()) && Constants.equalsInteger(Constants.ONE,model.getHkStatus()) && !delHkOrg(model)){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织删除下发失败,请确认该组织无下级组织或组织人员信息~");
        }
    }
@@ -429,7 +440,7 @@
    public void updateStatusById(Company company) {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(loginUserInfo==null){
            loginUserInfo = company.getLoginUserInfo()
            loginUserInfo = company.getLoginUserInfo();
        }
        company.setEditDate(new Date());
        company.setEditor(loginUserInfo.getId());