BgController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. package top.lvzhiqiang.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.ui.Model;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestParam;
  9. import org.springframework.web.bind.annotation.ResponseBody;
  10. import org.springframework.web.multipart.MultipartFile;
  11. import top.lvzhiqiang.config.WebAppConfig;
  12. import top.lvzhiqiang.dto.R;
  13. import top.lvzhiqiang.exception.ParameterException;
  14. import top.lvzhiqiang.service.BgService;
  15. import top.lvzhiqiang.util.StringUtils;
  16. import javax.annotation.Resource;
  17. import java.io.File;
  18. import java.io.IOException;
  19. import java.math.BigDecimal;
  20. import java.math.RoundingMode;
  21. /**
  22. * BG Controller
  23. *
  24. * @author lvzhiqiang
  25. * 2022/4/16 16:10
  26. */
  27. @Controller
  28. @RequestMapping("/bg")
  29. public class BgController {
  30. @Resource
  31. private BgService bgService;
  32. @Value("${spring.profiles.active}")
  33. private String env;
  34. /**
  35. * 初始化骑兵数据
  36. *
  37. * @author lvzhiqiang
  38. * 2022/4/16 16:10
  39. */
  40. @RequestMapping("/initVideoInfoData")
  41. @ResponseBody
  42. public String initVideoInfoData(Integer type, Integer isDel, String infantryType) {
  43. if (null == type) {
  44. throw new ParameterException("type不能为空!");
  45. }
  46. if (2 == type && StringUtils.isEmpty(infantryType)) {
  47. throw new ParameterException("选择步兵时infantryType不能为空!");
  48. }
  49. if (null == isDel) {
  50. isDel = 2;
  51. }
  52. bgService.initVideoInfoData(type, isDel, infantryType);
  53. return "success";
  54. }
  55. @RequestMapping("/ftlIndex")
  56. public String ftlIndex(Model model) {
  57. return "ftlIndex";
  58. }
  59. /**
  60. * 上传识别码文件
  61. *
  62. * @author lvzhiqiang
  63. * 2022/4/16 16:10
  64. */
  65. @RequestMapping("/uploadFile4IdentificationCode")
  66. @ResponseBody
  67. public R uploadFile4IdentificationCode(MultipartFile file, Integer isDel) throws IOException {
  68. if (StringUtils.isEmpty(file.getOriginalFilename())) {
  69. throw new ParameterException("文件为空!");
  70. } else {
  71. if (!file.getOriginalFilename().toLowerCase().endsWith("txt")) {
  72. throw new ParameterException("文件格式不正确!!");
  73. }
  74. }
  75. if (null == isDel) {
  76. isDel = 2;
  77. }
  78. bgService.uploadFile4IdentificationCode(file.getInputStream(), isDel);
  79. return R.ok();
  80. }
  81. /**
  82. * 上传识别码文件
  83. *
  84. * @author lvzhiqiang
  85. * 2022/4/16 16:10
  86. */
  87. @RequestMapping("/single4IdentificationCode")
  88. @ResponseBody
  89. public R single4IdentificationCode(String identificationCode) {
  90. if (StringUtils.isEmpty(identificationCode)) {
  91. throw new ParameterException("identificationCode为空!");
  92. }
  93. bgService.single4IdentificationCode(identificationCode);
  94. return R.ok();
  95. }
  96. /**
  97. * Jsoup IcodePool
  98. *
  99. * @author lvzhiqiang
  100. * 2022/4/16 16:10
  101. */
  102. @RequestMapping("/jsoupIcodePool")
  103. @ResponseBody
  104. public R jsoupIcodePool(Integer status, Integer isDel, Integer ignoreRetryCount) {
  105. if (null == status) {
  106. status = 1;
  107. }
  108. if (null == isDel) {
  109. isDel = 2;
  110. }
  111. if (null == ignoreRetryCount) {
  112. ignoreRetryCount = 2;
  113. }
  114. bgService.jsoupIcodePool(status, isDel, ignoreRetryCount);
  115. return R.ok();
  116. }
  117. /**
  118. * Jsoup VideoInfoUncensored
  119. *
  120. * @author lvzhiqiang
  121. * 2022/5/4 19:27
  122. */
  123. @RequestMapping("/jsoupVideoInfoUncensored")
  124. @ResponseBody
  125. public R jsoupVideoInfoUncensored(Integer status) {
  126. if (null == status) {
  127. status = 1;
  128. }
  129. bgService.jsoupVideoInfoUncensored(status);
  130. return R.ok();
  131. }
  132. /**
  133. * Jsoup VideoInfo
  134. *
  135. * @author lvzhiqiang
  136. * 2022/5/5 18:21
  137. */
  138. @RequestMapping("/jsoupVideoInfo")
  139. @ResponseBody
  140. public R jsoupVideoInfo(Integer status) {
  141. if (null == status) {
  142. status = 1;
  143. }
  144. bgService.jsoupVideoInfo(status);
  145. return R.ok();
  146. }
  147. /**
  148. * insertOrUpdateScoreOrComment
  149. *
  150. * @author lvzhiqiang
  151. * 2022/5/4 9:54
  152. */
  153. @RequestMapping("/insertOrUpdateScoreOrComment")
  154. @ResponseBody
  155. public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
  156. if (StringUtils.isEmpty(identificationCode)) {
  157. throw new ParameterException("identificationCode为空!");
  158. }
  159. if (StringUtils.isEmpty(score) && StringUtils.isEmpty(comment)) {
  160. throw new ParameterException("score和comment不能都为空!");
  161. }
  162. return bgService.insertOrUpdateScoreOrComment(identificationCode.toUpperCase(), score, comment);
  163. }
  164. /**
  165. * findVideoInfoOther
  166. *
  167. * @author lvzhiqiang
  168. * 2022/9/17 19:17
  169. */
  170. @RequestMapping("/findVideoInfoOther")
  171. @ResponseBody
  172. public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
  173. if (!"1".equals(crudT) && StringUtils.isEmpty(identificationCode)) {
  174. throw new ParameterException("identificationCode为空!");
  175. }
  176. return bgService.findVideoInfoOther(identificationCode.toUpperCase(), resolutionRatio, original, subtitle, recoding, crudT);
  177. }
  178. /**
  179. * findDicCode
  180. *
  181. * @author lvzhiqiang
  182. * 2022/5/3 17:37
  183. */
  184. @RequestMapping("/findDicCode")
  185. @ResponseBody
  186. public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
  187. return bgService.findDicCode(codeDesc, order);
  188. }
  189. /**
  190. * findIcodePool
  191. *
  192. * @author lvzhiqiang
  193. * 2022/5/3 17:37
  194. */
  195. @RequestMapping("/findIcodePool")
  196. @ResponseBody
  197. public String findIcodePool(String identificationCode, Integer status, String order) throws IllegalAccessException {
  198. if (StringUtils.isNotEmpty(identificationCode)) {
  199. identificationCode = identificationCode.toUpperCase();
  200. }
  201. return bgService.findIcodePool(identificationCode, status, order);
  202. }
  203. /**
  204. * findVideoSitePool
  205. *
  206. * @author lvzhiqiang
  207. * 2022/5/3 17:37
  208. */
  209. @RequestMapping("/findVideoSitePool")
  210. @ResponseBody
  211. public String findVideoSitePool(String url, String order) throws IllegalAccessException {
  212. return bgService.findVideoSitePool(url, order);
  213. }
  214. /**
  215. * findVideoInfoPool
  216. *
  217. * @author lvzhiqiang
  218. * 2022/5/3 17:37
  219. */
  220. @RequestMapping("/findVideoInfoPool")
  221. @ResponseBody
  222. public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  223. if (StringUtils.isNotEmpty(identificationCode)) {
  224. identificationCode = identificationCode.toUpperCase();
  225. }
  226. if (StringUtils.isEmpty(crudT)) {
  227. crudT = "1";
  228. }
  229. return bgService.findVideoInfoPool(identificationCode, type, order, crudT);
  230. }
  231. /**
  232. * findVideoInfo
  233. *
  234. * @author lvzhiqiang
  235. * 2022/5/3 17:37
  236. */
  237. @RequestMapping("/findVideoInfo")
  238. @ResponseBody
  239. public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  240. if (StringUtils.isNotEmpty(identificationCode)) {
  241. identificationCode = identificationCode.toUpperCase();
  242. }
  243. if (StringUtils.isEmpty(crudT)) {
  244. crudT = "1";
  245. }
  246. return bgService.findVideoInfo(identificationCode, type, order, crudT);
  247. }
  248. /**
  249. * 删除影片
  250. *
  251. * @param identificationCode
  252. * @param parentTypeName
  253. * @param allFlag {1:是2:否}
  254. * @author lvzhiqiang
  255. * 2022/5/29 12:59
  256. */
  257. @RequestMapping("/delVideoInfo")
  258. @ResponseBody
  259. public R delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
  260. if (StringUtils.isEmpty(identificationCode)) {
  261. throw new ParameterException("识别码不能为空");
  262. }
  263. if (StringUtils.isEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
  264. throw new ParameterException("上级类型名称与所有不能同时为空");
  265. }
  266. bgService.delVideoInfo(identificationCode, parentTypeName, allFlag);
  267. return R.ok();
  268. }
  269. /**
  270. * 增加影片
  271. *
  272. * @param identificationCode
  273. * @param videoName
  274. * @param parentType
  275. * @param parentName
  276. * @param type
  277. * @author lvzhiqiang
  278. * 2022/9/27 20:54
  279. */
  280. @RequestMapping("/insertVideoInfo")
  281. @ResponseBody
  282. public R insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
  283. if (StringUtils.isEmpty(identificationCode)) {
  284. throw new ParameterException("识别码不能为空");
  285. }
  286. if (StringUtils.isEmpty(parentName)) {
  287. throw new ParameterException("parentName不能为空");
  288. }
  289. if (StringUtils.isEmpty(videoName) && type == 1) {
  290. throw new ParameterException("type为主体时videoName不可为空");
  291. }
  292. bgService.insertVideoInfo(identificationCode.trim().toUpperCase(), videoName, parentType, parentName, type);
  293. return R.ok();
  294. }
  295. /**
  296. * 上传影片识别码
  297. *
  298. * @author lvzhiqiang
  299. * 2022/9/30 19:46
  300. */
  301. @RequestMapping("/uploadVideoInfoImgs")
  302. @ResponseBody
  303. public R uploadVideoInfoImgs(@RequestParam("files") MultipartFile[] files, String identificationCode, String imgType) throws Exception {
  304. if (StringUtils.isEmpty(identificationCode)) {
  305. throw new ParameterException("识别码不能为空");
  306. }
  307. if (files == null || files.length == 0) {
  308. throw new ParameterException("文件为空!");
  309. }
  310. String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  311. File imgParentFile = new File(qibingPath.concat("骑兵步兵/").concat(identificationCode.trim().toUpperCase()).concat("/").concat(imgType));
  312. if (!imgParentFile.exists()) {
  313. imgParentFile.mkdirs();
  314. }
  315. JSONObject result = new JSONObject();
  316. int i = 0;
  317. JSONArray jsonArray = new JSONArray();
  318. for (MultipartFile file : files) {
  319. String originalFilename = file.getOriginalFilename();
  320. File imgFile = new File(imgParentFile, originalFilename);
  321. file.transferTo(imgFile);
  322. i++;
  323. jsonArray.add(BigDecimal.valueOf(file.getSize()).divide(new BigDecimal("1024")).setScale(0, RoundingMode.UP).toPlainString().concat("KB"));
  324. }
  325. result.put("totalNum", i);
  326. result.put("list", jsonArray);
  327. return R.ok().data(result);
  328. }
  329. }