ZjxlCompanyCaseController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package cn.stylefeng.guns.zjxl.cnotroller;
  2. import cn.stylefeng.guns.zjxl.model.ZjxlArticleContent;
  3. import cn.stylefeng.guns.zjxl.model.ZjxlCompanyCase;
  4. import cn.stylefeng.guns.zjxl.service.ZjxlArticleContentService;
  5. import cn.stylefeng.guns.zjxl.service.ZjxlCompanyCaseService;
  6. import cn.stylefeng.guns.zjxlUtil.BaseController;
  7. import cn.stylefeng.guns.zjxlUtil.PageUtil;
  8. import com.alibaba.fastjson.JSONObject;
  9. import io.swagger.annotations.Api;
  10. import io.swagger.annotations.ApiOperation;
  11. import io.swagger.annotations.ApiParam;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. /***
  25. * @ClassName: ZjxlCompanyCaseController
  26. * @Description:
  27. * @Auther: shi kejing
  28. * @Date: 2020/11/2 9:21
  29. */
  30. @RestController
  31. @Api(description = "公司官网主页-公司案例")
  32. @RequestMapping(value = "/zjxl/CompanyCase")
  33. public class ZjxlCompanyCaseController extends BaseController {
  34. private Logger logger = (Logger) LoggerFactory.getLogger(ZjxlCompanyCaseController.class);
  35. @Autowired
  36. private ZjxlCompanyCaseService companyCaseService;
  37. @Autowired
  38. private ZjxlArticleContentService articleContentService;
  39. @Value("${article.id_url}")
  40. private String idUrl;
  41. @RequestMapping(value = "/findCompanyCaseById", method = RequestMethod.GET)
  42. @ApiOperation(value = "查看CompanyCase")
  43. public String findCompanyCaseById(@ApiParam(name = "id", value = "companyId", required = false) @RequestParam(value = "id", required = false)String id,
  44. @ApiParam(name = "name", value = "companyName", required = false) @RequestParam(value = "name", required = false)String name,
  45. @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo,
  46. @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){
  47. try {
  48. List<ZjxlCompanyCase> companyCaseList = companyCaseService.findById(id,name,pageNo-1,pageSize*pageNo);
  49. return write(200,"查询成功","data", PageUtil.getPage(companyCaseList,pageNo,pageSize,companyCaseService.allCount()));
  50. }catch (Exception e){
  51. e.printStackTrace();
  52. return write(-1,"查询失败");
  53. }
  54. }
  55. @RequestMapping(value = "/addCompanyCase", method = RequestMethod.POST)
  56. @ApiOperation(value = "添加公司案例")
  57. public String addCompanyCase(
  58. @ApiParam(name = "companyName", value = "案例名称", required = false) @RequestParam(value = "companyName", required = false)String companyName,
  59. @ApiParam(name = "companyDescribe", value = "案例描述", required = false) @RequestParam(value = "companyDescribe", required = false)String companyDescribe,
  60. @ApiParam(name = "companyDefaultImg", value = "默认图片", required = false) @RequestParam(value = "companyDefaultImg", required = false)String companyDefaultImg,
  61. @ApiParam(name = "companyExchangeImg", value = "交互图片", required = false) @RequestParam(value = "companyExchangeImg", required = false)String companyExchangeImg,
  62. @ApiParam(name = "companyAssociatedCase", value = "关联案例(对应的文章id)", required = false) @RequestParam(value = "companyAssociatedCase", required = false)String companyAssociatedCase,
  63. @ApiParam(name = "companyJumpUrl", value = "跳转链接", required = false) @RequestParam(value = "companyJumpUrl", required = false)String companyJumpUrl,
  64. @ApiParam(name = "companySort", value = "排序", required = false) @RequestParam(value = "companySort", required = false)Integer companySort,
  65. @ApiParam(name = "companyIsLine", value = "是否上线", required = false, defaultValue = "0") @RequestParam(value = "companyIsLine", required = false)Integer companyIsLine,
  66. @ApiParam(name = "companyTestBannerId", value = "测试用字段", required = false, defaultValue = "1") @RequestParam(value = "companyTestBannerId", required = false)String companyTestBannerId){
  67. try {
  68. ZjxlCompanyCase companyCase = new ZjxlCompanyCase();
  69. List<ZjxlCompanyCase> companyCases = companyCaseService.findAll();
  70. Iterator iterator = companyCases.iterator();
  71. while (iterator.hasNext()){
  72. if (companyName.equals(iterator.next())){
  73. return write(-1,"该案例名称已存在");
  74. }
  75. }
  76. companyCase.setCompanyName(companyName);
  77. companyCase.setCompanyDescribe(companyDescribe);
  78. companyCase.setCompanyDefaultImg(companyDefaultImg);
  79. companyCase.setCompanyExchangeImg(companyExchangeImg);
  80. //http://172.26.0.30:8080/zjxl/zjxlArticleContent/findArticleContentById?articleContentTitle=&id=1&pageNo=1&pageSize=10&systemDictType=
  81. // companyCase.setCompanyJumpUrl(idUrl+"id="+companyJumpUrl+"");
  82. companyCase.setCompanyJumpUrl(companyJumpUrl);
  83. companyCase.setCompanySort(companySort);
  84. companyCase.setCompanyIsLine(companyIsLine);
  85. companyCase.setCompanyTestBannerId(companyTestBannerId);
  86. List<ZjxlArticleContent> caseA = articleContentService.findArticleContentById(companyAssociatedCase);
  87. if (caseA.size()>0){
  88. JSONObject object = new JSONObject();
  89. object.put("articleContentId",caseA.get(0).getArticleContentId());
  90. object.put("articleContentType",caseA.get(0).getArticleContentType());
  91. object.put("articleContentClassify",caseA.get(0).getArticleContentClassify());
  92. object.put("articleContentSubclassify",caseA.get(0).getArticleContentSubclassify());
  93. object.put("articleContentTitle",caseA.get(0).getArticleContentTitle());
  94. companyCase.setCompanyAssociatedCase(object.toString());
  95. }else {
  96. return write(-1,"添加案例不存在");
  97. }
  98. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
  99. companyCase.setCompanyCreateTime(df.format(new Date()));// new Date()为获取当前系统时间
  100. return write(200,"添加成功","data",companyCaseService.addCompanyCase(companyCase));
  101. }catch (Exception e){
  102. e.printStackTrace();
  103. return write(-1,"添加失败");
  104. }
  105. }
  106. @RequestMapping(value = "/deleteCompanyCase", method = RequestMethod.POST)
  107. @ApiOperation(value = "根据id删除案例")
  108. public String deleteCompanyCase(String id){
  109. try{
  110. if (id == null){
  111. logger.info("删除合作伙伴 id===== "+id);
  112. return write(-1,"获取参数失败");
  113. }
  114. return write(200,"删除成功","data",companyCaseService.deleteCompanyCase(id));
  115. }catch (Exception e){
  116. e.printStackTrace();
  117. return write(-1,"删除失败");
  118. }
  119. }
  120. @RequestMapping(value = "/updateIsLine", method = RequestMethod.POST)
  121. @ApiOperation(value = "根据id修改案例是否上线")
  122. public String updateIsLine(String id, Integer isLine){
  123. try{
  124. if (id == null || isLine == null){
  125. logger.info("修改是否上线:id====="+id+",isLine===="+isLine);
  126. return write(-1,"获取参数失败");
  127. }
  128. return write(200,"修改成功","data",companyCaseService.updateIsLine(id, isLine));
  129. }catch (Exception e){
  130. e.printStackTrace();
  131. return write(-1,"修改失败");
  132. }
  133. }
  134. @RequestMapping(value = "/updateCompanyCase", method = RequestMethod.POST)
  135. @ApiOperation(value = "编辑公司案例")
  136. public String updateCompanyCase(
  137. @ApiParam(name = "companyId", value = "案例id", required = false) @RequestParam(value = "companyId", required = false)String companyId,
  138. @ApiParam(name = "companyName", value = "案例名称", required = false) @RequestParam(value = "companyName", required = false)String companyName,
  139. @ApiParam(name = "companyDescribe", value = "案例描述", required = false) @RequestParam(value = "companyDescribe", required = false)String companyDescribe,
  140. @ApiParam(name = "companyDefaultImg", value = "默认图片", required = false) @RequestParam(value = "companyDefaultImg", required = false)String companyDefaultImg,
  141. @ApiParam(name = "companyExchangeImg", value = "交互图片", required = false) @RequestParam(value = "companyExchangeImg", required = false)String companyExchangeImg,
  142. @ApiParam(name = "companyAssociatedCase", value = "关联案例(对应的文章id)", required = false) @RequestParam(value = "companyAssociatedCase", required = false)String companyAssociatedCase,
  143. @ApiParam(name = "companyJumpUrl", value = "跳转链接", required = false) @RequestParam(value = "companyJumpUrl", required = false)String companyJumpUrl,
  144. @ApiParam(name = "companySort", value = "排序", required = false) @RequestParam(value = "companySort", required = false)Integer companySort,
  145. @ApiParam(name = "companyIsLine", value = "是否上线", required = false, defaultValue = "0") @RequestParam(value = "companyIsLine", required = false)Integer companyIsLine,
  146. @ApiParam(name = "companyTestBannerId", value = "测试用字段", required = false, defaultValue = "1") @RequestParam(value = "companyTestBannerId", required = false)String companyTestBannerId){
  147. try {
  148. ZjxlCompanyCase companyCase = new ZjxlCompanyCase();
  149. companyCase.setCompanyId(companyId);
  150. List<ZjxlCompanyCase> companyCases = companyCaseService.findAll();
  151. Iterator iterator = companyCases.iterator();
  152. while (iterator.hasNext()){
  153. if (companyName.equals(iterator.next())){
  154. return write(-1,"该案例名称已存在");
  155. }
  156. }
  157. companyCase.setCompanyName(companyName);
  158. companyCase.setCompanyDescribe(companyDescribe);
  159. companyCase.setCompanyDefaultImg(companyDefaultImg);
  160. companyCase.setCompanyExchangeImg(companyExchangeImg);
  161. //http://172.26.0.30:8080/zjxl/zjxlArticleContent/findArticleContentById?articleContentTitle=&id=1&pageNo=1&pageSize=10&systemDictType=
  162. // companyCase.setCompanyJumpUrl(idUrl+"id="+companyJumpUrl+"");
  163. companyCase.setCompanyJumpUrl(companyJumpUrl);
  164. companyCase.setCompanySort(companySort);
  165. companyCase.setCompanyIsLine(companyIsLine);
  166. companyCase.setCompanyTestBannerId(companyTestBannerId);
  167. List<ZjxlArticleContent> caseA = articleContentService.findArticleContentById(companyAssociatedCase);
  168. if (caseA.size()>0){
  169. JSONObject object = new JSONObject();
  170. object.put("articleContentId",caseA.get(0).getArticleContentId());
  171. object.put("articleContentType",caseA.get(0).getArticleContentType());
  172. object.put("articleContentClassify",caseA.get(0).getArticleContentClassify());
  173. object.put("articleContentSubclassify",caseA.get(0).getArticleContentSubclassify());
  174. object.put("articleContentTitle",caseA.get(0).getArticleContentTitle());
  175. companyCase.setCompanyAssociatedCase(object.toString());
  176. }else {
  177. return write(-1,"添加案例不存在");
  178. }
  179. return write(200,"编辑成功","data",companyCaseService.updateCompanyCase(companyCase));
  180. }catch (Exception e){
  181. e.printStackTrace();
  182. return write(-1,"编辑失败");
  183. }
  184. }
  185. }