CollectionController.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package com.fdage.controller;
  2. import com.fdage.aop.WebControllerLog;
  3. import com.fdage.constant.ConfigConstant;
  4. import com.fdage.constant.ConstantUrl;
  5. import com.fdage.enums.ResponEnum;
  6. import com.fdage.pojo.TbCollection;
  7. import com.fdage.request.RequestCollection;
  8. import com.fdage.respon.ResponCollection;
  9. import com.fdage.service.ICollectionService;
  10. import com.fdage.util.AjaxJson;
  11. import com.fdage.util.FileUtil;
  12. import com.github.pagehelper.PageInfo;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiImplicitParam;
  15. import io.swagger.annotations.ApiImplicitParams;
  16. import io.swagger.annotations.ApiOperation;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.web.bind.annotation.*;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import java.util.List;
  26. /**
  27. * Created by Hb_zzZ on 2019/9/11.
  28. */
  29. @Api(tags = "文物库模块")
  30. @Controller
  31. @RequestMapping("/zhoushan/collection")
  32. @Slf4j
  33. public class CollectionController {
  34. @Autowired
  35. private ICollectionService service;
  36. @Value("${upload.collection}")
  37. private String uploadPath;
  38. @Autowired
  39. ConfigConstant configConstant;
  40. @PostMapping("timeList")
  41. @ResponseBody
  42. @ApiOperation("获取年代列表")
  43. public AjaxJson timeList(){
  44. return AjaxJson.success(service.timeList());
  45. }
  46. @PostMapping("typeList")
  47. @ResponseBody
  48. @ApiOperation("获取文物类别列表")
  49. public AjaxJson typeList(@RequestBody RequestCollection bo){
  50. return AjaxJson.success(service.typeList(bo));
  51. }
  52. @PostMapping("addCollection")
  53. @ResponseBody
  54. @WebControllerLog(description = "文物库-新增文物")
  55. @ApiOperation("新增文物")
  56. // @ApiImplicitParams({
  57. // @ApiImplicitParam(name = "name", value = "文物名称", dataType = "String"),
  58. // @ApiImplicitParam(name = "description", value = "文物描述", dataType = "String"),
  59. // @ApiImplicitParam(name = "timeId", value = "年代id", dataType = "String"),
  60. // @ApiImplicitParam(name = "typeId", value = "类型id", dataType = "String"),
  61. // @ApiImplicitParam(name = "modelUrl", value = "文物模型url", dataType = "String"),
  62. // @ApiImplicitParam(name = "discoveryTime", value = "文物发现时间", dataType = "String"),
  63. // @ApiImplicitParam(name = "repairTime", value = "文物维修时间", dataType = "String"),
  64. // @ApiImplicitParam(name = "venue", value = "文物所在场馆", dataType = "String"),
  65. // @ApiImplicitParam(name = "contentUrl", value = "多媒体内容Url", dataType = "String"),
  66. // @ApiImplicitParam(name = "pic", value = "4dmodel文物的封面图", dataType = "String"),
  67. // @ApiImplicitParam(name = "num", value = "藏品编号", dataType = "String"),
  68. // @ApiImplicitParam(name = "state", value = "状态,0:展示,1:隐藏", dataType = "String")})
  69. public AjaxJson addCollection(@RequestBody RequestCollection bo){
  70. if(bo == null || StringUtils.isEmpty(bo.getName()) ||
  71. bo.getTimeId() == null || bo.getTypeId() == null){
  72. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  73. }
  74. TbCollection collection = new TbCollection();
  75. BeanUtils.copyProperties(bo, collection);
  76. collection.setUnityUrl("/collection/unity/" + bo.getDirCode());
  77. // collection.setUnityUrl(configConstant.serverBasePath + "/collection/unity/" + bo.getDirCode());
  78. service.insert(collection);
  79. return AjaxJson.success();
  80. }
  81. @PostMapping("updateCollection")
  82. @ResponseBody
  83. @WebControllerLog(description = "文物库-修改文物")
  84. @ApiOperation("修改文物")
  85. // @ApiImplicitParams({
  86. // @ApiImplicitParam(name = "id", value = "文物id", dataType = "String"),
  87. // @ApiImplicitParam(name = "name", value = "文物名称", dataType = "String"),
  88. // @ApiImplicitParam(name = "description", value = "文物描述", dataType = "String"),
  89. // @ApiImplicitParam(name = "timeId", value = "年代id", dataType = "String"),
  90. // @ApiImplicitParam(name = "typeId", value = "类型id", dataType = "String"),
  91. // @ApiImplicitParam(name = "modelUrl", value = "文物模型url", dataType = "String"),
  92. // @ApiImplicitParam(name = "discoveryTime", value = "文物发现时间", dataType = "String"),
  93. // @ApiImplicitParam(name = "repairTime", value = "文物维修时间", dataType = "String"),
  94. // @ApiImplicitParam(name = "venue", value = "文物所在场馆", dataType = "String"),
  95. // @ApiImplicitParam(name = "contentUrl", value = "多媒体内容Url", dataType = "String"),
  96. // @ApiImplicitParam(name = "pic", value = "4dmodel文物的封面图", dataType = "String"),
  97. // @ApiImplicitParam(name = "num", value = "藏品编号", dataType = "String"),
  98. // @ApiImplicitParam(name = "state", value = "状态,0:展示,1:隐藏", dataType = "String")})
  99. public AjaxJson updateCollection(@RequestBody RequestCollection bo){
  100. if(bo == null || StringUtils.isEmpty(bo.getName()) ||
  101. bo.getTimeId() == null || bo.getTypeId() == null ){
  102. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  103. }
  104. TbCollection collection = new TbCollection();
  105. BeanUtils.copyProperties(bo, collection);
  106. service.update(collection);
  107. return AjaxJson.success();
  108. }
  109. @PostMapping("deleteCollection")
  110. @ResponseBody
  111. @WebControllerLog(description = "文物库-删除文物")
  112. @ApiOperation("删除文物")
  113. @ApiImplicitParams({
  114. @ApiImplicitParam(name = "id", value = "文物id", dataType = "String")})
  115. public AjaxJson deleteCollection(@RequestBody RequestCollection bo){
  116. if(bo == null || bo.getId() == null){
  117. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  118. }
  119. service.deleteById(bo.getId());
  120. return AjaxJson.success();
  121. }
  122. @PostMapping("findById")
  123. @ResponseBody
  124. @WebControllerLog(description = "文物库-查询文物库详情")
  125. @ApiOperation("查询文物库详情")
  126. @ApiImplicitParams({
  127. @ApiImplicitParam(name = "id", value = "文物id", dataType = "String")})
  128. public AjaxJson findById(@RequestBody RequestCollection bo){
  129. if(bo == null || bo.getId() == null){
  130. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  131. }
  132. return AjaxJson.success(service.findById(bo.getId()));
  133. }
  134. @PostMapping("list")
  135. @ResponseBody
  136. @WebControllerLog(description = "文物库-获取文物列表")
  137. @ApiOperation("获取文物列表")
  138. @ApiImplicitParams({
  139. @ApiImplicitParam(name = "timeId", value = "年代id", dataType = "String"),
  140. @ApiImplicitParam(name = "typeId", value = "类型id", dataType = "String"),
  141. @ApiImplicitParam(name = "name", value = "文物名称", dataType = "String"),
  142. @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
  143. @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "String")})
  144. public AjaxJson list(@RequestBody RequestCollection bo){
  145. List<ResponCollection> list = service.findList(bo);
  146. PageInfo<ResponCollection> pageInfo = new PageInfo<>(list);
  147. return AjaxJson.success(pageInfo);
  148. }
  149. @PostMapping("/upload")
  150. @ResponseBody
  151. @ApiOperation("上传文物图片")
  152. @ApiImplicitParams({
  153. @ApiImplicitParam(name = "file", value = "文件流", dataType = "String")})
  154. public AjaxJson upload(@RequestParam(value = "filename", defaultValue = "") String name, @RequestParam("file") MultipartFile file){
  155. if(file == null){
  156. return AjaxJson.failure("参数不能为空");
  157. }
  158. String fileName = System.currentTimeMillis() + "_";
  159. if(StringUtils.isNotEmpty(name)){
  160. fileName = fileName + name;
  161. }else {
  162. fileName = fileName + file.getOriginalFilename();
  163. }
  164. log.info("图片地址:" + fileName);
  165. boolean flag = FileUtil.upload(file, uploadPath, fileName);
  166. if(!flag){
  167. return AjaxJson.failure("上传图片失败");
  168. }
  169. // Map<String, String> map = new HashMap<>();
  170. // map.put(path + "/" + fileName, "company/" + fileName);
  171. // uploadToAlibabaService.upload(map);
  172. return AjaxJson.success((Object) ("/collection/" + fileName));
  173. }
  174. /**
  175. * 2021-08-09
  176. * @param file
  177. * @param code
  178. * @return
  179. */
  180. @PostMapping("/uploadCode")
  181. @ApiOperation("上传Unity")
  182. @ResponseBody
  183. public AjaxJson uploadCode(MultipartFile file, String code){
  184. return service.uploadCode(file, code);
  185. }
  186. @RequestMapping("/importCollection")
  187. @ResponseBody
  188. @ApiOperation("导入文物数据")
  189. @ApiImplicitParams({
  190. @ApiImplicitParam(name = "file", value = "文件流", dataType = "String")})
  191. public AjaxJson importCollection(@RequestParam("file") MultipartFile file){
  192. if(file == null){
  193. return AjaxJson.failure("参数不能为空");
  194. }
  195. String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
  196. log.info("导入文物数据地址:" + fileName);
  197. boolean flag = FileUtil.upload(file, uploadPath, fileName);
  198. if(!flag){
  199. return AjaxJson.failure("导入文物数据失败");
  200. }
  201. return service.importCollection(uploadPath + "/" + fileName);
  202. }
  203. }