Commit da13073c by kk

导数据

parent a6e13935
......@@ -92,6 +92,13 @@
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-core</artifactId>
<version>4.0.3</version>
</dependency>
</dependencies>
<build>
......
......@@ -54,7 +54,7 @@ public class CodeGenerator {
.strategyConfig(builder -> {
builder
// 设置需要生成的表名
.addInclude("photo_progress", "photo_progress_person", "video_product", "visual_video_plan", "sync_product_publish", "sync_solar_term_info")
.addInclude("sync_product_audit")
//entity策略配置
.entityBuilder()
......
package cn.kk.spring_simple_operation.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 对应inv 产品审核表 前端控制器
* </p>
*
* @author guokunkun
* @since 2025-01-02
*/
@RestController
@RequestMapping("/spring_simple_operation/sync-product-audit")
public class SyncProductAuditController {
}
package cn.kk.spring_simple_operation.controller;
import cn.kk.spring_simple_operation.entity.SyncProductPublish;
import cn.kk.spring_simple_operation.mapper.SyncProductPublishMapper;
import cn.kk.spring_simple_operation.mapper.VideoProductMapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* sku销量详情 前端控制器
* </p>
*
* @author guokunkun
* @since 2024-12-25
*/
@RestController
@RequestMapping("/productPublish")
public class SyncProductPublishController {
private static final BigDecimal TWENTY = new BigDecimal("20");
private static final BigDecimal FORTY = new BigDecimal("40");
@Resource
private SyncProductPublishMapper syncProductPublishMapper;
@Resource
private VideoProductMapper videoProductMapper;
@RequestMapping("/syncProductPublish")
public String syncProductPublish() {
Map<String, Integer> salesMap = new HashMap<>();
salesMap.put("<20", 0);
salesMap.put("20~40", 0);
salesMap.put(">40", 0);
Set<String> haveSkuSet = new HashSet<>();
// 母体sku
List<SyncProductPublish> syncProductPublishes = syncProductPublishMapper.selectMotherSku();
syncProductPublishes.forEach(item -> {
List<SyncProductPublish> subList = syncProductPublishMapper.selectList(Wrappers.<SyncProductPublish>lambdaQuery().eq(SyncProductPublish::getParentAsin, item.getRelationKey()).select(SyncProductPublish::getSku, SyncProductPublish::getThirtyDaySales));
subList.add(item);
String s = checkPriceAndSales(subList, item.getLowestPrice());
if (StringUtils.isBlank(s)) {
return;
}
salesMap.put(s, salesMap.get(s) + 1);
haveSkuSet.addAll(subList.stream().map(SyncProductPublish::getSku).collect(Collectors.toList()));
});
System.out.println(JSONObject.toJSONString(salesMap));
return JSONObject.toJSONString(salesMap);
}
private String checkPriceAndSales(List<SyncProductPublish> subList, BigDecimal lowestPrice) {
if (CollectionUtils.isEmpty(subList) || lowestPrice.compareTo(BigDecimal.ZERO) < 0) {
return null;
}
int sum = subList.stream().map(SyncProductPublish::getThirtyDaySales).reduce(Integer::sum).get();
if (lowestPrice.compareTo(TWENTY) <= 0 && sum >= 100) {
return "<20";
}
else if (lowestPrice.compareTo(TWENTY) > 0 && lowestPrice.compareTo(FORTY) <= 0 && sum >= 80) {
return "20~40";
}
else if (lowestPrice.compareTo(FORTY) > 0 && sum >= 50) {
return ">40";
}
return null;
}
}
package cn.kk.spring_simple_operation.mapper;
import cn.kk.spring_simple_operation.entity.SyncProductAudit;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* <p>
* 对应inv 产品审核表 Mapper 接口
* </p>
*
* @author guokunkun
* @since 2025-01-02
*/
@Mapper
public interface SyncProductAuditMapper extends BaseMapper<SyncProductAudit> {
List<String> groupSkuSolarTerm_1();
List<String> groupSkuSolarTerm_Q1Q2();
}
package cn.kk.spring_simple_operation.mapper;
import cn.kk.spring_simple_operation.entity.SyncProductPublish;
import cn.kk.spring_simple_operation.model.SkuVideoVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -18,11 +19,15 @@ import java.util.List;
@Mapper
public interface SyncProductPublishMapper extends BaseMapper<SyncProductPublish> {
List<SyncProductPublish> selectMotherSku();
List<SkuVideoVO> selectMotherSku();
List<SyncProductPublish> selectChildSku();
List<SkuVideoVO> selectChildSku();
List<SyncProductPublish> selectMotherSku_2();
List<SyncProductPublish> selectChildSku_2();
List<SkuVideoVO> selectChildSku_2();
List<SkuVideoVO> groupSkuSolarTerm_1(@Param("sku") String sku);
List<SkuVideoVO> groupSkuSolarTerm_Q1Q2(@Param("sku") String sku);
}
......@@ -3,6 +3,7 @@ package cn.kk.spring_simple_operation.mapper;
import cn.kk.spring_simple_operation.entity.VideoProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -17,5 +18,5 @@ import java.util.List;
@Mapper
public interface VideoProductMapper extends BaseMapper<VideoProduct> {
List<String> selectHaveTask();
List<String> selectHaveTask(@Param("skus") List<String> skus);
}
package cn.kk.spring_simple_operation.model;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author kk
* @date 2025/1/2
*/
@Data
public class SkuVideoVO {
private String sku;
private String relation_key;
private String parentAsin;
private BigDecimal lowestPrice;
private Integer thirtyDaySales;
private String saleStatus;
private String usUploadInfo;
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public String getRelation_key() {
return relation_key;
}
public void setRelation_key(String relation_key) {
this.relation_key = relation_key;
}
public String getParentAsin() {
return parentAsin;
}
public void setParentAsin(String parentAsin) {
this.parentAsin = parentAsin;
}
public BigDecimal getLowestPrice() {
return lowestPrice;
}
public void setLowestPrice(BigDecimal lowestPrice) {
this.lowestPrice = lowestPrice;
}
public Integer getThirtyDaySales() {
return thirtyDaySales;
}
public void setThirtyDaySales(Integer thirtyDaySales) {
this.thirtyDaySales = thirtyDaySales;
}
public String getSaleStatus() {
return saleStatus;
}
public void setSaleStatus(String saleStatus) {
this.saleStatus = saleStatus;
}
public String getUsUploadInfo() {
return usUploadInfo;
}
public void setUsUploadInfo(String usUploadInfo) {
this.usUploadInfo = usUploadInfo;
}
}
package cn.kk.spring_simple_operation.service;
import cn.kk.spring_simple_operation.entity.SyncProductAudit;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 对应inv 产品审核表 服务类
* </p>
*
* @author guokunkun
* @since 2025-01-02
*/
public interface SyncProductAuditService extends IService<SyncProductAudit> {
}
package cn.kk.spring_simple_operation.service.impl;
import cn.kk.spring_simple_operation.entity.SyncProductAudit;
import cn.kk.spring_simple_operation.mapper.SyncProductAuditMapper;
import cn.kk.spring_simple_operation.service.SyncProductAuditService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 对应inv 产品审核表 服务实现类
* </p>
*
* @author guokunkun
* @since 2025-01-02
*/
@Service
public class SyncProductAuditServiceImpl extends ServiceImpl<SyncProductAuditMapper, SyncProductAudit> implements SyncProductAuditService {
}
......@@ -21,13 +21,17 @@ spring:
# username: yswg_it_java
# password: Yswg@inv-java241011427
url: jdbc:mysql://mydb.com:3306/visual_1218?useUnicode=true&characterEncoding=utf8&useSSL=true
url: jdbc:mysql://mydb.com:3306/visual_0102?useUnicode=true&characterEncoding=utf8&useSSL=true
username: root
password: root
# url: jdbc:mysql://rm-wz9m4k931n87m9721oo.mysql.rds.aliyuncs.com:3306/visual?useUnicode=true&characterEncoding=utf8&useSSL=true
# username: guokunkun
# password: gkk1602
druid:
initial-size: 5
min-idle: 5
initial-size: 1
min-idle: 1
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.kk.spring_simple_operation.mapper.SyncProductAuditMapper">
<select id="groupSkuSolarTerm_1" resultType="java.lang.String">
SELECT
spa.sku
FROM
sync_product_audit spa
LEFT JOIN sync_product_publish spp ON spp.sku = spa.sku
WHERE
spa.sku > ''
AND spa.product_type = 2
AND spa.is_comb_variant = 0
AND spa.variant_amount > 0
AND spa.comb_parent_sku = ''
AND spp.open_date > 0
AND spp.sale_status IN ( '正常销售' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
AND spp.solar_term = 1
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
</select>
<select id="groupSkuSolarTerm_Q1Q2" resultType="java.lang.String">
SELECT
spa.sku
FROM
sync_product_audit spa
LEFT JOIN sync_product_publish spp ON spp.sku = spa.sku
LEFT JOIN sync_solar_term_info ti ON ti.solar_term_id = spp.solar_term
WHERE
spa.sku > ''
AND spa.product_type = 2
AND spa.is_comb_variant = 0
AND spa.variant_amount > 0
AND spa.comb_parent_sku = ''
AND spp.open_date > 0
AND spp.sale_status IN ( '正常销售', '保留页面', '限制跟卖暂保留', '发货限制安排跟卖' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
AND ti.`quarter` IN ( 'Q1', 'Q2' )
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
</select>
</mapper>
......@@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.kk.spring_simple_operation.mapper.SyncProductPublishMapper">
<select id="selectMotherSku" resultType="cn.kk.spring_simple_operation.entity.SyncProductPublish">
<select id="selectMotherSku" resultType="cn.kk.spring_simple_operation.model.SkuVideoVO">
with shortVideo as (select vp.sku
from video_product vp
INNER JOIN visual_video_plan vvp on vvp.id = vp.video_plan_id
......@@ -14,12 +14,13 @@
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales
spp.thirty_day_sales,
spp.sale_status
from sync_product_publish spp
LEFT JOIN photo_progress pp on pp.sku = spp.sku
LEFT JOIN shortVideo on shortVideo.sku = spp.sku
where spp.open_date BETWEEN 1 AND 1732550400
where spp.open_date > 0
and spp.sale_status IN ('正常销售')
and spp.site = 'Amazon.com'
and spp.is_delete = 0
......@@ -32,7 +33,7 @@
</select>
<select id="selectChildSku" resultType="cn.kk.spring_simple_operation.entity.SyncProductPublish">
<select id="selectChildSku" resultType="cn.kk.spring_simple_operation.model.SkuVideoVO">
with shortVideo as (select vp.sku
from video_product vp
INNER JOIN visual_video_plan vvp on vvp.id = vp.video_plan_id
......@@ -45,14 +46,17 @@
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales
spp.thirty_day_sales,
spp.sale_status,
ifnull(spa.us_upload_info, '无sku') as us_upload_info
FROM
sync_product_publish spp
LEFT JOIN photo_progress pp ON pp.sku = spp.sku
LEFT JOIN shortVideo ON shortVideo.sku = spp.sku
left join sync_product_audit spa on spa.sku = spp.sku
LEFT JOIN sync_amazon_item_day said ON said.asin = spp.relation_key AND said.site = spp.site
WHERE
spp.open_date BETWEEN 1
AND 1732550400
spp.open_date > 0
AND spp.sale_status IN ( '正常销售' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
......@@ -61,6 +65,7 @@
AND pp.id IS NULL
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
AND said.img_type not like '%2%'
</select>
<select id="selectMotherSku_2" resultType="cn.kk.spring_simple_operation.entity.SyncProductPublish">
......@@ -75,7 +80,8 @@
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales
spp.thirty_day_sales,
spp.sale_status
from sync_product_publish spp
LEFT JOIN photo_progress pp on pp.sku = spp.sku
LEFT JOIN shortVideo on shortVideo.sku = spp.sku
......@@ -92,7 +98,7 @@
and spp.lowest_price > 0
and spp.thirty_day_sales > 0
</select>
<select id="selectChildSku_2" resultType="cn.kk.spring_simple_operation.entity.SyncProductPublish">
<select id="selectChildSku_2" resultType="cn.kk.spring_simple_operation.model.SkuVideoVO">
with shortVideo as (select vp.sku
from video_product vp
INNER JOIN visual_video_plan vvp on vvp.id = vp.video_plan_id
......@@ -105,22 +111,79 @@
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales
spp.thirty_day_sales,
spp.sale_status,
ifnull(spa.us_upload_info, '无sku') as us_upload_info
FROM
sync_product_publish spp
LEFT JOIN photo_progress pp ON pp.sku = spp.sku
LEFT JOIN shortVideo ON shortVideo.sku = spp.sku
LEFT JOIN sync_solar_term_info ti ON ti.solar_term_id = spp.solar_term
left join sync_product_audit spa on spa.sku = spp.sku
LEFT JOIN sync_amazon_item_day said ON said.asin = spp.relation_key AND said.site = spp.site
WHERE
spp.open_date BETWEEN 1
AND 1732550400
AND spp.sale_status IN ( '正常销售', '保留页面' )
spp.open_date > 0
AND spp.sale_status IN ( '正常销售', '保留页面', '限制跟卖暂保留', '发货限制安排跟卖' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
AND ti.`month` BETWEEN 1 AND 6
AND ti.`quarter` in ('Q1', 'Q2')
AND shortVideo.sku IS NULL
AND pp.id IS NULL
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
AND said.img_type NOT LIKE '%2%'
</select>
<select id="groupSkuSolarTerm_1" resultType="cn.kk.spring_simple_operation.model.SkuVideoVO">
SELECT
spp.sku,
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales,
spp.sale_status,
ifnull(spa.us_upload_info, '无sku') as us_upload_info
FROM sync_product_audit spa
LEFT JOIN sync_product_publish spp on spp.sku = spa.sku
LEFT JOIN photo_progress pp ON pp.sku = spp.sku
WHERE
spp.open_date > 0
AND spp.sale_status IN ( '正常销售' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
AND spp.solar_term = 1
AND pp.id IS NULL
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
AND spa.sku > ''
AND (spa.sku = #{sku} or spa.comb_parent_sku = #{sku})
</select>
<select id="groupSkuSolarTerm_Q1Q2" resultType="cn.kk.spring_simple_operation.model.SkuVideoVO">
SELECT
spp.sku,
spp.relation_key,
spp.parent_asin,
spp.lowest_price,
spp.thirty_day_sales,
spp.sale_status,
ifnull(spa.us_upload_info, '无sku') as us_upload_info
FROM sync_product_audit spa
LEFT JOIN sync_product_publish spp on spp.sku = spa.sku
LEFT JOIN photo_progress pp ON pp.sku = spp.sku
LEFT JOIN sync_solar_term_info ti ON ti.solar_term_id = spp.solar_term
WHERE
spp.open_date > 0
AND spp.sale_status IN ( '正常销售', '保留页面', '限制跟卖暂保留', '发货限制安排跟卖' )
AND spp.site = 'Amazon.com'
AND spp.is_delete = 0
AND ti.`quarter` in ('Q1', 'Q2')
AND pp.id IS NULL
AND spp.lowest_price > 0
AND spp.thirty_day_sales > 0
AND spa.sku > ''
AND (spa.sku = #{sku} or spa.comb_parent_sku = #{sku})
</select>
</mapper>
......@@ -12,5 +12,9 @@
vp.is_delete = 0
AND vvp.is_delete = 0
AND vp.site = 'Amazon.com'
and vp.sku in
<foreach item="sku" collection="skus" open="(" separator="," close=")">
#{sku}
</foreach>
</select>
</mapper>
package cn.kk.spring_simple_operation;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.List;
/**
* @author kk
* @date 2025/1/2
*/
@SpringBootTest
public class ExcelTest {
@Test
public void noModelWrite() {
// 写法1
String fileName = "D:\\" + "noModelWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList());
}
private List<List<String>> head() {
List<List<String>> list = ListUtils.newArrayList();
List<String> head0 = ListUtils.newArrayList();
head0.add("字符串" + System.currentTimeMillis());
List<String> head1 = ListUtils.newArrayList();
head1.add("数字" + System.currentTimeMillis());
List<String> head2 = ListUtils.newArrayList();
head2.add("日期" + System.currentTimeMillis());
list.add(head0);
list.add(head1);
list.add(head2);
return list;
}
private List<List<Object>> dataList() {
List<List<Object>> list = ListUtils.newArrayList();
for (int i = 0; i < 10; i++) {
List<Object> data = ListUtils.newArrayList();
data.add("字符串" + i);
data.add(0.56);
data.add(new Date());
list.add(data);
}
return list;
}
}
package cn.kk.spring_simple_operation;
import cn.kk.spring_simple_operation.entity.SyncProductPublish;
import cn.kk.spring_simple_operation.mapper.SyncProductAuditMapper;
import cn.kk.spring_simple_operation.mapper.SyncProductPublishMapper;
import cn.kk.spring_simple_operation.mapper.VideoProductMapper;
import cn.kk.spring_simple_operation.model.SkuVideoVO;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@SpringBootTest
class SpringSimpleOperationApplicationTests2 {
private static final BigDecimal TWENTY = new BigDecimal("20");
private static final BigDecimal THIRTY = new BigDecimal("30");
private static final BigDecimal FORTY = new BigDecimal("40");
private static final BigDecimal SIXTY = new BigDecimal("60");
@Resource
private SyncProductPublishMapper syncProductPublishMapper;
@Resource
private VideoProductMapper videoProductMapper;
@Resource
private SyncProductAuditMapper syncProductAuditMapper;
@Test
void contextLoads() {
}
private Map<String, Integer> initSalesMap() {
Map<String, Integer> salesMap = new HashMap<>();
salesMap.put("0~20", 0);
salesMap.put("20~30", 0);
salesMap.put("30~40", 0);
salesMap.put("40~60", 0);
salesMap.put(">60", 0);
return salesMap;
}
@Test
void singleSkuSolarTerm_1() {
//List<String> shortUrlSkuList = videoProductMapper.selectHaveTask();
Map<String, Integer> salesMap = initSalesMap();
List<SkuVideoVO> publishList = syncProductPublishMapper.selectChildSku();
List<SkuVideoVO> publishList_2 = new LinkedList<>();
publishList.forEach(item -> {
ArrayList<SkuVideoVO> list = new ArrayList<>();
list.add(item);
String s = checkPriceAndSales(list, item);
if (StringUtils.isBlank(s)) {
return;
}
salesMap.put(s, salesMap.get(s) + 1);
publishList_2.add(item);
});
printMap(salesMap);
exportSkuList(publishList_2, "常规产品--单个sku");
}
@Test
void groupSkuSolarTerm_1() {
//List<String> shortUrlSkuList = videoProductMapper.selectHaveTask();
Map<String, Integer> salesMap = initSalesMap();
List<String> motherList = syncProductAuditMapper.groupSkuSolarTerm_1();
List<SkuVideoVO> publishList_2 = new LinkedList<>();
motherList.forEach(sku -> {
List<SkuVideoVO> skuVideoVOS = syncProductPublishMapper.groupSkuSolarTerm_1(sku);
Optional<SkuVideoVO> first = skuVideoVOS.stream().filter(t -> t.getSku().equals(sku)).findFirst();
if (!first.isPresent()) {
return;
}
List<String> shortUrlSkuList = videoProductMapper.selectHaveTask(skuVideoVOS.stream().map(SkuVideoVO::getSku).collect(Collectors.toList()));
Iterator<SkuVideoVO> iterator = skuVideoVOS.iterator();
while (iterator.hasNext()) {
SkuVideoVO skuVideoVO = iterator.next();
if (shortUrlSkuList.contains(skuVideoVO.getSku())) {
iterator.remove();
}
}
if (CollectionUtils.isEmpty(skuVideoVOS)) {
return;
}
String s = checkPriceAndSales(skuVideoVOS, first.get());
if (StringUtils.isBlank(s)) {
return;
}
salesMap.put(s, salesMap.get(s) + 1);
publishList_2.add(first.get());
});
printMap(salesMap);
exportSkuList(publishList_2, "常规产品--组合产品母体sku");
}
private String checkPriceAndSales(List<SkuVideoVO> subList, SkuVideoVO item) {
BigDecimal totalPrice = subList.stream().map(SkuVideoVO::getLowestPrice).reduce(BigDecimal::add).get();
BigDecimal lowestPrice = totalPrice.divide(new BigDecimal(subList.size()), 2, BigDecimal.ROUND_HALF_UP);
if (CollectionUtils.isEmpty(subList) || lowestPrice.compareTo(BigDecimal.ZERO) < 0) {
return null;
}
int sum = subList.stream().map(SkuVideoVO::getThirtyDaySales).reduce(Integer::sum).get();
item.setThirtyDaySales(sum);
item.setLowestPrice(lowestPrice);
if (lowestPrice.compareTo(TWENTY) <= 0 && sum >= 25) {
return "0~20";
}
else if (lowestPrice.compareTo(TWENTY) > 0 && lowestPrice.compareTo(THIRTY) <= 0 && sum >= 15) {
return "20~30";
}
else if (lowestPrice.compareTo(THIRTY) > 0 && lowestPrice.compareTo(FORTY) <= 0 && sum >= 10) {
return "30~40";
}
else if (lowestPrice.compareTo(FORTY) > 0 && lowestPrice.compareTo(SIXTY) <= 0 && sum >= 8) {
return "40~60";
}
else if (lowestPrice.compareTo(SIXTY) > 0 && sum >= 5) {
return ">60";
}
return null;
}
private void printSkuList(List<SyncProductPublish> list) {
list.forEach(item -> {
String content = String.format("sku: %s, 30天销量: %d, price: %s, relationKey: %s, parentAsin: %s", item.getSku(), item.getThirtyDaySales(), item.getLowestPrice(), item.getRelationKey(), item.getParentAsin());
System.out.println(content);
});
}
private void exportSkuList(List<SkuVideoVO> list, String originName) {
list.sort(Comparator.comparing(SkuVideoVO::getLowestPrice));
List<List<Object>> dataList = ListUtils.newArrayList();
for (SkuVideoVO syncProductPublish : list) {
List<Object> data = ListUtils.newArrayList();
data.add(syncProductPublish.getSku());
data.add(syncProductPublish.getLowestPrice());
data.add(syncProductPublish.getThirtyDaySales());
data.add(syncProductPublish.getSaleStatus());
data.add(syncProductPublish.getUsUploadInfo());
dataList.add(data);
}
// 写法1
String fileName = "D:\\" + originName + "_" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName).head(head()).sheet(originName).doWrite(dataList);
}
private void printMap(Map<String, Integer> salesMap) {
System.out.println("0~20: " + salesMap.get("0~20"));
System.out.println("20~30: " + salesMap.get("20~30"));
System.out.println("30~40: " + salesMap.get("30~40"));
System.out.println("40~60: " + salesMap.get("40~60"));
System.out.println(">60: " + salesMap.get(">60"));
}
private List<List<String>> head() {
List<List<String>> list = ListUtils.newArrayList();
List<String> head0 = ListUtils.newArrayList();
head0.add("sku");
List<String> head1 = ListUtils.newArrayList();
head1.add("单价");
List<String> head2 = ListUtils.newArrayList();
head2.add("月销");
List<String> head3 = ListUtils.newArrayList();
head3.add("销售状态");
List<String> head4 = ListUtils.newArrayList();
head4.add("是否拍摄");
list.add(head0);
list.add(head1);
list.add(head2);
list.add(head3);
list.add(head4);
return list;
}
@Test
void singleSkuSolarTerm_Q1Q2() {
Map<String, Integer> salesMap = initSalesMap();
List<SkuVideoVO> publishList = syncProductPublishMapper.selectChildSku_2();
List<SkuVideoVO> publishList_2 = new LinkedList<>();
publishList.forEach(item -> {
ArrayList<SkuVideoVO> list = new ArrayList<>();
list.add(item);
String s = checkPriceAndSales(list, item);
if (StringUtils.isBlank(s)) {
return;
}
salesMap.put(s, salesMap.get(s) + 1);
publishList_2.add(item);
});
printMap(salesMap);
exportSkuList(publishList_2, "节气产品--单个sku");
}
@Test
void groupSkuSolarTerm_Q1Q2() {
//List<String> shortUrlSkuList = videoProductMapper.selectHaveTask();
Map<String, Integer> salesMap = initSalesMap();
List<String> motherList = syncProductAuditMapper.groupSkuSolarTerm_Q1Q2();
List<SkuVideoVO> publishList_2 = new LinkedList<>();
motherList.forEach(sku -> {
List<SkuVideoVO> skuVideoVOS = syncProductPublishMapper.groupSkuSolarTerm_Q1Q2(sku);
Optional<SkuVideoVO> first = skuVideoVOS.stream().filter(t -> t.getSku().equals(sku)).findFirst();
if (!first.isPresent()) {
return;
}
List<String> shortUrlSkuList = videoProductMapper.selectHaveTask(skuVideoVOS.stream().map(SkuVideoVO::getSku).collect(Collectors.toList()));
skuVideoVOS.removeIf(skuVideoVO -> shortUrlSkuList.contains(skuVideoVO.getSku()));
if (CollectionUtils.isEmpty(skuVideoVOS)) {
return;
}
String s = checkPriceAndSales(skuVideoVOS, first.get());
if (StringUtils.isBlank(s)) {
return;
}
salesMap.put(s, salesMap.get(s) + 1);
publishList_2.add(first.get());
});
printMap(salesMap);
exportSkuList(publishList_2, "节气产品--组合产品母体sku");
}
}
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