|
|
|
@ -17,26 +17,50 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.TagCustomerDao; |
|
|
|
import com.epmet.dao.TagScopeDao; |
|
|
|
import com.epmet.dto.TagCustomerDTO; |
|
|
|
import com.epmet.dto.form.TagCustomerFormDTO; |
|
|
|
import com.epmet.dto.form.TagCustomerPageFormDTO; |
|
|
|
import com.epmet.dto.form.UpdateTagFormDTO; |
|
|
|
import com.epmet.dto.result.AgencyResultDTO; |
|
|
|
import com.epmet.dto.result.TagInfoResultDTO; |
|
|
|
import com.epmet.dto.result.UpdateTagUseCountsResultDTO; |
|
|
|
import com.epmet.entity.TagCustomerEntity; |
|
|
|
import com.epmet.entity.TagScopeEntity; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.redis.TagRedis; |
|
|
|
import com.epmet.service.TagCustomerService; |
|
|
|
import com.epmet.utils.TagColorUtils; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* 客户标签表 |
|
|
|
@ -44,32 +68,27 @@ import java.util.Map; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2020-06-02 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagCustomerEntity> implements TagCustomerService { |
|
|
|
@Autowired |
|
|
|
private TagScopeDao tagScopeDao; |
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private TagRedis tagRedis; |
|
|
|
|
|
|
|
/** |
|
|
|
* pc标签管理-分页查询 |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public PageData<TagCustomerDTO> page(Map<String, Object> params) { |
|
|
|
IPage<TagCustomerEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, TagCustomerDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<TagCustomerDTO> list(Map<String, Object> params) { |
|
|
|
List<TagCustomerEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, TagCustomerDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<TagCustomerEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<TagCustomerEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
|
|
|
|
|
return wrapper; |
|
|
|
public PageData<TagCustomerDTO> page(TagCustomerPageFormDTO formDTO) { |
|
|
|
PageHelper.startPage(formDTO.getPageNo(),formDTO.getPageSize()); |
|
|
|
List<TagCustomerDTO> list=baseDao.pageList(formDTO.getCustomerId(),formDTO.getTagName()); |
|
|
|
PageInfo<TagCustomerDTO> pageInfo = new PageInfo<>(list); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -78,18 +97,69 @@ public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagC |
|
|
|
return ConvertUtils.sourceToTarget(entity, TagCustomerDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* pc标签管理-新增 |
|
|
|
* @param dto |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(TagCustomerDTO dto) { |
|
|
|
public void save(TagCustomerFormDTO dto) { |
|
|
|
// 标签名称是否存在
|
|
|
|
LambdaQueryWrapper<TagCustomerEntity> queryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(TagCustomerEntity::getCustomerId,dto.getCustomerId()) |
|
|
|
.eq(TagCustomerEntity::getTagName,dto.getTagName()); |
|
|
|
if(baseDao.selectCount(queryWrapper)>0){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"标签名称已存在","标签名称已存在"); |
|
|
|
} |
|
|
|
TagCustomerEntity entity = ConvertUtils.sourceToTarget(dto, TagCustomerEntity.class); |
|
|
|
entity.setTagColor(StrConstant.EPMETY_STR); |
|
|
|
entity.setUseCount(NumConstant.ZERO); |
|
|
|
entity.setShowFlag(NumConstant.ONE); |
|
|
|
insert(entity); |
|
|
|
if(CollectionUtils.isNotEmpty(dto.getAgencyList())){ |
|
|
|
dto.getAgencyList().forEach(tagScopeDTO->{ |
|
|
|
TagScopeEntity tagScopeEntity=new TagScopeEntity(); |
|
|
|
tagScopeEntity.setCustomerId(entity.getCustomerId()); |
|
|
|
tagScopeEntity.setTagId(entity.getId()); |
|
|
|
tagScopeEntity.setAgencyId(tagScopeDTO.getAgencyId()); |
|
|
|
tagScopeEntity.setOrgIdPath(tagScopeDTO.getOrgIdPath()); |
|
|
|
tagScopeDao.insert(tagScopeEntity); |
|
|
|
}); |
|
|
|
} |
|
|
|
//删除redis缓存
|
|
|
|
tagRedis.clearCustomerTag(dto.getCustomerId()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* pc标签管理-修改 |
|
|
|
* @param dto |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(TagCustomerDTO dto) { |
|
|
|
public void update(TagCustomerFormDTO dto) { |
|
|
|
// 标签名称是否存在
|
|
|
|
LambdaQueryWrapper<TagCustomerEntity> queryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(TagCustomerEntity::getCustomerId,dto.getCustomerId()) |
|
|
|
.eq(TagCustomerEntity::getTagName,dto.getTagName()) |
|
|
|
.ne(TagCustomerEntity::getId,dto.getId()); |
|
|
|
if(baseDao.selectCount(queryWrapper)>0){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"标签名称已存在","标签名称已存在"); |
|
|
|
} |
|
|
|
TagCustomerEntity entity = ConvertUtils.sourceToTarget(dto, TagCustomerEntity.class); |
|
|
|
updateById(entity); |
|
|
|
//删除应用范围
|
|
|
|
tagScopeDao.deleteByTagId(entity.getId(),entity.getCustomerId()); |
|
|
|
if(CollectionUtils.isNotEmpty(dto.getAgencyList())){ |
|
|
|
dto.getAgencyList().forEach(tagScopeDTO->{ |
|
|
|
TagScopeEntity tagScopeEntity=new TagScopeEntity(); |
|
|
|
tagScopeEntity.setCustomerId(entity.getCustomerId()); |
|
|
|
tagScopeEntity.setTagId(entity.getId()); |
|
|
|
tagScopeEntity.setAgencyId(tagScopeDTO.getAgencyId()); |
|
|
|
tagScopeEntity.setOrgIdPath(tagScopeDTO.getOrgIdPath()); |
|
|
|
tagScopeDao.insert(tagScopeEntity); |
|
|
|
}); |
|
|
|
} |
|
|
|
tagRedis.clearCustomerTag(dto.getCustomerId()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -126,4 +196,99 @@ public class TagCustomerServiceImpl extends BaseServiceImpl<TagCustomerDao, TagC |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 隐藏、显示 |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @param showFlag |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void changeShowFlag(String id, Integer showFlag) { |
|
|
|
LambdaUpdateWrapper<TagCustomerEntity> tagCustomerUpdateWrapper = new LambdaUpdateWrapper<>(); |
|
|
|
tagCustomerUpdateWrapper.eq(TagCustomerEntity::getId, id) |
|
|
|
.set(TagCustomerEntity::getUpdatedBy, EpmetRequestHolder.getLoginUserId()) |
|
|
|
.set(TagCustomerEntity::getUpdatedTime, new Date()) |
|
|
|
.set(TagCustomerEntity::getShowFlag,showFlag); |
|
|
|
baseDao.update(null,tagCustomerUpdateWrapper); |
|
|
|
tagRedis.clearCustomerTag(EpmetRequestHolder.getLoginUserCustomerId()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化标签应用范围, |
|
|
|
* 每个标签,和当前客户下所有社区关联 |
|
|
|
* |
|
|
|
* @param customerId@return |
|
|
|
*/ |
|
|
|
@Async |
|
|
|
@Override |
|
|
|
public void initTagScope(String customerId) { |
|
|
|
if (StringUtils.isBlank(customerId)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
LambdaQueryWrapper<TagCustomerEntity> queryWrapper = new LambdaQueryWrapper(); |
|
|
|
queryWrapper.eq(TagCustomerEntity::getCustomerId, customerId); |
|
|
|
List<TagCustomerEntity> tagList = baseDao.selectList(queryWrapper); |
|
|
|
if (CollectionUtils.isEmpty(tagList)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
int tagTotal = tagList.size(); |
|
|
|
// 获取当前客户下所有的社区组织
|
|
|
|
Result<List<AgencyResultDTO>> communityRes = govOrgOpenFeignClient.getAllCommunity(customerId); |
|
|
|
if (communityRes.success() && CollectionUtils.isNotEmpty(communityRes.getData())) { |
|
|
|
int communityTotal = communityRes.getData().size(); |
|
|
|
int num = 0; |
|
|
|
for (TagCustomerEntity tag : tagList) { |
|
|
|
for (AgencyResultDTO agencyResultDTO : communityRes.getData()) { |
|
|
|
TagScopeEntity tagScopeEntity = new TagScopeEntity(); |
|
|
|
tagScopeEntity.setCustomerId(tag.getCustomerId()); |
|
|
|
tagScopeEntity.setTagId(tag.getId()); |
|
|
|
tagScopeEntity.setAgencyId(agencyResultDTO.getAgencyId()); |
|
|
|
tagScopeEntity.setOrgIdPath(agencyResultDTO.getOrgIdPath()); |
|
|
|
tagScopeDao.insert(tagScopeEntity); |
|
|
|
num++; |
|
|
|
} |
|
|
|
} |
|
|
|
log.error(String.format("customerId:%s,已经将%s个标签应用给%s个社区,tag_scope产生%s条记录", customerId, tagTotal, communityTotal, num)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 钉钉实时动态,获取网格所属社区下, 的标签列表 |
|
|
|
* 只返回tagId,tagName |
|
|
|
* |
|
|
|
* @param gridId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<TagCustomerDTO> getAgencyTag(String gridId) { |
|
|
|
GridInfoCache gridInfoCache= CustomerOrgRedis.getGridInfo(gridId); |
|
|
|
if(null==gridInfoCache){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"查询网格信息异常gridId:"+gridId,"查询网格信息异常"); |
|
|
|
} |
|
|
|
List<TagCustomerDTO> list=baseDao.getAgencyTag(gridInfoCache.getPid(),gridInfoCache.getCustomerId()); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 工作端获取登录用户所属组织下的标签列表 |
|
|
|
* |
|
|
|
* @param staffId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<TagInfoResultDTO> queryAgencyTag(String customerId,String staffId) { |
|
|
|
CustomerStaffInfoCacheResult staffInfoCacheResult= CustomerStaffRedis.getStaffInfo(customerId,staffId); |
|
|
|
List<TagCustomerDTO> list=baseDao.getAgencyTag(staffInfoCacheResult.getAgencyId(),customerId); |
|
|
|
List<TagInfoResultDTO> resultDTOList=new ArrayList<>(); |
|
|
|
list.forEach(tagCustomerDTO->{ |
|
|
|
TagInfoResultDTO resultDTO=new TagInfoResultDTO(); |
|
|
|
resultDTO.setTagId(tagCustomerDTO.getId()); |
|
|
|
resultDTO.setTagColor(tagCustomerDTO.getTagColor()); |
|
|
|
resultDTO.setTagName(tagCustomerDTO.getTagName()); |
|
|
|
resultDTOList.add(resultDTO); |
|
|
|
}); |
|
|
|
return resultDTOList; |
|
|
|
} |
|
|
|
} |
|
|
|
|