Commit 7b2df62c by 苗权威

9.23

parent 43bd8ab8
...@@ -20,8 +20,8 @@ public class Config { ...@@ -20,8 +20,8 @@ public class Config {
private static Properties properties; private static Properties properties;
static { static {
// String filename = "tts.properties"; String filename = "tts.properties";
String filename = "ttsTest.properties"; // String filename = "ttsTest.properties";
properties = new Properties(); properties = new Properties();
try { try {
properties.load(new InputStreamReader(Config.class.getClassLoader().getResourceAsStream(filename), StandardCharsets.UTF_8)); properties.load(new InputStreamReader(Config.class.getClassLoader().getResourceAsStream(filename), StandardCharsets.UTF_8));
......
...@@ -17,6 +17,8 @@ import java.nio.charset.Charset; ...@@ -17,6 +17,8 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
...@@ -437,8 +439,16 @@ public class TTSUtils { ...@@ -437,8 +439,16 @@ public class TTSUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
String v1 = "/home/yf01/下载/齐齐-人工配音关系对于表(1).csv"; String s = "好的。苏琪家好像是住北城,我家乡刚好在北城隔壁,顺路。";
String v2 = "/home/yf01/下载/%E6%B0%B4%E5%BF%83%E6%B9%96.csv"; Pattern pattern = Pattern.compile("\uD83C\uDD70(.*?)\uD83C\uDD71");
test(v1, v2); Matcher matcher = pattern.matcher(s);
System.out.println(matcher.find());
System.out.println(s);
// while (matcher.find()) {
// String variableText = matcher.group(1);
// System.out.println(variableText);
// }
String ss = "他们循{/xun2/}声{/sheng1/}来到一颗大榕树后{/hou4/}的一座^木{/mu4/}屋{/wu1/}旁,见到音乐家捧{/peng3/}着{/zhe/}一个像笛子一样的乐器正在入{/ru4/}神地吹奏{/zou4/}着{/zhe/}。后来,音乐家很高兴接纳了他们,并{/bing4/}在^木{/mu4/}屋{/wu1/}旁边给他们^安{/an1/}了新家,四个小伙伴和善良的音乐家开心地住在水{/shui3/}心{/xin1/}湖{/hu2/}边,再{/zai4/}也{/ye3/}不用担惊受怕了。每天和{/he2/}音乐家一起弹{/tan2/}奏{/zou4/}唱跳,认识他们的人都亲切地称他们为{/wei2/}“水{/shui3/}心{/xin1/}湖{/hu2/}的音乐家”。";
System.out.println(buildMP3Filename(ss));
} }
} }
...@@ -24,12 +24,12 @@ logging: ...@@ -24,12 +24,12 @@ logging:
level: level:
root: info root: info
server: server:
# port: 9663 port: 9663
port: 8188 # port: 8188
tomcat: tomcat:
accesslog: accesslog:
enabled: true enabled: true
pattern: '%h %l %u %t "%r" %s %b bytes %D ms' pattern: '%h %l %u %t "%r" %s %b bytes %D ms'
# directory: /home/ubuntu/project/tts/tomcat directory: /home/ubuntu/project/tts/tomcat
directory: /root/GameEditor/mqw/project/ttsTest/tomcat # directory: /root/GameEditor/mqw/project/ttsTest/tomcat
connection-timeout: 240000 connection-timeout: 240000
package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
/**
* @author 苗权威
* @dateTime 19-9-23 下午5:22
*/
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ProductInfoDocument {
private ProductInfoMainTemplate mainTemplate;
}
package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
/**
* @author 苗权威
* @dateTime 19-9-23 下午5:23
*/
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ProductInfoMainTemplate {
private List<String> parameters = new ArrayList<>();
private List<ProductInfoPojo> items;
public ProductInfoMainTemplate() {
this.parameters.add("payload");
this.items = new ArrayList<>();
}
}
package ai.qiwu.com.xiaoduhome.common.temple.productInfo;
import ai.qiwu.com.xiaoduhome.pojo.dpl.Event;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author 苗权威
* @dateTime 19-9-23 下午5:24
*/
@Getter
@Setter
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class ProductInfoPojo {
private String type;
private String position;
private String top;
private String bottom;
private String left;
private String src;
private String height;
private String width;
private String headerTitle;
private Boolean hasBackIcon;
private String componentId;
private List<ProductInfoPojo> items;
@JsonProperty("flex-direction")
private String flexDirection;
@JsonProperty("border-radius")
private String borderRadius;
@JsonProperty("scale-type")
private String scaleType;
@JsonProperty("margin-left")
private String marginLeft;
@JsonProperty("margin-top")
private String marginTop;
private List<Event> onClick;
@JsonProperty("font-size")
private String fontSize;
private String text;
@JsonProperty("max-lines")
private Integer maxLines;
@JsonProperty("margin-right")
private String marginRight;
@JsonProperty("line-height")
private String lineHeight;
@JsonProperty("text-overflow")
private String textOverflow;
@JsonProperty("align-items")
private String alignItems;
private List<String> hints;
}
...@@ -14,10 +14,10 @@ import javax.persistence.*; ...@@ -14,10 +14,10 @@ import javax.persistence.*;
public class AppFlowerTBTiny { public class AppFlowerTBTiny {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Long id;
@Column(name = "user_id") @Column(name = "user_id")
private Integer userId; private Long userId;
@Column(name = "unit_price") @Column(name = "unit_price")
private Double unitPrice; private Double unitPrice;
...@@ -26,5 +26,5 @@ public class AppFlowerTBTiny { ...@@ -26,5 +26,5 @@ public class AppFlowerTBTiny {
private String botId; private String botId;
@Column @Column
private Integer number; private Long number;
} }
...@@ -6,6 +6,7 @@ import com.csvreader.CsvReader; ...@@ -6,6 +6,7 @@ import com.csvreader.CsvReader;
import com.csvreader.CsvWriter; import com.csvreader.CsvWriter;
import com.eclipsesource.json.JsonObject; import com.eclipsesource.json.JsonObject;
import lombok.*; import lombok.*;
import org.apache.commons.lang3.StringUtils;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
...@@ -195,6 +196,6 @@ public class TestBuild { ...@@ -195,6 +196,6 @@ public class TestBuild {
String v2 = "/home/yf01/下载/齐齐-人工配音关系对于表.csv"; String v2 = "/home/yf01/下载/齐齐-人工配音关系对于表.csv";
//csvUtil(target, src, srcModify, v2); //csvUtil(target, src, srcModify, v2);
check(src, srcModify, target); //check(src, srcModify, target);
} }
} }
...@@ -13,8 +13,16 @@ import java.util.List; ...@@ -13,8 +13,16 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class UserBehaviorData { public class UserBehaviorData {
// 用户浏览历史
private volatile HashMap<String, Byte> userBotId2History = new HashMap<>(); private volatile HashMap<String, Byte> userBotId2History = new HashMap<>();
private volatile HashMap<String, Integer> userBotId2Flowers = new HashMap<>(); // 用户对作品所送花的数目
private volatile HashMap<String, Long> userBotId2Flowers = new HashMap<>();
// 用户是否收藏该作品
private volatile HashMap<String, Byte> userBotId2Collected = new HashMap<>(); private volatile HashMap<String, Byte> userBotId2Collected = new HashMap<>();
// timestamp与mark之间的关系:清扫线程每五分钟更新缓存中所有mark为1的对象的timestamp并将mark改为0,
// 若发现mark为0的timestamp五分钟之前的则删除缓存
private volatile Long timeStamp = System.currentTimeMillis(); private volatile Long timeStamp = System.currentTimeMillis();
private volatile Byte mark = 1;
private volatile String jytUserId;
} }
...@@ -30,6 +30,7 @@ public class Event { ...@@ -30,6 +30,7 @@ public class Event {
private String repeatCount; private String repeatCount;
private String position; private String position;
private String value; private String value;
private String repeatMode;
public Event() { public Event() {
} }
......
...@@ -36,7 +36,7 @@ public interface AppFavoriteTBRepository extends JpaRepository<AppFavoriteTB, In ...@@ -36,7 +36,7 @@ public interface AppFavoriteTBRepository extends JpaRepository<AppFavoriteTB, In
void deleteByBotIdAndUserId(String botId, Integer userId); void deleteByBotIdAndUserId(String botId, Integer userId);
@Query(value="SELECT bot_username from app_favorite_tb where user_id=?1", nativeQuery = true) @Query(value="SELECT bot_username from app_favorite_tb where user_id=?1", nativeQuery = true)
List<String> getFavoriteBotIds(Integer userId); List<String> getFavoriteBotIds(Long userId);
@Override @Override
<S extends AppFavoriteTB> long count(Example<S> example); <S extends AppFavoriteTB> long count(Example<S> example);
......
...@@ -2,6 +2,7 @@ package ai.qiwu.com.xiaoduhome.repository.primary; ...@@ -2,6 +2,7 @@ package ai.qiwu.com.xiaoduhome.repository.primary;
import ai.qiwu.com.xiaoduhome.entity.primary.AppFlowerTBTiny; import ai.qiwu.com.xiaoduhome.entity.primary.AppFlowerTBTiny;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -16,4 +17,7 @@ public interface AppFlowerTBTintRepository extends JpaRepository<AppFlowerTBTiny ...@@ -16,4 +17,7 @@ public interface AppFlowerTBTintRepository extends JpaRepository<AppFlowerTBTiny
AppFlowerTBTiny getByUserIdAndBotIdAndUnitPrice(Integer userId, String botId, Double unitPrice); AppFlowerTBTiny getByUserIdAndBotIdAndUnitPrice(Integer userId, String botId, Double unitPrice);
List<AppFlowerTBTiny> getByUserIdAndBotId(Integer userId, String botId); List<AppFlowerTBTiny> getByUserIdAndBotId(Integer userId, String botId);
@Query(value = "select number from app_flower_tb where user_id=?1 and bot_username=?2", nativeQuery = true)
List<Long> getFlowerNumByUserIdAndBotAccount(Long userId, String botAccount);
} }
...@@ -34,6 +34,6 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB ...@@ -34,6 +34,6 @@ public interface XiaoDuHistoryTBRepository extends JpaRepository<XiaoDuHistoryTB
XiaoDuHistoryTB getByXiaoduUserIdAndBotId(String xiaoduUserId, String botId); XiaoDuHistoryTB getByXiaoduUserIdAndBotId(String xiaoduUserId, String botId);
@Query(value = "select distinct bot_id from xiaodu_history_tb where xiaodu_user_id=?1",nativeQuery = true) @Query(value = "select bot_id from xiaodu_history_tb where xiaodu_user_id=?1",nativeQuery = true)
List<String> getUserHostory(String userId); List<String> getUserHostory(String userId);
} }
package ai.qiwu.com.xiaoduhome.service;
import ai.qiwu.com.xiaoduhome.common.BaseHolder;
import ai.qiwu.com.xiaoduhome.common.OkHttp3Utils;
import ai.qiwu.com.xiaoduhome.entity.primary.AppFavoriteTB;
import ai.qiwu.com.xiaoduhome.entity.primary.OnProductDetail;
import ai.qiwu.com.xiaoduhome.pojo.Payload;
import ai.qiwu.com.xiaoduhome.pojo.UserBehaviorData;
import ai.qiwu.com.xiaoduhome.pojo.UserInfoByTokenResult;
import ai.qiwu.com.xiaoduhome.repository.primary.AppFavoriteTBRepository;
import ai.qiwu.com.xiaoduhome.repository.primary.AppFlowerTBTintRepository;
import ai.qiwu.com.xiaoduhome.repository.secondary.XiaoDuHistoryTBRepository;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.data.domain.Example;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.BEARER;
import static ai.qiwu.com.xiaoduhome.common.Constants.XIAOWU_API.USER_ID_BY_TOKEN;
/**
* @author 苗权威
* @dateTime 19-9-23 上午10:26
*/
@Slf4j
public class DplbotServiceUtil {
private static final byte byteFill = 1;
private static final int CORE = Runtime.getRuntime().availableProcessors();
private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(CORE+1, 1500,
2500, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(CORE), new ThreadPoolExecutor.CallerRunsPolicy());
private static final ConcurrentHashMap<String, UserBehaviorData> USER_HISTORY = new ConcurrentHashMap<>();
static void getUserFavorite(final String userId, final String usUserId) {
POOL.submit(() -> {
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, byteFill);
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
static void getUserSendFlowerInfo(final String userId) {
POOL.submit(() -> {
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
AppFlowerTBTintRepository repository = BaseHolder.getBean("appFlowerTBTintRepository");
for (OnProductDetail detail: ScheduleService.getAllOnProduct()) {
long sum = 0;
List<Long> nums = repository.getFlowerNumByUserIdAndBotAccount(Long.parseLong(userId), detail.getBotAccount());
for (Long num: nums) sum += num;
data.getUserBotId2Flowers().put(detail.getBotAccount(), sum);
}
});
}
static String getUsUserId(String userId, String accessToken) {
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
String usId = data.getJytUserId();
if (usId == null) {
usId = getUserIdByToken(accessToken, userId);
data.setJytUserId(usId);
}
return usId;
}
static String getUserIdByToken(String accessToken, String userId) {
try {
HashMap<String, String> headers = new HashMap<>();
headers.put("App-Channel-Id", "JIAOYOUTIANXIA");
headers.put("Authorization", new StringBuilder(BEARER).append(accessToken).toString());
String str = OkHttp3Utils.doGet(USER_ID_BY_TOKEN, new HashMap<>(), headers);
log.info("getUserIdByToken:{}",str);
UserInfoByTokenResult info = JSON.parseObject(str, UserInfoByTokenResult.class);
if (info.getRetcode() == 0) {
Payload payload = JSON.parseObject(info.getPayload(), Payload.class);
String jytUserId = payload.getInfoId();
log.info("通过Token获取的用户在app端的id:{}", userId);
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
data.setJytUserId(jytUserId);
return jytUserId;
}
} catch (Exception e) {
log.error("获取郊游天下用户id出错:{}", ExceptionUtils.getStackTrace(e));
}
return null;
}
static void onLunchGetUserHistory(final String userId) {
DplbotServiceUtil.getPOOL().submit(() -> {
XiaoDuHistoryTBRepository repository = BaseHolder.getBean("xiaoDuHistoryTBRepository");
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
HashMap<String,Byte> userBotId2History = data.getUserBotId2History();
for (String botId: repository.getUserHostory(userId)) {
userBotId2History.put(botId, byteFill);
}
//log.info("用户历史记录:{}",USER_HISTORY);
});
}
static void onLunchFillUserBehaviorData(final String accessToken, final String userId) {
POOL.submit(() -> {
String jytUserId = DplbotServiceUtil.getUserIdByToken(accessToken, userId);
if (jytUserId != null) {
UserBehaviorData data = USER_HISTORY.computeIfAbsent(userId, s -> new UserBehaviorData());
data.setJytUserId(jytUserId);
getUserFavorite(userId, jytUserId);
getUserSendFlowerInfo(userId);
}
});
}
public static ThreadPoolExecutor getPOOL() {
return POOL;
}
static String getDPLTemple(String path) {
String temple = null;
try {
temple = getJsonFromName(path);
} catch (IOException e) {
log.error("没有获取到json字符串:{}", e.toString());
}
return temple;
}
private static String getJsonFromName(String filename) throws IOException {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
InputStreamReader reader = new InputStreamReader(inputStream);
char[] buffer = new char[512];
int ln;
StringBuilder builder = new StringBuilder();
while ((ln = reader.read(buffer)) != -1) {
builder.append(buffer, 0, ln);
}
return builder.toString();
}
static boolean doesUserCollectThisBot(String botID, String accessToken, String userId) {
boolean collected = false;
if (accessToken != null) {
UserBehaviorData userData = USER_HISTORY.get(userId);
if (userData != null) {
collected = userData.getUserBotId2Collected().containsKey(botID);
} else {
getUserFavorite(userId, getUsUserId(userId, accessToken));
try {
AppFavoriteTBRepository repository = BaseHolder.getBean("appFavoriteTBRepository");
AppFavoriteTB tb = new AppFavoriteTB();
tb.setBotId(botID);
tb.setUserId(Integer.valueOf(getUsUserId(userId, accessToken)));
Example<AppFavoriteTB> example = Example.of(tb);
collected = repository.exists(example);
} catch (Exception e) {
}
}
}
return collected;
}
static String getAsideText(String text) {
int i1 = text.indexOf("【");
int i2 = text.indexOf("@");
return text.substring(i1+1, i2);
}
}
...@@ -157,11 +157,15 @@ public class ScheduleService implements InitializingBean { ...@@ -157,11 +157,15 @@ public class ScheduleService implements InitializingBean {
} }
private void getAsideImg() { private void getAsideImg() {
DplBotService.POOL.submit(() -> { DplbotServiceUtil.getPOOL().submit(() -> {
List<String> botIds = gameProjectTbRepository.getAllOnTableProductIds(); List<String> botIds = gameProjectTbRepository.getAllOnTableProductIds();
for (String botId: botIds) { for (String botId: botIds) {
try { try {
botId = HZ1_BOT_TO_NX2.get(botId); botId = HZ1_BOT_TO_NX2.get(botId);
if (botId == null) {
log.info("找不到对应关系:{}",botId);
continue;
}
HashMap<String, String> params = new HashMap<>(); HashMap<String, String> params = new HashMap<>();
params.put("include", "npcHeadImgUrl"); params.put("include", "npcHeadImgUrl");
params.put("aipioneerUsername",botId); params.put("aipioneerUsername",botId);
...@@ -286,14 +290,14 @@ public class ScheduleService implements InitializingBean { ...@@ -286,14 +290,14 @@ public class ScheduleService implements InitializingBean {
} }
public static String getAsideImgUrl(String botId, String name) { public static String getAsideImgUrl(String botId, String name) {
String url = DEFAULT_ASIDE_IMG_URL; String url;
Map<String,String> imgs = ASIDE_IMG.get(botId);
if (imgs == null) {
url = DEFAULT_ASIDE_IMG_URL;
} else {
url = imgs.get(name);
}
if (url == null) url = DEFAULT_ASIDE_IMG_URL;
return url; return url;
// Map<String,String> imgs = ASIDE_IMG.get(botId);
// if (imgs == null) {
// url = DEFAULT_ASIDE_IMG_URL
// }
// String url = ASIDE_IMG.get(botId).get(name);
// if (url == null) url = DEFAULT_ASIDE_IMG_URL;
// return url;
} }
} }
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