79931cdf5a2ad76b015a358951013a7f1da797ec.svn-base 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package cn.com.goldenwater.dcproj.controller.tac;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dto.TacSlbLawIndexDto;
  5. import cn.com.goldenwater.dcproj.model.TacSlbLawIndex;
  6. import cn.com.goldenwater.dcproj.param.TacSlbLawIndexParam;
  7. import cn.com.goldenwater.dcproj.service.GwComFileService;
  8. import cn.com.goldenwater.dcproj.service.TacSlbLawIndexService;
  9. import cn.com.goldenwater.dcproj.utils.WorldExoprtWithPicUtils;
  10. import cn.com.goldenwater.id.util.UuidUtil;
  11. import com.github.pagehelper.PageInfo;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import io.swagger.annotations.ApiParam;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.web.bind.annotation.*;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * @author lune
  26. * @date 2019-9-25
  27. */
  28. @Api(value = "TAC 法律法规目录索引管理", tags = "TAC 法律法规目录索引管理")
  29. @RestController
  30. @RequestMapping("/tac/slb/law/index")
  31. public class TacSlbLawIndexController extends BaseController {
  32. private Logger logger = LoggerFactory.getLogger(getClass());
  33. @Value("${export.basePath.docx}")
  34. private String docxPath;
  35. @Value("${web.upload-path}")
  36. private String uploadPath;
  37. @Value("${export.basePath.docx.path}")
  38. private String baseDocxPath;
  39. @Value("${getFile.prefix}")
  40. private String filePreFix;
  41. @Autowired
  42. private TacSlbLawIndexService tacSlbLawIndexService;
  43. @Autowired
  44. private GwComFileService comFileService;
  45. @ApiOperation(value = "添加/修改")
  46. @RequestMapping(value = "", method = RequestMethod.POST)
  47. public BaseResponse<TacSlbLawIndex> insert(@ApiParam(name = "tacSlbLawIndex", value = "TacSlbLawIndex", required = true) @RequestBody TacSlbLawIndex tacSlbLawIndex) {
  48. tacSlbLawIndex.setFlagValid("1");
  49. if (StringUtils.isNotBlank(tacSlbLawIndex.getDocId() + "")) {
  50. List<TacSlbLawIndex> slbLawIndices = tacSlbLawIndexService.findDocs(1, Integer.parseInt(tacSlbLawIndex.getDocId()));
  51. if (slbLawIndices != null && slbLawIndices.size() == 1) {
  52. String title = slbLawIndices.get(0).getLawTitle();
  53. tacSlbLawIndex.setLawTitle(title);
  54. }
  55. }
  56. if (StringUtils.isBlank(tacSlbLawIndex.getId())) {
  57. String uuid = UuidUtil.uuid(); // 生成uuid
  58. tacSlbLawIndex.setId(uuid);
  59. tacSlbLawIndex.setFileId(uuid);
  60. tacSlbLawIndexService.insert(tacSlbLawIndex);
  61. } else {
  62. tacSlbLawIndexService.update(tacSlbLawIndex);
  63. }
  64. return buildSuccessResponse(tacSlbLawIndex);
  65. }
  66. @ApiOperation(value = "根据ID删除")
  67. @RequestMapping(value = "/del/{id}", method = RequestMethod.GET)
  68. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  69. int ret = tacSlbLawIndexService.deleteInFlag(id);
  70. return buildSuccessResponse();
  71. }
  72. @ApiOperation(value = "根据ID获取(单表)")
  73. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  74. public BaseResponse<TacSlbLawIndex> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  75. TacSlbLawIndex tacSlbLawIndex = tacSlbLawIndexService.get(id);
  76. if (tacSlbLawIndex != null && StringUtils.isBlank(tacSlbLawIndex.getBookContent())) {
  77. tacSlbLawIndex.setGwComFile(comFileService.findFileByBiz(tacSlbLawIndex.getFileId()));
  78. }
  79. return buildSuccessResponse(tacSlbLawIndex);
  80. }
  81. @ApiOperation(value = "获取(列表所有)")
  82. @RequestMapping(value = "/list", method = RequestMethod.POST)
  83. public BaseResponse<List<TacSlbLawIndex>> list(@ApiParam(name = "tacSlbLawIndexParam", value = "tacSlbLawIndexParam", required = true) @RequestBody TacSlbLawIndexParam tacSlbLawIndexParam) {
  84. List<TacSlbLawIndex> tacSlbLawIndexList = tacSlbLawIndexService.findList(tacSlbLawIndexParam);
  85. return buildSuccessResponse(tacSlbLawIndexList);
  86. }
  87. @ApiOperation(value = "获取(列表--分页)")
  88. @RequestMapping(value = "/page", method = RequestMethod.POST)
  89. public BaseResponse<PageInfo<TacSlbLawIndex>> page(@ApiParam(name = "tacSlbLawIndexParam", value = "tacSlbLawIndexParam", required = true) @RequestBody TacSlbLawIndexParam tacSlbLawIndexParam) {
  90. if (tacSlbLawIndexParam.getLawKeyword().contains("*")) {
  91. return buildFailResponse("异常请求!");
  92. }
  93. PageInfo<TacSlbLawIndex> tacSlbLawIndexList = tacSlbLawIndexService.findPageInfo(tacSlbLawIndexParam);
  94. return buildSuccessResponse(tacSlbLawIndexList);
  95. }
  96. @ApiOperation(value = "获取(法规的所有篇幅,默认输入1)")
  97. @RequestMapping(value = "/list/{bookId}", method = RequestMethod.GET)
  98. public BaseResponse<List<TacSlbLawIndexDto>> listDocs(@PathVariable(required = true) int bookId) {
  99. List<TacSlbLawIndexDto> tacSlbLawIndexList = tacSlbLawIndexService.findDocs(bookId);
  100. return buildSuccessResponse(tacSlbLawIndexList);
  101. }
  102. @ApiOperation(value = "获取(法规的所有篇幅,默认输入1)")
  103. @RequestMapping(value = "/tree", method = RequestMethod.GET)
  104. public BaseResponse<List<TacSlbLawIndexDto>> tree() {
  105. List<TacSlbLawIndexDto> tacSlbLawIndexList = tacSlbLawIndexService.findDocs(1);
  106. for (TacSlbLawIndexDto lawIndex : tacSlbLawIndexList) {
  107. TacSlbLawIndexParam lawIndexParam = new TacSlbLawIndexParam();
  108. lawIndexParam.setDocId(lawIndex.getDocId() + "");
  109. List<TacSlbLawIndex> lawIndexList = tacSlbLawIndexService.findList(lawIndexParam);
  110. lawIndex.setChildren(lawIndexList);
  111. }
  112. return buildSuccessResponse(tacSlbLawIndexList);
  113. }
  114. @ApiOperation(value = "下载稽察法规")
  115. @RequestMapping(value = "/doc/{id}", method = RequestMethod.GET)
  116. public BaseResponse doc(@PathVariable String id) {
  117. TacSlbLawIndex slbLawIndex = tacSlbLawIndexService.get(id);
  118. StringBuffer buffer = new StringBuffer();
  119. String content = slbLawIndex.getBookContent().replace(slbLawIndex.getLawKeyword(), "").replace(slbLawIndex.getLawModify(), "");
  120. content = content.replace("\n", "<p/><p>");
  121. buffer.append("<h3>").append(slbLawIndex.getLawKeyword()).append("</h3>").append("<h4>")
  122. .append(slbLawIndex.getLawModify()).append("</h4>").append("<p>").append(content).append("</p>");
  123. try {
  124. uploadPath = uploadPath.replace(filePreFix, "");
  125. String filename = WorldExoprtWithPicUtils.createWord("tac_" + id, buffer.toString(), docxPath, uploadPath, "8");
  126. Map<String, String> params = new HashMap<>();
  127. params.put("downloadPath", baseDocxPath + filename);
  128. return buildSuccessResponse(params);
  129. } catch (Exception e) {
  130. e.printStackTrace();
  131. }
  132. return buildFailResponse();
  133. }
  134. }