|
|
@@ -10,6 +10,7 @@ import com.ytpm.agent.model.YtApp;
|
|
|
import com.ytpm.agent.model.YtPlatformUserPromoter;
|
|
|
import com.ytpm.agent.param.PromoterAssignParam;
|
|
|
import com.ytpm.agent.param.PromoterUserParam;
|
|
|
+import com.ytpm.agent.view.AgentUserInfo;
|
|
|
import com.ytpm.dao.AgentUserMapper;
|
|
|
import com.ytpm.dao.AppMapper;
|
|
|
import com.ytpm.dao.PromoterUserMapper;
|
|
|
@@ -17,10 +18,10 @@ import com.ytpm.general.RepMessage;
|
|
|
import com.ytpm.general.ResultTable;
|
|
|
import com.ytpm.handle.CustomerException;
|
|
|
import com.ytpm.middle.param.MiddleUserParam;
|
|
|
-import com.ytpm.middle.view.MiddleUserInfo;
|
|
|
import com.ytpm.oauth.model.YtPlatformUser;
|
|
|
import com.ytpm.service.PromoterUserService;
|
|
|
import com.ytpm.util.IDUtil;
|
|
|
+import com.ytpm.util.NumberUtils;
|
|
|
import com.ytpm.util.RandomPasswordGenerator;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -28,6 +29,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
@@ -57,7 +59,7 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String addOne(MiddleUserParam param, MiddleUserInfo userInfo) {
|
|
|
+ public String addOne(MiddleUserParam param, AgentUserInfo userInfo) {
|
|
|
//根据登录名生成登录账号
|
|
|
YtPlatformUser user = new YtPlatformUser();
|
|
|
user.setUserId(IDUtil.generateFlowID("yt_agent_"));
|
|
|
@@ -65,9 +67,12 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
user.setUserType(UserTypeEnum.APP_PROMOTER.getCode());
|
|
|
user.setNickName(param.getNickName());
|
|
|
user.setLoginName(param.getLoginName());
|
|
|
- String generatedPassword = RandomPasswordGenerator.generatePassword(8);
|
|
|
- log.info("创建推广用户成功,您本次的登录密码为:{}", generatedPassword);
|
|
|
- user.setEncryptPwd(new BCryptPasswordEncoder().encode(generatedPassword));
|
|
|
+ if (StrUtil.isEmpty(param.getPassword())) {
|
|
|
+ String generatedPassword = RandomPasswordGenerator.generatePassword(8);
|
|
|
+ log.info("创建推广用户成功,您本次的登录密码为:{}", generatedPassword);
|
|
|
+ param.setPassword(generatedPassword);
|
|
|
+ }
|
|
|
+ user.setEncryptPwd(new BCryptPasswordEncoder().encode(param.getPassword()));
|
|
|
user.setPhone(param.getPhone());
|
|
|
user.setLastLoginTime(new Date());
|
|
|
user.setRegistryTime(new Date());
|
|
|
@@ -77,7 +82,7 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String updateOne(MiddleUserParam param, MiddleUserInfo userInfo) {
|
|
|
+ public String updateOne(MiddleUserParam param, AgentUserInfo userInfo) {
|
|
|
YtPlatformUser platformUser = agentUserMapper.selectPrimary(param.getUserId());
|
|
|
if (Objects.isNull(platformUser)) {
|
|
|
return RepMessage.OBJECT_NOT_EXIST;
|
|
|
@@ -108,7 +113,7 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String assignmentApp(PromoterAssignParam assignParam, MiddleUserInfo userInfo) {
|
|
|
+ public String assignmentApp(PromoterAssignParam assignParam, AgentUserInfo userInfo) {
|
|
|
YtApp ytApp = appMapper.selectPrimary(assignParam.getAppId());
|
|
|
if (ytApp == null) {
|
|
|
throw new CustomerException("应用不存在!");
|
|
|
@@ -118,6 +123,15 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
if (promoter != null) {
|
|
|
throw new CustomerException("该应用已绑定推广人!");
|
|
|
}
|
|
|
+ if (StrUtil.isNotEmpty(assignParam.getShareRate())) {
|
|
|
+ BigDecimal shareRate = NumberUtils.rateToBigDecimal(assignParam.getShareRate());
|
|
|
+ if (BigDecimal.ZERO.compareTo(shareRate) > 0) {
|
|
|
+ throw new CustomerException("分成比例不得小于0");
|
|
|
+ }
|
|
|
+ if (new BigDecimal("1").compareTo(shareRate) < 0) {
|
|
|
+ throw new CustomerException("分成比例不得大于100%");
|
|
|
+ }
|
|
|
+ }
|
|
|
// 开始时间为空则默认当前时间
|
|
|
if (assignParam.getStartTime() == null) {
|
|
|
assignParam.setStartTime(new Date());
|
|
|
@@ -137,4 +151,27 @@ public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
log.info("[agent promoter]渠道商为应用{}指派推广人{}", ytApp.getAppId(), assignParam.getUserId());
|
|
|
return RepMessage.SAVE_SUCCESS;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String unAssignmentApp(PromoterAssignParam assignParam, AgentUserInfo userInfo) {
|
|
|
+ if (StrUtil.isEmpty(assignParam.getAppId())) {
|
|
|
+ throw new CustomerException("appId不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isEmpty(assignParam.getUserId())) {
|
|
|
+ throw new CustomerException("userId不能为空");
|
|
|
+ }
|
|
|
+ YtApp ytApp = appMapper.selectPrimary(assignParam.getAppId());
|
|
|
+ if (ytApp == null) {
|
|
|
+ throw new CustomerException("应用不存在!");
|
|
|
+ }
|
|
|
+ List<YtPlatformUserPromoter> list = promoterUserMapper.selectPromoterByUserId(assignParam.getUserId());
|
|
|
+ YtPlatformUserPromoter promoter = list.stream()
|
|
|
+ .filter(item -> StrUtil.equals(ytApp.getAppId(), item.getAppId()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (promoter != null) {
|
|
|
+ promoter.setEndTime(new Date());
|
|
|
+ promoterUserMapper.updatePromoter(promoter);
|
|
|
+ }
|
|
|
+ return RepMessage.PROCESS_SUCCESS;
|
|
|
+ }
|
|
|
}
|