| | |
| | | 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 com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.admin.response.CompanyDTO; |
| | | import com.doumee.dao.business.CompanyMapper; |
| | | import com.doumee.dao.business.join.CompanyJoinMapper; |
| | | import com.doumee.dao.business.model.Category; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.CompanyService; |
| | | 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.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | 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.util.CollectionUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 企业信息表Service实现 |
| | | * @author 江蹄蹄 |
| | | * @date 2023/11/23 18:16 |
| | | * @date 2023/11/30 15:33 |
| | | */ |
| | | @Service |
| | | public class CompanyServiceImpl implements CompanyService { |
| | | |
| | | @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(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 |
| | | public Integer createLaborServices(Company company) { |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | 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()); |
| | | insert.setLinkPhone(company.getLinkPhone()); |
| | | companyMapper.insert(insert); |
| | | return insert.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | companyMapper.deleteById(id); |
| | | LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if(id== null ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | 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.setEditDate(new Date()); |
| | | company.setEditor(user.getId()); |
| | | company.setIsdeleted(Constants.ONE); |
| | | company.setHkStatus(Constants.ONE); |
| | | company.setHkDate(company.getHkDate()); |
| | | companyMapper.updateById(company); |
| | | //下发海康安防平台 |
| | | if(!delHkOrg(model)){ |
| | | throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,组织删除下发失败,请确认该组织无下级组织或组织人员信息~"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | companyMapper.deleteBatchIds(ids); |
| | | ids.stream().forEach(s->{ |
| | | 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 |
| | | public Integer updateLaborServicesById(Company company) { |
| | | checkUnique(company); |
| | | companyMapper.updateById(company); |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | |
| | | QueryWrapper<Company> wrapper = new QueryWrapper<>(company); |
| | | return companyMapper.selectList(wrapper); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<Company> findPage(PageWrap<Company> pageWrap) { |
| | | IPage<Company> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<Company> queryWrapper = new QueryWrapper<>(); |
| | | MPJLambdaWrapper<Company> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(Company::getId, pageWrap.getModel().getId()); |
| | | queryWrapper.eq(Company::getId, pageWrap.getModel().getId()); |
| | | } |
| | | if (pageWrap.getModel().getCreator() != null) { |
| | | queryWrapper.lambda().eq(Company::getCreator, pageWrap.getModel().getCreator()); |
| | | queryWrapper.eq(Company::getCreator, pageWrap.getModel().getCreator()); |
| | | } |
| | | if (pageWrap.getModel().getCreateDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); |
| | | queryWrapper.lambda().le(Company::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); |
| | | 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.lambda().eq(Company::getEditor, pageWrap.getModel().getEditor()); |
| | | queryWrapper.eq(Company::getEditor, pageWrap.getModel().getEditor()); |
| | | } |
| | | if (pageWrap.getModel().getEditDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); |
| | | queryWrapper.lambda().le(Company::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); |
| | | 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.lambda().eq(Company::getIsdeleted, pageWrap.getModel().getIsdeleted()); |
| | | queryWrapper.eq(Company::getIsdeleted, pageWrap.getModel().getIsdeleted()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.lambda().eq(Company::getName, pageWrap.getModel().getName()); |
| | | queryWrapper.like(Company::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getRemark() != null) { |
| | | queryWrapper.lambda().eq(Company::getRemark, pageWrap.getModel().getRemark()); |
| | | queryWrapper.eq(Company::getRemark, pageWrap.getModel().getRemark()); |
| | | } |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.lambda().eq(Company::getStatus, pageWrap.getModel().getStatus()); |
| | | queryWrapper.eq(Company::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | if (pageWrap.getModel().getSortnum() != null) { |
| | | queryWrapper.lambda().eq(Company::getSortnum, pageWrap.getModel().getSortnum()); |
| | | queryWrapper.eq(Company::getSortnum, pageWrap.getModel().getSortnum()); |
| | | } |
| | | if (pageWrap.getModel().getImgurl() != null) { |
| | | queryWrapper.lambda().eq(Company::getImgurl, pageWrap.getModel().getImgurl()); |
| | | queryWrapper.eq(Company::getImgurl, pageWrap.getModel().getImgurl()); |
| | | } |
| | | if (pageWrap.getModel().getType() != null) { |
| | | queryWrapper.lambda().eq(Company::getType, pageWrap.getModel().getType()); |
| | | queryWrapper.eq(Company::getType, pageWrap.getModel().getType()); |
| | | } |
| | | if (pageWrap.getModel().getCategoryId() != null) { |
| | | queryWrapper.lambda().eq(Company::getCategoryId, pageWrap.getModel().getCategoryId()); |
| | | queryWrapper.eq(Company::getCategoryId, pageWrap.getModel().getCategoryId()); |
| | | } |
| | | if (pageWrap.getModel().getCode() != null) { |
| | | queryWrapper.lambda().eq(Company::getCode, pageWrap.getModel().getCode()); |
| | | queryWrapper.eq(Company::getCode, pageWrap.getModel().getCode()); |
| | | } |
| | | if (pageWrap.getModel().getParentId() != null) { |
| | | queryWrapper.lambda().eq(Company::getParentId, pageWrap.getModel().getParentId()); |
| | | queryWrapper.eq(Company::getParentId, pageWrap.getModel().getParentId()); |
| | | } |
| | | if (pageWrap.getModel().getLinkName() != null) { |
| | | queryWrapper.lambda().eq(Company::getLinkName, pageWrap.getModel().getLinkName()); |
| | | queryWrapper.eq(Company::getLinkName, pageWrap.getModel().getLinkName()); |
| | | } |
| | | if (pageWrap.getModel().getLinkPhone() != null) { |
| | | queryWrapper.lambda().eq(Company::getLinkPhone, pageWrap.getModel().getLinkPhone()); |
| | | queryWrapper.eq(Company::getLinkPhone, pageWrap.getModel().getLinkPhone()); |
| | | } |
| | | if (pageWrap.getModel().getHkId() != null) { |
| | | queryWrapper.lambda().eq(Company::getHkId, pageWrap.getModel().getHkId()); |
| | | queryWrapper.eq(Company::getHkId, pageWrap.getModel().getHkId()); |
| | | } |
| | | if (pageWrap.getModel().getHkStatus() != null) { |
| | | queryWrapper.lambda().eq(Company::getHkStatus, pageWrap.getModel().getHkStatus()); |
| | | queryWrapper.eq(Company::getHkStatus, pageWrap.getModel().getHkStatus()); |
| | | } |
| | | if (pageWrap.getModel().getHkDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getHkDate, Utils.Date.getStart(pageWrap.getModel().getHkDate())); |
| | | queryWrapper.lambda().le(Company::getHkDate, Utils.Date.getEnd(pageWrap.getModel().getHkDate())); |
| | | 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.lambda().eq(Company::getErpId, pageWrap.getModel().getErpId()); |
| | | queryWrapper.eq(Company::getErpId, pageWrap.getModel().getErpId()); |
| | | } |
| | | if (pageWrap.getModel().getErpDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getErpDate, Utils.Date.getStart(pageWrap.getModel().getErpDate())); |
| | | queryWrapper.lambda().le(Company::getErpDate, Utils.Date.getEnd(pageWrap.getModel().getErpDate())); |
| | | 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.lambda().eq(Company::getErpStatus, pageWrap.getModel().getErpStatus()); |
| | | queryWrapper.eq(Company::getErpStatus, pageWrap.getModel().getErpStatus()); |
| | | } |
| | | if (pageWrap.getModel().getDdId() != null) { |
| | | queryWrapper.lambda().eq(Company::getDdId, pageWrap.getModel().getDdId()); |
| | | queryWrapper.eq(Company::getDdId, pageWrap.getModel().getDdId()); |
| | | } |
| | | if (pageWrap.getModel().getDdDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getDdDate, Utils.Date.getStart(pageWrap.getModel().getDdDate())); |
| | | queryWrapper.lambda().le(Company::getDdDate, Utils.Date.getEnd(pageWrap.getModel().getDdDate())); |
| | | 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.lambda().eq(Company::getDdStatus, pageWrap.getModel().getDdStatus()); |
| | | 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.lambda().eq(Company::getFsStatus, pageWrap.getModel().getFsStatus()); |
| | | queryWrapper.eq(Company::getFsStatus, pageWrap.getModel().getFsStatus()); |
| | | } |
| | | if (pageWrap.getModel().getFsDate() != null) { |
| | | queryWrapper.lambda().ge(Company::getFsDate, Utils.Date.getStart(pageWrap.getModel().getFsDate())); |
| | | queryWrapper.lambda().le(Company::getFsDate, Utils.Date.getEnd(pageWrap.getModel().getFsDate())); |
| | | queryWrapper.ge(Company::getFsDate, Utils.Date.getStart(pageWrap.getModel().getFsDate())); |
| | | queryWrapper.le(Company::getFsDate, Utils.Date.getEnd(pageWrap.getModel().getFsDate())); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | return PageData.from(companyMapper.selectPage(page, queryWrapper)); |
| | | queryWrapper.orderByDesc(Company::getCreateDate); |
| | | queryWrapper.leftJoin(Category.class,Category::getId,Company::getCategoryId); |
| | | /* .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") |
| | | /*.select("c.name as parentName");*/ |
| | | .selectAs(Category::getName,Company::getCategoryName); |
| | | /* .selectAs(Member::getName,Company::getHeadName) |
| | | .selectAs(Member::getPhone,Company::getHeadPhone) |
| | | .select("count(t1.id) as countNum");*/ |
| | | // queryWrapper.eq(Company::getType,Constants.ZERO); |
| | | 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()); |
| | | 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(); |
| | | |
| | | 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 |
| | | 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,origin); |
| | | } |
| | | |
| | | |
| | | private List<CompanyDTO> getCompanyTree(List<Company> companies, String parentId,String origin){ |
| | | if (CollectionUtils.isEmpty(companies)){ |
| | | return null; |
| | | } |
| | | List<Company> collect = companies.stream() |
| | | .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; |
| | | } |
| | | 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); |
| | | companyDTO.setCompanyDTOList(getCompanyTree(companies,StringUtils.equals(origin, Constants.ONE+"")?company.getErpId(): company.getId()+"",origin)); |
| | | 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::getType,Constants.ZERO) |
| | | .eq(Company::getName,company.getName()); |
| | | List<Company> companies = companyMapper.selectList(wrapper); |
| | | if (CollectionUtils.isEmpty(companies)){ |
| | | return; |
| | | } |
| | | //新增的情况存在记录 |
| | | 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(),"公司名称已存在"); |
| | | } |
| | | } |
| | | } |