package cn.com.goldenwater.dcproj.controller.tac; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.dto.TacSlbLawIndexDto; import cn.com.goldenwater.dcproj.model.TacSlbLawIndex; import cn.com.goldenwater.dcproj.param.TacSlbLawIndexParam; import cn.com.goldenwater.dcproj.service.GwComFileService; import cn.com.goldenwater.dcproj.service.TacSlbLawIndexService; import cn.com.goldenwater.dcproj.utils.WorldExoprtWithPicUtils; import cn.com.goldenwater.id.util.UuidUtil; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author lune * @date 2019-9-25 */ @Api(value = "TAC 法律法规目录索引管理", tags = "TAC 法律法规目录索引管理") @RestController @RequestMapping("/tac/slb/law/index") public class TacSlbLawIndexController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Value("${export.basePath.docx}") private String docxPath; @Value("${web.upload-path}") private String uploadPath; @Value("${export.basePath.docx.path}") private String baseDocxPath; @Value("${getFile.prefix}") private String filePreFix; @Autowired private TacSlbLawIndexService tacSlbLawIndexService; @Autowired private GwComFileService comFileService; @ApiOperation(value = "添加/修改") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "tacSlbLawIndex", value = "TacSlbLawIndex", required = true) @RequestBody TacSlbLawIndex tacSlbLawIndex) { tacSlbLawIndex.setFlagValid("1"); if (StringUtils.isNotBlank(tacSlbLawIndex.getDocId() + "")) { List slbLawIndices = tacSlbLawIndexService.findDocs(1, Integer.parseInt(tacSlbLawIndex.getDocId())); if (slbLawIndices != null && slbLawIndices.size() == 1) { String title = slbLawIndices.get(0).getLawTitle(); tacSlbLawIndex.setLawTitle(title); } } if (StringUtils.isBlank(tacSlbLawIndex.getId())) { String uuid = UuidUtil.uuid(); // 生成uuid tacSlbLawIndex.setId(uuid); tacSlbLawIndex.setFileId(uuid); tacSlbLawIndexService.insert(tacSlbLawIndex); } else { tacSlbLawIndexService.update(tacSlbLawIndex); } return buildSuccessResponse(tacSlbLawIndex); } @ApiOperation(value = "根据ID删除") @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = tacSlbLawIndexService.deleteInFlag(id); return buildSuccessResponse(); } @ApiOperation(value = "根据ID获取(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { TacSlbLawIndex tacSlbLawIndex = tacSlbLawIndexService.get(id); if (tacSlbLawIndex != null && StringUtils.isBlank(tacSlbLawIndex.getBookContent())) { tacSlbLawIndex.setGwComFile(comFileService.findFileByBiz(tacSlbLawIndex.getFileId())); } return buildSuccessResponse(tacSlbLawIndex); } @ApiOperation(value = "获取(列表所有)") @RequestMapping(value = "/list", method = RequestMethod.POST) public BaseResponse> list(@ApiParam(name = "tacSlbLawIndexParam", value = "tacSlbLawIndexParam", required = true) @RequestBody TacSlbLawIndexParam tacSlbLawIndexParam) { List tacSlbLawIndexList = tacSlbLawIndexService.findList(tacSlbLawIndexParam); return buildSuccessResponse(tacSlbLawIndexList); } @ApiOperation(value = "获取(列表--分页)") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse> page(@ApiParam(name = "tacSlbLawIndexParam", value = "tacSlbLawIndexParam", required = true) @RequestBody TacSlbLawIndexParam tacSlbLawIndexParam) { if (tacSlbLawIndexParam.getLawKeyword().contains("*")) { return buildFailResponse("异常请求!"); } PageInfo tacSlbLawIndexList = tacSlbLawIndexService.findPageInfo(tacSlbLawIndexParam); return buildSuccessResponse(tacSlbLawIndexList); } @ApiOperation(value = "获取(法规的所有篇幅,默认输入1)") @RequestMapping(value = "/list/{bookId}", method = RequestMethod.GET) public BaseResponse> listDocs(@PathVariable(required = true) int bookId) { List tacSlbLawIndexList = tacSlbLawIndexService.findDocs(bookId); return buildSuccessResponse(tacSlbLawIndexList); } @ApiOperation(value = "获取(法规的所有篇幅,默认输入1)") @RequestMapping(value = "/tree", method = RequestMethod.GET) public BaseResponse> tree() { List tacSlbLawIndexList = tacSlbLawIndexService.findDocs(1); for (TacSlbLawIndexDto lawIndex : tacSlbLawIndexList) { TacSlbLawIndexParam lawIndexParam = new TacSlbLawIndexParam(); lawIndexParam.setDocId(lawIndex.getDocId() + ""); List lawIndexList = tacSlbLawIndexService.findList(lawIndexParam); lawIndex.setChildren(lawIndexList); } return buildSuccessResponse(tacSlbLawIndexList); } @ApiOperation(value = "下载稽察法规") @RequestMapping(value = "/doc/{id}", method = RequestMethod.GET) public BaseResponse doc(@PathVariable String id) { TacSlbLawIndex slbLawIndex = tacSlbLawIndexService.get(id); StringBuffer buffer = new StringBuffer(); String content = slbLawIndex.getBookContent().replace(slbLawIndex.getLawKeyword(), "").replace(slbLawIndex.getLawModify(), ""); content = content.replace("\n", "

"); buffer.append("

").append(slbLawIndex.getLawKeyword()).append("

").append("

") .append(slbLawIndex.getLawModify()).append("

").append("

").append(content).append("

"); try { uploadPath = uploadPath.replace(filePreFix, ""); String filename = WorldExoprtWithPicUtils.createWord("tac_" + id, buffer.toString(), docxPath, uploadPath, "8"); Map params = new HashMap<>(); params.put("downloadPath", baseDocxPath + filename); return buildSuccessResponse(params); } catch (Exception e) { e.printStackTrace(); } return buildFailResponse(); } }