批量按部门修改代理商的寄卖状态,用户状态
This commit is contained in:
246
src/main/java/com/rj/service/impl/MemberInfoServiceImpl.java
Normal file
246
src/main/java/com/rj/service/impl/MemberInfoServiceImpl.java
Normal file
@@ -0,0 +1,246 @@
|
||||
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.MemberInfo;
|
||||
import com.rj.mapper.MemberInfoMapper;
|
||||
import com.rj.service.IMemberInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MemberInfoServiceImpl extends ServiceImpl<MemberInfoMapper, MemberInfo> implements IMemberInfoService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(MemberInfo entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getPhone() == null || entity.getPhone().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "phone(手机号)不能为空");
|
||||
return result;
|
||||
}
|
||||
entity.setPhone(entity.getPhone().trim());
|
||||
// 同一手机号唯一
|
||||
MemberInfo existing = this.getOne(
|
||||
new LambdaQueryWrapper<MemberInfo>().eq(MemberInfo::getPhone, entity.getPhone()),
|
||||
false);
|
||||
if (existing != null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "该手机号已存在");
|
||||
return result;
|
||||
}
|
||||
// 设置默认值
|
||||
if (entity.getStatus() == null) {
|
||||
entity.setStatus(1);
|
||||
}
|
||||
if (entity.getUserLevel() == null || entity.getUserLevel().trim().isEmpty()) {
|
||||
entity.setUserLevel("normal");
|
||||
}
|
||||
if (entity.getAvailableOrderCount() == null) {
|
||||
entity.setAvailableOrderCount(0);
|
||||
}
|
||||
if (entity.getIsPriorityBuy() == null) {
|
||||
entity.setIsPriorityBuy(0);
|
||||
}
|
||||
if (entity.getCanConsign() == null) {
|
||||
entity.setCanConsign(1);
|
||||
}
|
||||
if (entity.getAuditStatus() == null) {
|
||||
entity.setAuditStatus(0);
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (entity.getCreateTime() == null) {
|
||||
entity.setCreateTime(now);
|
||||
}
|
||||
entity.setUpdateTime(now);
|
||||
if (entity.getJoinTime() == null) {
|
||||
entity.setJoinTime(now);
|
||||
}
|
||||
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "新增成功" : "新增失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "新增异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(MemberInfo entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
if (this.getById(entity.getId()) == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "记录不存在");
|
||||
return result;
|
||||
}
|
||||
if (entity.getPhone() != null) {
|
||||
entity.setPhone(entity.getPhone().trim());
|
||||
}
|
||||
entity.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "编辑成功" : "编辑失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "编辑异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (id == null || id.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
if (this.getById(id) == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "记录不存在");
|
||||
return result;
|
||||
}
|
||||
boolean ok = this.removeById(id);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(
|
||||
Integer current,
|
||||
Integer size,
|
||||
String phone,
|
||||
String nickname,
|
||||
String inviteCode,
|
||||
String parentId,
|
||||
String userLevel,
|
||||
Integer status,
|
||||
Integer auditStatus,
|
||||
Integer canConsign) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<MemberInfo> w = buildWrapper(
|
||||
phone, nickname, inviteCode, parentId, userLevel, status, auditStatus, canConsign);
|
||||
w.orderByDesc(MemberInfo::getCreateTime);
|
||||
|
||||
Page<MemberInfo> page = this.page(new Page<>(current, size), w);
|
||||
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) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> listAll(
|
||||
String phone,
|
||||
String nickname,
|
||||
String inviteCode,
|
||||
String parentId,
|
||||
String userLevel,
|
||||
Integer status,
|
||||
Integer auditStatus,
|
||||
Integer canConsign) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
LambdaQueryWrapper<MemberInfo> w = buildWrapper(
|
||||
phone, nickname, inviteCode, parentId, userLevel, status, auditStatus, canConsign);
|
||||
w.orderByDesc(MemberInfo::getCreateTime);
|
||||
|
||||
List<MemberInfo> list = this.list(w);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", list);
|
||||
result.put("total", list.size());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<MemberInfo> buildWrapper(
|
||||
String phone,
|
||||
String nickname,
|
||||
String inviteCode,
|
||||
String parentId,
|
||||
String userLevel,
|
||||
Integer status,
|
||||
Integer auditStatus,
|
||||
Integer canConsign) {
|
||||
LambdaQueryWrapper<MemberInfo> w = new LambdaQueryWrapper<>();
|
||||
if (phone != null && !phone.trim().isEmpty()) {
|
||||
w.like(MemberInfo::getPhone, phone.trim());
|
||||
}
|
||||
if (nickname != null && !nickname.trim().isEmpty()) {
|
||||
w.like(MemberInfo::getNickname, nickname.trim());
|
||||
}
|
||||
if (inviteCode != null && !inviteCode.trim().isEmpty()) {
|
||||
w.eq(MemberInfo::getInviteCode, inviteCode.trim());
|
||||
}
|
||||
if (parentId != null && !parentId.trim().isEmpty()) {
|
||||
w.eq(MemberInfo::getParentId, parentId.trim());
|
||||
}
|
||||
if (userLevel != null && !userLevel.trim().isEmpty()) {
|
||||
w.eq(MemberInfo::getUserLevel, userLevel.trim());
|
||||
}
|
||||
if (status != null) {
|
||||
w.eq(MemberInfo::getStatus, status);
|
||||
}
|
||||
if (auditStatus != null) {
|
||||
w.eq(MemberInfo::getAuditStatus, auditStatus);
|
||||
}
|
||||
if (canConsign != null) {
|
||||
w.eq(MemberInfo::getCanConsign, canConsign);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user