package com.iformall.controller; import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.sm.MouldPatch; import com.iformall.domain.po.sm.PersonMould; import com.iformall.domain.po.sm.UserMouldVideo; import com.iformall.domain.po.sm.VoiceMould; import com.iformall.enums.EnumLanguages; import com.iformall.enums.EnumMouldPatchType; import com.iformall.enums.EnumMouldSendType; import com.iformall.enums.EnumaMouldPatchStatus; 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 io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController @RequestMapping("/api/voiceMould") @Api(description = "模板接口") public class VoiceMouldController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private VoiceMouldService voiceMouldService; @Autowired private PersonMouldService personMouldService; @Autowired private MouldPatchSignService mouldPatchSignService; @ApiOperation("分页列表接口") @GetMapping("list") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData list(@ModelAttribute VoiceMould record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] MouldPatchController::list"); if (record == null) record = new VoiceMould(); // record.setSendType(EnumMouldSendType.auto.getCode()); record.setStatus(EnumaMouldPatchStatus.put_on.getCode()); record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = voiceMouldService.cListAsPage(record, pageNum, pageSize); return new ResultData(page); } @ApiOperation("根据id查询接口") @GetMapping("/findById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData findById(Long id) { logger.debug("[" + getIpAddr() + "] MouldPatchController::findById"); VoiceMould voiceMould = voiceMouldService.getDetailById(id); if(voiceMould != null && voiceMould.getParentId() == 0l && voiceMould.getCountSub() > 0){ VoiceMould voiceQ = new VoiceMould(); voiceQ.setParentId(voiceMould.getId()); voiceQ.setStatus(EnumaMouldPatchStatus.put_on.getCode()); voiceQ.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); List sublist = voiceMouldService.getClist(voiceQ); if(sublist != null && !sublist.isEmpty()){ voiceMould.setSubVoiceMould(sublist); } } return new ResultData(voiceMould); } @ApiOperation("根据输入文案获取音色") @PostMapping("voiceList") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData voiceList(@RequestBody UserMouldVideo record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] MouldPatchController::voiceList"); if (record == null || StringUtils.isBlank(record.getPaperwork())) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } Integer sex = null; if(record.getPersonMouldId() != null){ PersonMould personMode = personMouldService.getDetailById(record.getPersonMouldId()); if(personMode == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"选择模板不存在"); } sex = personMode.getSex(); } String detect = LanguageDetect.detect(record.getPaperwork()); if(StringUtils.isBlank(detect)){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"语种识别失败"); } EnumLanguages anEnum = EnumLanguages.getEnum(detect); if(anEnum == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"暂不支持该语种"); } VoiceMould voiceMould = new VoiceMould(); voiceMould.setParentId(0l); voiceMould.setSex(sex); voiceMould.setSendType(EnumMouldSendType.auto.getCode()); voiceMould.setStatus(EnumaMouldPatchStatus.put_on.getCode()); voiceMould.setLanguages(anEnum.getCode()); voiceMould.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = voiceMouldService.cListAsPage(voiceMould, pageNum, pageSize); return new ResultData(page); } }