fix customer invited count
This commit is contained in:
@@ -6,6 +6,7 @@ import com.imyeyu.api.modules.gao.vo.GaoCustomerGenderStatView;
|
|||||||
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
import com.imyeyu.api.modules.gao.vo.GaoCustomerPage;
|
||||||
import com.imyeyu.spring.mapper.BaseMapper;
|
import com.imyeyu.spring.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -48,4 +49,11 @@ public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
|
|||||||
/// @param page 查询条件
|
/// @param page 查询条件
|
||||||
/// @return 客户列表
|
/// @return 客户列表
|
||||||
List<GaoCustomer> selectByQuery(GaoCustomerPage page);
|
List<GaoCustomer> selectByQuery(GaoCustomerPage page);
|
||||||
|
|
||||||
|
/// 原子调整邀请客户数
|
||||||
|
///
|
||||||
|
/// @param customerId 客户 ID
|
||||||
|
/// @param delta 变化量
|
||||||
|
@Update("UPDATE `gao_customer` SET `invited_count` = GREATEST(IFNULL(`invited_count`, 0) + #{delta}, 0), `updated_at` = " + UNIX_TIME + " WHERE `id` = #{customerId}" + NOT_DELETE)
|
||||||
|
void updateInvitedCountDelta(@Param("customerId") String customerId, @Param("delta") Long delta);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -117,12 +117,10 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
customer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
customer.setAge(ChronoUnit.YEARS.between(customer.getBirthdate(), LocalDate.now()));
|
||||||
}
|
}
|
||||||
customer.setInvitedCount(0L);
|
customer.setInvitedCount(0L);
|
||||||
if (customer.hasIntroducer()) {
|
|
||||||
customer.setInvitedCount(1L);
|
|
||||||
}
|
|
||||||
customer.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
customer.setCreatorUserId(userLoginService.getRequireLoginUserId());
|
||||||
|
|
||||||
super.create(customer);
|
super.create(customer);
|
||||||
|
changeInvitedCount(customer.getIntroducerCustomerId(), 1);
|
||||||
// 标签
|
// 标签
|
||||||
if (customer.getTagApply() != null) {
|
if (customer.getTagApply() != null) {
|
||||||
tagService.apply(TagApply.BizType.GAO_CUSTOMER, customer.getId(), customer.getTagApply().getTagIdList());
|
tagService.apply(TagApply.BizType.GAO_CUSTOMER, customer.getId(), customer.getTagApply().getTagIdList());
|
||||||
@@ -369,10 +367,12 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
try {
|
try {
|
||||||
logger.setContent(customerId);
|
logger.setContent(customerId);
|
||||||
GaoCustomer customer = get(customerId);
|
GaoCustomer customer = get(customerId);
|
||||||
|
TimiException.required(customer, "not found customer");
|
||||||
|
String oldIntroducerCustomerId = customer.getIntroducerCustomerId();
|
||||||
customer.setIntroducerCustomerId(null);
|
customer.setIntroducerCustomerId(null);
|
||||||
mapper.update(customer);
|
mapper.update(customer);
|
||||||
|
|
||||||
changeInvitedCount(customer.getIntroducerCustomerId(), -1);
|
changeInvitedCount(oldIntroducerCustomerId, -1);
|
||||||
logger.setLevel(Logger.Level.INFO);
|
logger.setLevel(Logger.Level.INFO);
|
||||||
logger.setResult(customerId);
|
logger.setResult(customerId);
|
||||||
} catch (TimiException e) {
|
} catch (TimiException e) {
|
||||||
@@ -434,9 +434,7 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
|
|||||||
if (TimiJava.isEmpty(customerId) || delta == 0) {
|
if (TimiJava.isEmpty(customerId) || delta == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GaoCustomer customer = get(customerId);
|
mapper.updateInvitedCountDelta(customerId, delta);
|
||||||
customer.setInvitedCount(customer.getInvitedCount() + delta);
|
|
||||||
mapper.update(customer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillPinyin(GaoCustomer customer) {
|
private void fillPinyin(GaoCustomer customer) {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
UPDATE `gao_customer` AS `customer`
|
||||||
|
SET `invited_count` = (
|
||||||
|
SELECT COUNT(1)
|
||||||
|
FROM `gao_customer` AS `invitee`
|
||||||
|
WHERE
|
||||||
|
`invitee`.`introducer_customer_id` = `customer`.`id`
|
||||||
|
AND `invitee`.`deleted_at` IS NULL
|
||||||
|
)
|
||||||
|
WHERE `customer`.`deleted_at` IS NULL;
|
||||||
Reference in New Issue
Block a user