Commit b525a320 by 苗权威

9.26

parent 235064dd
......@@ -20,6 +20,7 @@ import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -1063,7 +1064,7 @@ public class TTService {
String encoding = TTSUtils.charset(csvFile);
// 所有成功上传的id,若多个id指向同一文件,任何一个成功则都应该将其余的id加入集合中
final List<String> successUpLoadFileIds = new ArrayList<>();
final Set<String> successUpLoadFileIds = new HashSet<>();
// 所有失败了的id以及失败原因
HashMap<String,String> allFailUpLoadId2Reason = new HashMap<>();
......@@ -1091,21 +1092,25 @@ public class TTService {
// filename列不为空代表用户为该句指定了文件
if (StringUtils.isNotBlank(audioFileName)) {
id2Info.put(arr[0],arr); // 存储该行的详细信息,用于之后展示错误信息使用
boolean hasSuffix = StringUtils.endsWith(audioFileName,".mp3") || StringUtils.endsWith(audioFileName,".MP3");
// 修正文件名,不包含后缀名的加上.mp3后缀名
audioFileName = StringUtils.endsWith(audioFileName,".mp3") ? audioFileName : audioFileName+".mp3";
if (!hasSuffix) audioFileName = audioFileName+".mp3";
// String previousId;
// 若之前已有相同文件名,则将该文件的id加入集合,以该文件名为key
// (previousId = allOldname2Id.putIfAbsent(audioFileName, arr[0])) != null
List<String> repeateIds = repeateName2Ids.computeIfAbsent(audioFileName, s -> new ArrayList<>());
if (repeateIds.size() != 0) {
// Set<String> repeateIds = repeateName2Ids.computeIfAbsent(audioFileName, s -> new HashSet<>());
// repeateIds.add(arr[0]);
// repeateIds.add(previousId);
//遍历指向相同文件的语句,生成text与当前一样的语句的提示信息
boolean doesBeforeRepeate = false;
boolean beforeSuccess = false;
hasRepeate = true;
for (String repeateId: repeateIds) {
if (arr[1].equals(id2Info.get(repeateId)[1])) {
doesBeforeRepeate = true;
Set<String> textIdEqualIds = allRepeateName2Info.computeIfAbsent(audioFileName, s -> new HashSet<>());
textIdEqualIds.add(arr[0]);
textIdEqualIds.add(repeateId);
......@@ -1114,7 +1119,7 @@ public class TTService {
if (successUpLoadFileIds.contains(repeateId)) beforeSuccess = true;
}
// 之前的重复语句并不一定执行成功,若不成功则放行当前的这条重复语句
if (beforeSuccess) {
if (beforeSuccess && doesBeforeRepeate) {
repeateIds.add(arr[0]);
continue;
}
......@@ -1126,7 +1131,13 @@ public class TTService {
// audio_dir/botname/record/npcname/xxx.mp3
final String usFilename = new StringBuilder(folder).append(File.separator).append(md5Name).toString();
// 压缩包中有该mp3文件
if (TTSUtils.doesFileExist(fileInPackage)) {
boolean doesFileExit = TTSUtils.doesFileExist(fileInPackage);
if (!doesFileExit && !hasSuffix) {
fileInPackage = new StringBuilder(zipFolder).append(File.separator)
.append(audioFileName, 0, audioFileName.lastIndexOf(".")).append(".MP3").toString();
doesFileExit = TTSUtils.doesFileExist(fileInPackage);
}
if (doesFileExit) {
File usFile = new File(usFilename);
boolean result=true;
// 删除之前的旧文件
......@@ -1136,10 +1147,16 @@ public class TTService {
// 删除成功后删除其b64文件,且将压缩包中的文件移到安置目录下,即
// /root/TTS-service/mqwZip/audioFilename -> audio_dir/botname/record/npcname/xxx.mp3
if (result) {
POOL.submit(() -> new File(new StringBuilder(usFilename).append(".b64").toString()).delete());
if (new File(fileInPackage).renameTo(usFile)) {
new File(new StringBuilder(usFilename).append(".b64").toString()).delete();
try {
Files.copy(new File(fileInPackage).toPath(), usFile.toPath());
successUpLoadFileIds.add(arr[0]);
} catch (Exception e) {
}
// if (new File(fileInPackage).renameTo(usFile)) {
// successUpLoadFileIds.add(arr[0]);
// }
}else {
allFailUpLoadId2Reason.put(arr[0], "程序原因,请重新上传");
log.error("删除之前的就音频失败:{}",fileInPackage);
......@@ -1159,13 +1176,12 @@ public class TTService {
//log.info("repeateName2Ids:{}",repeateName2Ids);
if (successUpLoadFileIds.size() != 0) {
if (hasRepeate) {
List<String> repeatNameIdList = new ArrayList<>();
Set<String> repeatNameIdList = new HashSet<>();
for (String successId: successUpLoadFileIds) {
String name = id2Info.get(successId)[3];
name = StringUtils.endsWith(name,".mp3") ? name : name+".mp3";
List<String> nameRepeats = repeateName2Ids.get(name);
Set<String> nameRepeats = allRepeateName2Info.get(name);
if (nameRepeats != null && nameRepeats.size()>0) {
nameRepeats.remove(successId);
repeatNameIdList.addAll(nameRepeats);
}
}
......@@ -1218,7 +1234,7 @@ public class TTService {
StringBuilder msgBuild = new StringBuilder(msg).append(";\n").append("下面为提醒信息,请确认:");
for (String id : successUpLoadFileIds) {
String name = id2Info.get(id)[3];
name = StringUtils.endsWith(name,".mp3") ? name : name+".mp3";
name = StringUtils.endsWith(name,".mp3") || StringUtils.endsWith(name,".MP3") ? name : name+".mp3";
Set<String> infos = allRepeateName2Info.remove(name);
if (infos != null && infos.size() != 0) msgBuild
.append("下面的id列表,其所代表的语句的text皆为:\"").append(id2Info.get(id)[1]).append("\",且他们指向同一个文件,这是您想要的结果吗?").append(":")
......
......@@ -19,8 +19,8 @@ spring:
ansi:
enabled: detect
logging:
# path: /home/ubuntu/project/tts/logs
path: /root/GameEditor/mqw/project/ttsTest/logs
path: /home/ubuntu/project/tts/logs
# path: /root/GameEditor/mqw/project/ttsTest/logs
level:
root: info
server:
......
......@@ -11,7 +11,7 @@
<groupId>ai.qiwu.mi</groupId>
<artifactId>xiaoai</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!--<packaging>war</packaging>-->
<name>xiaoai</name>
<description>Demo project for Spring Boot</description>
......@@ -23,12 +23,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>
<dependency>
......@@ -36,13 +36,13 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--添加servlet-api的依赖,用来打war包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<!--&lt;!&ndash;添加servlet-api的依赖,用来打war包 &ndash;&gt;-->
<!--<dependency>-->
<!--<groupId>javax.servlet</groupId>-->
<!--<artifactId>javax.servlet-api</artifactId>-->
<!--<version>LATEST</version>-->
<!--<scope>provided</scope>-->
<!--</dependency>-->
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
......
upload.sh:将jar包上传到服务器
start.sh:服务器上执行该文件,启动项目
\ No newline at end of file
......@@ -6,14 +6,9 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class XiaoaiApplication extends SpringBootServletInitializer {
public class XiaoaiApplication{
public static void main(String[] args) {
SpringApplication.run(XiaoaiApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(XiaoaiApplication.class);
}
}
server.port=8189
logging.path=/usr/mqw/logs/xiaoai
logging.level.root = info
spring.output.ansi.enabled=detect
\ No newline at end of file
nohup java -jar /root/GameEditor/mqw/project/xiaoai/xiaoai.jar > nohup.log 2>&1 &
\ No newline at end of file
scp /usr/local/intellij/workplace/smartbox/xiaoai/target/xiaoai.jar root@aliyun-hz1.chewrobot.com:/root/GameEditor/mqw/project/xiaoai/
\ No newline at end of file
......@@ -33,6 +33,9 @@ public interface Constants {
String REWARD_FLOWER = "请扫码支付";
String UNIT_PRICE = "1";
Integer CO_HI_PAGE_SIZE = 4;
Integer RE_RA_CA_PAGE_SIZE = 20;
interface DPL_COMPONENT_ID {
String FLOWE = "flowe";
String FLOWER_PRODUCT_ID = "190817185926388308";
......
......@@ -70,4 +70,10 @@ public class CollectHistoryPagePojo {
private String paddingLeft;
@JsonProperty("scale-type")
private String scaleType;
@JsonProperty("background-color")
private String backgroundColor;
@JsonProperty("align-items")
private String alignItems;
@JsonProperty("justify-content")
private String justifyContent;
}
......@@ -19,7 +19,8 @@ public class CollectHistoryUtils {
private static final CollectHistoryPagePojo HISTORY_HEAD = buildHistoryHead();
private static final CollectHistoryPagePojo FOOTER = buildFooter();
public static CollectHistoryDocument getDocument(List<HistoryData> datas, boolean collect) {
public static CollectHistoryDocument getDocument(List<HistoryData> datas, boolean collect,
int index, int num) {
CollectHistoryDocument document = new CollectHistoryDocument();
document.setDuration(120000);
CollectHistoryMainTemplate mainTemplate = new CollectHistoryMainTemplate();
......@@ -30,7 +31,7 @@ public class CollectHistoryUtils {
allContainer.setWidth("100%");
allContainer.setPaddingRight("15dp");
allContainer.setPaddingLeft("15dp");
allContainer.setPaddingBottom("120dp");
allContainer.setPaddingBottom("180dp");
CollectHistoryPagePojo list = new CollectHistoryPagePojo();
list.setType("List");
......@@ -45,7 +46,7 @@ public class CollectHistoryUtils {
CollectHistoryPagePojo head;
if (collect) head = COLLECT_HEAD;
else head = HISTORY_HEAD;
mainTemplate.getItems().addAll(Arrays.asList(BACK_IMG, head, allContainer, FOOTER));
mainTemplate.getItems().addAll(Arrays.asList(BACK_IMG, head, allContainer, FOOTER, buildPageButton(index, num)));
return document;
}
......@@ -121,6 +122,37 @@ public class CollectHistoryUtils {
return main;
}
private static CollectHistoryPagePojo buildPageButton(int curIndex, int num) {
CollectHistoryPagePojo fCon = new CollectHistoryPagePojo();
fCon.setType("Container");
fCon.setLeft("447dp");
fCon.setBottom("70dp");
fCon.setPosition("absolute");
CollectHistoryPagePojo frame = new CollectHistoryPagePojo();
frame.setType("Frame");
frame.setBorderRadius("40dp");
frame.setBackgroundColor("rgba(0,0,0,0.5)");
CollectHistoryPagePojo sCon = new CollectHistoryPagePojo();
sCon.setType("Container");
sCon.setWidth("130dp");
sCon.setHeight("35dp");
sCon.setAlignItems("center");
sCon.setJustifyContent("center");
CollectHistoryPagePojo text = new CollectHistoryPagePojo();
text.setType("Text");
text.setFontSize("22dp");
if (num == 0) text.setText("第"+curIndex+"页");
else text.setText(curIndex+"/"+num);
sCon.setItems(Collections.singletonList(text));
frame.setItems(Collections.singletonList(sCon));
fCon.setItems(Collections.singletonList(frame));
return fCon;
}
private static CollectHistoryPagePojo buildFooter() {
CollectHistoryPagePojo footerCon = new CollectHistoryPagePojo();
footerCon.setType("Container");
......@@ -131,7 +163,7 @@ public class CollectHistoryUtils {
CollectHistoryPagePojo footer = new CollectHistoryPagePojo();
footer.setType("Footer");
footer.setHints(Arrays.asList("打开第一个","下一页","上一页","返回"));
footer.setHints(Arrays.asList("打开第一个","下一页","上一页","返回","跳到第三页"));
footerCon.setItems(Collections.singletonList(footer));
return footerCon;
}
......
......@@ -9,6 +9,7 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
/**
......@@ -36,9 +37,9 @@ public class AppFavoriteTB {
@CreatedDate
@Column(name = "gmt_create", updatable = false, nullable = false)
private Date createTime;
private Timestamp createTime;
@LastModifiedDate
@Column(name = "gmt_modified", nullable = false)
private Date updateTime;
private Timestamp updateTime;
}
......@@ -48,9 +48,9 @@ public class AppFlowerTB {
@CreatedDate
@Column(name = "gmt_create", updatable = false, nullable = false)
private Date createTime;
private Timestamp createTime;
@LastModifiedDate
@Column(name = "gmt_modified", nullable = false)
private Date updateTime;
private Timestamp updateTime;
}
......@@ -7,6 +7,7 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
/**
......@@ -29,5 +30,5 @@ public class AppUserTB {
@CreatedDate
@Column(name = "gmt_create", updatable = false, nullable = false)
private Date createTime;
private Timestamp createTime;
}
......@@ -5,6 +5,7 @@ import lombok.Setter;
import lombok.ToString;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
......@@ -38,7 +39,7 @@ public class OnProductDetail {
private Integer applyStatus;
@Column(name = "gmt_create")
private Date createTime;
private Timestamp createTime;
@Column(name = "user_nickname")
private String authorName;
......
......@@ -3,12 +3,12 @@ package ai.qiwu.com.xiaoduhome.entity.secondary;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
/**
......@@ -36,9 +36,9 @@ public class XiaoDuHistoryTB {
@CreatedDate
@Column(name = "create_time", updatable = false, nullable = false)
private Date createTime;
private Timestamp createTime;
@LastModifiedDate
@Column(name = "update_time")
private Date updateTime;
private Timestamp updateTime;
}
......@@ -7,6 +7,7 @@ import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Date;
/**
......@@ -58,9 +59,9 @@ public class XiaoDuOrderTB {
@CreatedDate
@Column(name = "create_time", updatable = false, nullable = false)
private Date createTime;
private Timestamp createTime;
@LastModifiedDate
@Column(name = "update_time", nullable = false)
private Date updateTime;
private Timestamp updateTime;
}
......@@ -191,11 +191,11 @@ public class TestBuild {
public static void main(String[] args) throws IOException {
String target = "/home/yf01/下载/tts/target.csv";
String src = "/home/yf01/下载/齐齐-人工配音关系对于表(1).csv";
String srcModify = "/home/yf01/下载/%E6%B0%B4%E5%BF%83%E6%B9%96.csv";
String v2 = "/home/yf01/下载/齐齐-人工配音关系对于表.csv";
String src = "/home/yf01/下载/齐齐-人工配音关系对于表(2).csv";
String srcModify = "/home/yf01/下载/qiOld.csv";
String v2 = "/home/yf01/下载/qiNew.csv";
//csvUtil(target, src, srcModify, v2);
//check(src, srcModify, target);
check(src, srcModify, target);
}
}
......@@ -20,9 +20,9 @@ public class UserBehaviorData {
// 用户对作品所送花的数目
private volatile HashMap<String, Long> userBotId2Flowers = new HashMap<>();
// 用户是否收藏该作品
private volatile HashMap<String, Byte> userBotId2Collected = new HashMap<>();
private volatile HashMap<String, Long> userBotId2Collected = new HashMap<>();
// 标记清除,每半小时标记一次
private volatile Byte mark = 1;
private volatile Byte mark = 0;
private volatile String jytUserId;
}
......@@ -23,8 +23,10 @@ public interface AppFavoriteTBRepository extends JpaRepository<AppFavoriteTB, In
@Transactional
void deleteByBotIdAndUserId(String botId, Long userId);
@Query(value="SELECT bot_username from app_favorite_tb where user_id=?1", nativeQuery = true)
List<String> getFavoriteBotIds(Long userId);
List<AppFavoriteTB> getByUserId(Long userId);
@Query(value = "select bot_username from app_favorite_tb where user_id=?1 order by gmt_create desc limit ?2,10", nativeQuery = true)
List<String> getFavoriteLimit(Long userId, Integer start);
@Override
<S extends AppFavoriteTB> long count(Example<S> example);
......
......@@ -2,6 +2,7 @@ package ai.qiwu.com.xiaoduhome.repository.secondary;
import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryBotIdTime;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
......@@ -11,4 +12,7 @@ import java.util.List;
*/
public interface XiaoDuHistoryBotTimeRepository extends JpaRepository<XiaoDuHistoryBotIdTime, Integer> {
List<XiaoDuHistoryBotIdTime> getByXiaoduUserId(String xiaoduUserId);
@Query(value = "select bot_id,last_time from xiaodu_history_tb where xiaodu_user_id=?1 order by last_time desc limit ?2,10",nativeQuery = true)
List<XiaoDuHistoryBotIdTime> getByXiaoduUserIdLimit(String xiaoduUserId, Integer start);
}
......@@ -43,7 +43,9 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static ai.qiwu.com.xiaoduhome.common.Constants.CO_HI_PAGE_SIZE;
import static ai.qiwu.com.xiaoduhome.common.Constants.IMG_PREFIX;
import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.*;
import static ai.qiwu.com.xiaoduhome.service.ScheduleService.curTime;
......@@ -54,9 +56,6 @@ import static ai.qiwu.com.xiaoduhome.service.ScheduleService.curTime;
*/
@Slf4j
public class DplbotServiceUtil {
private static final byte BYTE_FILL = 1;
private static final int CORE = Runtime.getRuntime().availableProcessors();
static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
......@@ -68,10 +67,11 @@ public class DplbotServiceUtil {
AppFavoriteTBRepository favoriteTBRepository = BaseHolder.getBean("appFavoriteTBRepository");
try {
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
List<String> favoriteBotIDS = favoriteTBRepository.getFavoriteBotIds(Long.valueOf(usUserId));
for(String botId : favoriteBotIDS) {
data.getUserBotId2Collected().put(botId, BYTE_FILL);
List<AppFavoriteTB> favoriteBots = favoriteTBRepository.getByUserId(Long.valueOf(usUserId));
for(AppFavoriteTB bot : favoriteBots) {
data.getUserBotId2Collected().put(bot.getBotId(), bot.getCreateTime().getTime());
}
log.info("UserBotId2Collected:"+data.getUserBotId2Collected());
} catch (Exception e) {
e.printStackTrace();
}
......@@ -99,7 +99,7 @@ public class DplbotServiceUtil {
return usId;
}
private static String getUserIdByToken(String accessToken) {
static String getUserIdByToken(String accessToken) {
try {
HashMap<String, String> headers = new HashMap<>();
headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
......@@ -235,8 +235,8 @@ public class DplbotServiceUtil {
static boolean didUserCollecThisProduct(String botAccount, String userID, String accessToken, String jytUserId) {
UserBehaviorData data = USER_HISTORY.get(userID);
if (data != null) {
Byte count = data.getUserBotId2Collected().get(botAccount);
return count != null;
Long time = data.getUserBotId2Collected().get(botAccount);
return time != null;
} else {
onLunchFillUserBehaviorData(accessToken, userID);
if (jytUserId == null) {
......@@ -293,7 +293,7 @@ public class DplbotServiceUtil {
}
UserBehaviorData behaviorData = USER_HISTORY.get(userId);
if (behaviorData != null) {
behaviorData.getUserBotId2Collected().put(botAccount, BYTE_FILL);
behaviorData.getUserBotId2Collected().put(botAccount, curTime);
} else {
if (jytUserId != null) {
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
......@@ -402,7 +402,7 @@ public class DplbotServiceUtil {
if (historyTB.getLastTime().equals(time)) continue;
historyTB.setLastTime(time);
}
repository.saveAndFlush(historyTB);
repository.save(historyTB);
}
}
});
......@@ -496,15 +496,34 @@ public class DplbotServiceUtil {
});
}
static CollectHistoryDocument getCollectPage(String userId, String accessToken, String jytId) {
Collection<String> favoriteProducts;
static CollectHistoryDocument getCollectPage(String userId, String accessToken, String jytId, int start) {
List<String> favoriteProducts = new ArrayList<>();
UserBehaviorData behaviorData = USER_HISTORY.get(userId);
int pageNum = 0;
if (behaviorData == null) {
onLunchFillUserBehaviorData(accessToken, userId);
if (jytId == null) jytId = getUserIdByToken(accessToken);
if (jytId != null) {
AppFavoriteTBRepository favorite = BaseHolder.getBean("appFavoriteTBRepository");
favoriteProducts = favorite.getFavoriteBotIds(Long.parseLong(jytId));
favoriteProducts = favorite.getFavoriteLimit(Long.parseLong(jytId), start);
}
}else {
favoriteProducts = behaviorData.getUserBotId2Collected().keySet();
int bound = behaviorData.getUserBotId2Collected().size();
if (start >= bound) {
return null;
}
pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1);
TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1));
for (Map.Entry<String, Long> entry: behaviorData.getUserBotId2Collected().entrySet()) {
order.put(entry.getValue(), entry.getKey());
}
int i = 0, e = start+CO_HI_PAGE_SIZE;
for (Map.Entry<Long, String> entry: order.entrySet()) {
if (i == e) break;
if (i++ >= start) {
favoriteProducts.add(entry.getValue());
}
}
}
if (favoriteProducts.size() == 0) return null;
ArrayList<HistoryData> projectInfoList = new ArrayList<>();
......@@ -524,7 +543,8 @@ public class DplbotServiceUtil {
data.setAuthorName(productDetail.getAuthorName());
projectInfoList.add(data);
}
CollectHistoryDocument collectHistoryDocument = CollectHistoryUtils.getDocument(projectInfoList, true);
CollectHistoryDocument collectHistoryDocument = CollectHistoryUtils.getDocument(projectInfoList, true,
start/CO_HI_PAGE_SIZE+1, pageNum);
String idToken;
if (build.length() != 0) {
build.deleteCharAt(build.length()-1);
......@@ -534,21 +554,33 @@ public class DplbotServiceUtil {
return collectHistoryDocument;
}
static CollectHistoryDocument getHistory(String userId, String accessToken) {
static CollectHistoryDocument getHistory(String userId, String accessToken, int start) {
List<XiaoDuHistoryBotIdTime> historyProducts = new ArrayList<>();
UserBehaviorData behaviorData = USER_HISTORY.get(userId);
int pageNum = 0;
if (behaviorData == null) {
onLunchFillUserBehaviorData(accessToken, userId);
XiaoDuHistoryBotTimeRepository historyRepository = BaseHolder.getBean("xiaoDuHistoryBotTimeRepository");
historyProducts = historyRepository.getByXiaoduUserId(userId);
historyProducts = historyRepository.getByXiaoduUserIdLimit(userId, start);
} else {
try {
int bound = behaviorData.getUserBotId2History().size();
if (start >= bound) return null;
pageNum = bound/CO_HI_PAGE_SIZE + (bound%CO_HI_PAGE_SIZE == 0 ? 0 : 1);
TreeMap<Long, String> order = new TreeMap<>((o1, o2) -> (o1 < o2) ? 1 : ((o1.equals(o2)) ? 0 : -1));
for (Map.Entry<String, Long> entry: behaviorData.getUserBotId2History().entrySet()) {
order.put(entry.getValue(), entry.getKey());
}
int i = 0, end = start+CO_HI_PAGE_SIZE;
for (Map.Entry<Long, String> entry: order.entrySet()) {
if (i == end) break;
if (i++ >= start) {
XiaoDuHistoryBotIdTime history = new XiaoDuHistoryBotIdTime();
history.setBotId(entry.getKey());
history.setLastTime(entry.getValue());
history.setBotId(entry.getValue());
history.setLastTime(entry.getKey());
historyProducts.add(history);
}
}
} catch (Exception e){}
}
if (historyProducts.size() == 0) return null;
......@@ -557,6 +589,7 @@ public class DplbotServiceUtil {
int i = 1;
final StringBuilder build = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
historyProducts.sort((o1, o2) -> (o1.getLastTime()<o2.getLastTime()) ? 1 : (o1.getLastTime().equals(o2.getLastTime())) ? 0 : -1);
for (XiaoDuHistoryBotIdTime historyInfo: historyProducts) {
String botAccount = historyInfo.getBotId();
build.append(botAccount).append(File.separator);
......@@ -572,7 +605,8 @@ public class DplbotServiceUtil {
data.setAuthorName(lastTime);
projectInfoList.add(data);
}
CollectHistoryDocument document = CollectHistoryUtils.getDocument(projectInfoList, false);
CollectHistoryDocument document = CollectHistoryUtils.getDocument(projectInfoList, false,
start/CO_HI_PAGE_SIZE+1, pageNum);
String idToken;
if (build.length() != 0) {
build.deleteCharAt(build.length()-1);
......
package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.BaseHolder;
import ai.qiwu.com.xiaoduhome.common.Config;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.common.temple.onLunch.LunchUtils;
import ai.qiwu.com.xiaoduhome.entity.primary.GameProjectTb;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.entity.secondary.XiaoDuHistoryTB;
import ai.qiwu.com.xiaoduhome.pojo.UserBehaviorData;
import ai.qiwu.com.xiaoduhome.pojo.playAside.AsideImageResponse;
import ai.qiwu.com.xiaoduhome.repository.primary.AllOnProductInfoRepository;
......@@ -90,7 +92,28 @@ public class ScheduleService implements InitializingBean {
UserBehaviorData data = DplbotServiceUtil.USER_HISTORY.get(userId);
if (data != null) {
if (data.getMark() == 1) data.setMark((byte) 0);
else needClear.add(userId);
else {
needClear.add(userId);
XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
for (Map.Entry<String, Long> entry: data.getUserBotId2History().entrySet()) {
String botId = entry.getKey();
Long time = entry.getValue();
XiaoDuHistoryTB historyTB = repository.getByXiaoduUserIdAndBotId(userId, botId);
if (historyTB == null) {
historyTB = new XiaoDuHistoryTB();
historyTB.setLastTime(time);
historyTB.setBotId(botId);
historyTB.setXiaoduUserId(userId);
} else {
if (historyTB.getLastTime().equals(time)) continue;
historyTB.setLastTime(time);
}
repository.save(historyTB);
}
data.setUserBotId2Collected(null);
data.setUserBotId2Flowers(null);
data.setUserBotId2History(null);
}
}
}
for (String userId: needClear) DplbotServiceUtil.USER_HISTORY.remove(userId);
......
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