粉丝管理
This commit is contained in:
27
src/main/java/com/rj/service/IFanManagementService.java
Normal file
27
src/main/java/com/rj/service/IFanManagementService.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.FanManagement;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 粉丝管理服务
|
||||
*/
|
||||
public interface IFanManagementService extends IService<FanManagement> {
|
||||
|
||||
Map<String, Object> add(FanManagement entity);
|
||||
|
||||
Map<String, Object> update(FanManagement entity);
|
||||
|
||||
Map<String, Object> deleteById(Long id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String nickname,
|
||||
String mobile,
|
||||
Integer shareNumMin,
|
||||
Integer shareNumMax,
|
||||
String createdAtStart,
|
||||
String createdAtEnd);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public interface ILbGoodsService extends IService<LbGoods> {
|
||||
* 成功笔数达到 {@code maxBuyCount} 后停止,且循环抢购总次数不超过 {@code maxBuyCount} 的5倍。
|
||||
*
|
||||
* @param token 可选;非空时作为请求头 token,否则使用 {@code lb_third_integration_config} 中的 goodsApiToken
|
||||
* @param rushBuyAccountLabel 可选;批量账号抢单时传入,用于日志标识当前抢单账号
|
||||
* @param ;批量账号抢单时传入,用于日志标识当前抢单账号
|
||||
*/
|
||||
default Map<String, Object> rushBuy(String tenantId, String token, Integer maxBuyCount) {
|
||||
return rushBuy(tenantId, token, maxBuyCount, null);
|
||||
|
||||
223
src/main/java/com/rj/service/impl/FanManagementServiceImpl.java
Normal file
223
src/main/java/com/rj/service/impl/FanManagementServiceImpl.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.FanManagement;
|
||||
import com.rj.mapper.FanManagementMapper;
|
||||
import com.rj.service.IFanManagementService;
|
||||
import com.rj.tenant.TenantContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 粉丝管理服务实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class FanManagementServiceImpl
|
||||
extends ServiceImpl<FanManagementMapper, FanManagement>
|
||||
implements IFanManagementService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(FanManagement entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "粉丝ID不能为空");
|
||||
return result;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
if (entity.getShareNum() == null) {
|
||||
entity.setShareNum(0);
|
||||
}
|
||||
if (entity.getCreatedAt() == null) {
|
||||
entity.setCreatedAt(LocalDateTime.now());
|
||||
}
|
||||
fillTenantIdIfAbsent(entity);
|
||||
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "新增成功" : "新增失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("粉丝管理新增异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "新增异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(FanManagement entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "粉丝ID不能为空");
|
||||
return result;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
fillTenantIdIfAbsent(entity);
|
||||
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "修改成功" : "修改失败,记录可能不存在");
|
||||
if (ok) {
|
||||
result.put("data", getOneByIdAndTenant(entity.getId(), entity.getTenantId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("粉丝管理修改异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "修改异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (id == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "粉丝ID不能为空");
|
||||
return result;
|
||||
}
|
||||
boolean ok = this.removeById(id);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败,记录可能不存在");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("粉丝管理删除异常, id={}", id, e);
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String nickname,
|
||||
String mobile,
|
||||
Integer shareNumMin,
|
||||
Integer shareNumMax,
|
||||
String createdAtStart,
|
||||
String createdAtEnd) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<FanManagement> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (nickname != null && !nickname.trim().isEmpty()) {
|
||||
queryWrapper.like(FanManagement::getNickname, nickname.trim());
|
||||
}
|
||||
if (mobile != null && !mobile.trim().isEmpty()) {
|
||||
queryWrapper.like(FanManagement::getMobile, mobile.trim());
|
||||
}
|
||||
if (shareNumMin != null) {
|
||||
queryWrapper.ge(FanManagement::getShareNum, shareNumMin);
|
||||
}
|
||||
if (shareNumMax != null) {
|
||||
queryWrapper.le(FanManagement::getShareNum, shareNumMax);
|
||||
}
|
||||
|
||||
LocalDateTime start = parseDateTime(createdAtStart);
|
||||
if (createdAtStart != null && !createdAtStart.trim().isEmpty() && start == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createdAtStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
LocalDateTime end = parseDateTime(createdAtEnd);
|
||||
if (createdAtEnd != null && !createdAtEnd.trim().isEmpty() && end == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createdAtEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
if (start != null) {
|
||||
queryWrapper.ge(FanManagement::getCreatedAt, start);
|
||||
}
|
||||
if (end != null) {
|
||||
queryWrapper.le(FanManagement::getCreatedAt, end);
|
||||
}
|
||||
queryWrapper.orderByDesc(FanManagement::getCreatedAt);
|
||||
|
||||
Page<FanManagement> page = this.page(new Page<>(current, size), queryWrapper);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", page.getRecords());
|
||||
result.put("total", page.getTotal());
|
||||
result.put("current", page.getCurrent());
|
||||
result.put("size", page.getSize());
|
||||
result.put("pages", page.getPages());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("粉丝管理分页查询异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private FanManagement getOneByIdAndTenant(Long id, String tenantId) {
|
||||
LambdaQueryWrapper<FanManagement> q = new LambdaQueryWrapper<>();
|
||||
q.eq(FanManagement::getId, id);
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
q.eq(FanManagement::getTenantId, tenantId.trim());
|
||||
}
|
||||
return this.getOne(q, false);
|
||||
}
|
||||
|
||||
private void fillTenantIdIfAbsent(FanManagement entity) {
|
||||
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||
String tenantId = TenantContextHolder.getTenantId();
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
entity.setTenantId(tenantId.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void trimStringFields(FanManagement entity) {
|
||||
if (entity.getTenantId() != null) {
|
||||
entity.setTenantId(entity.getTenantId().trim());
|
||||
}
|
||||
if (entity.getAvatar() != null) {
|
||||
entity.setAvatar(entity.getAvatar().trim());
|
||||
}
|
||||
if (entity.getNickname() != null) {
|
||||
entity.setNickname(entity.getNickname().trim());
|
||||
}
|
||||
if (entity.getMobile() != null) {
|
||||
entity.setMobile(entity.getMobile().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private LocalDateTime parseDateTime(String text) {
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(text.trim(), DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ import java.util.Optional;
|
||||
@RequiredArgsConstructor
|
||||
public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> implements ILbGoodsService {
|
||||
|
||||
private static final BigDecimal RUSH_BUY_MIN_TOTAL_MONEY = new BigDecimal("29000");
|
||||
private static final BigDecimal RUSH_BUY_MIN_TOTAL_MONEY = new BigDecimal("26000");
|
||||
|
||||
private static final DateTimeFormatter DATETIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@@ -551,7 +551,7 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
w.isNotNull(LbGoods::getSellerId);
|
||||
w.gt(LbGoods::getTotalMoney, RUSH_BUY_MIN_TOTAL_MONEY);
|
||||
w.ge(LbGoods::getUpdatedAt, updatedAfter);
|
||||
w.orderByDesc(LbGoods::getUpdatedAt);
|
||||
w.orderByDesc(LbGoods::getTotalMoney);
|
||||
List<LbGoods> goodsList = this.list(w);
|
||||
if (goodsList.isEmpty()) {
|
||||
result.put("success", false);
|
||||
|
||||
Reference in New Issue
Block a user