ExhibitionController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. package com.fdage.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdage.aop.WebControllerLog;
  4. import com.fdage.enums.ResponEnum;
  5. import com.fdage.pojo.TbExhibition;
  6. import com.fdage.pojo.TbExhibitionCollection;
  7. import com.fdage.request.RequestCollection;
  8. import com.fdage.request.RequestExhibition;
  9. import com.fdage.respon.ResponExhibition;
  10. import com.fdage.respon.ResponInformation;
  11. import com.fdage.service.IExhibitionService;
  12. import com.fdage.util.AjaxJson;
  13. import com.fdage.util.DateUtil;
  14. import com.fdage.util.FileUtil;
  15. import com.github.pagehelper.PageInfo;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiImplicitParam;
  18. import io.swagger.annotations.ApiImplicitParams;
  19. import io.swagger.annotations.ApiOperation;
  20. import lombok.extern.slf4j.Slf4j;
  21. import org.springframework.beans.BeanUtils;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Value;
  24. import org.springframework.stereotype.Controller;
  25. import org.springframework.util.StringUtils;
  26. import org.springframework.web.bind.annotation.*;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import java.util.Date;
  29. import java.util.List;
  30. /**
  31. * Created by Hb_zzZ on 2019/9/12.
  32. */
  33. @Controller
  34. @RequestMapping("/zhoushan/exhibition")
  35. @Slf4j
  36. @Api(tags = "展示管理模块")
  37. public class ExhibitionController {
  38. @Value("${upload.exhibition}")
  39. private String uploadPath;
  40. @Autowired
  41. private IExhibitionService service;
  42. @PostMapping("insertExhibitionCollection")
  43. @ResponseBody
  44. @ApiOperation("新增展览方案-推送给文通")
  45. @ApiImplicitParams({
  46. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  47. @ApiImplicitParam(name = "collectionId", value = "文物id", dataType = "String")})
  48. public AjaxJson insertExhibitionCollection(@RequestBody RequestExhibition bo){
  49. if(bo == null || bo.getExhibitionId() == null || StringUtils.isEmpty(bo.getCollectionId())){
  50. // if(bo == null || bo.getExhibitionId() == null){
  51. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  52. }
  53. String[] ids = bo.getCollectionId().split(",");
  54. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  55. for(int i = 0, len = ids.length; i < len; i++){
  56. exhibitionCollection.setExhibitionId(bo.getExhibitionId());
  57. // 2021-08-16 by owen
  58. // if (ids.length > 1) {
  59. // exhibitionCollection.setCollectionId(Long.valueOf(ids[i]));
  60. // }
  61. exhibitionCollection.setCollectionId(Long.valueOf(ids[i]));
  62. service.insertExhibitionCollection(exhibitionCollection);
  63. }
  64. //发送sse消息
  65. SseController.send("data:" + "0\r\n");
  66. return AjaxJson.success();
  67. }
  68. @PostMapping("updateExhibitionCollection")
  69. @ResponseBody
  70. @ApiOperation("修改展览方案-推送给文通")
  71. @ApiImplicitParams({
  72. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  73. @ApiImplicitParam(name = "collectionId", value = "文物id", dataType = "String")})
  74. public AjaxJson updateExhibitionCollection(@RequestBody RequestExhibition bo){
  75. if(bo == null || bo.getExhibitionId() == null || StringUtils.isEmpty(bo.getCollectionId())){
  76. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  77. }
  78. service.deleteExhibitionCollection(bo.getExhibitionId());
  79. String[] ids = bo.getCollectionId().split(",");
  80. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  81. for(int i = 0, len = ids.length; i < len; i++){
  82. exhibitionCollection.setExhibitionId(bo.getExhibitionId());
  83. exhibitionCollection.setCollectionId(Long.valueOf(ids[i]));
  84. service.insertExhibitionCollection(exhibitionCollection);
  85. }
  86. //发送sse消息
  87. SseController.send("data:" + "0\r\n");
  88. return AjaxJson.success();
  89. }
  90. @PostMapping("addExhibition")
  91. @ResponseBody
  92. @WebControllerLog(description = "展示管理-新增展览方案")
  93. @ApiOperation("新增展览方案")
  94. @ApiImplicitParams({
  95. @ApiImplicitParam(name = "name", value = "展览方案名称", dataType = "String"),
  96. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  97. @ApiImplicitParam(name = "equipmentId", value = "关联设备id", dataType = "String"),
  98. @ApiImplicitParam(name = "webUrl", value = "展示封面", dataType = "String"),
  99. @ApiImplicitParam(name = "state", value = "状态,0:启用,1:禁用", dataType = "String")})
  100. public AjaxJson addExhibition(@RequestBody RequestExhibition bo){
  101. if(bo == null || StringUtils.isEmpty(bo.getName()) || bo.getTypeId() == null || bo.getState() == null){
  102. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  103. }
  104. TbExhibition exhibition = new TbExhibition();
  105. BeanUtils.copyProperties(bo, exhibition);
  106. service.insert(exhibition);
  107. return AjaxJson.success(exhibition);
  108. }
  109. @PostMapping("updateExhibition")
  110. @ResponseBody
  111. @WebControllerLog(description = "展示管理-修改展览方案")
  112. @ApiOperation("修改展览方案")
  113. @ApiImplicitParams({
  114. @ApiImplicitParam(name = "isSend", value = "是否推送给问题,1推送", dataType = "String"),
  115. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String"),
  116. @ApiImplicitParam(name = "name", value = "展览方案名称", dataType = "String"),
  117. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  118. @ApiImplicitParam(name = "equipmentId", value = "关联设备id", dataType = "String"),
  119. @ApiImplicitParam(name = "state", value = "状态,0:启用,1:禁用", dataType = "String")})
  120. public AjaxJson updateExhibition(@RequestBody RequestExhibition bo){
  121. if(bo == null || StringUtils.isEmpty(bo.getName()) || bo.getTypeId() == null || bo.getState() == null){
  122. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  123. }
  124. TbExhibition exhibition = new TbExhibition();
  125. BeanUtils.copyProperties(bo, exhibition);
  126. exhibition.setCreateTime(new Date());
  127. service.update(exhibition);
  128. if(bo.getIsSend() != null && bo.getIsSend() == 1){
  129. //发送sse消息
  130. SseController.send("data:" + "0\r\n");
  131. }
  132. return AjaxJson.success(exhibition);
  133. }
  134. @PostMapping("deleteExhibition")
  135. @ResponseBody
  136. @WebControllerLog(description = "展示管理-删除展览方案")
  137. @ApiOperation("删除展览方案")
  138. @ApiImplicitParams({
  139. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String")})
  140. public AjaxJson deleteExhibition(@RequestBody RequestExhibition bo){
  141. if(bo == null || bo.getId() == null){
  142. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  143. }
  144. service.delete(bo.getId());
  145. return AjaxJson.success();
  146. }
  147. @PostMapping("copyExhibition")
  148. @ResponseBody
  149. @WebControllerLog(description = "展示管理-复制展览方案")
  150. @ApiOperation("复制展览方案")
  151. @ApiImplicitParams({
  152. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String")})
  153. public AjaxJson copyExhibition(@RequestBody RequestExhibition bo){
  154. if(bo == null || bo.getId() == null){
  155. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  156. }
  157. TbExhibition exhibition = service.findById(bo.getId());
  158. exhibition.setId(null);
  159. exhibition.setState(1);
  160. service.insert(exhibition);
  161. List<ResponExhibition> list = service.findExhibitionCollection(bo.getId());
  162. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  163. for(ResponExhibition responExhibition : list){
  164. exhibitionCollection.setExhibitionId(exhibition.getId());
  165. exhibitionCollection.setCollectionId(responExhibition.getCollectionId());
  166. service.insertExhibitionCollection(exhibitionCollection);
  167. }
  168. return AjaxJson.success();
  169. }
  170. @PostMapping("findCollectionByExhibition")
  171. @ResponseBody
  172. @ApiOperation("通过展示方案找文物")
  173. @ApiImplicitParams({
  174. @ApiImplicitParam(name = "exhibitionId", value = "展览方案id", dataType = "String")})
  175. public AjaxJson findCollectionByExhibition(@RequestBody RequestExhibition bo){
  176. if(bo == null || bo.getExhibitionId() == null){
  177. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  178. }
  179. return AjaxJson.success(service.findCollectionByExhibition(bo.getExhibitionId()));
  180. }
  181. @PostMapping("list")
  182. @ResponseBody
  183. @WebControllerLog(description = "展示管理-获取展览方案列表")
  184. @ApiOperation("获取展览方案列表")
  185. @ApiImplicitParams({
  186. @ApiImplicitParam(name = "name", value = "方案名称", dataType = "String"),
  187. @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
  188. @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "String")})
  189. public AjaxJson list(@RequestBody RequestExhibition bo){
  190. List<ResponExhibition> list = service.findList(bo);
  191. for(ResponExhibition exhibition : list){
  192. exhibition.setCreateTime(String.valueOf(DateUtil.convert2CST(exhibition.getCreateTime())));
  193. }
  194. PageInfo<ResponExhibition> pageInfo = new PageInfo<>(list);
  195. return AjaxJson.success(pageInfo);
  196. }
  197. @PostMapping("getExhibitionByEquipmentId")
  198. @ResponseBody
  199. @ApiOperation("通过设备id获取展示方案")
  200. @ApiImplicitParams({
  201. @ApiImplicitParam(name = "equipmentId", value = "设备id", dataType = "String")})
  202. public AjaxJson getExhibitionByEquipmentId(@RequestBody RequestExhibition bo){
  203. if(bo == null || bo.getEquipmentId() == null){
  204. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  205. }
  206. ResponExhibition responExhibition = service.getExhibitionByEquipmentId(bo.getEquipmentId());
  207. return AjaxJson.success(responExhibition);
  208. }
  209. @PostMapping("getExhibitionById")
  210. @ResponseBody
  211. @ApiOperation("通过id获取展示方案")
  212. @ApiImplicitParams({
  213. @ApiImplicitParam(name = "id", value = "id", dataType = "String")})
  214. public AjaxJson getExhibitionById(@RequestBody RequestExhibition bo){
  215. if(bo == null || bo.getId() == null){
  216. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  217. }
  218. ResponExhibition responExhibition = service.getExhibitionById(bo.getId());
  219. return AjaxJson.success(responExhibition);
  220. }
  221. @PostMapping("/upload")
  222. @ResponseBody
  223. @ApiOperation("上传展示方案图片")
  224. @ApiImplicitParams({
  225. @ApiImplicitParam(name = "file", value = "文件流", dataType = "String")})
  226. public AjaxJson upload(@RequestParam(value = "filename", defaultValue = "") String name, @RequestParam("file") MultipartFile file){
  227. if(file == null){
  228. return AjaxJson.failure("参数不能为空");
  229. }
  230. String fileName = System.currentTimeMillis() + "_";
  231. if(org.apache.commons.lang3.StringUtils.isNotEmpty(name)){
  232. fileName = fileName + name;
  233. }else {
  234. fileName = fileName + file.getOriginalFilename();
  235. }
  236. log.info("图片地址:" + fileName);
  237. boolean flag = FileUtil.upload(file, uploadPath, fileName);
  238. if(!flag){
  239. return AjaxJson.failure("上传图片失败");
  240. }
  241. // Map<String, String> map = new HashMap<>();
  242. // map.put(path + "/" + fileName, "company/" + fileName);
  243. // uploadToAlibabaService.upload(map);
  244. return AjaxJson.success((Object) ("/exhibition/" + fileName));
  245. }
  246. @PostMapping("typeList")
  247. @ResponseBody
  248. @ApiOperation("获取展示类别列表")
  249. public AjaxJson typeList(){
  250. return AjaxJson.success(service.typeList());
  251. }
  252. }