| @@ -0,0 +1,96 @@ | |||||
| package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.json.JsonRootBean; | |||||
| import com.iformall.domain.po.sm.VoiceInfo; | |||||
| import com.iformall.domain.po.sm.VoiceLanguage; | |||||
| import com.iformall.domain.po.sm.VoiceMould; | |||||
| import com.iformall.enums.EnumSex; | |||||
| import com.iformall.mapper.VoiceLanguageMapper; | |||||
| import com.iformall.mapper.VoiceMapper; | |||||
| import com.iformall.mapper.VoiceMouldMapper; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.transaction.annotation.Transactional; | |||||
| import org.springframework.util.ObjectUtils; | |||||
| import org.springframework.util.StringUtils; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.*; | |||||
| @RestController | |||||
| @RequestMapping("/import") | |||||
| public class JsonImportController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private VoiceLanguageMapper voiceLanguageMapper; | |||||
| @Autowired | |||||
| private VoiceMouldMapper voiceMouldMapper; | |||||
| @Autowired | |||||
| private VoiceMapper voiceMapper; | |||||
| @Transactional(rollbackFor = Exception.class) | |||||
| @PostMapping("/json") | |||||
| public ResultData importMethod(@RequestBody List<JsonRootBean> list) { | |||||
| String str = "https://suimang.oss-accelerate.aliyuncs.com/builtin/country/"; | |||||
| HashSet<VoiceLanguage> set = new HashSet<>(); | |||||
| for (JsonRootBean bean : list) { | |||||
| VoiceLanguage language = new VoiceLanguage(); | |||||
| String[] split = bean.getLocale().split("-"); | |||||
| language.setCountry(split[0]); | |||||
| language.setLanguage(split[1]); | |||||
| language.setImg(str + split[0] + ".png"); | |||||
| language.setLocal(bean.getLocale()); | |||||
| language.setName(bean.getLocaleName()); | |||||
| language.setIsDel(0); | |||||
| set.add(language); | |||||
| } | |||||
| voiceLanguageMapper.saveBatch(set); | |||||
| List<VoiceInfo> list1 = new ArrayList<>(); | |||||
| for (JsonRootBean bean : list) { | |||||
| Date date = new Date(); | |||||
| VoiceInfo voiceInfo = new VoiceInfo(); | |||||
| voiceInfo.setIsDel(0); | |||||
| VoiceMould voiceMould = voiceMouldMapper.selectOne(new QueryWrapper<VoiceMould>().lambda().eq(VoiceMould::getMouldSmId, bean.getShortName()).eq(VoiceMould::getParentId, 0).select(VoiceMould::getId)); | |||||
| if (!ObjectUtils.isEmpty(voiceMould)) { | |||||
| voiceInfo.setId(voiceMould.getId()); | |||||
| } | |||||
| VoiceLanguage voiceLanguage = voiceLanguageMapper.selectOne(new QueryWrapper<VoiceLanguage>().lambda().eq(VoiceLanguage::getLocal, bean.getLocale())); | |||||
| if (!ObjectUtils.isEmpty(voiceLanguage)) { | |||||
| voiceInfo.setLanguageId(voiceLanguage.getId()); | |||||
| }else { | |||||
| System.out.println(bean.getName()); | |||||
| } | |||||
| String gender = bean.getGender(); | |||||
| if (gender.equals("Male")) { | |||||
| voiceInfo.setSex(EnumSex.MALE.getCode()); | |||||
| } else if (gender.equals("Female")) { | |||||
| voiceInfo.setSex(EnumSex.FEMALE.getCode()); | |||||
| } else { | |||||
| voiceInfo.setSex(EnumSex.UNKNOWN.getCode()); | |||||
| } | |||||
| voiceInfo.setDisplayName(bean.getDisplayName()); | |||||
| voiceInfo.setLocalName(bean.getLocalName()); | |||||
| voiceInfo.setMouldSmId(bean.getShortName()); | |||||
| voiceInfo.setSampleRateHertz(bean.getSampleRateHertz()); | |||||
| voiceInfo.setWordsPerMinute(bean.getWordsPerMinute()); | |||||
| voiceInfo.setVoiceType(bean.getVoiceType()); | |||||
| if (!StringUtils.isEmpty(bean.getStyleList())) { | |||||
| voiceInfo.setStyleList(JSON.toJSONString(bean.getStyleList())); | |||||
| } | |||||
| voiceInfo.setCreateDate(date); | |||||
| voiceInfo.setUpdateDate(date); | |||||
| list1.add(voiceInfo); | |||||
| } | |||||
| voiceMapper.saveBatch(list1); | |||||
| return new ResultData("导入完成"); | |||||
| } | |||||
| } | |||||
| @@ -11,15 +11,14 @@ import com.iformall.domain.po.sm.UserMouldVideo; | |||||
| import com.iformall.domain.po.sm.VoiceMould; | import com.iformall.domain.po.sm.VoiceMould; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.language.LanguageDetect; | import com.iformall.language.LanguageDetect; | ||||
| import com.iformall.service.sm.MouldPatchService; | |||||
| import com.iformall.service.sm.MouldPatchSignService; | |||||
| import com.iformall.service.sm.PersonMouldService; | |||||
| import com.iformall.service.sm.VoiceMouldService; | |||||
| import com.iformall.mapper.VoiceLanguageMapper; | |||||
| import com.iformall.service.sm.*; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.checkerframework.checker.units.qual.A; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -44,6 +43,12 @@ public class VoiceMouldController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private MouldPatchSignService mouldPatchSignService; | private MouldPatchSignService mouldPatchSignService; | ||||
| @Autowired | |||||
| private VoiceInfoService voiceInfoService; | |||||
| @Autowired | |||||
| private VoiceLanguageService voiceLanguageService; | |||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("获取语种") | @ApiOperation("获取语种") | ||||
| @GetMapping("getLanguages") | @GetMapping("getLanguages") | ||||
| @@ -131,4 +136,21 @@ public class VoiceMouldController extends BaseController { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @AuthIgnore | |||||
| @ApiOperation("语言选择下拉框") | |||||
| @GetMapping("/voiceTotal") | |||||
| @ApiImplicitParams({}) | |||||
| public ResultData voiceTotal() { | |||||
| logger.debug("[" + getIpAddr() + "] MouldPatchController::voiceTotal"); | |||||
| return new ResultData(voiceLanguageService.voiceTotal()); | |||||
| } | |||||
| @AuthIgnore | |||||
| @ApiOperation("选择声音选择风格") | |||||
| @GetMapping("/chooseType") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData chooseType(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] MouldPatchController::chooseType"); | |||||
| return new ResultData(voiceInfoService.chooseType(id)); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,114 @@ | |||||
| package com.iformall.domain.po.json; | |||||
| import java.util.List; | |||||
| public class JsonRootBean { | |||||
| private String name; | |||||
| private String displayName; | |||||
| private String localName; | |||||
| private String shortName; | |||||
| private String gender; | |||||
| private String locale; | |||||
| private String localeName; | |||||
| private String sampleRateHertz; | |||||
| private String voiceType; | |||||
| private String status; | |||||
| private String wordsPerMinute; | |||||
| private List<String> styleList; | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public String getDisplayName() { | |||||
| return displayName; | |||||
| } | |||||
| public void setDisplayName(String displayName) { | |||||
| this.displayName = displayName; | |||||
| } | |||||
| public String getLocalName() { | |||||
| return localName; | |||||
| } | |||||
| public void setLocalName(String localName) { | |||||
| this.localName = localName; | |||||
| } | |||||
| public String getShortName() { | |||||
| return shortName; | |||||
| } | |||||
| public void setShortName(String shortName) { | |||||
| this.shortName = shortName; | |||||
| } | |||||
| public String getGender() { | |||||
| return gender; | |||||
| } | |||||
| public void setGender(String gender) { | |||||
| this.gender = gender; | |||||
| } | |||||
| public String getLocale() { | |||||
| return locale; | |||||
| } | |||||
| public void setLocale(String locale) { | |||||
| this.locale = locale; | |||||
| } | |||||
| public String getLocaleName() { | |||||
| return localeName; | |||||
| } | |||||
| public void setLocaleName(String localeName) { | |||||
| this.localeName = localeName; | |||||
| } | |||||
| public String getSampleRateHertz() { | |||||
| return sampleRateHertz; | |||||
| } | |||||
| public void setSampleRateHertz(String sampleRateHertz) { | |||||
| this.sampleRateHertz = sampleRateHertz; | |||||
| } | |||||
| public String getVoiceType() { | |||||
| return voiceType; | |||||
| } | |||||
| public void setVoiceType(String voiceType) { | |||||
| this.voiceType = voiceType; | |||||
| } | |||||
| public String getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(String status) { | |||||
| this.status = status; | |||||
| } | |||||
| public String getWordsPerMinute() { | |||||
| return wordsPerMinute; | |||||
| } | |||||
| public void setWordsPerMinute(String wordsPerMinute) { | |||||
| this.wordsPerMinute = wordsPerMinute; | |||||
| } | |||||
| public List<String> getStyleList() { | |||||
| return styleList; | |||||
| } | |||||
| public void setStyleList(List<String> styleList) { | |||||
| this.styleList = styleList; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,75 @@ | |||||
| package com.iformall.domain.po.sm; | |||||
| import lombok.Data; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | |||||
| * 声音表 | |||||
| */ | |||||
| @Data | |||||
| public class VoiceInfo { | |||||
| /** | |||||
| * 主键ID | |||||
| */ | |||||
| private Long id; | |||||
| /** | |||||
| * 语种表id(voice_language.id) | |||||
| */ | |||||
| private Long languageId; | |||||
| /** | |||||
| * 租户ID | |||||
| */ | |||||
| private String tenantId; | |||||
| /** | |||||
| * 父租户ID | |||||
| */ | |||||
| private String parentTenantId; | |||||
| /** | |||||
| * 性别 | |||||
| */ | |||||
| private Integer sex; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String displayName; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String localName; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String mouldSmId; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String sampleRateHertz; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String wordsPerMinute; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String voiceType; | |||||
| /** | |||||
| * 说话类型json | |||||
| */ | |||||
| private String styleList; | |||||
| private List<String> style; | |||||
| /** | |||||
| * 创建时间 | |||||
| */ | |||||
| private Date createDate; | |||||
| /** | |||||
| * 更新时间 | |||||
| */ | |||||
| private Date updateDate; | |||||
| /** | |||||
| * 是否删除1是0否 | |||||
| */ | |||||
| private Integer isDel; | |||||
| } | |||||
| @@ -0,0 +1,75 @@ | |||||
| package com.iformall.domain.po.sm; | |||||
| import lombok.Data; | |||||
| import java.util.Date; | |||||
| import java.util.Objects; | |||||
| /** | |||||
| * 语种表 | |||||
| */ | |||||
| @Data | |||||
| public class VoiceLanguage implements Comparable { | |||||
| /** | |||||
| * 主键ID | |||||
| */ | |||||
| private Long id; | |||||
| /** | |||||
| * 租户ID | |||||
| */ | |||||
| private String tenantId; | |||||
| /** | |||||
| * 父租户ID | |||||
| */ | |||||
| private String parentTenantId; | |||||
| /** | |||||
| * 国家code | |||||
| */ | |||||
| private String country; | |||||
| /** | |||||
| * 语言code | |||||
| */ | |||||
| private String language; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String local; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private String name; | |||||
| /** | |||||
| * 图片 | |||||
| */ | |||||
| private String img; | |||||
| /** | |||||
| * 创建时间 | |||||
| */ | |||||
| private Date createDate; | |||||
| /** | |||||
| * 更新时间 | |||||
| */ | |||||
| private Date updateDate; | |||||
| /** | |||||
| * 是否删除1是0否 | |||||
| */ | |||||
| private Integer isDel; | |||||
| @Override | |||||
| public int compareTo(Object obj) { | |||||
| // 判断是否是学生类型 | |||||
| if (obj instanceof VoiceLanguage) { | |||||
| VoiceLanguage s = (VoiceLanguage) obj; | |||||
| // 如果是学生类型,如果学号相等,则不加入Set | |||||
| if (Objects.equals(s.getLanguage(), this.getLanguage()) && Objects.equals(s.getCountry(), this.getCountry())) { | |||||
| return 0; | |||||
| } else { | |||||
| return 1; | |||||
| } | |||||
| } else { | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.sm.VoiceLanguage; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.HashSet; | |||||
| public interface VoiceLanguageMapper extends CommonMapper<VoiceLanguage, String> { | |||||
| void saveBatch(@Param("set") HashSet<VoiceLanguage> set); | |||||
| } | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.sm.VoiceInfo; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.List; | |||||
| public interface VoiceMapper extends CommonMapper<VoiceInfo, String> { | |||||
| void saveBatch(@Param("list") List<VoiceInfo> list); | |||||
| } | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.iformall.service.sm; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.sm.VoiceInfo; | |||||
| import com.iformall.domain.po.sm.VoiceLanguage; | |||||
| import java.util.List; | |||||
| public interface VoiceInfoService { | |||||
| List<VoiceInfo> chooseType(Long id); | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.service.sm; | |||||
| import com.iformall.domain.po.sm.VoiceLanguage; | |||||
| import java.util.List; | |||||
| public interface VoiceLanguageService { | |||||
| List<VoiceLanguage> voiceTotal(); | |||||
| } | |||||
| @@ -0,0 +1,32 @@ | |||||
| package com.iformall.service.sm.impl; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
| import com.iformall.domain.po.sm.VoiceInfo; | |||||
| import com.iformall.mapper.VoiceMapper; | |||||
| import com.iformall.service.sm.VoiceInfoService; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class VoiceInfoServiceImpl implements VoiceInfoService { | |||||
| @Autowired | |||||
| private VoiceMapper voiceMapper; | |||||
| @Override | |||||
| public List<VoiceInfo> chooseType(Long id) { | |||||
| List<VoiceInfo> voiceInfos = voiceMapper.selectList(new LambdaQueryWrapper<VoiceInfo>().eq(VoiceInfo::getLanguageId, id).select(VoiceInfo::getId, VoiceInfo::getDisplayName, VoiceInfo::getStyleList)); | |||||
| voiceInfos.forEach(x -> { | |||||
| if (StringUtils.isNotEmpty(x.getStyleList())) { | |||||
| List<String> strings = JSON.parseArray(x.getStyleList(), String.class); | |||||
| x.setStyle(strings); | |||||
| } | |||||
| }); | |||||
| return voiceInfos; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,26 @@ | |||||
| package com.iformall.service.sm.impl; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||||
| import com.google.common.collect.Lists; | |||||
| import com.iformall.domain.po.sm.VoiceLanguage; | |||||
| import com.iformall.mapper.VoiceLanguageMapper; | |||||
| import com.iformall.service.sm.VoiceLanguageService; | |||||
| import org.apache.commons.collections.CollectionUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class VoiceLanguageServiceImpl implements VoiceLanguageService { | |||||
| @Autowired | |||||
| private VoiceLanguageMapper voiceLanguageMapper; | |||||
| @Override | |||||
| public List<VoiceLanguage> voiceTotal() { | |||||
| List<VoiceLanguage> languages = voiceLanguageMapper.selectList(new LambdaQueryWrapper<VoiceLanguage>().eq(VoiceLanguage::getIsDel, 0).select(VoiceLanguage::getId, VoiceLanguage::getName)); | |||||
| return CollectionUtils.isEmpty(languages) ? Lists.newArrayList() : languages; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| <?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="com.iformall.mapper.VoiceLanguageMapper"> | |||||
| <insert id="saveBatch" parameterType="java.util.HashSet"> | |||||
| INSERT INTO voice_language (`id`, `country`, | |||||
| `language`, `local`, `name`, `img`, `is_del`) | |||||
| VALUES | |||||
| <foreach collection="set" item="item" separator=","> | |||||
| ( | |||||
| #{item.id}, | |||||
| #{item.country}, | |||||
| #{item.language}, | |||||
| #{item.local}, | |||||
| #{item.name}, | |||||
| #{item.img}, | |||||
| #{item.isDel} | |||||
| ) | |||||
| </foreach> | |||||
| </insert> | |||||
| </mapper> | |||||
| @@ -0,0 +1,28 @@ | |||||
| <?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="com.iformall.mapper.VoiceMapper"> | |||||
| <insert id="saveBatch" parameterType="java.util.List"> | |||||
| INSERT INTO voice_info (`id`, `language_id`, `sex`, | |||||
| `display_name`, `local_name`, `mould_sm_id`, | |||||
| `sample_rate_hertz`, `words_per_minute`, `voice_type`, | |||||
| `style_list`, `create_date`, `update_date`, `is_del`) | |||||
| VALUES | |||||
| <foreach collection="list" item="item" separator=","> | |||||
| ( | |||||
| #{item.id}, | |||||
| #{item.languageId}, | |||||
| #{item.sex}, | |||||
| #{item.localName}, | |||||
| #{item.displayName}, | |||||
| #{item.mouldSmId}, | |||||
| #{item.sampleRateHertz}, | |||||
| #{item.wordsPerMinute}, | |||||
| #{item.voiceType}, | |||||
| #{item.styleList}, | |||||
| #{item.createDate}, | |||||
| #{item.updateDate}, | |||||
| #{item.isDel} | |||||
| ) | |||||
| </foreach> | |||||
| </insert> | |||||
| </mapper> | |||||