ZjxlCompanyCaseController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestMethod;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import java.text.SimpleDateFormat;
  20. import java.util.Date;
  21. import java.util.List;
  22. /***
  23. * @ClassName: ZjxlCompanyCaseController
  24. * @Description:
  25. * @Auther: shi kejing
  26. * @Date: 2020/11/2 9:21
  27. */
  28. @RestController
  29. @Api(description = "公司官网主页-公司案例")
  30. @RequestMapping(value = "/zjxl/CompanyCase")
  31. public class ZjxlCompanyCaseController extends BaseController {
  32. private Logger logger = (Logger) LoggerFactory.getLogger(ZjxlCompanyCaseController.class);
  33. @Autowired
  34. private ZjxlCompanyCaseService companyCaseService;
  35. @Autowired
  36. private ZjxlArticleContentService articleContentService;
  37. @RequestMapping(value = "/findCompanyCaseById", method = RequestMethod.GET)
  38. @ApiOperation(value = "查看CompanyCase")
  39. public String findCompanyCaseById(@ApiParam(name = "id", value = "companyId", required = false) @RequestParam(value = "id", required = false)String id,
  40. @ApiParam(name = "name", value = "companyName", required = false) @RequestParam(value = "name", required = false)String name,
  41. @ApiParam(name = "pageNo", value = "第几页", defaultValue = "1") @RequestParam(value = "pageNo", required = false) Integer pageNo,
  42. @ApiParam(name = "pageSize", value = "分页大小", defaultValue = "10") @RequestParam(value = "pageSize", required = false) Integer pageSize){
  43. try {
  44. List<ZjxlCompanyCase> companyCaseList = companyCaseService.findById(id,name,pageNo-1,pageSize);
  45. return write(200,"查询成功","data", PageUtil.getPage(companyCaseList,pageNo,pageSize,companyCaseService.allCount()));
  46. }catch (Exception e){
  47. e.printStackTrace();
  48. return write(-1,"查询失败");
  49. }
  50. }
  51. @RequestMapping(value = "/addCompanyCase", method = RequestMethod.POST)
  52. @ApiOperation(value = "添加公司案例")
  53. public String addCompanyCase(
  54. @ApiParam(name = "companyName", value = "案例名称", required = false) @RequestParam(value = "companyName", required = false)String companyName,
  55. @ApiParam(name = "companyDescribe", value = "案例描述", required = false) @RequestParam(value = "companyDescribe", required = false)String companyDescribe,
  56. @ApiParam(name = "companyDefaultImg", value = "默认图片", required = false) @RequestParam(value = "companyDefaultImg", required = false)String companyDefaultImg,
  57. @ApiParam(name = "companyExchangeImg", value = "交互图片", required = false) @RequestParam(value = "companyExchangeImg", required = false)String companyExchangeImg,
  58. @ApiParam(name = "companyAssociatedCase", value = "关联案例(对应的文章id)", required = false) @RequestParam(value = "companyAssociatedCase", required = false)String companyAssociatedCase,
  59. @ApiParam(name = "companyJumpUrl", value = "跳转链接", required = false) @RequestParam(value = "companyJumpUrl", required = false)String companyJumpUrl,
  60. @ApiParam(name = "companySort", value = "排序", required = false) @RequestParam(value = "companySort", required = false)Integer companySort,
  61. @ApiParam(name = "companyIsLine", value = "是否上线", required = false, defaultValue = "0") @RequestParam(value = "companyIsLine", required = false)Integer companyIsLine,
  62. @ApiParam(name = "companyTestBannerId", value = "测试用字段", required = false, defaultValue = "1") @RequestParam(value = "companyTestBannerId", required = false)String companyTestBannerId){
  63. try {
  64. ZjxlCompanyCase companyCase = new ZjxlCompanyCase();
  65. companyCase.setCompanyName(companyName);
  66. companyCase.setCompanyDescribe(companyDescribe);
  67. companyCase.setCompanyDefaultImg(companyDefaultImg);
  68. companyCase.setCompanyExchangeImg(companyExchangeImg);
  69. companyCase.setCompanyJumpUrl(companyJumpUrl);
  70. companyCase.setCompanySort(companySort);
  71. companyCase.setCompanyIsLine(companyIsLine);
  72. companyCase.setCompanyTestBannerId(companyTestBannerId);
  73. List<ZjxlArticleContent> caseA = articleContentService.findArticleContentById(companyAssociatedCase);
  74. if (caseA.size()>0){
  75. JSONObject object = new JSONObject();
  76. object.put("articleContentId",caseA.get(0).getArticleContentId());
  77. object.put("articleContentType",caseA.get(0).getArticleContentType());
  78. object.put("articleContentClassify",caseA.get(0).getArticleContentClassify());
  79. object.put("articleContentSubclassify",caseA.get(0).getArticleContentSubclassify());
  80. object.put("articleContentTitle",caseA.get(0).getArticleContentTitle());
  81. companyCase.setCompanyAssociatedCase(object.toString());
  82. }else {
  83. return write(-1,"添加案例不存在");
  84. }
  85. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
  86. companyCase.setCompanyCreateTime(df.format(new Date()));// new Date()为获取当前系统时间
  87. return write(200,"添加成功","data",companyCaseService.addCompanyCase(companyCase));
  88. }catch (Exception e){
  89. e.printStackTrace();
  90. return write(-1,"添加失败");
  91. }
  92. }
  93. @RequestMapping(value = "/deleteCompanyCase", method = RequestMethod.POST)
  94. @ApiOperation(value = "根据id删除案例")
  95. public String deleteCompanyCase(String id){
  96. try{
  97. if (id == null){
  98. logger.info("删除合作伙伴 id===== "+id);
  99. return write(-1,"获取参数失败");
  100. }
  101. return write(200,"删除成功","data",companyCaseService.deleteCompanyCase(id));
  102. }catch (Exception e){
  103. e.printStackTrace();
  104. return write(-1,"删除失败");
  105. }
  106. }
  107. @RequestMapping(value = "/updateIsLine", method = RequestMethod.POST)
  108. @ApiOperation(value = "根据id修改案例是否上线")
  109. public String updateIsLine(String id, Integer isLine){
  110. try{
  111. if (id == null || isLine == null){
  112. logger.info("修改是否上线:id====="+id+",isLine===="+isLine);
  113. return write(-1,"获取参数失败");
  114. }
  115. return write(200,"修改成功","data",companyCaseService.updateIsLine(id, isLine));
  116. }catch (Exception e){
  117. e.printStackTrace();
  118. return write(-1,"修改失败");
  119. }
  120. }
  121. }