| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- package top.lvzhiqiang.controller;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.multipart.MultipartFile;
- import top.lvzhiqiang.config.WebAppConfig;
- import top.lvzhiqiang.dto.R;
- import top.lvzhiqiang.exception.ParameterException;
- import top.lvzhiqiang.service.BgService;
- import top.lvzhiqiang.util.StringUtils;
- import javax.annotation.Resource;
- import java.io.File;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- /**
- * BG Controller
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @Controller
- @RequestMapping("/bg")
- public class BgController {
- @Resource
- private BgService bgService;
- @Value("${spring.profiles.active}")
- private String env;
- /**
- * 初始化骑兵数据
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @RequestMapping("/initVideoInfoData")
- @ResponseBody
- public String initVideoInfoData(Integer type, Integer isDel, String infantryType) {
- if (null == type) {
- throw new ParameterException("type不能为空!");
- }
- if (2 == type && StringUtils.isEmpty(infantryType)) {
- throw new ParameterException("选择步兵时infantryType不能为空!");
- }
- if (null == isDel) {
- isDel = 2;
- }
- bgService.initVideoInfoData(type, isDel, infantryType);
- return "success";
- }
- @RequestMapping("/ftlIndex")
- public String ftlIndex(Model model) {
- return "ftlIndex";
- }
- /**
- * 上传识别码文件
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @RequestMapping("/uploadFile4IdentificationCode")
- @ResponseBody
- public R uploadFile4IdentificationCode(MultipartFile file, Integer isDel) throws IOException {
- if (StringUtils.isEmpty(file.getOriginalFilename())) {
- throw new ParameterException("文件为空!");
- } else {
- if (!file.getOriginalFilename().toLowerCase().endsWith("txt")) {
- throw new ParameterException("文件格式不正确!!");
- }
- }
- if (null == isDel) {
- isDel = 2;
- }
- bgService.uploadFile4IdentificationCode(file.getInputStream(), isDel);
- return R.ok();
- }
- /**
- * 上传识别码文件
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @RequestMapping("/single4IdentificationCode")
- @ResponseBody
- public R single4IdentificationCode(String identificationCode) {
- if (StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("identificationCode为空!");
- }
- bgService.single4IdentificationCode(identificationCode);
- return R.ok();
- }
- /**
- * Jsoup IcodePool
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @RequestMapping("/jsoupIcodePool")
- @ResponseBody
- public R jsoupIcodePool(Integer status, Integer isDel, Integer ignoreRetryCount) {
- if (null == status) {
- status = 1;
- }
- if (null == isDel) {
- isDel = 2;
- }
- if (null == ignoreRetryCount) {
- ignoreRetryCount = 2;
- }
- bgService.jsoupIcodePool(status, isDel, ignoreRetryCount);
- return R.ok();
- }
- /**
- * Jsoup VideoInfoUncensored
- *
- * @author lvzhiqiang
- * 2022/5/4 19:27
- */
- @RequestMapping("/jsoupVideoInfoUncensored")
- @ResponseBody
- public R jsoupVideoInfoUncensored(Integer status) {
- if (null == status) {
- status = 1;
- }
- bgService.jsoupVideoInfoUncensored(status);
- return R.ok();
- }
- /**
- * Jsoup VideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/5 18:21
- */
- @RequestMapping("/jsoupVideoInfo")
- @ResponseBody
- public R jsoupVideoInfo(Integer status) {
- if (null == status) {
- status = 1;
- }
- bgService.jsoupVideoInfo(status);
- return R.ok();
- }
- /**
- * insertOrUpdateScoreOrComment
- *
- * @author lvzhiqiang
- * 2022/5/4 9:54
- */
- @RequestMapping("/insertOrUpdateScoreOrComment")
- @ResponseBody
- public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
- if (StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("identificationCode为空!");
- }
- if (StringUtils.isEmpty(score) && StringUtils.isEmpty(comment)) {
- throw new ParameterException("score和comment不能都为空!");
- }
- return bgService.insertOrUpdateScoreOrComment(identificationCode.toUpperCase(), score, comment);
- }
- /**
- * findVideoInfoOther
- *
- * @author lvzhiqiang
- * 2022/9/17 19:17
- */
- @RequestMapping("/findVideoInfoOther")
- @ResponseBody
- public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
- if (!"1".equals(crudT) && StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("identificationCode为空!");
- }
- return bgService.findVideoInfoOther(identificationCode.toUpperCase(), resolutionRatio, original, subtitle, recoding, crudT);
- }
- /**
- * findDicCode
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @RequestMapping("/findDicCode")
- @ResponseBody
- public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
- return bgService.findDicCode(codeDesc, order);
- }
- /**
- * findIcodePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @RequestMapping("/findIcodePool")
- @ResponseBody
- public String findIcodePool(String identificationCode, Integer status, String order) throws IllegalAccessException {
- if (StringUtils.isNotEmpty(identificationCode)) {
- identificationCode = identificationCode.toUpperCase();
- }
- return bgService.findIcodePool(identificationCode, status, order);
- }
- /**
- * findVideoSitePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @RequestMapping("/findVideoSitePool")
- @ResponseBody
- public String findVideoSitePool(String url, String order) throws IllegalAccessException {
- return bgService.findVideoSitePool(url, order);
- }
- /**
- * findVideoInfoPool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @RequestMapping("/findVideoInfoPool")
- @ResponseBody
- public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if (StringUtils.isNotEmpty(identificationCode)) {
- identificationCode = identificationCode.toUpperCase();
- }
- if (StringUtils.isEmpty(crudT)) {
- crudT = "1";
- }
- return bgService.findVideoInfoPool(identificationCode, type, order, crudT);
- }
- /**
- * findVideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @RequestMapping("/findVideoInfo")
- @ResponseBody
- public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if (StringUtils.isNotEmpty(identificationCode)) {
- identificationCode = identificationCode.toUpperCase();
- }
- if (StringUtils.isEmpty(crudT)) {
- crudT = "1";
- }
- return bgService.findVideoInfo(identificationCode, type, order, crudT);
- }
- /**
- * 删除影片
- *
- * @param identificationCode
- * @param parentTypeName
- * @param allFlag {1:是2:否}
- * @author lvzhiqiang
- * 2022/5/29 12:59
- */
- @RequestMapping("/delVideoInfo")
- @ResponseBody
- public R delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
- if (StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("识别码不能为空");
- }
- if (StringUtils.isEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
- throw new ParameterException("上级类型名称与所有不能同时为空");
- }
- bgService.delVideoInfo(identificationCode, parentTypeName, allFlag);
- return R.ok();
- }
- /**
- * 增加影片
- *
- * @param identificationCode
- * @param videoName
- * @param parentType
- * @param parentName
- * @param type
- * @author lvzhiqiang
- * 2022/9/27 20:54
- */
- @RequestMapping("/insertVideoInfo")
- @ResponseBody
- public R insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
- if (StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("识别码不能为空");
- }
- if (StringUtils.isEmpty(parentName)) {
- throw new ParameterException("parentName不能为空");
- }
- if (StringUtils.isEmpty(videoName) && type == 1) {
- throw new ParameterException("type为主体时videoName不可为空");
- }
- bgService.insertVideoInfo(identificationCode.trim().toUpperCase(), videoName, parentType, parentName, type);
- return R.ok();
- }
- /**
- * 上传影片识别码
- *
- * @author lvzhiqiang
- * 2022/9/30 19:46
- */
- @RequestMapping("/uploadVideoInfoImgs")
- @ResponseBody
- public R uploadVideoInfoImgs(@RequestParam("files") MultipartFile[] files, String identificationCode, String imgType) throws Exception {
- if (StringUtils.isEmpty(identificationCode)) {
- throw new ParameterException("识别码不能为空");
- }
- if (files == null || files.length == 0) {
- throw new ParameterException("文件为空!");
- }
- String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- File imgParentFile = new File(qibingPath.concat("骑兵步兵/").concat(identificationCode.trim().toUpperCase()).concat("/").concat(imgType));
- if (!imgParentFile.exists()) {
- imgParentFile.mkdirs();
- }
- JSONObject result = new JSONObject();
- int i = 0;
- JSONArray jsonArray = new JSONArray();
- for (MultipartFile file : files) {
- String originalFilename = file.getOriginalFilename();
- File imgFile = new File(imgParentFile, originalFilename);
- file.transferTo(imgFile);
- i++;
- jsonArray.add(BigDecimal.valueOf(file.getSize()).divide(new BigDecimal("1024")).setScale(0, RoundingMode.UP).toPlainString().concat("KB"));
- }
- result.put("totalNum", i);
- result.put("list", jsonArray);
- return R.ok().data(result);
- }
- }
|