feat: show collaboration record creators
This commit is contained in:
+3
-2
@@ -70,8 +70,9 @@ public class CollaborationRecordController extends BaseController {
|
||||
@Operation(summary = "合作记录月度统计")
|
||||
@PreAuthorize("@permission.has('collaboration:record:statistics')")
|
||||
@GetMapping("/monthly-statistics")
|
||||
public ResponseDTO<List<CollaborationMonthlyStatisticsDTO>> monthlyStatistics(@RequestParam Integer year) {
|
||||
return ResponseDTO.ok(recordApplicationService.getMonthlyStatistics(year));
|
||||
public ResponseDTO<List<CollaborationMonthlyStatisticsDTO>> monthlyStatistics(
|
||||
@RequestParam Integer year, @RequestParam(required = false) Long creatorId) {
|
||||
return ResponseDTO.ok(recordApplicationService.getMonthlyStatistics(year, creatorId));
|
||||
}
|
||||
|
||||
@Operation(summary = "新增合作记录")
|
||||
|
||||
+57
-18
@@ -34,7 +34,9 @@ import com.agileboot.domain.collaboration.record.enumtype.SettlementStatusEnum;
|
||||
import com.agileboot.domain.collaboration.record.model.CollaborationRecordModel;
|
||||
import com.agileboot.domain.collaboration.record.model.CollaborationRecordModelFactory;
|
||||
import com.agileboot.domain.collaboration.record.query.CollaborationRecordQuery;
|
||||
import com.agileboot.domain.common.cache.CacheCenter;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
import com.agileboot.infrastructure.user.AuthenticationUtils;
|
||||
import com.agileboot.infrastructure.user.web.SystemLoginUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -130,17 +132,21 @@ public class CollaborationRecordApplicationService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<CollaborationMonthlyStatisticsDTO> getMonthlyStatistics(Integer year) {
|
||||
public List<CollaborationMonthlyStatisticsDTO> getMonthlyStatistics(Integer year, Long creatorId) {
|
||||
List<CollaborationMonthlyStatisticsDTO> statistics = new ArrayList<>();
|
||||
for (int month = 1; month <= 12; month++) {
|
||||
statistics.add(buildMonthlyStatistics(year, month));
|
||||
statistics.add(buildMonthlyStatistics(year, month, creatorId));
|
||||
}
|
||||
return statistics;
|
||||
}
|
||||
|
||||
public List<CollaborationMonthlyStatisticsDTO> getMonthlyStatistics(Integer year) {
|
||||
return getMonthlyStatistics(year, null);
|
||||
}
|
||||
|
||||
private QueryWrapper<CollaborationRecordEntity> getScopedRecordWrapper(CollaborationRecordQuery query) {
|
||||
applyQueryCreatorScope(query);
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = query.toQueryWrapper();
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -235,6 +241,13 @@ public class CollaborationRecordApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
private void applyQueryCreatorScope(CollaborationRecordQuery query) {
|
||||
Long creatorId = getCurrentCreatorScope();
|
||||
if (creatorId != null) {
|
||||
query.setCreatorId(creatorId);
|
||||
}
|
||||
}
|
||||
|
||||
private Long getCurrentCreatorScope() {
|
||||
SystemLoginUser loginUser = AuthenticationUtils.getSystemLoginUser();
|
||||
return loginUser.isAdmin() ? null : loginUser.getUserId();
|
||||
@@ -242,10 +255,22 @@ public class CollaborationRecordApplicationService {
|
||||
|
||||
private CollaborationRecordDTO buildRecordDTO(CollaborationRecordEntity entity) {
|
||||
CollaborationRecordDTO dto = new CollaborationRecordDTO(entity);
|
||||
dto.setCreatorName(getCreatorName(entity.getCreatorId()));
|
||||
fillRecordStats(dto, entity.getRecordId());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private String getCreatorName(Long creatorId) {
|
||||
if (creatorId == null) {
|
||||
return "";
|
||||
}
|
||||
SysUserEntity user = CacheCenter.userCache.getObjectById(creatorId);
|
||||
if (user == null) {
|
||||
return "";
|
||||
}
|
||||
return StrUtil.blankToDefault(user.getNickname(), user.getUsername());
|
||||
}
|
||||
|
||||
private void fillDetailChildren(CollaborationRecordDetailDTO dto, Long recordId) {
|
||||
dto.setTasks(taskService.listByRecordId(recordId).stream()
|
||||
.map(CollaborationTaskDTO::new)
|
||||
@@ -454,21 +479,21 @@ public class CollaborationRecordApplicationService {
|
||||
return entity;
|
||||
}
|
||||
|
||||
private CollaborationMonthlyStatisticsDTO buildMonthlyStatistics(Integer year, Integer month) {
|
||||
private CollaborationMonthlyStatisticsDTO buildMonthlyStatistics(Integer year, Integer month, Long creatorId) {
|
||||
Date[] range = getMonthRange(year, month);
|
||||
BigDecimal purchasePrice = sumPurchasePrice(range);
|
||||
BigDecimal expenditureAmount = sumExpenditure(range);
|
||||
BigDecimal settledRemuneration = sumSettlement(range, REMUNERATION_FEE);
|
||||
BigDecimal settledTotal = sumSettlement(range, null);
|
||||
BigDecimal purchasePrice = sumPurchasePrice(range, creatorId);
|
||||
BigDecimal expenditureAmount = sumExpenditure(range, creatorId);
|
||||
BigDecimal settledRemuneration = sumSettlement(range, REMUNERATION_FEE, creatorId);
|
||||
BigDecimal settledTotal = sumSettlement(range, null, creatorId);
|
||||
return new CollaborationMonthlyStatisticsDTO(month, purchasePrice, expenditureAmount,
|
||||
settledRemuneration, settledTotal);
|
||||
}
|
||||
|
||||
private BigDecimal sumPurchasePrice(Date[] range) {
|
||||
private BigDecimal sumPurchasePrice(Date[] range, Long creatorId) {
|
||||
QueryWrapper<CollaborationRecordEntity> wrapper = new QueryWrapper<CollaborationRecordEntity>()
|
||||
.ge("purchase_date", range[0])
|
||||
.le("purchase_date", range[1]);
|
||||
applyCurrentCreatorScope(wrapper);
|
||||
applyCreatorScope(wrapper, creatorId);
|
||||
List<CollaborationRecordEntity> records = recordService.list(wrapper);
|
||||
return records.stream()
|
||||
.map(CollaborationRecordEntity::getPurchasePrice)
|
||||
@@ -476,11 +501,11 @@ public class CollaborationRecordApplicationService {
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
private BigDecimal sumExpenditure(Date[] range) {
|
||||
private BigDecimal sumExpenditure(Date[] range, Long creatorId) {
|
||||
QueryWrapper<CollaborationExpenditureEntity> wrapper = new QueryWrapper<CollaborationExpenditureEntity>()
|
||||
.ge("spend_date", range[0])
|
||||
.le("spend_date", range[1]);
|
||||
applyChildRecordScope(wrapper);
|
||||
applyChildRecordScope(wrapper, creatorId);
|
||||
List<CollaborationExpenditureEntity> expenditures = expenditureService.list(wrapper);
|
||||
return expenditures.stream()
|
||||
.map(CollaborationExpenditureEntity::getAmount)
|
||||
@@ -488,20 +513,34 @@ public class CollaborationRecordApplicationService {
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
private BigDecimal sumSettlement(Date[] range, String purpose) {
|
||||
private BigDecimal sumSettlement(Date[] range, String purpose, Long creatorId) {
|
||||
QueryWrapper<CollaborationSettlementEntity> wrapper = new QueryWrapper<CollaborationSettlementEntity>()
|
||||
.ge("settle_date", range[0])
|
||||
.le("settle_date", range[1])
|
||||
.eq(purpose != null, "purpose", purpose);
|
||||
applyChildRecordScope(wrapper);
|
||||
applyChildRecordScope(wrapper, creatorId);
|
||||
return sumSettlement(settlementService.list(wrapper));
|
||||
}
|
||||
|
||||
private void applyChildRecordScope(QueryWrapper<?> wrapper) {
|
||||
Long creatorId = getCurrentCreatorScope();
|
||||
if (creatorId != null) {
|
||||
wrapper.inSql("record_id", buildCreatorRecordSubQuery(creatorId));
|
||||
private void applyChildRecordScope(QueryWrapper<?> wrapper, Long requestedCreatorId) {
|
||||
Long creatorId = getEffectiveCreatorScope(requestedCreatorId);
|
||||
if (creatorId == null) {
|
||||
return;
|
||||
}
|
||||
wrapper.inSql("record_id", buildCreatorRecordSubQuery(creatorId));
|
||||
}
|
||||
|
||||
private void applyCreatorScope(QueryWrapper<CollaborationRecordEntity> wrapper, Long requestedCreatorId) {
|
||||
Long creatorId = getEffectiveCreatorScope(requestedCreatorId);
|
||||
if (creatorId == null) {
|
||||
return;
|
||||
}
|
||||
wrapper.eq("creator_id", creatorId);
|
||||
}
|
||||
|
||||
private Long getEffectiveCreatorScope(Long requestedCreatorId) {
|
||||
Long currentCreatorScope = getCurrentCreatorScope();
|
||||
return currentCreatorScope == null ? requestedCreatorId : currentCreatorScope;
|
||||
}
|
||||
|
||||
private String buildCreatorRecordSubQuery(Long creatorId) {
|
||||
|
||||
+4
@@ -56,6 +56,10 @@ public class CollaborationRecordDTO {
|
||||
|
||||
private String remark;
|
||||
|
||||
private Long creatorId;
|
||||
|
||||
private String creatorName;
|
||||
|
||||
private Integer tasksNum;
|
||||
|
||||
private Integer completedTasksNum;
|
||||
|
||||
+3
@@ -27,6 +27,8 @@ public class CollaborationRecordQuery extends AbstractPageQuery<CollaborationRec
|
||||
|
||||
private String taskStatus;
|
||||
|
||||
private Long creatorId;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
private Date purchaseBeginTime;
|
||||
|
||||
@@ -39,6 +41,7 @@ public class CollaborationRecordQuery extends AbstractPageQuery<CollaborationRec
|
||||
.like(StrUtil.isNotEmpty(brand), "brand", brand)
|
||||
.like(StrUtil.isNotEmpty(goods), "goods", goods)
|
||||
.eq(StrUtil.isNotEmpty(cooperationPlatform), "cooperation_platform", cooperationPlatform)
|
||||
.eq(creatorId != null, "creator_id", creatorId)
|
||||
.ge(purchaseBeginTime != null, "purchase_date", DatePickUtil.getBeginOfTheDay(purchaseBeginTime))
|
||||
.le(purchaseEndTime != null, "purchase_date", DatePickUtil.getEndOfTheDay(purchaseEndTime));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user