增加部门树形+接口
This commit is contained in:
@@ -67,9 +67,10 @@ public class LbDepartmentUserController {
|
|||||||
@RequestParam(required = false) String parentId,
|
@RequestParam(required = false) String parentId,
|
||||||
@RequestParam(required = false) String name,
|
@RequestParam(required = false) String name,
|
||||||
@RequestParam(required = false) String phone,
|
@RequestParam(required = false) String phone,
|
||||||
@RequestParam(required = false) String industry) {
|
@RequestParam(required = false) String industry,
|
||||||
|
@Parameter(description = "是否有效:0否 1是") @RequestParam(required = false) Integer isActive) {
|
||||||
Map<String, Object> result = lbDepartmentUserService.pageQuery(
|
Map<String, Object> result = lbDepartmentUserService.pageQuery(
|
||||||
current, size, tenantId, userId, parentId, name, phone, industry
|
current, size, tenantId, userId, parentId, name, phone, industry, isActive
|
||||||
);
|
);
|
||||||
Boolean success = (Boolean) result.get("success");
|
Boolean success = (Boolean) result.get("success");
|
||||||
if (success != null && success) {
|
if (success != null && success) {
|
||||||
@@ -124,8 +125,12 @@ public class LbDepartmentUserController {
|
|||||||
@GetMapping("/tree")
|
@GetMapping("/tree")
|
||||||
@Operation(summary = "部门用户树形结构")
|
@Operation(summary = "部门用户树形结构")
|
||||||
public ResponseEntity<Map<String, Object>> tree(
|
public ResponseEntity<Map<String, Object>> tree(
|
||||||
@Parameter(description = "租户id", required = true) @RequestParam String tenantId) {
|
@Parameter(description = "租户id", required = true) @RequestParam String tenantId,
|
||||||
Map<String, Object> result = lbDepartmentUserService.getDepartmentUserTree(tenantId);
|
@Parameter(description = "是否活跃:1活跃 0不活跃") @RequestParam(name = "is_active", required = false) Integer isActive,
|
||||||
|
@Parameter(description = "加入日期,查询 join_date 大于该日期的数据")
|
||||||
|
@RequestParam(name = "join_date", required = false)
|
||||||
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate joinDate) {
|
||||||
|
Map<String, Object> result = lbDepartmentUserService.getDepartmentUserTree(tenantId, isActive, joinDate);
|
||||||
Boolean success = (Boolean) result.get("success");
|
Boolean success = (Boolean) result.get("success");
|
||||||
if (success != null && success) {
|
if (success != null && success) {
|
||||||
return ResponseEntity.ok(result);
|
return ResponseEntity.ok(result);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@@ -59,10 +60,22 @@ public class LbDepartmentUser implements Serializable {
|
|||||||
@Schema(description = "上级链条(从直接上级到根上级,节点内 id,name,phone 逗号分隔,节点间 -> 连接)")
|
@Schema(description = "上级链条(从直接上级到根上级,节点内 id,name,phone 逗号分隔,节点间 -> 连接)")
|
||||||
private String orgChain;
|
private String orgChain;
|
||||||
|
|
||||||
|
@TableField("is_active")
|
||||||
|
@Schema(description = "是否有效:0否 1是")
|
||||||
|
private Integer isActive;
|
||||||
|
|
||||||
@TableField("join_date")
|
@TableField("join_date")
|
||||||
@Schema(description = "加入日期(不含时分秒)")
|
@Schema(description = "加入日期(不含时分秒)")
|
||||||
private LocalDate joinDate;
|
private LocalDate joinDate;
|
||||||
|
|
||||||
|
@TableField("last_trade_date")
|
||||||
|
@Schema(description = "最近交易日期(不含时分秒)")
|
||||||
|
private LocalDate lastTradeDate;
|
||||||
|
|
||||||
|
@TableField("last_buy_amt")
|
||||||
|
@Schema(description = "最近交易日买入金额")
|
||||||
|
private BigDecimal lastBuyAmt;
|
||||||
|
|
||||||
@TableField("create_time")
|
@TableField("create_time")
|
||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ public interface ILbDepartmentUserService extends IService<LbDepartmentUser> {
|
|||||||
String parentId,
|
String parentId,
|
||||||
String name,
|
String name,
|
||||||
String phone,
|
String phone,
|
||||||
String industry);
|
String industry,
|
||||||
|
Integer isActive);
|
||||||
|
|
||||||
Map<String, Object> bindParentUser(String parentUserId,
|
Map<String, Object> bindParentUser(String parentUserId,
|
||||||
String parentUserName,
|
String parentUserName,
|
||||||
@@ -39,5 +40,5 @@ public interface ILbDepartmentUserService extends IService<LbDepartmentUser> {
|
|||||||
/**
|
/**
|
||||||
* 按租户查询部门用户并构建父子树(parent_id 对应 lb_user.pid)。
|
* 按租户查询部门用户并构建父子树(parent_id 对应 lb_user.pid)。
|
||||||
*/
|
*/
|
||||||
Map<String, Object> getDepartmentUserTree(String tenantId);
|
Map<String, Object> getDepartmentUserTree(String tenantId, Integer isActive, LocalDate joinDate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -67,6 +68,9 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
entity.setCreateTime(now);
|
entity.setCreateTime(now);
|
||||||
entity.setUpdateTime(now);
|
entity.setUpdateTime(now);
|
||||||
|
if (entity.getIsActive() == null) {
|
||||||
|
entity.setIsActive(1);
|
||||||
|
}
|
||||||
|
|
||||||
boolean ok = this.save(entity);
|
boolean ok = this.save(entity);
|
||||||
result.put("success", ok);
|
result.put("success", ok);
|
||||||
@@ -129,7 +133,8 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
String parentId,
|
String parentId,
|
||||||
String name,
|
String name,
|
||||||
String phone,
|
String phone,
|
||||||
String industry) {
|
String industry,
|
||||||
|
Integer isActive) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
if (current == null || current < 1) {
|
if (current == null || current < 1) {
|
||||||
@@ -158,6 +163,9 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
if (industry != null && !industry.trim().isEmpty()) {
|
if (industry != null && !industry.trim().isEmpty()) {
|
||||||
queryWrapper.like(LbDepartmentUser::getIndustry, industry.trim());
|
queryWrapper.like(LbDepartmentUser::getIndustry, industry.trim());
|
||||||
}
|
}
|
||||||
|
if (isActive != null) {
|
||||||
|
queryWrapper.eq(LbDepartmentUser::getIsActive, isActive);
|
||||||
|
}
|
||||||
queryWrapper.orderByDesc(LbDepartmentUser::getUpdateTime)
|
queryWrapper.orderByDesc(LbDepartmentUser::getUpdateTime)
|
||||||
.orderByDesc(LbDepartmentUser::getCreateTime);
|
.orderByDesc(LbDepartmentUser::getCreateTime);
|
||||||
|
|
||||||
@@ -303,8 +311,10 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
candidateNicknameSet.add(nickname);
|
candidateNicknameSet.add(nickname);
|
||||||
// tradeList 已按更新时间倒序,首次写入即最新数据
|
LbDailyUserTrade prev = latestTradeByNickname.get(nickname);
|
||||||
latestTradeByNickname.putIfAbsent(nickname, trade);
|
if (prev == null || isTradeReportDateNewer(trade, prev)) {
|
||||||
|
latestTradeByNickname.put(nickname, trade);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, LbPurchaseApply> phoneMap = buildPurchaseApplyPhoneMap(candidateNicknameSet);
|
Map<String, LbPurchaseApply> phoneMap = buildPurchaseApplyPhoneMap(candidateNicknameSet);
|
||||||
@@ -317,6 +327,7 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
entity = new LbDepartmentUser();
|
entity = new LbDepartmentUser();
|
||||||
entity.setId(UUID.randomUUID().toString());
|
entity.setId(UUID.randomUUID().toString());
|
||||||
entity.setCreateTime(now);
|
entity.setCreateTime(now);
|
||||||
|
entity.setIsActive(1);
|
||||||
isInsert = true;
|
isInsert = true;
|
||||||
}
|
}
|
||||||
entity.setTenantId(trade.getTenantId());
|
entity.setTenantId(trade.getTenantId());
|
||||||
@@ -331,6 +342,7 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
entity.setPhone(phone.isEmpty() ? null : phone);
|
entity.setPhone(phone.isEmpty() ? null : phone);
|
||||||
entity.setJoinDate(purchaseApply.getApplyDate());
|
entity.setJoinDate(purchaseApply.getApplyDate());
|
||||||
}
|
}
|
||||||
|
applyLatestTradeFields(entity, trade);
|
||||||
entity.setUpdateTime(now);
|
entity.setUpdateTime(now);
|
||||||
if (isInsert) {
|
if (isInsert) {
|
||||||
toInsert.add(entity);
|
toInsert.add(entity);
|
||||||
@@ -445,6 +457,33 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<String> tradeActiveUserIds = new HashSet<>();
|
||||||
|
Map<String, LbDailyUserTrade> latestTradeByUserId = new HashMap<>();
|
||||||
|
List<LbDailyUserTrade> tradeUserRows = lbDailyUserTradeMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<LbDailyUserTrade>()
|
||||||
|
.eq(LbDailyUserTrade::getTenantId, tenantIdTrim)
|
||||||
|
.isNotNull(LbDailyUserTrade::getUserId)
|
||||||
|
.select(LbDailyUserTrade::getUserId,
|
||||||
|
LbDailyUserTrade::getReportDate,
|
||||||
|
LbDailyUserTrade::getDailyBuyAmt));
|
||||||
|
if (tradeUserRows != null) {
|
||||||
|
for (LbDailyUserTrade row : tradeUserRows) {
|
||||||
|
String tradeUserId = trimToNull(row.getUserId());
|
||||||
|
if (tradeUserId == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tradeActiveUserIds.add(tradeUserId);
|
||||||
|
if (row.getReportDate() != null
|
||||||
|
&& row.getDailyBuyAmt() != null
|
||||||
|
&& row.getDailyBuyAmt().compareTo(BigDecimal.ONE) >= 0) {
|
||||||
|
LbDailyUserTrade prev = latestTradeByUserId.get(tradeUserId);
|
||||||
|
if (prev == null || isTradeReportDateNewer(row, prev)) {
|
||||||
|
latestTradeByUserId.put(tradeUserId, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<LbDepartmentUser> toInsert = new ArrayList<>();
|
List<LbDepartmentUser> toInsert = new ArrayList<>();
|
||||||
List<LbDepartmentUser> toUpdate = new ArrayList<>();
|
List<LbDepartmentUser> toUpdate = new ArrayList<>();
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
@@ -485,7 +524,16 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
entity.setOrgChain(buildOrgChain(lbUser.getId(), userById));
|
entity.setOrgChain(buildOrgChain(lbUser.getId(), userById));
|
||||||
|
LbDailyUserTrade latestTrade = latestTradeByUserId.get(userId);
|
||||||
|
if (latestTrade != null) {
|
||||||
|
entity.setLastTradeDate(latestTrade.getReportDate());
|
||||||
|
entity.setLastBuyAmt(latestTrade.getDailyBuyAmt());
|
||||||
|
} else {
|
||||||
|
entity.setLastTradeDate(null);
|
||||||
|
entity.setLastBuyAmt(null);
|
||||||
|
}
|
||||||
entity.setUpdateTime(now);
|
entity.setUpdateTime(now);
|
||||||
|
entity.setIsActive(tradeActiveUserIds.contains(userId) ? 1 : 0);
|
||||||
|
|
||||||
if (isInsert) {
|
if (isInsert) {
|
||||||
toInsert.add(entity);
|
toInsert.add(entity);
|
||||||
@@ -493,7 +541,6 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
toUpdate.add(entity);
|
toUpdate.add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toInsert.isEmpty()) {
|
if (!toInsert.isEmpty()) {
|
||||||
this.saveBatch(toInsert);
|
this.saveBatch(toInsert);
|
||||||
}
|
}
|
||||||
@@ -586,7 +633,7 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getDepartmentUserTree(String tenantId) {
|
public Map<String, Object> getDepartmentUserTree(String tenantId, Integer isActive, LocalDate joinDate) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||||
@@ -596,9 +643,15 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
}
|
}
|
||||||
String tenantIdTrim = tenantId.trim();
|
String tenantIdTrim = tenantId.trim();
|
||||||
|
|
||||||
List<LbDepartmentUser> deptUsers = this.list(
|
LambdaQueryWrapper<LbDepartmentUser> queryWrapper = new LambdaQueryWrapper<LbDepartmentUser>()
|
||||||
new LambdaQueryWrapper<LbDepartmentUser>()
|
.eq(LbDepartmentUser::getTenantId, tenantIdTrim);
|
||||||
.eq(LbDepartmentUser::getTenantId, tenantIdTrim));
|
if (isActive != null) {
|
||||||
|
queryWrapper.eq(LbDepartmentUser::getIsActive, isActive);
|
||||||
|
}
|
||||||
|
if (joinDate != null) {
|
||||||
|
queryWrapper.gt(LbDepartmentUser::getJoinDate, joinDate);
|
||||||
|
}
|
||||||
|
List<LbDepartmentUser> deptUsers = this.list(queryWrapper);
|
||||||
if (deptUsers == null || deptUsers.isEmpty()) {
|
if (deptUsers == null || deptUsers.isEmpty()) {
|
||||||
result.put("success", true);
|
result.put("success", true);
|
||||||
result.put("message", "查询成功");
|
result.put("message", "查询成功");
|
||||||
@@ -695,6 +748,9 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
node.put("name", trimToNull(row.getName()));
|
node.put("name", trimToNull(row.getName()));
|
||||||
node.put("phone", trimToNull(row.getPhone()));
|
node.put("phone", trimToNull(row.getPhone()));
|
||||||
node.put("joinDate", row.getJoinDate());
|
node.put("joinDate", row.getJoinDate());
|
||||||
|
node.put("lastTradeDate", row.getLastTradeDate());
|
||||||
|
node.put("lastBuyAmt", row.getLastBuyAmt());
|
||||||
|
node.put("isActive", row.getIsActive());
|
||||||
node.put("children", new ArrayList<Map<String, Object>>());
|
node.put("children", new ArrayList<Map<String, Object>>());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -733,4 +789,32 @@ public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMap
|
|||||||
String trimmed = value.trim();
|
String trimmed = value.trim();
|
||||||
return trimmed.isEmpty() ? null : trimmed;
|
return trimmed.isEmpty() ? null : trimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isTradeReportDateNewer(LbDailyUserTrade trade, LbDailyUserTrade prev) {
|
||||||
|
LocalDate reportDate = trade.getReportDate();
|
||||||
|
LocalDate prevReportDate = prev.getReportDate();
|
||||||
|
if (reportDate == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (prevReportDate == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return reportDate.isAfter(prevReportDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按最近交易日写入 last_trade_date、last_buy_amt;若新交易日更晚则覆盖,否则保留原值。
|
||||||
|
*/
|
||||||
|
private static void applyLatestTradeFields(LbDepartmentUser entity, LbDailyUserTrade trade) {
|
||||||
|
LocalDate reportDate = trade.getReportDate();
|
||||||
|
LocalDate existingDate = entity.getLastTradeDate();
|
||||||
|
if (existingDate == null || (reportDate != null && reportDate.isAfter(existingDate))) {
|
||||||
|
entity.setLastTradeDate(reportDate);
|
||||||
|
entity.setLastBuyAmt(trade.getDailyBuyAmt());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (reportDate != null && reportDate.equals(existingDate)) {
|
||||||
|
entity.setLastBuyAmt(trade.getDailyBuyAmt());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/main/sql/lb_department_user_alter_add_is_active.sql
Normal file
2
src/main/sql/lb_department_user_alter_add_is_active.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `lb_department_user`
|
||||||
|
ADD COLUMN `is_active` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否有效:0否 1是' AFTER `org_chain`;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `lb_department_user`
|
||||||
|
ADD COLUMN `last_buy_amt` DECIMAL(18, 2) NULL COMMENT '最近交易日买入金额' AFTER `last_trade_date`;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `lb_department_user`
|
||||||
|
ADD COLUMN `last_trade_date` DATE NULL COMMENT '最近交易日期(不含时分秒)' AFTER `join_date`;
|
||||||
Reference in New Issue
Block a user