| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.annotation.excel.ExcelColumn; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | 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.OrgOrUserAddSuccessResponse; |
| | | import com.doumee.core.haikang.model.param.respose.OrgUpdateFailureResponse; |
| | | import com.doumee.core.haikang.service.HKService; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private CompanyJoinMapper companyJoinMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public Integer create(Company company) { |
| | | if(StringUtils.isBlank(company.getName())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | //查询名称不能重复 |
| | | if(companyMapper.selectCount(new QueryWrapper<Company>().lambda() |
| | | // .eq(Company::getType,Constants.ONE) |
| | | .eq(Company::getName,company.getName()) |
| | | .eq(Company::getIsdeleted,Constants.ZERO)) >0){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,组织名称不能重复~"); |
| | | } |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | String rootOrgId = systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_ROOTORG_CODE).getCode(); |
| | | company.setHkParentId(rootOrgId); |
| | | 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.getHkParentId())){ |
| | | throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "对不起,父级组织信息尚未同步下发成功~"); |
| | | |
| | | } |
| | | company.setHkParentId(parent.getHkParentId()); |
| | | } |
| | | company.setCreateDate(new Date()); |
| | | company.setCreator(user.getId()); |
| | | company.setIsdeleted(Constants.ZERO); |
| | | company.setHkStatus(Constants.ONE); |
| | | company.setStatus(Constants.ZERO); |
| | | company.setHkDate(company.getHkDate()); |
| | | company.setHkId(UUID.randomUUID().toString().replace("-","")); |
| | | |
| | | companyMapper.insert(company); |
| | | //下发海康安防平台 |
| | | if(!addHkOrg(company)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织同步下发失败,请稍后重试"); |
| | | } |
| | | 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(HKConstants.RES_ORG_INDEX+ UUID.randomUUID().toString().replace("-","")); |
| | | 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 |
| | | public Integer createLaborServices(Company company) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(id== null ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | Company company=new Company(); |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | 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(), "对不起,组织信息尚未同步下发成功,暂不支持修改,请尝试删除后重新添加~"); |
| | | } |
| | | Company company = new Company(); |
| | | company.setId(id); |
| | | company.setIsdeleted(Constants.ZERO); |
| | | company.setEditDate(new Date()); |
| | | company.setEditor(loginUserInfo.getId()); |
| | | company.setEditor(user.getId()); |
| | | company.setIsdeleted(Constants.ONE); |
| | | company.setHkStatus(Constants.ONE); |
| | | company.setHkDate(company.getHkDate()); |
| | | companyMapper.updateById(company); |
| | | //下发海康安防平台 |
| | | if(!delHkOrg(company)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织删除下发失败,请确认该组织无下级组织或组织人员信息~"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Company company=new Company(); |
| | | |
| | | // companyMapper.deleteBatchIds(ids); |
| | | ids.stream().forEach(s->{ |
| | | company.setId(s); |
| | | company.setIsdeleted(Constants.ZERO); |
| | | company.setEditDate(new Date()); |
| | | company.setEditor(loginUserInfo.getId()); |
| | | companyMapper.updateById(company); |
| | | Company company = new Company(); |
| | | deleteById(s); |
| | | }); |
| | | } |
| | | |
| | | @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(companyMapper.selectCount(new QueryWrapper<Company>().lambda() |
| | | // .eq(Company::getType,Constants.ONE) |
| | | .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(); |
| | | Company model = findById(company.getId()); |
| | | 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(), "对不起,组织信息尚未同步下发成功,暂不支持修改,请尝试删除后重新添加~"); |
| | | } |
| | | company.setEditDate(new Date()); |
| | | company.setEditor(user.getId()); |
| | | company.setHkStatus(Constants.ONE); |
| | | company.setHkDate(company.getHkDate()); |
| | | company.setHkId(model.getHkId()); |
| | | companyMapper.updateById(company); |
| | | //下发海康安防平台 |
| | | if(StringUtils.isNotBlank(company.getHkId()) |
| | | && Constants.equalsObject(Constants.ONE,model.getHkId()) |
| | | && !editHkOrg(company)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织同步下发失败,请稍后重试"); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<CompanyDTO> findCompanyTreePage(Integer type) { |
| | | |
| | | //配置组员人员类型来源方式 0自建 1ERP |
| | | String origin = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ORG_USER_ORIGIN).getCode(); |
| | | LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | wrapper.eq(Company::getIsdeleted,Constants.ZERO) |
| | | .eq(Constants.equalsInteger(type,Constants.ONE),Company::getType,type); |
| | | List<Company> companies = companyMapper.selectList(wrapper); |
| | | return getCompanyTree( companies, null); |
| | | return getCompanyTree( companies, null,origin); |
| | | } |
| | | |
| | | |
| | | private List<CompanyDTO> getCompanyTree(List<Company> companies, Integer parentId){ |
| | | private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId,String origin){ |
| | | if (CollectionUtils.isEmpty(companies)){ |
| | | return null; |
| | | } |
| | | List<Company> collect = companies.stream() |
| | | .filter(s -> Constants.equalsInteger(s.getParentId(), parentId)) |
| | | .filter(s -> (StringUtils.equals(origin, Constants.ONE+"")?StringUtils.equals(s.getErpParentId(), parentId):StringUtils.equals(s.getParentId()+"", parentId))) |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isEmpty(companies)){ |
| | | return null; |
| | |
| | | Company company = collect.get(i); |
| | | CompanyDTO companyDTO = new CompanyDTO(); |
| | | BeanUtils.copyProperties(company,companyDTO); |
| | | companyDTO.setCompanyDTOList(getCompanyTree(companies, company.getId())); |
| | | companyDTO.setCompanyDTOList(getCompanyTree(companies,StringUtils.equals(origin, Constants.ONE+"")?company.getErpId(): company.getId()+"",origin)); |
| | | companyDTOList.add(companyDTO); |
| | | } |
| | | return companyDTOList; |