解决重复分发

master
yqy 9 months ago
parent 6cb8a75157
commit f0f950f271

@ -33,6 +33,7 @@ import com.baiye.system.model.entity.SysUser;
import com.baiye.system.service.SysUserRoleService;
import com.baiye.system.service.SysUserService;
import com.baiye.util.AESUtils;
import com.baiye.util.RedisUtils;
import com.baiye.utils.SerialCode;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.google.common.collect.Lists;
@ -43,6 +44,8 @@ import org.apache.commons.lang3.StringUtils;
import org.ballcat.security.properties.SecurityProperties;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -50,6 +53,8 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@Slf4j
@ -71,6 +76,8 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
private final StoreService storeService;
private final RedisTemplate<Object, Object> redisTemplate;
@Value("${snowflake.workerId}")
private int workerId;
@ -80,7 +87,7 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
@Override
public PageResult<CustomVO> queryPage(PageParam pageParam, CustomQo qo) {
if (qo.getSalesmanType() == DefaultNumberConstants.TWO_NUMBER && qo.getSalesmanUserId() != null){
if (qo.getSalesmanType() == DefaultNumberConstants.TWO_NUMBER && qo.getSalesmanUserId() != null) {
List<Long> customIdList = clueService.findCustomId(qo.getSalesmanUserId(), SecurityUtils.getCurrentUserId());
qo.setCustomIds(customIdList);
}
@ -95,7 +102,7 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
CustomEntity customEntity = getCustomEntity(CustomConverter.INSTANCE.dtoToPo(customDTO), user.getWhichUserId(), user.getUsername());
int insert = baseMapper.insert(customEntity);
List<CustomStoreEntity> customStoreEntities = customDTO.getCustomStoreEntities();
if (CollUtil.isNotEmpty(customStoreEntities)){
if (CollUtil.isNotEmpty(customStoreEntities)) {
customStoreEntities.forEach(c -> c.setCustomId(customEntity.getCustomId()));
customStoreService.saveBatch(customStoreEntities);
}
@ -117,13 +124,13 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
CustomVO customVO = new CustomVO();
CustomEntity customEntity = baseMapper.selectById(id);
BeanUtils.copyProperties(customEntity, customVO);
if (CollUtil.isNotEmpty(customEntity.getSalesmanUserId())){
if (CollUtil.isNotEmpty(customEntity.getSalesmanUserId())) {
customVO.setSalesmanUserId(customEntity.getSalesmanUserId().stream().map(Long::parseLong).collect(Collectors.toList()));
ClueQo clueQo = new ClueQo();
clueQo.setCustomId(id);
List<ClueVO> clueVOS = clueService.queryList(clueQo);
if (CollUtil.isNotEmpty(clueVOS)){
if (CollUtil.isNotEmpty(clueVOS)) {
customVO.setUserNameList(clueVOS.stream().map(ClueVO::getAssignedName).collect(Collectors.toList()));
}
}
@ -162,13 +169,18 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean auditFormById(ChangeCustomDTO dto) {
ValueOperations<Object, Object> valueOperations = redisTemplate.opsForValue();
String key = "custom::audit:" + dto.getCustomId();
Long currentUserId = SecurityUtils.getCurrentUserId();
// 加锁
Boolean ifAbsent = valueOperations.setIfAbsent(key, currentUserId, 10, TimeUnit.SECONDS);
if ((null == ifAbsent) || (!ifAbsent)) throw new BadRequestException("10秒内不能重复分发同一客户");
Integer status = dto.getStatus();
List<Long> salesmanUserIdList = dto.getSalesmanUserId();
Long currentUserId = SecurityUtils.getCurrentUserId();
List<ClueDTO> list = Lists.newArrayList();
CustomEntity customEntity = baseMapper.selectById(dto.getCustomId());
if (ObjectUtil.isNotNull(customEntity)) {
if (ObjectUtil.isNotNull(customEntity) || customEntity.getEnrollStatus() != DefaultNumberConstants.TWO_NUMBER) {
String phone = AESUtils.encrypt(customEntity.getCustomNid(), securityProperties.getPasswordSecretKey());
Long companyId = customEntity.getCompanyId();
if (status == 0) {
@ -189,7 +201,7 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
if (Boolean.TRUE.equals(result)) {
ClueDTO clueDTO = new ClueDTO(clueId, customEntity.getChannelName(), phone, customEntity.getRemark(),
otherClue, entity.getUserId(), username, currentUserId, Boolean.TRUE, companyId, customEntity.getSex(),
customEntity.getCustomInformation(), customEntity.getChannelIdentifying(), customEntity.getChannelType(),dto.getCustomId());
customEntity.getCustomInformation(), customEntity.getChannelIdentifying(), customEntity.getChannelType(), dto.getCustomId());
list.add(clueDTO);
}
}
@ -222,9 +234,10 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
customEntity.setEnrollStatus(2);
customEntity.setDistributeTime(DateUtil.date());
customEntity.setUpdateTime(LocalDateTime.now());
return SqlHelper.retBool(baseMapper.updateById(customEntity));
int update = baseMapper.updateById(customEntity);
return SqlHelper.retBool(update);
}
}
} else throw new BadRequestException("已分发,请勿重复分发");
return Boolean.FALSE;
}
@ -297,7 +310,7 @@ public class CustomServiceImpl extends ExtendServiceImpl<CustomMapper, CustomEnt
}
private CustomEntity getCustomEntity(CustomEntity entity,Long companyId,String username) {
private CustomEntity getCustomEntity(CustomEntity entity, Long companyId, String username) {
String code = LetterConst.D.concat(StrPool.DASHED.concat(DateUtil.format(DateUtil.date(), DateConst.YYYY_MM_DD)));
String maxCode = baseMapper.selectMaxBatchNoByCompanyId(code, companyId);
// 拼接编号

Loading…
Cancel
Save