Commit f8893b57 by guanchen

添加处理 合伙人 和 代理商 关系变更

用户的 代理商上级改为从自己开始找
parent 0086b85a
......@@ -44,12 +44,21 @@ public class UserController {
@RequestMapping(value = "/relation/change", method = RequestMethod.POST)
public Result<String> changeRelation(@RequestBody @Valid User user, @RequestHeader HttpHeaders headers) {
if (logger.isInfoEnabled()) {
logger.info("changeRelation userId:{},header:{},time:{}", user.getUserId(), headers.keySet().toArray(), LocalDateTime.now());
logger.info("purgeRelation userId:{},header:{},time:{}", user.getUserId(), headers.keySet().toArray(), LocalDateTime.now());
}
userManager.changeRelation(user.getUserId());
userManager.purgeRelation(user.getUserId());
logger.info("============>" + Thread.currentThread().getName());
Result<String> result = new Result<String>();
result.setData("异步,正在执行刷新......");
return result;
}
@RequestMapping(value = "/update/relation/{from}/{to}/{type}" ,method = RequestMethod.GET)
public Result<String> updateRelation(@PathVariable("from") String from, @PathVariable("to") String to, @PathVariable("type") int type) {
userManager.updateRelation(from, to, type);
logger.info("============>" + Thread.currentThread().getName());
Result<String> result = new Result<String>();
result.setData("异步,正在执行更新新......");
return result;
}
}
......@@ -39,4 +39,8 @@ public interface PartnerAccountMapper extends BaseMapper<PartnerAccount> {
List<PartnerAccount> getChildListByUserId(Integer userId);
PartnerAccount selectOneForUpdate(Integer userId);
int updatePartnerRelation(String from, String to);
PartnerAccount getPartnerAccountByPhone(String phone);
}
\ No newline at end of file
......@@ -24,24 +24,19 @@ public interface UserAgentMapper extends BaseMapper<UserAgent> {
* @param agentId
* @return
*/
// @Select("SELECT b.* " +
// "FROM user_agent a " +
// "JOIN user_agent b on a.#{parentColumnName}=b.agent_id " +
// "WHERE a.agent_id=#{agentId} and b.agent_level<=4")
// UserAgent getParentAgent(Integer agentId, String parentColumnName);
@SelectProvider(type = UserAgentSqlProvider.class, method = "getParentAgent")
UserAgent getParentAgent(@Param("agentId") Integer agentId, @Param("parentColumnName") String parentColumnName);
/**
* 按uid查找下级 UserAgent
*/
// @Select("SELECT b.* " +
// "FROM user_agent a " +
// "JOIN user_agent b on a.#{parentColumnName}=b.agent_id " +
// "WHERE b.user_id=#{userId}")
// List<UserAgent> getChildListByUserId(Integer userId, String parentColumnName);
@SelectProvider(type = UserAgentSqlProvider.class, method = "getChildListByUserId")
List<UserAgent> getChildListByUserId(@Param("userId") Integer userId, @Param("parentColumnName") String parentColumnName);
/**
* 将手机号为from的代理商的 平推 上级改为手机号为to的代理商
*/
int updatePingtuiRelation(String from, String to);
/**
* 将手机号为from的代理商的 层级 上级改为手机号为to的代理商
*/
int updateCengjiRelation(String from, String to);
}
\ No newline at end of file
......@@ -48,10 +48,10 @@ public class UserManager {
* @param userId
*/
@Async
public Result<String> changeRelation(Integer userId) {
public Result<String> purgeRelation(Integer userId) {
Result<String> result = new Result<String>();
try{
logger.info("start changeRelation for userId: {} ...", userId);
logger.info("start purgeRelation for userId: {} ...", userId);
PartnerAccount partnerAccount = userService.getPartnerAccountByUserId(userId);
if (partnerAccount == null) {
result.setCode(413);
......@@ -78,7 +78,7 @@ public class UserManager {
recursiveSet(agentRoot, PARENT_COLUMN_NAME_CENGJI);
recursiveSet(agentRoot, PARENT_COLUMN_NAME_PINGTUI);
}
logger.info("done changeRelation for userId: {}", userId);
logger.info("done purgeRelation for userId: {}", userId);
result.setData("用户刷新成功");
} catch (Exception e) {
logger.error(e.getMessage(), e);
......@@ -189,10 +189,10 @@ public class UserManager {
logger.info("do recursiveSet for userId: {}", tree.getUserId());
if (logger.isDebugEnabled()) {
logger.info("do recursiveSet for userId: {}", tree.getUserId());
}
/**
* 先找到直接下级
*/
}
setChildList(tree, parentColumnName);
ArrayList<AgentTree> children = tree.getChildList();
/**
......@@ -263,4 +263,39 @@ public class UserManager {
}
}
}
/**
* 变更 代理商 或 用户的 上级
* 变更类型: 1改层级关系 2改推荐关系 3改层级和推荐关系 4改C端邀请关系 5全部都改
*/
@Async
public Result<String> updateRelation(String from, String to, int type) {
if (type == 1 || type == 3 || type == 5) {
int cnt = updateCengjiRelation(from, to);
logger.info("更新代理商层级关系, 将{}的上级改为{},更新{}行数据", from, to, cnt);
}
if (type == 2 || type == 3 || type == 5) {
int cnt = updatePingtuiRelation(from, to);
logger.info("更新代理商推荐关系, 将{}的上级改为{},更新{}行数据", from, to, cnt);
}
if (type == 4 || type == 5) {
int cnt = updatePartnerRelation(from, to);
logger.info("更新合伙人推荐关系, 将{}的上级改为{},更新{}行数据", from, to, cnt);
}
PartnerAccount partnerAccount = userService.getPartnerAccountByPhone(from);
return purgeRelation(partnerAccount.getUserId());
}
private int updatePartnerRelation(String from, String to) {
return userService.updatePartnerRelation(from, to);
}
private int updatePingtuiRelation(String from, String to) {
return userService.updatePingtuiRelation(from, to);
}
private int updateCengjiRelation(String from, String to) {
return userService.updateCengjiRelation(from, to);
}
}
......@@ -177,7 +177,11 @@ public class PartnerSettleTask {
partnerIncomeSummary.setYeartime(yeartime);
partnerIncomeSummary.setMonthtime(monthtime);
partnerIncomeSummary.setIncome(ZERO);
partnerIncomeSummary.setState(15);
partnerIncomeSummaryService.save(partnerIncomeSummary);
} else {
partnerIncomeSummary.setState(15);
partnerIncomeSummaryService.updateById(partnerIncomeSummary);
}
}
......
package com.lanren.huhu.partner.service; import com.lanren.huhu.partner.domain.PartnerAccount;import com.lanren.huhu.partner.domain.UserAgent;import com.lanren.huhu.partner.model.ParentAgent;import com.lanren.huhu.partner.model.User; import java.util.List; /** * @author houseme * @date 2019-06-28 18:35 * @Project partner * @Package com.lanren.huhu.partner.service * @File: UserService */public interface UserService { /** * @description: 根据用户id, 查找一个用户的全部合伙人上级 和 代理商上级(此处为层级关系 非平推关系) * 缓存用户邀请关系和代理商关系数据 * 缓存不能带有构造方法的Bean 所以只能返回User的Bean * 包装Result在Cacheable注解的方法之外进行操作 * 注意 !!!!!!!! 这个方法是按输入用户的邀请关系链上查找 第一个有agent_level<=4的代理商身份的邀请人, 然后再走他的代理关系 * 注意 !!!!!!!! 如果需要获取一个代理商的上级代理 需要从UserAgentService里的方法获取 * @param userId * @return User * @throws * @author chen * @date 2019-06-26 20:01 */ User getRelationByUserId(Integer userId); List<ParentAgent> getAgentListByUserId(Integer userId, String parentColumnName); /** * 清理用户缓存 */ boolean deleteRalationByUserId(Integer userId); /*** * PartnerAccount * * 根据用户id查询账户信息 * @param userId * @return PartnerAccount */ PartnerAccount getPartnerAccountByUserId(Integer userId); /** * @description: 根据用户id查询全部直属下级合伙人 * @param userId * @return List<PartnerAccount> * @author chen * @date 2019-06-28 11:49 */ List<PartnerAccount> getPartnerAccountChildListByUserId(Integer userId); /*** * UserAgent * 根据用户id查询账户信息 * @param userId * @return */ UserAgent getUserAgentByUserId(Integer userId); /** * @description: 根据用户id查询全部直属下级代理商 * @param userId * @return List<PartnerAccount> * @author chen * @date 2019-06-28 11:49 */ List<UserAgent> getUserAgentChildListByUserId(Integer userId, String parentColumnName); }
\ No newline at end of file
package com.lanren.huhu.partner.service; import com.lanren.huhu.partner.domain.PartnerAccount;import com.lanren.huhu.partner.domain.UserAgent;import com.lanren.huhu.partner.model.ParentAgent;import com.lanren.huhu.partner.model.User; import java.util.List; /** * @author houseme * @date 2019-06-28 18:35 * @Project partner * @Package com.lanren.huhu.partner.service * @File: UserService */public interface UserService { /** * @description: 根据用户id, 查找一个用户的全部合伙人上级 和 代理商上级(此处为层级关系 非平推关系) * 缓存用户邀请关系和代理商关系数据 * 缓存不能带有构造方法的Bean 所以只能返回User的Bean * 包装Result在Cacheable注解的方法之外进行操作 * 注意 !!!!!!!! 这个方法是按输入用户的邀请关系链上查找 第一个有agent_level<=4的代理商身份的邀请人, 然后再走他的代理关系 * 注意 !!!!!!!! 如果需要获取一个代理商的上级代理 需要从UserAgentService里的方法获取 * @param userId * @return User * @throws * @author chen * @date 2019-06-26 20:01 */ User getRelationByUserId(Integer userId); List<ParentAgent> getAgentListByUserId(Integer userId, String parentColumnName); /** * 清理用户缓存 */ boolean deleteRalationByUserId(Integer userId); /*** * PartnerAccount * * 根据用户id查询账户信息 * @param userId * @return PartnerAccount */ PartnerAccount getPartnerAccountByUserId(Integer userId); /** * @description: 根据用户id查询全部直属下级合伙人 * @param userId * @return List<PartnerAccount> * @author chen * @date 2019-06-28 11:49 */ List<PartnerAccount> getPartnerAccountChildListByUserId(Integer userId); /*** * UserAgent * 根据用户id查询账户信息 * @param userId * @return */ UserAgent getUserAgentByUserId(Integer userId); /** * @description: 根据用户id查询全部直属下级代理商 * @param userId * @return List<PartnerAccount> * @author chen * @date 2019-06-28 11:49 */ List<UserAgent> getUserAgentChildListByUserId(Integer userId, String parentColumnName); int updatePartnerRelation(String from, String to); int updatePingtuiRelation(String from, String to); int updateCengjiRelation(String from, String to); PartnerAccount getPartnerAccountByPhone(String phone);}
\ No newline at end of file
......
......@@ -501,4 +501,20 @@
<select id="selectOneForUpdate" resultMap="BaseResultMap">
SELECT * FROM partner_account WHERE user_id = #{userId} FOR UPDATE;
</select>
<update id="updatePartnerRelation">
UPDATE partner_invite_relation a
JOIN user_info b ON a.user_id=b.user_id
SET a.invite_user_id = (
SELECT a.user_id
FROM partner_account a JOIN user_info b ON a.user_id=b.user_id
WHERE b.user_phone='#{to}'
)
WHERE b.user_phone='#{from}'
</update>
<select id="getPartnerAccountByPhone" resultMap="BaseResultMap">
SELECT a.*
FROM partner_account a
JOIN user_info b on a.user_id=b.user_id
WHERE b.user_phone=#{phone}
</select>
</mapper>
\ No newline at end of file
......@@ -688,7 +688,7 @@
</select>
<update id="updateRewardStatusByUidAndTs">
UPDATE partner_reward
SET reward_status=120
SET reward_status=120,settle_state=case when settle_state>0 then 300 else settle_state end
WHERE recharge_time
BETWEEN FROM_UNIXTIME(#{beginTs}) AND FROM_UNIXTIME(#{endTs})
AND user_id = #{userId}
......
......@@ -588,4 +588,14 @@
</if>
</trim>
</insert>
<update id="updatePingtuiRelation">
UPDATE user_agent
SET presenter_id=(SELECT agent_id FROM user_agent WHERE agent_phone=#{to})
WHERE agent_phone=#{from}
</update>
<update id="updateCengjiRelation">
UPDATE user_agent
SET parent_agent_id=(SELECT agent_id FROM user_agent WHERE agent_phone=#{to})
WHERE agent_phone=#{from}
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment