Commit 3d30f125 by kk

修复策划月度统计数据

parent d7863363
File added
......@@ -16,4 +16,14 @@ public class SkuPeopleNameDto {
@Excel(name = "上传人")
private String peopleName;
@Excel(name = "编号")
private String number;
@Excel(name = "正销量增长")
private Integer positiveSalesGrowth;
@Excel(name = "月份")
private String month;
}
......@@ -54,7 +54,7 @@
AND vp.video_is_upload_backstage = 1
AND vvp.long_video_url > ''
AND vp2.editor_status = 2
AND vvp.upload_long_video_time BETWEEN 1735660800 AND 1770800400
AND vvp.upload_long_video_time BETWEEN 1735660800 AND 1770886799
group by vp.id
</select>
......
package cn.kk.spring_simple_operation;
import cn.kk.spring_simple_operation.mapper.PhotoProgressMapper;
import cn.kk.spring_simple_operation.mapper.SyncProductPublishMapper;
import cn.kk.spring_simple_operation.mapper.VideoProductMapper;
import cn.kk.spring_simple_operation.entity.VisualDesigner;
import cn.kk.spring_simple_operation.entity.VisualPlanExecutorTaskRecord;
import cn.kk.spring_simple_operation.mapper.*;
import cn.kk.spring_simple_operation.model.dto.SkuPeopleNameDto;
import cn.kk.spring_simple_operation.model.vo.BrandRecordStatisticsVo;
import cn.kk.spring_simple_operation.model.vo.PhotoProcessExportVo;
import cn.kk.spring_simple_operation.model.vo.VideoProductExportVo;
import cn.kk.spring_simple_operation.utils.CommonUtils;
import cn.kk.spring_simple_operation.utils.DateUtils;
import cn.kk.spring_simple_operation.utils.ExcelUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author kk
......@@ -25,6 +35,7 @@ import java.util.List;
@SpringBootTest
public class MyTest {
private static final Logger log = LoggerFactory.getLogger(MyTest.class);
@Resource
private SyncProductPublishMapper syncProductPublishMapper;
......@@ -34,6 +45,12 @@ public class MyTest {
@Resource
private VideoProductMapper videoProductMapper;
@Resource
private VisualPlanExecutorTaskRecordMapper visualPlanExecutorTaskRecordMapper;
@Resource
private VisualDesignerMapper visualDesignerMapper;
@Test
void exportVideoProductList() {
......@@ -84,4 +101,143 @@ public class MyTest {
util.exportExcelFile(exports, "运营导数据.xlsx");
}
@Test
public void updatePlanMonthData() throws Exception {
Set<Integer> userSet = new HashSet<>();
userSet.add(5384);
userSet.add(5779);
userSet.add(8317);
Map<String, Integer> userNumberMap = visualDesignerMapper.selectList(Wrappers.<VisualDesigner>lambdaQuery()
.in(VisualDesigner::getDepartmentKey, "a_plus_plan", "video_plan")
.select(VisualDesigner::getVisualNumber, VisualDesigner::getUserId)
).stream().collect(Collectors.toMap(VisualDesigner::getVisualNumber, VisualDesigner::getUserId, (a, b) -> b));
File file = new File("A+.xlsx");
ExcelUtil<SkuPeopleNameDto> util = new ExcelUtil<>(SkuPeopleNameDto.class);
List<SkuPeopleNameDto> list = util.importExcel(Files.newInputStream(file.toPath()));
list.stream().collect(Collectors.groupingBy(SkuPeopleNameDto::getMonth))
.forEach((monthCh, voList) -> {
int month = Integer.parseInt(monthCh.replace("月", ""));
List<VisualPlanExecutorTaskRecord> visualPlanExecutorTaskRecords = visualPlanExecutorTaskRecordMapper.selectList(Wrappers.<VisualPlanExecutorTaskRecord>lambdaQuery()
.eq(VisualPlanExecutorTaskRecord::getYearInt, 2026)
.eq(VisualPlanExecutorTaskRecord::getMonthInt, month)
);
if (CollectionUtils.isEmpty(visualPlanExecutorTaskRecords)) return;
Map<Integer, VisualPlanExecutorTaskRecord> userMap = visualPlanExecutorTaskRecords.stream().collect(Collectors.toMap(VisualPlanExecutorTaskRecord::getUserId, Function.identity()));
for (SkuPeopleNameDto dto : voList) {
Integer userId = userNumberMap.get(dto.getNumber());
if (CommonUtils.isNullOrZero(userId)) {
log.error("未找到用户:{}", dto.getNumber());
continue;
}
VisualPlanExecutorTaskRecord record = userMap.get(userId);
if (record != null) {
record.setSalesGrowth(dto.getPositiveSalesGrowth());
Calendar calendar = Calendar.getInstance();
calendar.set(2026, month, 1);
Date time = calendar.getTime();
int appraisingNum = visualPlanExecutorTaskRecordMapper.getAPlusAppraisingCountByUser(DateUtils.formatDate(time, "yyyy-MM"), dto.getNumber());
record.setAppraisingNum(appraisingNum);
}
}
List<VisualPlanExecutorTaskRecord> sortList = visualPlanExecutorTaskRecords.stream().filter(t -> !userSet.contains(t.getUserId()))
.sorted(Comparator.comparingInt(VisualPlanExecutorTaskRecord::getSalesGrowth).reversed()).collect(Collectors.toList());
// 设置排名,相同值排名相同,下一位跳过当前排名
int rank = 1;
int lastSales = 0;
for (int i = 0; i < sortList.size(); i++) {
VisualPlanExecutorTaskRecord current = sortList.get(i);
if (i > 0) {
// 如果当前值与前一个值不同,则更新排名为当前位置+1
if (current.getSalesGrowth() != lastSales) {
rank = i + 1; // 实现相同值排名相同且下一位跳过排名
}
}
lastSales = current.getSalesGrowth();
current.setSalesGrowthRank(rank);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter("a_plus_plan_month_data_" + month + ".sql"))) {
for (VisualPlanExecutorTaskRecord record : visualPlanExecutorTaskRecords) {
writer.write(String.format("update visual_plan_executor_task_record set appraising_num = %d, sales_growth_rank = %d, sales_growth = %d where id = %d;\n",
record.getAppraisingNum(), record.getSalesGrowthRank(), record.getSalesGrowth(), record.getId()));
}
} catch (IOException e) {
e.printStackTrace();
}
});
file = new File("视频.xlsx");
util = new ExcelUtil<>(SkuPeopleNameDto.class);
list = util.importExcel(Files.newInputStream(file.toPath()));
list.stream().collect(Collectors.groupingBy(SkuPeopleNameDto::getMonth))
.forEach((monthCh, voList) -> {
int month = Integer.parseInt(monthCh.replace("月", ""));
List<VisualPlanExecutorTaskRecord> visualPlanExecutorTaskRecords = visualPlanExecutorTaskRecordMapper.selectList(Wrappers.<VisualPlanExecutorTaskRecord>lambdaQuery()
.eq(VisualPlanExecutorTaskRecord::getYearInt, 2026)
.eq(VisualPlanExecutorTaskRecord::getMonthInt, month)
);
if (CollectionUtils.isEmpty(visualPlanExecutorTaskRecords)) return;
Map<Integer, VisualPlanExecutorTaskRecord> userMap = visualPlanExecutorTaskRecords.stream().collect(Collectors.toMap(VisualPlanExecutorTaskRecord::getUserId, Function.identity()));
for (SkuPeopleNameDto dto : voList) {
Integer userId = userNumberMap.get(dto.getNumber());
if (CommonUtils.isNullOrZero(userId)) {
log.error("未找到用户:{}", dto.getNumber());
continue;
}
VisualPlanExecutorTaskRecord record = userMap.get(userId);
if (record != null) {
record.setSalesGrowth(dto.getPositiveSalesGrowth());
Calendar calendar = Calendar.getInstance();
calendar.set(2026, month - 1, 1);
Date time = calendar.getTime();
Integer timeSecond = DateUtils.date2TimeSecond(time);
int appraisingNum = visualPlanExecutorTaskRecordMapper.getVideoAppraisingCountByUser(DateUtils.getStartMonthOffset(timeSecond, 0), DateUtils.getEndMonthOffset(timeSecond, 0), dto.getNumber());
record.setAppraisingNum(appraisingNum);
}
}
List<VisualPlanExecutorTaskRecord> sortList = visualPlanExecutorTaskRecords.stream().filter(t -> !userSet.contains(t.getUserId())).collect(Collectors.toList());
// 设置排名,相同值排名相同,下一位跳过当前排名
int rank = 1;
int lastSales = 0;
for (int i = 0; i < sortList.size(); i++) {
VisualPlanExecutorTaskRecord current = sortList.get(i);
if (i > 0) {
// 如果当前值与前一个值不同,则更新排名为当前位置+1
if (current.getSalesGrowth() != lastSales) {
rank = i + 1; // 实现相同值排名相同且下一位跳过排名
}
}
lastSales = current.getSalesGrowth();
current.setSalesGrowthRank(rank);
}
try (BufferedWriter writer = new BufferedWriter(new FileWriter("video_plan_month_data_" + month + ".sql"))) {
for (VisualPlanExecutorTaskRecord record : visualPlanExecutorTaskRecords) {
writer.write(String.format("update visual_plan_executor_task_record set appraising_num = %d, sales_growth_rank = %d, sales_growth = %d where id = %d;\n",
record.getAppraisingNum(), record.getSalesGrowthRank(), record.getSalesGrowth(), record.getId()));
}
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment