ExhibitionController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  51. }
  52. String[] ids = bo.getCollectionId().split(",");
  53. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  54. for(int i = 0, len = ids.length; i < len; i++){
  55. exhibitionCollection.setExhibitionId(bo.getExhibitionId());
  56. exhibitionCollection.setCollectionId(Long.valueOf(ids[i]));
  57. service.insertExhibitionCollection(exhibitionCollection);
  58. }
  59. //发送sse消息
  60. SseController.send("data:" + "0\r\n");
  61. return AjaxJson.success();
  62. }
  63. @PostMapping("updateExhibitionCollection")
  64. @ResponseBody
  65. @ApiOperation("修改展览方案-推送给文通")
  66. @ApiImplicitParams({
  67. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  68. @ApiImplicitParam(name = "collectionId", value = "文物id", dataType = "String")})
  69. public AjaxJson updateExhibitionCollection(@RequestBody RequestExhibition bo){
  70. if(bo == null || bo.getExhibitionId() == null || StringUtils.isEmpty(bo.getCollectionId())){
  71. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  72. }
  73. service.deleteExhibitionCollection(bo.getExhibitionId());
  74. String[] ids = bo.getCollectionId().split(",");
  75. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  76. for(int i = 0, len = ids.length; i < len; i++){
  77. exhibitionCollection.setExhibitionId(bo.getExhibitionId());
  78. exhibitionCollection.setCollectionId(Long.valueOf(ids[i]));
  79. service.insertExhibitionCollection(exhibitionCollection);
  80. }
  81. //发送sse消息
  82. SseController.send("data:" + "0\r\n");
  83. return AjaxJson.success();
  84. }
  85. @PostMapping("addExhibition")
  86. @ResponseBody
  87. @WebControllerLog(description = "展示管理-新增展览方案")
  88. @ApiOperation("新增展览方案")
  89. @ApiImplicitParams({
  90. @ApiImplicitParam(name = "name", value = "展览方案名称", dataType = "String"),
  91. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  92. @ApiImplicitParam(name = "equipmentId", value = "关联设备id", dataType = "String"),
  93. @ApiImplicitParam(name = "webUrl", value = "展示封面", dataType = "String"),
  94. @ApiImplicitParam(name = "state", value = "状态,0:启用,1:禁用", dataType = "String")})
  95. public AjaxJson addExhibition(@RequestBody RequestExhibition bo){
  96. if(bo == null || StringUtils.isEmpty(bo.getName()) || bo.getTypeId() == null || bo.getState() == null){
  97. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  98. }
  99. TbExhibition exhibition = new TbExhibition();
  100. BeanUtils.copyProperties(bo, exhibition);
  101. service.insert(exhibition);
  102. return AjaxJson.success(exhibition);
  103. }
  104. @PostMapping("updateExhibition")
  105. @ResponseBody
  106. @WebControllerLog(description = "展示管理-修改展览方案")
  107. @ApiOperation("修改展览方案")
  108. @ApiImplicitParams({
  109. @ApiImplicitParam(name = "isSend", value = "是否推送给问题,1推送", dataType = "String"),
  110. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String"),
  111. @ApiImplicitParam(name = "name", value = "展览方案名称", dataType = "String"),
  112. @ApiImplicitParam(name = "exhibitionId", value = "展览id", dataType = "String"),
  113. @ApiImplicitParam(name = "equipmentId", value = "关联设备id", dataType = "String"),
  114. @ApiImplicitParam(name = "state", value = "状态,0:启用,1:禁用", dataType = "String")})
  115. public AjaxJson updateExhibition(@RequestBody RequestExhibition bo){
  116. if(bo == null || StringUtils.isEmpty(bo.getName()) || bo.getTypeId() == null || bo.getState() == null){
  117. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  118. }
  119. TbExhibition exhibition = new TbExhibition();
  120. BeanUtils.copyProperties(bo, exhibition);
  121. exhibition.setCreateTime(new Date());
  122. service.update(exhibition);
  123. if(bo.getIsSend() != null && bo.getIsSend() == 1){
  124. //发送sse消息
  125. SseController.send("data:" + "0\r\n");
  126. }
  127. return AjaxJson.success(exhibition);
  128. }
  129. @PostMapping("deleteExhibition")
  130. @ResponseBody
  131. @WebControllerLog(description = "展示管理-删除展览方案")
  132. @ApiOperation("删除展览方案")
  133. @ApiImplicitParams({
  134. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String")})
  135. public AjaxJson deleteExhibition(@RequestBody RequestExhibition bo){
  136. if(bo == null || bo.getId() == null){
  137. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  138. }
  139. service.delete(bo.getId());
  140. return AjaxJson.success();
  141. }
  142. @PostMapping("copyExhibition")
  143. @ResponseBody
  144. @WebControllerLog(description = "展示管理-复制展览方案")
  145. @ApiOperation("复制展览方案")
  146. @ApiImplicitParams({
  147. @ApiImplicitParam(name = "id", value = "展览方案id", dataType = "String")})
  148. public AjaxJson copyExhibition(@RequestBody RequestExhibition bo){
  149. if(bo == null || bo.getId() == null){
  150. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  151. }
  152. TbExhibition exhibition = service.findById(bo.getId());
  153. exhibition.setId(null);
  154. exhibition.setState(1);
  155. service.insert(exhibition);
  156. List<ResponExhibition> list = service.findExhibitionCollection(bo.getId());
  157. TbExhibitionCollection exhibitionCollection = new TbExhibitionCollection();
  158. for(ResponExhibition responExhibition : list){
  159. exhibitionCollection.setExhibitionId(exhibition.getId());
  160. exhibitionCollection.setCollectionId(responExhibition.getCollectionId());
  161. service.insertExhibitionCollection(exhibitionCollection);
  162. }
  163. return AjaxJson.success();
  164. }
  165. @PostMapping("findCollectionByExhibition")
  166. @ResponseBody
  167. @ApiOperation("通过展示方案找文物")
  168. @ApiImplicitParams({
  169. @ApiImplicitParam(name = "exhibitionId", value = "展览方案id", dataType = "String")})
  170. public AjaxJson findCollectionByExhibition(@RequestBody RequestExhibition bo){
  171. if(bo == null || bo.getExhibitionId() == null){
  172. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  173. }
  174. return AjaxJson.success(service.findCollectionByExhibition(bo.getExhibitionId()));
  175. }
  176. @PostMapping("list")
  177. @ResponseBody
  178. @WebControllerLog(description = "展示管理-获取展览方案列表")
  179. @ApiOperation("获取展览方案列表")
  180. @ApiImplicitParams({
  181. @ApiImplicitParam(name = "name", value = "方案名称", dataType = "String"),
  182. @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "String"),
  183. @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "String")})
  184. public AjaxJson list(@RequestBody RequestExhibition bo){
  185. List<ResponExhibition> list = service.findList(bo);
  186. for(ResponExhibition exhibition : list){
  187. exhibition.setCreateTime(String.valueOf(DateUtil.convert2CST(exhibition.getCreateTime())));
  188. }
  189. PageInfo<ResponExhibition> pageInfo = new PageInfo<>(list);
  190. return AjaxJson.success(pageInfo);
  191. }
  192. @PostMapping("getExhibitionByEquipmentId")
  193. @ResponseBody
  194. @ApiOperation("通过设备id获取展示方案")
  195. @ApiImplicitParams({
  196. @ApiImplicitParam(name = "equipmentId", value = "设备id", dataType = "String")})
  197. public AjaxJson getExhibitionByEquipmentId(@RequestBody RequestExhibition bo){
  198. if(bo == null || bo.getEquipmentId() == null){
  199. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  200. }
  201. ResponExhibition responExhibition = service.getExhibitionByEquipmentId(bo.getEquipmentId());
  202. return AjaxJson.success(responExhibition);
  203. }
  204. @PostMapping("getExhibitionById")
  205. @ResponseBody
  206. @ApiOperation("通过id获取展示方案")
  207. @ApiImplicitParams({
  208. @ApiImplicitParam(name = "id", value = "id", dataType = "String")})
  209. public AjaxJson getExhibitionById(@RequestBody RequestExhibition bo){
  210. if(bo == null || bo.getId() == null){
  211. return AjaxJson.failure(ResponEnum.NOT_NULL.getCode(), ResponEnum.NOT_NULL.getMessage());
  212. }
  213. ResponExhibition responExhibition = service.getExhibitionById(bo.getId());
  214. return AjaxJson.success(responExhibition);
  215. }
  216. @PostMapping("/upload")
  217. @ResponseBody
  218. @ApiOperation("上传展示方案图片")
  219. @ApiImplicitParams({
  220. @ApiImplicitParam(name = "file", value = "文件流", dataType = "String")})
  221. public AjaxJson upload(@RequestParam(value = "filename", defaultValue = "") String name, @RequestParam("file") MultipartFile file){
  222. if(file == null){
  223. return AjaxJson.failure("参数不能为空");
  224. }
  225. String fileName = System.currentTimeMillis() + "_";
  226. if(org.apache.commons.lang3.StringUtils.isNotEmpty(name)){
  227. fileName = fileName + name;
  228. }else {
  229. fileName = fileName + file.getOriginalFilename();
  230. }
  231. log.info("图片地址:" + fileName);
  232. boolean flag = FileUtil.upload(file, uploadPath, fileName);
  233. if(!flag){
  234. return AjaxJson.failure("上传图片失败");
  235. }
  236. // Map<String, String> map = new HashMap<>();
  237. // map.put(path + "/" + fileName, "company/" + fileName);
  238. // uploadToAlibabaService.upload(map);
  239. return AjaxJson.success((Object) ("/exhibition/" + fileName));
  240. }
  241. @PostMapping("typeList")
  242. @ResponseBody
  243. @ApiOperation("获取展示类别列表")
  244. public AjaxJson typeList(){
  245. return AjaxJson.success(service.typeList());
  246. }
  247. }