21 changed files with 485 additions and 33 deletions
@ -0,0 +1,107 @@ |
|||||
|
package com.qs.serve.modules.his.entity; |
||||
|
|
||||
|
import java.time.LocalDate; |
||||
|
import java.io.Serializable; |
||||
|
import java.math.BigDecimal; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
|
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* 渠道站点 实体类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-04-12 |
||||
|
*/ |
||||
|
@Data |
||||
|
@TableName("his_user_channel_point") |
||||
|
public class HisUserChannelPoint implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** id */ |
||||
|
@TableId(type = IdType.AUTO) |
||||
|
private Long id; |
||||
|
|
||||
|
/** 用户id */ |
||||
|
@Length(max = 64,message = "用户id长度不能超过64字") |
||||
|
private String userId; |
||||
|
|
||||
|
/** 网点ID */ |
||||
|
private Long pointId; |
||||
|
|
||||
|
/** 来源类型:0->我管理的;1->行政区域;2->销售区域 */ |
||||
|
@NotNull(message = "来源类型:0->我管理的;1->行政区域;2->销售区域不能为空") |
||||
|
private Integer sourceType; |
||||
|
|
||||
|
/** 来源id路径 */ |
||||
|
@Length(max = 255,message = "来源id路径长度不能超过255字") |
||||
|
private String sourceIds; |
||||
|
|
||||
|
/** 备注 */ |
||||
|
@Length(max = 255,message = "备注长度不能超过255字") |
||||
|
private String remark; |
||||
|
|
||||
|
/** 创建时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
/** 最后更新时间 */ |
||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private LocalDateTime updateTime; |
||||
|
|
||||
|
/** 所属租户 */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String tenantId; |
||||
|
|
||||
|
/** 逻辑删除标记(0:显示;1:隐藏) */ |
||||
|
@JsonIgnore |
||||
|
@JsonProperty |
||||
|
private String delFlag; |
||||
|
|
||||
|
/** 创建人 */ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private String createBy; |
||||
|
|
||||
|
/** 更新人 */ |
||||
|
@TableField(fill = FieldFill.UPDATE) |
||||
|
private String updateBy; |
||||
|
|
||||
|
/** 可投放费用 */ |
||||
|
@NotNull(message = "可投放费用不能为空") |
||||
|
private Integer costFlag; |
||||
|
|
||||
|
|
||||
|
public static HisUserChannelPoint toNewObject(HisUserChannelPoint source){ |
||||
|
HisUserChannelPoint userChannelPoint = new HisUserChannelPoint(); |
||||
|
userChannelPoint.setId(source.getId()); |
||||
|
userChannelPoint.setUserId(source.getUserId()); |
||||
|
userChannelPoint.setPointId(source.getPointId()); |
||||
|
userChannelPoint.setSourceType(source.getSourceType()); |
||||
|
userChannelPoint.setSourceIds(source.getSourceIds()); |
||||
|
userChannelPoint.setRemark(source.getRemark()); |
||||
|
userChannelPoint.setCreateTime(source.getCreateTime()); |
||||
|
userChannelPoint.setUpdateTime(source.getUpdateTime()); |
||||
|
userChannelPoint.setTenantId(source.getTenantId()); |
||||
|
userChannelPoint.setDelFlag(source.getDelFlag()); |
||||
|
userChannelPoint.setCreateBy(source.getCreateBy()); |
||||
|
userChannelPoint.setUpdateBy(source.getUpdateBy()); |
||||
|
userChannelPoint.setCostFlag(source.getCostFlag()); |
||||
|
return userChannelPoint; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
package com.qs.serve.modules.his.mapper; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.qs.serve.modules.his.entity.HisUserChannelPoint; |
||||
|
|
||||
|
/** |
||||
|
* 渠道站点 Mapper |
||||
|
* @author YenHex |
||||
|
* @date 2023-04-12 |
||||
|
*/ |
||||
|
public interface HisUserChannelPointMapper extends BaseMapper<HisUserChannelPoint> { |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,46 @@ |
|||||
|
package com.qs.serve.modules.his.service; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||
|
import com.qs.serve.modules.his.entity.HisUserChannelPoint; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* 渠道站点 服务接口 |
||||
|
* @author YenHex |
||||
|
* @date 2023-04-12 |
||||
|
*/ |
||||
|
public interface HisUserChannelPointService extends IService<HisUserChannelPoint> { |
||||
|
|
||||
|
/** |
||||
|
* 删除 |
||||
|
* @param pointId |
||||
|
*/ |
||||
|
void removeByPointId(Long pointId); |
||||
|
|
||||
|
/** |
||||
|
* 初始化网点 |
||||
|
* @param pointId |
||||
|
* @param saleRegionIds |
||||
|
* @param bizRegionIds |
||||
|
*/ |
||||
|
void flushPoint(Long pointId ,String saleRegionIds,String bizRegionIds); |
||||
|
|
||||
|
/** |
||||
|
* 删除用户区域 |
||||
|
* @param userId |
||||
|
* @param saleRegionIds |
||||
|
* @param bizRegionIds |
||||
|
*/ |
||||
|
void removeUserRegion(String userId,String saleRegionIds,String bizRegionIds); |
||||
|
|
||||
|
/** |
||||
|
* 批量刷新 |
||||
|
* @param userIds |
||||
|
* @param pointIds |
||||
|
* @param sourceType |
||||
|
* @param regionIds |
||||
|
*/ |
||||
|
void flushBatchUserRegion(List<String> userIds,List<Long> pointIds,Integer sourceType,String regionIds); |
||||
|
|
||||
|
} |
||||
|
|
@ -0,0 +1,148 @@ |
|||||
|
package com.qs.serve.modules.his.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.qs.serve.common.util.CollectionUtil; |
||||
|
import com.qs.serve.common.util.StringUtils; |
||||
|
import com.qs.serve.modules.bms.common.MasterUserType; |
||||
|
import com.qs.serve.modules.bms.entity.BmsMasterUser; |
||||
|
import com.qs.serve.modules.bms.entity.BmsRegionUser; |
||||
|
import com.qs.serve.modules.bms.mapper.BmsMasterUserMapper; |
||||
|
import com.qs.serve.modules.bms.mapper.BmsRegionUserMapper; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import com.qs.serve.modules.his.entity.HisUserChannelPoint; |
||||
|
import com.qs.serve.modules.his.service.HisUserChannelPointService; |
||||
|
import com.qs.serve.modules.his.mapper.HisUserChannelPointMapper; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Arrays; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* 渠道站点 服务实现类 |
||||
|
* @author YenHex |
||||
|
* @since 2023-04-12 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class HisUserChannelPointServiceImpl extends ServiceImpl<HisUserChannelPointMapper,HisUserChannelPoint> implements HisUserChannelPointService { |
||||
|
|
||||
|
private final BmsRegionUserMapper regionUserMapper; |
||||
|
private final BmsMasterUserMapper masterUserMapper; |
||||
|
|
||||
|
@Override |
||||
|
public void removeByPointId(Long pointId) { |
||||
|
LambdaQueryWrapper<HisUserChannelPoint> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(HisUserChannelPoint::getPointId,pointId); |
||||
|
this.remove(lqw); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void flushPoint(Long pointId, String saleRegionIds, String bizRegionIds) { |
||||
|
this.removeByPointId(pointId); |
||||
|
List<HisUserChannelPoint> channelPointList = new ArrayList<>(); |
||||
|
if(StringUtils.hasText(saleRegionIds)){ |
||||
|
List<String> saleRegionArr = Arrays.asList(saleRegionIds.split("_")); |
||||
|
LambdaQueryWrapper<BmsRegionUser> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.in(BmsRegionUser::getRegionId,saleRegionArr); |
||||
|
lqw.eq(BmsRegionUser::getType,0); |
||||
|
lqw.select(BmsRegionUser::getUserId); |
||||
|
List<BmsRegionUser> regionUserList = regionUserMapper.selectList(lqw); |
||||
|
List<String> userIds = regionUserList.stream().map(BmsRegionUser::getUserId) |
||||
|
.distinct().collect(Collectors.toList()); |
||||
|
for (String userId : userIds) { |
||||
|
HisUserChannelPoint userChannelPoint = new HisUserChannelPoint(); |
||||
|
userChannelPoint.setUserId(userId); |
||||
|
userChannelPoint.setPointId(pointId); |
||||
|
userChannelPoint.setSourceType(2); |
||||
|
userChannelPoint.setSourceIds(saleRegionIds); |
||||
|
channelPointList.add(userChannelPoint); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(StringUtils.hasText(bizRegionIds)){ |
||||
|
List<String> bizRegionArr = Arrays.asList(bizRegionIds.split("_")); |
||||
|
LambdaQueryWrapper<BmsRegionUser> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.in(BmsRegionUser::getRegionId,bizRegionArr); |
||||
|
lqw.eq(BmsRegionUser::getType,1); |
||||
|
lqw.select(BmsRegionUser::getUserId); |
||||
|
List<BmsRegionUser> regionUserList = regionUserMapper.selectList(lqw); |
||||
|
List<String> userIds = regionUserList.stream().map(BmsRegionUser::getUserId) |
||||
|
.distinct().collect(Collectors.toList()); |
||||
|
for (String userId : userIds) { |
||||
|
HisUserChannelPoint userChannelPoint = new HisUserChannelPoint(); |
||||
|
userChannelPoint.setUserId(userId); |
||||
|
userChannelPoint.setPointId(pointId); |
||||
|
userChannelPoint.setSourceType(1); |
||||
|
userChannelPoint.setSourceIds(bizRegionIds); |
||||
|
channelPointList.add(userChannelPoint); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<BmsMasterUser> masterUserLqw = new LambdaQueryWrapper<>(); |
||||
|
masterUserLqw.eq(BmsMasterUser::getType, MasterUserType.Point); |
||||
|
masterUserLqw.eq(BmsMasterUser::getTargetId,pointId); |
||||
|
masterUserLqw.select(BmsMasterUser::getUserId); |
||||
|
List<BmsMasterUser> masterUsers = masterUserMapper.selectList(masterUserLqw); |
||||
|
List<String> userIds = masterUsers.stream().map(a->a.getUserId()).distinct().collect(Collectors.toList()); |
||||
|
for (String userId : userIds) { |
||||
|
HisUserChannelPoint userChannelPoint = new HisUserChannelPoint(); |
||||
|
userChannelPoint.setUserId(userId); |
||||
|
userChannelPoint.setPointId(pointId); |
||||
|
userChannelPoint.setSourceType(0); |
||||
|
channelPointList.add(userChannelPoint); |
||||
|
} |
||||
|
if(CollectionUtil.isNotEmpty(channelPointList)){ |
||||
|
this.saveBatch(channelPointList); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void removeUserRegion(String userId, String saleRegionIds, String bizRegionIds) { |
||||
|
if(StringUtils.hasText(saleRegionIds)){ |
||||
|
LambdaQueryWrapper<HisUserChannelPoint> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(HisUserChannelPoint::getUserId,userId); |
||||
|
lqw.eq(HisUserChannelPoint::getSourceIds,saleRegionIds); |
||||
|
lqw.eq(HisUserChannelPoint::getSourceType,2); |
||||
|
this.remove(lqw); |
||||
|
} |
||||
|
if(StringUtils.hasText(bizRegionIds)){ |
||||
|
LambdaQueryWrapper<HisUserChannelPoint> lqw = new LambdaQueryWrapper<>(); |
||||
|
lqw.eq(HisUserChannelPoint::getUserId,userId); |
||||
|
lqw.eq(HisUserChannelPoint::getSourceIds,bizRegionIds); |
||||
|
lqw.eq(HisUserChannelPoint::getSourceType,1); |
||||
|
this.remove(lqw); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void flushBatchUserRegion(List<String> userIds, List<Long> pointIds, Integer sourceType, String regionIds) { |
||||
|
List<HisUserChannelPoint> hisUserChannelPointList = new ArrayList<>(); |
||||
|
for (String userId : userIds) { |
||||
|
if(sourceType.equals(2)){ |
||||
|
this.removeUserRegion(userId,regionIds,null); |
||||
|
}else { |
||||
|
this.removeUserRegion(userId,null,regionIds); |
||||
|
} |
||||
|
for (Long pointId : pointIds) { |
||||
|
HisUserChannelPoint userChannelPoint = new HisUserChannelPoint(); |
||||
|
userChannelPoint.setUserId(userId); |
||||
|
userChannelPoint.setPointId(pointId); |
||||
|
userChannelPoint.setSourceType(sourceType); |
||||
|
userChannelPoint.setSourceIds(regionIds); |
||||
|
hisUserChannelPointList.add(userChannelPoint); |
||||
|
} |
||||
|
} |
||||
|
if(CollectionUtil.isNotEmpty(hisUserChannelPointList)){ |
||||
|
this.saveBatch(hisUserChannelPointList); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
Loading…
Reference in new issue