package com.doumee.service.business.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
|
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.config.DataSyncConfig;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.dingTalk.DingTalk;
|
import com.doumee.core.erp.ErpConstants;
|
import com.doumee.core.erp.model.openapi.request.erp.OrgListRequest;
|
import com.doumee.core.erp.model.openapi.response.erp.ErpOrgListResponse;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.haikang.model.HKConstants;
|
import com.doumee.core.haikang.model.param.BaseResponse;
|
import com.doumee.core.haikang.model.param.request.OrgAddRequest;
|
import com.doumee.core.haikang.model.param.request.OrgDelRequest;
|
import com.doumee.core.haikang.model.param.request.OrgEditRequest;
|
import com.doumee.core.haikang.model.param.respose.OrgOrUserAddResponse;
|
import com.doumee.core.haikang.model.param.respose.OrgUpdateFailureResponse;
|
import com.doumee.core.haikang.service.HKService;
|
import com.doumee.service.business.third.model.LoginUserInfo;
|
import com.doumee.service.business.third.model.PageData;
|
import com.doumee.service.business.third.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.admin.request.UpdateCompanySortDTO;
|
import com.doumee.dao.admin.response.CompanyDTO;
|
import com.doumee.dao.business.dao.MemberMapper;
|
import com.doumee.dao.business.dao.CompanyMapper;
|
import com.doumee.dao.business.dao.join.CompanyJoinMapper;
|
import com.doumee.dao.business.model.Company;
|
import com.doumee.dao.business.model.Member;
|
import com.doumee.dao.business.vo.CompanyTree;
|
import com.doumee.dao.system.model.SystemUser;
|
import com.doumee.service.business.CompanyService;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.taobao.api.ApiException;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import shade.com.alibaba.fastjson2.JSONArray;
|
import shade.com.alibaba.fastjson2.JSONObject;
|
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 企业信息表Service实现
|
* @author 江蹄蹄
|
* @date 2023/11/30 15:33
|
*/
|
@Service
|
public class CompanyServiceImpl implements CompanyService {
|
|
@Autowired
|
private CompanyMapper companyMapper;
|
@Autowired
|
private MemberMapper memberMapper;
|
@Autowired
|
private DataSyncConfig dataSyncConfig;
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Autowired
|
private CompanyJoinMapper companyJoinMapper;
|
|
@Autowired
|
private DingTalk dingTalk;
|
|
@Override
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
public Integer create(Company company) {
|
if(StringUtils.isBlank(company.getName())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
if(company.getType()==null || !(company.getType() ==0 || company.getType() ==1)){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织类型不正确,请按要求填写~");
|
}
|
//查询名称不能重复
|
if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
|
.eq(Company::getName,company.getName())
|
.eq(Company::getIsdeleted,Constants.ZERO)) >0){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织名称不能重复~");
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(user ==null){
|
user = company.getLoginUserInfo();
|
}
|
String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
|
company.setCompanyPath(company.getId()+"/");//名称路径
|
company.setCompanyNamePath(company.getName());//名称路径
|
company.setHkParentId(rootOrgId);
|
String idPath = "";
|
if(company.getParentId() !=null){
|
Company parent = findById(company.getParentId());
|
if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息不存在~");
|
}
|
if(StringUtils.isBlank(parent.getHkId())){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息尚未同步下发成功~");
|
}
|
if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
|
if(!Constants.equalsInteger(company.getType(),parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
}else if(Objects.isNull(parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
// if(Constants.equalsInteger(parent.getType(),Constants.ZERO)){
|
// //如果父级是相关方组织,下级不能建立内部组织
|
// if(Constants.equalsInteger(company.getType(),Constants.ONE)){
|
// throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,相关方组织,下级不能建立内部组织~");
|
// }
|
// }
|
idPath = parent.getCompanyPath();
|
company.setHkParentId(parent.getHkId());
|
company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
|
company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
|
}
|
company.setHkCompanyPath(company.getCompanyNamePath());
|
company.setCreateDate(new Date());
|
company.setCreator(user.getId());
|
company.setIsdeleted(Constants.ZERO);
|
company.setHkStatus(Constants.ONE);
|
company.setStatus(Constants.ZERO);
|
company.setSortnum(0);//默认最上面
|
company.setHkDate(company.getCreateDate());
|
company.setEditDate(company.getCreateDate());
|
company.setEditor(company.getCreator());
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
company.setHkId(UUID.randomUUID().toString().replace("-",""));
|
companyMapper.insert(company);
|
//下发海康安防平台
|
if(!addHkOrg(company)){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织同步下发失败,请稍后重试");
|
}
|
Company com = new Company();
|
com.setId(company.getId());
|
com.setCompanyPath(idPath+company.getId()+"/");
|
companyMapper.updateById(com);
|
return company.getId();
|
}
|
|
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();
|
if(data.getSuccesses()!=null && data.getSuccesses().size()>0){
|
//处理新增成功的数据,修改海康同步状态
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
private boolean editHkOrg(Company company) {
|
OrgEditRequest request = (getOrgHkEditModel(company));
|
BaseResponse result = HKService.editOrg(request);
|
if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
|
//处理新增成功的数据,修改海康同步状态
|
return true;
|
}
|
return false;
|
}
|
private boolean delHkOrg(Company company) {
|
OrgDelRequest request =new OrgDelRequest();
|
|
request.setIndexCodes(new String[]{company.getHkId()});
|
BaseResponse<List<OrgUpdateFailureResponse>> result = HKService.delBatchOrg(request);
|
if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
|
//处理新增成功的数据,修改海康同步状态
|
if(result.getData()!=null && result.getData().size()==0){
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
|
private OrgAddRequest getOrgAddModel(Company c ) {
|
OrgAddRequest model = new OrgAddRequest();
|
model.setOrgIndexCode(c.getHkId());
|
model.setOrgName(c.getName());
|
// model.setOrgCode(c.getCode());
|
model.setParentIndexCode(c.getHkParentId());
|
return model;
|
}
|
private OrgEditRequest getOrgHkEditModel(Company c ) {
|
OrgEditRequest model = new OrgEditRequest();
|
model.setOrgIndexCode(c.getHkId());
|
model.setOrgName(c.getName());
|
return model;
|
}
|
@Override
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
public Integer createLaborServices(Company company) {
|
LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(loginUserInfo ==null){
|
loginUserInfo = company.getLoginUserInfo();
|
}
|
checkUnique(company);
|
Company insert = new Company();
|
insert.setCreator(loginUserInfo.getId());
|
insert.setCreateDate(new Date());
|
insert.setEditor(loginUserInfo.getId());
|
insert.setEditDate(new Date());
|
insert.setIsdeleted(Constants.ZERO);
|
insert.setName(company.getName());
|
insert.setRemark(company.getRemark());
|
insert.setStatus(Constants.ZERO);
|
insert.setSortnum(company.getSortnum());
|
insert.setImgurl(company.getImgurl());
|
insert.setType(Constants.ZERO);
|
insert.setCategoryId(company.getCategoryId());
|
insert.setCode(company.getCode());
|
insert.setParentId(company.getParentId());
|
insert.setLinkName(company.getLinkName());
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
insert.setLinkPhone(company.getLinkPhone());
|
companyMapper.insert(insert);
|
return insert.getId();
|
}
|
|
@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(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());
|
company.setEditor(user.getId());
|
company.setIsdeleted(Constants.ONE);
|
company.setHkStatus(Constants.ONE);
|
company.setHkDate(company.getHkDate());
|
companyMapper.updateById(company);
|
//下发海康安防平台
|
if(StringUtils.isNotBlank(model.getHkId()) && Constants.equalsInteger(Constants.ONE,model.getHkStatus()) && !delHkOrg(model)){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织删除下发失败,请确认该组织无下级组织或组织人员信息~");
|
}
|
}
|
|
@Override
|
public void delete(Company company) {
|
UpdateWrapper<Company> deleteWrapper = new UpdateWrapper<>(company);
|
companyMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids,LoginUserInfo user) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
ids.stream().forEach(s->{
|
Company company = new Company();
|
deleteById(s,user);
|
});
|
}
|
|
@Override
|
@Transactional(rollbackFor = {BusinessException.class,Exception.class})
|
public void updateById(Company company) {
|
if(company.getId() == null|| StringUtils.isBlank(company.getName())){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
if(company.getType()!=null && !(company.getType() ==0 || company.getType() ==1)){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织类型不正确,请按要求填写~");
|
}
|
//查询名称不能重复
|
if(companyMapper.selectCount(new QueryWrapper<Company>().lambda()
|
.eq(Company::getName,company.getName())
|
.ne(Company::getId,company.getId())
|
.eq(Company::getIsdeleted,Constants.ZERO)) >0){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织名称不能重复~");
|
}
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(user == null){
|
user = company.getLoginUserInfo();
|
}
|
Company model = findById(company.getId());
|
if(model == null || Constants.equalsInteger(model.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,组织信息不存在~");
|
}
|
|
// if( Constants.equalsInteger(Constants.ONE,model.getType())&& Constants.equalsInteger(Constants.ZERO,company.getType())){
|
// //如果由内部组织切换成内部组织,排查下级组织是否有内部组织
|
// if(companyJoinMapper.selectCount(new QueryWrapper<Company>().lambda()
|
// .eq(Company::getIsdeleted,Constants.ZERO )
|
// .eq(Company::getType,Constants.ONE )
|
// .ne(Company::getId,model.getId())
|
// .likeRight(Company::getCompanyPath,model.getCompanyPath())) >0){
|
// throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,下级部门存在内部组织,该部门不支持切换为相关方组织!~");
|
// }
|
// }
|
company.setType(null);
|
company.setEditDate(new Date());
|
company.setEditor(user.getId());
|
company.setHkStatus(Constants.ONE);
|
company.setHkDate(company.getHkDate());
|
company.setHkId(StringUtils.defaultString(model.getHkId(),UUID.randomUUID().toString().replace("-","")));
|
company.setParentId(null);//不支持修改父级
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
companyMapper.updateById(company);
|
//更新的companyPath
|
String newName = model.getCompanyNamePath().replace(model.getName(),company.getName());
|
companyMapper.update(null,new UpdateWrapper<Company>().lambda()
|
.setSql("company_name_path=REPLACE(company_name_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
|
.setSql("hk_company_path=REPLACE(hk_company_path,'"+ model.getCompanyNamePath()+"','"+newName+"')")
|
.likeRight(Company::getCompanyPath,model.getCompanyPath()));
|
//下发海康安防平台
|
if(StringUtils.isNotBlank(model.getHkId())){
|
if(!editHkOrg(company)){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织同步下发失败,请稍后重试");
|
}
|
}else{//如果没有下发过,直接新建安防平台组织
|
if(!addHkOrg(company)){
|
throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织同步下发失败,请稍后重试");
|
}
|
}
|
}
|
|
@Override
|
public Integer updateLaborServicesById(Company company) {
|
checkUnique(company);
|
companyMapper.updateById(company);
|
return null;
|
}
|
|
@Override
|
public void updateByIdInBatch(List<Company> companys) {
|
if (CollectionUtils.isEmpty(companys)) {
|
return;
|
}
|
for (Company company: companys) {
|
this.updateById(company);
|
}
|
}
|
|
@Override
|
public Company findById(Integer id) {
|
return companyMapper.selectById(id);
|
}
|
|
@Override
|
public Company findOne(Company company) {
|
QueryWrapper<Company> wrapper = new QueryWrapper<>(company);
|
return companyMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<Company> findList(Company company) {
|
MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
|
if (company.getId() != null) {
|
queryWrapper.eq(Company::getId, company.getId());
|
}
|
if (company.getCreator() != null) {
|
queryWrapper.eq(Company::getCreator, company.getCreator());
|
}
|
if (company.getCreateDate() != null) {
|
queryWrapper.ge(Company::getCreateDate, Utils.Date.getStart(company.getCreateDate()));
|
queryWrapper.le(Company::getCreateDate, Utils.Date.getEnd(company.getCreateDate()));
|
}
|
if (company.getEditor() != null) {
|
queryWrapper.eq(Company::getEditor, company.getEditor());
|
}
|
if (company.getEditDate() != null) {
|
queryWrapper.ge(Company::getEditDate, Utils.Date.getStart(company.getEditDate()));
|
queryWrapper.le(Company::getEditDate, Utils.Date.getEnd(company.getEditDate()));
|
}
|
if (company.getIsdeleted() != null) {
|
queryWrapper.eq(Company::getIsdeleted, company.getIsdeleted());
|
}
|
if (company.getName() != null) {
|
queryWrapper.like(Company::getName, company.getName());
|
}
|
if (company.getRemark() != null) {
|
queryWrapper.eq(Company::getRemark, company.getRemark());
|
}
|
if (company.getStatus() != null) {
|
queryWrapper.eq(Company::getStatus, company.getStatus());
|
}
|
if (company.getSortnum() != null) {
|
queryWrapper.eq(Company::getSortnum, company.getSortnum());
|
}
|
if (company.getImgurl() != null) {
|
queryWrapper.eq(Company::getImgurl, company.getImgurl());
|
}
|
if (company.getType() != null) {
|
queryWrapper.eq(Company::getType, company.getType());
|
}
|
if (company.getCategoryId() != null) {
|
queryWrapper.eq(Company::getCategoryId, company.getCategoryId());
|
}
|
if (company.getCode() != null) {
|
queryWrapper.eq(Company::getCode, company.getCode());
|
}
|
if (company.getParentId() != null) {
|
queryWrapper.eq(Company::getParentId, company.getParentId());
|
}
|
if (company.getLinkName() != null) {
|
queryWrapper.eq(Company::getLinkName, company.getLinkName());
|
}
|
if (company.getLinkPhone() != null) {
|
queryWrapper.eq(Company::getLinkPhone, company.getLinkPhone());
|
}
|
if (company.getHkId() != null) {
|
queryWrapper.eq(Company::getHkId, company.getHkId());
|
}
|
if (company.getHkStatus() != null) {
|
queryWrapper.eq(Company::getHkStatus, company.getHkStatus());
|
}
|
if (company.getHkDate() != null) {
|
queryWrapper.ge(Company::getHkDate, Utils.Date.getStart(company.getHkDate()));
|
queryWrapper.le(Company::getHkDate, Utils.Date.getEnd(company.getHkDate()));
|
}
|
if (company.getErpId() != null) {
|
queryWrapper.eq(Company::getErpId, company.getErpId());
|
}
|
if (company.getErpDate() != null) {
|
queryWrapper.ge(Company::getErpDate, Utils.Date.getStart(company.getErpDate()));
|
queryWrapper.le(Company::getErpDate, Utils.Date.getEnd(company.getErpDate()));
|
}
|
if (company.getErpStatus() != null) {
|
queryWrapper.eq(Company::getErpStatus, company.getErpStatus());
|
}
|
if (company.getDdId() != null) {
|
queryWrapper.eq(Company::getDdId, company.getDdId());
|
}
|
if (company.getDdDate() != null) {
|
queryWrapper.ge(Company::getDdDate, Utils.Date.getStart(company.getDdDate()));
|
queryWrapper.le(Company::getDdDate, Utils.Date.getEnd(company.getDdDate()));
|
}
|
if (company.getDdStatus() != null) {
|
queryWrapper.eq(Company::getDdStatus, company.getDdStatus());
|
}
|
if (company.getFsId() != null) {
|
queryWrapper.eq(Company::getFsId, company.getFsId());
|
}
|
if (company.getFsStatus() != null) {
|
queryWrapper.eq(Company::getFsStatus, company.getFsStatus());
|
}
|
if (company.getFsDate() != null) {
|
queryWrapper.ge(Company::getFsDate, Utils.Date.getStart(company.getFsDate()));
|
queryWrapper.le(Company::getFsDate, Utils.Date.getEnd(company.getFsDate()));
|
}
|
if (company.getQueryHiddenDanger() != null && Constants.equalsInteger(company.getQueryHiddenDanger(),Constants.ONE)) {
|
queryWrapper.apply(" t.id in ( select hdp.COMPANY_ID from hidden_danger_param hdp where hdp.ISDELETED = 0 and hdp.STATUS = 0 and hdp.TYPE = 0 ) ");
|
}
|
queryWrapper.orderByAsc(Company::getPinyin);
|
queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
|
queryWrapper.select(" t.* ")
|
.select("(select count(m.id) from member m where m.COMPANY_ID=t.id and m.ISDELETED=0) as countNum") ;
|
queryWrapper.select("t1.name",Company::getParentName);
|
queryWrapper.select("t1.company_path",Company::getParentCompanyPath);
|
queryWrapper.apply(" t.isdeleted = 0 ") ;
|
queryWrapper.eq(Objects.nonNull(company.getStatus()),Company::getStatus,Constants.ZERO);
|
queryWrapper.like(StringUtils.isNotBlank(company.getName()),Company::getName,company.getName());
|
queryWrapper.like(StringUtils.isNotBlank(company.getParentName()),"c.name",company.getParentName());
|
return companyMapper.selectList(queryWrapper);
|
}
|
|
@Override
|
public PageData<Company> findPage(PageWrap<Company> pageWrap) {
|
IPage<Company> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
pageWrap.getModel().setIsdeleted(Constants.ZERO);
|
if (pageWrap.getModel().getId() != null) {
|
queryWrapper.eq(Company::getId, pageWrap.getModel().getId());
|
}
|
if (pageWrap.getModel().getCreator() != null) {
|
queryWrapper.eq(Company::getCreator, pageWrap.getModel().getCreator());
|
}
|
if (pageWrap.getModel().getCreateDate() != null) {
|
queryWrapper.ge(Company::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
|
queryWrapper.le(Company::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
|
}
|
if (pageWrap.getModel().getEditor() != null) {
|
queryWrapper.eq(Company::getEditor, pageWrap.getModel().getEditor());
|
}
|
if (pageWrap.getModel().getEditDate() != null) {
|
queryWrapper.ge(Company::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
|
queryWrapper.le(Company::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
|
}
|
if (pageWrap.getModel().getIsdeleted() != null) {
|
queryWrapper.eq(Company::getIsdeleted, pageWrap.getModel().getIsdeleted());
|
}
|
if (pageWrap.getModel().getName() != null) {
|
queryWrapper.like(Company::getName, pageWrap.getModel().getName());
|
}
|
if (pageWrap.getModel().getRemark() != null) {
|
queryWrapper.eq(Company::getRemark, pageWrap.getModel().getRemark());
|
}
|
if (pageWrap.getModel().getStatus() != null) {
|
queryWrapper.eq(Company::getStatus, pageWrap.getModel().getStatus());
|
}
|
if (pageWrap.getModel().getSortnum() != null) {
|
queryWrapper.eq(Company::getSortnum, pageWrap.getModel().getSortnum());
|
}
|
if (pageWrap.getModel().getImgurl() != null) {
|
queryWrapper.eq(Company::getImgurl, pageWrap.getModel().getImgurl());
|
}
|
if (pageWrap.getModel().getType() != null) {
|
queryWrapper.eq(Company::getType, pageWrap.getModel().getType());
|
}
|
if (pageWrap.getModel().getCategoryId() != null) {
|
queryWrapper.eq(Company::getCategoryId, pageWrap.getModel().getCategoryId());
|
}
|
if (pageWrap.getModel().getCode() != null) {
|
queryWrapper.eq(Company::getCode, pageWrap.getModel().getCode());
|
}
|
if (pageWrap.getModel().getParentId() != null) {
|
queryWrapper.eq(Company::getParentId, pageWrap.getModel().getParentId());
|
}
|
if (pageWrap.getModel().getLinkName() != null) {
|
queryWrapper.eq(Company::getLinkName, pageWrap.getModel().getLinkName());
|
}
|
if (pageWrap.getModel().getLinkPhone() != null) {
|
queryWrapper.eq(Company::getLinkPhone, pageWrap.getModel().getLinkPhone());
|
}
|
if (pageWrap.getModel().getHkId() != null) {
|
queryWrapper.eq(Company::getHkId, pageWrap.getModel().getHkId());
|
}
|
if (pageWrap.getModel().getHkStatus() != null) {
|
queryWrapper.eq(Company::getHkStatus, pageWrap.getModel().getHkStatus());
|
}
|
if (pageWrap.getModel().getHkDate() != null) {
|
queryWrapper.ge(Company::getHkDate, Utils.Date.getStart(pageWrap.getModel().getHkDate()));
|
queryWrapper.le(Company::getHkDate, Utils.Date.getEnd(pageWrap.getModel().getHkDate()));
|
}
|
if (pageWrap.getModel().getErpId() != null) {
|
queryWrapper.eq(Company::getErpId, pageWrap.getModel().getErpId());
|
}
|
if (pageWrap.getModel().getErpDate() != null) {
|
queryWrapper.ge(Company::getErpDate, Utils.Date.getStart(pageWrap.getModel().getErpDate()));
|
queryWrapper.le(Company::getErpDate, Utils.Date.getEnd(pageWrap.getModel().getErpDate()));
|
}
|
if (pageWrap.getModel().getErpStatus() != null) {
|
queryWrapper.eq(Company::getErpStatus, pageWrap.getModel().getErpStatus());
|
}
|
if (pageWrap.getModel().getDdId() != null) {
|
queryWrapper.eq(Company::getDdId, pageWrap.getModel().getDdId());
|
}
|
if (pageWrap.getModel().getDdDate() != null) {
|
queryWrapper.ge(Company::getDdDate, Utils.Date.getStart(pageWrap.getModel().getDdDate()));
|
queryWrapper.le(Company::getDdDate, Utils.Date.getEnd(pageWrap.getModel().getDdDate()));
|
}
|
if (pageWrap.getModel().getDdStatus() != null) {
|
queryWrapper.eq(Company::getDdStatus, pageWrap.getModel().getDdStatus());
|
}
|
if (pageWrap.getModel().getFsId() != null) {
|
queryWrapper.eq(Company::getFsId, pageWrap.getModel().getFsId());
|
}
|
if (pageWrap.getModel().getFsStatus() != null) {
|
queryWrapper.eq(Company::getFsStatus, pageWrap.getModel().getFsStatus());
|
}
|
if (pageWrap.getModel().getFsDate() != null) {
|
queryWrapper.ge(Company::getFsDate, Utils.Date.getStart(pageWrap.getModel().getFsDate()));
|
queryWrapper.le(Company::getFsDate, Utils.Date.getEnd(pageWrap.getModel().getFsDate()));
|
}
|
queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
|
/* .leftJoin(Member.class, Member::getId,Company::getHeadId)*/
|
/* queryWrapper.leftJoin(" company c on c.id=t.parent_id");*/
|
queryWrapper.selectAll(Company.class)
|
.select("(select count(m.id) from member m where m.COMPANY_ID=t.id and m.ISDELETED=0) as countNum") ;
|
queryWrapper.select("t1.name",Company::getParentName);
|
queryWrapper.select("t1.company_path",Company::getParentCompanyPath);
|
queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getStatus()),Company::getStatus,Constants.ZERO);
|
queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),Company::getName,pageWrap.getModel().getName());
|
queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getParentName()),"c.name",pageWrap.getModel().getParentName());
|
queryWrapper.orderByAsc(Company::getSortnum);
|
IPage<Company> companyIPage = companyJoinMapper.selectJoinPage(page, Company.class, queryWrapper);
|
return PageData.from(companyIPage);
|
}
|
|
@Override
|
public void updateStatusById(Company company) {
|
LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(loginUserInfo==null){
|
loginUserInfo = company.getLoginUserInfo();
|
}
|
company.setEditDate(new Date());
|
company.setEditor(loginUserInfo.getId());
|
company.setStatus(company.getStatus());
|
companyMapper.updateById(company);
|
}
|
|
@Override
|
public long count(Company company) {
|
QueryWrapper<Company> wrapper = new QueryWrapper<>(company);
|
return companyMapper.selectCount(wrapper);
|
}
|
|
@Override
|
public List<CompanyDTO> findCompanyTreePage(Integer type) {
|
//配置组员人员类型来源方式 0自建 1ERP
|
LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
|
|
wrapper.eq(Company::getIsdeleted,Constants.ZERO)
|
.eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type)
|
.orderByAsc(Company::getSortnum);
|
List<Company> companies = companyMapper.selectList(wrapper);
|
return getCompanyTree( companies, null);
|
}
|
|
private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId){
|
if (CollectionUtils.isEmpty(companies)){
|
return null;
|
}
|
int origin =Constants.formatIntegerNum(dataSyncConfig.getOrgUserDataOrigin());
|
List<Company> collect = null;
|
if(origin == DataSyncConfig.origin.erp){
|
collect= companies.stream().filter(s -> ( StringUtils.defaultString(s.getErpParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
|
}else if(origin == DataSyncConfig.origin.hk){
|
collect= companies.stream().filter(s ->
|
( StringUtils.defaultString(s.getHkParentId(),"").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
|
}else{
|
collect= companies.stream().filter(s -> (StringUtils.defaultString(s.getParentId()+"","").equals(StringUtils.defaultString(parentId)))).collect(Collectors.toList());
|
}
|
if (CollectionUtils.isEmpty(collect)){
|
return null;
|
}
|
List<CompanyDTO> companyDTOList = new ArrayList<>();
|
for (int i = 0; i < collect.size(); i++) {
|
Company company = collect.get(i);
|
CompanyDTO companyDTO = new CompanyDTO();
|
BeanUtils.copyProperties(company,companyDTO);
|
String pId = company.getId()+"";
|
if(origin == 1){
|
pId = company.getErpId();
|
}else if(origin == 2){
|
pId = company.getHkParentId();
|
}
|
companyDTO.setCompanyDTOList(getCompanyTree(companies,pId));
|
companyDTOList.add(companyDTO);
|
}
|
return companyDTOList;
|
}
|
|
|
/**
|
* 劳务公司唯一性校验
|
* @param company
|
*/
|
private void checkUnique(Company company){
|
QueryWrapper<Company> wrapper = new QueryWrapper<>();
|
wrapper.lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO)
|
.eq(Company::getName,company.getName());
|
List<Company> companies = companyMapper.selectList(wrapper);
|
if (CollectionUtils.isEmpty(companies)){
|
return;
|
}
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
//新增的情况存在记录
|
if (Objects.isNull(company.getId())){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"公司名称已存在");
|
}
|
//修改的情况存在记录 匹配不到 own
|
if (!companies.stream().map(s -> s.getId()).anyMatch(s -> s.equals(company.getId()))){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"公司名称已存在");
|
}
|
}
|
|
|
|
@Override
|
public List<Company> companyTree(Integer type) {
|
MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>();
|
queryWrapper.selectAll(Company.class);
|
queryWrapper.selectAs(SystemUser::getRealname,Company::getEditorName);
|
queryWrapper.selectAs(Member::getName,Company::getHeadName);
|
queryWrapper.selectAs(Member::getPhone,Company::getHeadPhone);
|
queryWrapper.select("t1.name",Company::getParentName);
|
queryWrapper.select("t1.company_path",Company::getParentCompanyPath);
|
queryWrapper.select("t1.type",Company::getParentType);
|
queryWrapper.leftJoin(Company.class,Company::getId,Company::getParentId);
|
queryWrapper.leftJoin(Member.class,Member::getId,Company::getHeadId);
|
queryWrapper.leftJoin(SystemUser.class,SystemUser::getId,Company::getEditor);
|
queryWrapper.eq(Company::getIsdeleted,Constants.ZERO);
|
if(Objects.nonNull(type) && ( Constants.equalsInteger(type,Constants.ONE) || Constants.equalsInteger(type,Constants.ZERO))){
|
// queryWrapper.eq(type!=null,Company::getType,type);
|
queryWrapper.apply("( t.type = "+type+" or t.type = -1 )");
|
}else if(Objects.nonNull(type) && Constants.equalsInteger(type,Constants.TWO)){
|
String companySpecialId = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SPECIAL_COMPANY_ID).getCode();
|
if(StringUtils.isNotBlank(companySpecialId)){
|
queryWrapper.apply(" (find_in_set('"+companySpecialId+"',REPLACE(t.company_path,'/',',')) or t.parent_id is null ) ");
|
}
|
}
|
queryWrapper.orderByAsc(true,"t.sortnum");
|
List<Company> companyList = companyJoinMapper.selectJoinList(Company.class,queryWrapper);
|
//配置组员人员类型来源方式 0自建 1ERP
|
CompanyTree treeBuild = new CompanyTree(companyList, dataSyncConfig.getOrgUserDataOrigin());
|
companyList = treeBuild.buildTree();
|
return companyList;
|
}
|
|
|
@Override
|
public void updateSort(UpdateCompanySortDTO dto) {
|
Company company = companyMapper.selectById(dto.getId());
|
if(Objects.isNull(company)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
|
List<Company> companyPool;
|
if (company.getParentId() == null) {
|
companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO)
|
.isNull(Company::getParentId)
|
.orderByAsc(Company::getSortnum)
|
);
|
} else {
|
companyPool = companyMapper.selectList(new QueryWrapper<Company>().lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO)
|
.eq(Company::getParentId,company.getParentId())
|
.orderByAsc(Company::getSortnum)
|
);
|
}
|
int currentMenuIndex = 0;
|
for (int i = 0; i < companyPool.size(); i++) {
|
if (companyPool.get(i).getId().equals(dto.getId())) {
|
currentMenuIndex = i;
|
break;
|
}
|
}
|
// 上移
|
if ("top".equals(dto.getDirection())) {
|
if (currentMenuIndex - 1 < 0) {
|
return;
|
}
|
Company preMenu = companyPool.get(currentMenuIndex - 1);
|
companyPool.remove(currentMenuIndex - 1);
|
companyPool.add(currentMenuIndex, preMenu);
|
}
|
// 下移
|
else {
|
if (currentMenuIndex + 1 > companyPool.size() - 1) {
|
return;
|
}
|
Company nextMenu = companyPool.remove(currentMenuIndex + 1);
|
companyPool.add(currentMenuIndex, nextMenu);
|
}
|
for (int i = 0; i < companyPool.size(); i++) {
|
companyPool.get(i).setSortnum(i);
|
}
|
|
for (Company updCompany:companyPool) {
|
companyMapper.updateById(updCompany);
|
}
|
}
|
|
|
|
// org_dept_create 部门新建 {"timeStamp":"1758783935796","eventId":"0c779adba04143958a3960e8e36bbce5","deptId":[1040735458]}
|
// org_dept_modify 部门修改 {"timeStamp":"1758785791639","eventId":"6c2d8c7a61a7419e8928fda3effb3bf4","deptId":[1040735458]}
|
// org_dept_remove 部门删除 {"timeStamp":"1758785817760","eventId":"47e289f334e041719ed354052da474de","deptId":[1040735458]}
|
|
@Override
|
public void ddPushCompanyInfo(String eventType, JSONObject eventData) throws ApiException {
|
JSONArray jsonArray = eventData.getJSONArray("deptId");
|
if(jsonArray.isEmpty()){
|
return;
|
}
|
if(eventType.equals("org_dept_remove")){
|
//删除对应部门信息
|
List<Long> deptIdList = new ArrayList<>();
|
for (int i = 0; i < jsonArray.size(); i++) {
|
Long deptId = jsonArray.getLong(i);
|
deptIdList.add(deptId);
|
}
|
if(CollectionUtils.isNotEmpty(deptIdList)){
|
syncDelCompany(deptIdList);
|
}
|
}else if(eventType.equals("org_dept_create")||eventType.equals("org_dept_modify")){
|
for (int i = 0; i < jsonArray.size(); i++) {
|
Company company = companyMapper.selectOne(new QueryWrapper<Company>().lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO)
|
.eq(Company::getErpId,jsonArray.getLong(i))
|
);
|
OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse = dingTalk.syncDepartmentInfo(jsonArray.getLong(i));
|
if(Objects.isNull(company)){
|
getAddCompanyModel(deptGetResponse,company);
|
}else{
|
getUpdateCompanyModel(deptGetResponse,company);
|
}
|
}
|
}
|
}
|
|
private void doHkDeleteOrg(List<Integer> delIds,List<String> delHkIds, Date date) {
|
if(delHkIds.size() == 0){
|
return;
|
}
|
OrgDelRequest request = new OrgDelRequest();
|
request.setIndexCodes( delHkIds.toArray(new String[]{}));
|
BaseResponse<List<OrgUpdateFailureResponse>> result = HKService.delBatchOrg(request);
|
if(result !=null && StringUtils.equals(result.getCode(),HKConstants.RESPONSE_SUCCEE)){
|
List<String> fIds = new ArrayList<>();
|
if(result.getData()!=null){
|
for(OrgUpdateFailureResponse r : result.getData()){
|
if(r.getCode().equals("0x00052102")){
|
//不存在的也算删除成功
|
fIds.add(r.getOrgIndexCode());//删除失败的数据集合
|
}
|
}
|
}
|
//标记删除成功的数据(海康对接状态为已同步,,同步失败的仍为待同步,等下一次继续处理,知道全部删除完毕)
|
companyMapper.update(null,new UpdateWrapper<Company>().lambda()
|
.set(Company::getHkStatus,Constants.ONE)
|
.set(Company::getHkDate,date)
|
.set(Company::getHkId,null )
|
.in(Company::getId, delIds)
|
.notIn(fIds.size()>0,Company::getHkId, fIds));
|
companyMapper.update(null,new UpdateWrapper<Company>().lambda()
|
.set(Company::getHkStatus,Constants.TWO)
|
.set(Company::getHkDate,date)
|
.in(Company::getId, delIds)
|
.in(fIds.size()>0,Company::getHkId, fIds));
|
}
|
}
|
|
@Override
|
public String syncDDCompany() throws ApiException {
|
List<OapiV2DepartmentGetResponse.DeptGetResponse> list = dingTalk.syncAllDDDepartmentList();
|
if(list !=null && list.size()>0){
|
List<Company> addList = new ArrayList<>();
|
List<Company> updateList = new ArrayList<>();
|
List<Long> delIds = new ArrayList<>();//修改为使用钉钉id erpId
|
List<Company> allList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO).eq(Company::getType,Constants.ONE));
|
dealCompanyChangeList(list,addList,updateList,delIds,allList);
|
if(delIds.size()>0){
|
syncDelCompany(delIds);
|
}
|
return "同步数据:新增【"+addList.size()+"】条,更新【"+updateList.size()+"】条,删除【"+delIds.size()+"】条";
|
}else{
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "同步钉钉数据为空!");
|
}
|
}
|
|
private void dealCompanyChangeList(List<OapiV2DepartmentGetResponse.DeptGetResponse> list, List<Company> addList, List<Company> updateList, List<Long> delIds, List<Company> allList) {
|
Date date = new Date();
|
for(OapiV2DepartmentGetResponse.DeptGetResponse respone : list){
|
//根据erpid查询企业信息,判断是新增还是更新
|
Company company = findCompanyByERPId(allList,respone.getDeptId().toString());
|
if(company == null){
|
//如果是新增
|
//封装新增组织对象数据
|
addList.add(getAddCompanyModel(respone,new Company()));
|
}else{
|
updateList.add(getUpdateCompanyModel(respone,company));
|
}
|
}
|
if(allList!=null && allList.size()>0){
|
for(Company c : allList){
|
if(!isCompanyDeleted(c,list)){
|
delIds.add(Long.valueOf(c.getErpId()));
|
}
|
}
|
}
|
}
|
|
|
/**
|
* 整理钉钉同步 新增组织对象
|
* @param deptGetResponse
|
* @return
|
*/
|
private Company getAddCompanyModel(OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse,Company company) {
|
return syncDDAddCompanyModel(deptGetResponse,company);
|
}
|
|
/**
|
* 整理钉钉同步 新增 需要修改的组织对象
|
* @param deptGetResponse
|
* @param company
|
* @return
|
*/
|
private Company getUpdateCompanyModel(OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse, Company company) {
|
return syncDDEditCompanyModel(deptGetResponse,company);
|
}
|
|
|
/**
|
* 根据ERPID 判断数据是否已在集合里存在
|
* @param allList
|
* @param id
|
* @return
|
*/
|
private Company findCompanyByERPId(List<Company> allList, String id) {
|
if(allList!=null){
|
for(Company com :allList){
|
if(StringUtils.equals(com.getErpId(),id)){
|
return com;
|
}
|
}
|
}
|
return null;
|
}
|
|
private boolean isCompanyDeleted(Company c, List<OapiV2DepartmentGetResponse.DeptGetResponse> list) {
|
for(OapiV2DepartmentGetResponse.DeptGetResponse m : list){
|
if(StringUtils.equals(c.getErpId(),m.getDeptId().toString())){
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/**
|
* 整理 钉钉同步的 组织信息
|
* @param deptGetResponse
|
* @param company
|
* @return
|
*/
|
public Company syncDDAddCompanyModel(OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse,Company company){
|
company = new Company();
|
company.setCreateDate(new Date());
|
company.setIsdeleted(Constants.ZERO);
|
company.setStatus(Constants.ZERO);
|
|
company.setName(deptGetResponse.getName());
|
company.setErpId(deptGetResponse.getDeptId().toString());
|
company.setErpParentId(deptGetResponse.getParentId().toString());
|
company.setSortnum(deptGetResponse.getOrder().intValue());//默认最上面
|
|
company.setType(Constants.ONE);
|
String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode();
|
company.setCompanyPath(company.getId()+"/");//名称路径
|
company.setCompanyNamePath(company.getName());//名称路径
|
company.setHkParentId(rootOrgId);
|
String idPath = "";
|
if(StringUtils.isNotBlank(company.getErpParentId()) && !StringUtils.equals(company.getErpParentId(),Constants.ONE+"")){
|
Company parent = companyMapper.selectOne(new QueryWrapper<Company>().lambda().eq(Company::getErpId,company.getErpParentId())
|
.eq(Company::getIsdeleted,Constants.ZERO).last(" limit 1 "));
|
if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息不存在~");
|
}
|
// if(StringUtils.isBlank(parent.getHkId())){
|
// throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息尚未同步下发成功~");
|
// }
|
if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
|
if(!Constants.equalsInteger(company.getType(),parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
}else if(Objects.isNull(parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
idPath = parent.getCompanyPath();
|
company.setHkParentId(parent.getHkId());
|
company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
|
company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
|
}
|
company.setHkCompanyPath(company.getCompanyNamePath());
|
company.setCreateDate(new Date());
|
company.setIsdeleted(Constants.ZERO);
|
company.setHkStatus(Constants.ZERO);
|
company.setStatus(Constants.ZERO);
|
company.setHkDate(company.getCreateDate());
|
company.setEditDate(company.getCreateDate());
|
company.setEditor(company.getCreator());
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
companyMapper.insert(company);
|
|
company.setHkId(UUID.randomUUID().toString().replace("-",""));
|
//下发海康安防平台
|
Boolean issueStatus = addHkOrg(company);
|
Company com = new Company();
|
com.setId(company.getId());
|
com.setHkId(issueStatus?company.getHkId():null);
|
com.setHkStatus(issueStatus?Constants.ONE:Constants.TWO);
|
com.setCompanyPath(idPath+company.getId()+"/");
|
companyMapper.updateById(com);
|
return company;
|
}
|
|
|
public Company syncDDEditCompanyModel(OapiV2DepartmentGetResponse.DeptGetResponse deptGetResponse,Company company){
|
company.setErpParentId(deptGetResponse.getParentId().toString());
|
String idPath = "";
|
if(StringUtils.isNotBlank(company.getErpParentId()) && !StringUtils.equals(company.getErpParentId(),Constants.ONE+"")){
|
Company parent = companyMapper.selectOne(new QueryWrapper<Company>().lambda().eq(Company::getErpId,company.getErpParentId())
|
.eq(Company::getIsdeleted,Constants.ZERO).last("limit 1 "));
|
if(parent == null || Constants.equalsInteger(parent.getIsdeleted(),Constants.ONE)){
|
throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息不存在~");
|
}
|
if(Objects.nonNull(parent.getType())&&!Constants.equalsInteger(parent.getType(),-1)){
|
if(!Constants.equalsInteger(company.getType(),parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
}else if(Objects.isNull(parent.getType())){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,组织信息错误");
|
}
|
idPath = parent.getCompanyPath();
|
company.setHkParentId(parent.getHkId());
|
company.setCompanyPath(parent.getCompanyPath()+company.getId()+"/");
|
company.setCompanyNamePath(parent.getCompanyNamePath()+"/"+company.getName());
|
}
|
|
company.setName(deptGetResponse.getName());
|
company.setErpId(deptGetResponse.getDeptId().toString());
|
company.setErpParentId(deptGetResponse.getParentId().toString());
|
company.setSortnum(deptGetResponse.getOrder().intValue());//默认最上面
|
company.setEditDate(new Date());
|
company.setHkCompanyPath(company.getCompanyNamePath());
|
company.setHkStatus(Constants.ZERO);
|
company.setStatus(Constants.ZERO);
|
company.setSortnum(deptGetResponse.getOrder().intValue());
|
company.setHkDate(company.getCreateDate());
|
company.setEditDate(company.getCreateDate());
|
company.setEditor(company.getCreator());
|
company.setPinyin(Constants.getChinesePingyin(company.getName()));
|
companyMapper.updateById(company);
|
//下发海康安防平台
|
Boolean issueStatus = editHkOrg(company);
|
Company com = new Company();
|
com.setId(company.getId());
|
com.setHkId(issueStatus?company.getHkId():null);
|
com.setHkStatus(issueStatus?Constants.ONE:Constants.TWO);
|
com.setCompanyPath(idPath+company.getId()+"/");
|
companyMapper.updateById(com);
|
return company;
|
}
|
|
|
|
public void syncDelCompany(List<Long> deptIdList){
|
List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>()
|
.lambda()
|
.eq(Company::getIsdeleted,Constants.ZERO)
|
.in(Company::getErpId,deptIdList)
|
);
|
if(CollectionUtils.isNotEmpty(companyList)){
|
List<Integer> delIds = companyList.stream().map(i->i.getId()).collect(Collectors.toList());
|
List<String> delHKIds = companyList.stream().filter(i->StringUtils.isNotBlank(i.getHkId())).map(i->i.getHkId()).collect(Collectors.toList());
|
|
//标记业务删除
|
companyMapper.update(new UpdateWrapper<Company>().lambda()
|
.set(Company::getIsdeleted,Constants.ONE)
|
.set(Company::getEditDate,new Date())
|
.in(Company::getId,delIds)
|
);
|
//海康删除的数据,进行删除
|
doHkDeleteOrg(delIds,delHKIds,new Date());
|
}
|
}
|
|
|
|
}
|