diff --git a/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java b/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java index 20f2c329..1d629b4a 100644 --- a/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java +++ b/renren-admin/src/main/java/io/renren/modules/category/controller/CategoryController.java @@ -15,6 +15,7 @@ import io.renren.modules.category.service.CategoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -26,12 +27,11 @@ import java.util.List; @Api(tags="编目管理") public class CategoryController { + @Value("${resource.devModelFilePath}") + private String devModelFilePath; @Autowired private CategoryService categoryService; - /** - * 查询顶级分类 - * @return - */ + @GetMapping("/getTopCategory") @ApiOperation("获取一级分类") public Result getTopCategory() { @@ -58,20 +58,19 @@ public class CategoryController { @PostMapping("/insert") @ApiOperation("保存") - @Transactional(rollbackFor = RuntimeException.class) + @Transactional(rollbackFor = Exception.class) public Object insert(@RequestBody CategoryDTO categoryDTO) { //效验数据 ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class); categoryDTO.setDelFlag(0); - categoryService.save(categoryDTO); //若为一级分类,增加文件夹 - //if (ObjectUtil.isNull(categoryDTO.getPid())) { - // File file = new File("D:\\新建文件夹\\resource\\" + categoryDTO.getName()); - // file.mkdirs(); - // if (file.mkdirs()) { - // throw new RuntimeException("创建文件夹失败!"); - // } - //} + if (ObjectUtil.isNull(categoryDTO.getPid())) { + File file = new File(devModelFilePath + categoryDTO.getName()); + if (file.mkdirs()) { + throw new RuntimeException("创建文件夹失败!"); + } + } + categoryService.save(categoryDTO); return new Result(); } diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java new file mode 100644 index 00000000..690dd608 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/controller/DevelopmentGuideController.java @@ -0,0 +1,86 @@ +package io.renren.modules.developmentGuide.controller; + +import io.renren.common.annotation.LogOperation; +import io.renren.common.utils.Result; +import io.renren.modules.developmentGuide.service.DevelopmentGuideService; +import io.renren.modules.resource.controller.ResourceController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +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 org.springframework.web.multipart.MultipartFile; +import springfox.documentation.annotations.ApiIgnore; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; + +@RestController +@RequestMapping("/developmentGuide") +@Api(tags = "开发指南") +public class DevelopmentGuideController { + + @Autowired + private DevelopmentGuideService developmentGuideService; + + @Value("${resource.devModelFilePath}") + private String devModelFilePath; + + private static Logger logger = LoggerFactory.getLogger(ResourceController.class); + + + @GetMapping("/getDevelopmentFile") + @ApiOperation("获取开发指南") + @LogOperation("获取开发指南") + @ApiImplicitParams({ + @ApiImplicitParam(name = "type", value = "类型", paramType = "query", required = true, dataType = "String"), + @ApiImplicitParam(name = "resourceId", value = "能力ID", paramType = "query", required = false, dataType = "Long"), + }) + public void getDevelopmentFile(@ApiIgnore HttpServletRequest request, @ApiIgnore HttpServletResponse response) { + try { + developmentGuideService.getDevelopmentFile(request, response); + } catch (Exception e) { + System.err.println(e.getMessage()); + e.printStackTrace(); + new Result<>().error(500, "文件获取失败!"); + } + } + + @PostMapping("/upload") + @ApiOperation("开发指南文件上传") + @ApiImplicitParams({ + @ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true) + }) + public Result upload(@RequestParam("file") MultipartFile uploadFile, + HttpServletRequest request) { + logger.info("上传文件:" + uploadFile.getOriginalFilename()); + File folder = new File(devModelFilePath); + if (!folder.isDirectory()) { + folder.mkdirs(); + } + if (folder.exists()) { + if (folder.isFile()) { + if (!folder.delete()) { + return new Result<>().error("保存开发指南失败!!!"); + } + } + } + // 对上传的文件重命名,避免文件重名 + String fileName = "devModelFile.md"; + try { + // 文件保存 + uploadFile.transferTo(new File(folder, fileName)); + + return new Result<>(); + } catch (IOException e) { + return new Result().error(e.getMessage()); + } + } + +} diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/DevelopmentGuideService.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/DevelopmentGuideService.java new file mode 100644 index 00000000..e2a0cc39 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/DevelopmentGuideService.java @@ -0,0 +1,11 @@ +package io.renren.modules.developmentGuide.service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public interface DevelopmentGuideService { + + void getDevelopmentFile(HttpServletRequest request, HttpServletResponse response) throws Exception; + + +} diff --git a/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java new file mode 100644 index 00000000..3dd7b2f8 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/modules/developmentGuide/service/impl/DevelopmentGuideServiceImpl.java @@ -0,0 +1,61 @@ +package io.renren.modules.developmentGuide.service.impl; + +import io.renren.modules.developmentGuide.service.DevelopmentGuideService; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; + +@Service +public class DevelopmentGuideServiceImpl implements DevelopmentGuideService { + + @Value("${resource.devModelFilePath}") + private String delModelFilePath; + + @Override + public void getDevelopmentFile(HttpServletRequest request, HttpServletResponse response) throws Exception { + //String type = request.getParameter("type").toString(); + //Long resourceId = Long.parseLong(request.getParameter("resourceId")); + //String url = type + "/devModelFile.txt"; + String url = delModelFilePath + File.separator + "devModelFile.md"; + File file = new File(url); + if (!file.exists()) { + Exception e = new Exception("文件不存在"); + e.printStackTrace(); + throw e;//抛出文件不存在的 + } + response.setContentType("text/html"); + FileInputStream fis = null; + OutputStream outputStream = response.getOutputStream(); + try { + fis = new FileInputStream(file); + //将读取流拷贝到输出流中 + IOUtils.copy(fis, outputStream); + //清空缓存的读取流,保证数据完整性 + response.flushBuffer(); + } catch (IOException e) { + System.err.println("解析失败!!!"); + e.printStackTrace(); + throw new Exception("解析失败"); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (outputStream != null) { + outputStream.close();//输出流关闭 + } + } + System.err.println("获取开发指南成功!!!"); + } + +} diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index fd11d13e..213bd7f3 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -39,9 +39,6 @@ import java.util.Map; @Api(tags = "资源表") public class ResourceController { - @Value("${resource.devModelFilePath}") - private String devModelFilePath; - @Autowired private ResourceService resourceService; @@ -157,55 +154,6 @@ public class ResourceController { return new Result(); } - @GetMapping("/getDevelopmentFile") - @ApiOperation("获取开发指南") - @LogOperation("获取开发指南") - @ApiImplicitParams({ - @ApiImplicitParam(name = "type", value = "类型", paramType = "query", required = true, dataType = "String"), - @ApiImplicitParam(name = "resourceId", value = "能力ID", paramType = "query", required = false, dataType = "Long"), - }) - public void getDevelopmentFile(@ApiIgnore HttpServletRequest request, @ApiIgnore HttpServletResponse response) { - try { - resourceService.getDevelopmentFile(request, response); - } catch (Exception e) { - System.err.println(e.getMessage()); - e.printStackTrace(); - new Result<>().error(500, "文件获取失败!"); - } - } - - @PostMapping("/upload") - @ApiOperation("开发指南文件上传") - @ApiImplicitParams({ - @ApiImplicitParam(name = "file", value = "开发指南文件", paramType = "file", dataType = "file", required = true) - }) - public Result upload(@RequestParam("file") MultipartFile uploadFile, - HttpServletRequest request) { - logger.info("上传文件:" + uploadFile.getOriginalFilename()); - File folder = new File(devModelFilePath); - if (!folder.isDirectory()) { - folder.mkdirs(); - } - if (folder.exists()) { - if (folder.isFile()) { - if (!folder.delete()) { - return new Result<>().error("保存开发指南失败!!!"); - } - } - } - // 对上传的文件重命名,避免文件重名 - //String oldName = uploadFile.getOriginalFilename(); - String fileName = "devModelFile.md"; - try { - // 文件保存 - uploadFile.transferTo(new File(folder, fileName)); - - return new Result<>(); - } catch (IOException e) { - return new Result().error(e.getMessage()); - } - } - /* @GetMapping("export") @ApiOperation("导出") diff --git a/renren-admin/src/main/java/io/renren/modules/resource/dto/ResourceDTO.java b/renren-admin/src/main/java/io/renren/modules/resource/dto/ResourceDTO.java index 4c7734a8..517e9a39 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/dto/ResourceDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/dto/ResourceDTO.java @@ -40,11 +40,17 @@ public class ResourceDTO implements Serializable { private String deptContacts; @ApiModelProperty(value = "联系电话") private String deptPhone; + @ApiModelProperty(value = "共享类型") + private String shareType; + @ApiModelProperty(value = "共享方式") + private String shareMode; + @ApiModelProperty(value = "共享条件") + private String shareCondition; @ApiModelProperty(value = "地区编码") private Long districtId; @ApiModelProperty(value = "访问量") private Long visits; - @ApiModelProperty(value = "删除标志:0:正常;1:已删除;9其他") + @ApiModelProperty(value = "删除标志:0:正常;1:已删除;2:待审核;3:审核中;9其他") private Integer delFlag; @ApiModelProperty(value = "创建人") private Long creator; @@ -65,6 +71,13 @@ public class ResourceDTO implements Serializable { @ApiModelProperty(value = "备用字段") private String note5; + @ApiModelProperty(value = "部门名称") + private String deptName; + @ApiModelProperty(value = "收藏标志") + private String isCollect; + @ApiModelProperty(value = "评分") + private Long score; + @ApiModelProperty(value = "属性信息") private List infoList; diff --git a/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java b/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java index b50c40d3..1da7317f 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/entity/ResourceEntity.java @@ -61,6 +61,18 @@ public class ResourceEntity extends BaseEntity { */ private String deptPhone; /** + * 共享类型 + */ + private String shareType; + /** + * 共享方式 + */ + private String shareMode; + /** + * 共享条件 + */ + private String shareCondition; + /** * 地区编码 */ private Long districtId; diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java b/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java index 8c2f954a..f44c791b 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/ResourceService.java @@ -32,8 +32,6 @@ public interface ResourceService extends CrudService implements ResourceService { - @Value("${resource.devModelFilePath}") - private String delModelFilePath; - @Value("${resource.root_url}") - private String root_url; @Autowired private SysDeptService sysDeptService; @@ -144,6 +140,10 @@ public class ResourceServiceImpl extends CrudServiceImpl resultPage = new Page<>(pageNum, pageSize); if (resourceDTO.getInfoList().isEmpty()) { Page page = new Page(pageNum, pageSize); @@ -152,7 +152,8 @@ public class ResourceServiceImpl extends CrudServiceImpl entityPage = resourceDao.selectPage(page, queryWrapper); ArrayList list = new ArrayList<>(); entityPage.getRecords().forEach(item -> { @@ -202,45 +203,6 @@ public class ResourceServiceImpl extends CrudServiceImpl page = new Page<>(jsonObject.getIntValue("pageNum"), jsonObject.getIntValue("pageSize")); Map selectMap = JSON.toJavaObject(jsonObject, Map.class); List resourceDTOS = resourceDao.selectMostPopular(selectMap); - return resourceDTOS; + page.setRecords(resourceDTOS); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("del_flag", 0).eq("type", jsonObject.getString("type")); + Integer count = resourceDao.selectCount(queryWrapper); + page.setTotal(count); + return page; } @Override diff --git a/renren-admin/src/main/resources/application-dev.yml b/renren-admin/src/main/resources/application-dev.yml index d3b28cd0..a239fb37 100644 --- a/renren-admin/src/main/resources/application-dev.yml +++ b/renren-admin/src/main/resources/application-dev.yml @@ -55,7 +55,7 @@ spring: resource: root_url: 15.2.21.238 path: /home/yth/files/ - devModelFilePath: /home/yth/files/resource + devModelFilePath: /home/yth/files/devModelFile # 大数据部门相关配置 big_date: name: 青岛市大数据发展管理局 diff --git a/renren-admin/src/main/resources/application-prod.yml b/renren-admin/src/main/resources/application-prod.yml index 7111c7ba..f85e42f5 100644 --- a/renren-admin/src/main/resources/application-prod.yml +++ b/renren-admin/src/main/resources/application-prod.yml @@ -38,7 +38,7 @@ spring: resource: root_url: 15.2.21.238 path: /data/services/nengli/files/ - devModelFilePath: /data/services/nengli/files/resource + devModelFilePath: /data/services/nengli/files/devModelFile # 大数据部门相关配置 big_date: name: 青岛市大数据发展管理局 diff --git a/renren-admin/src/main/resources/application-test.yml b/renren-admin/src/main/resources/application-test.yml index 7240a4e0..d248544f 100644 --- a/renren-admin/src/main/resources/application-test.yml +++ b/renren-admin/src/main/resources/application-test.yml @@ -39,7 +39,7 @@ spring: resource: root_url: 15.2.21.238 path: /home/yth/files/ - devModelFilePath: /home/yth/files/resource + devModelFilePath: /home/yth/files/devModelFile # 大数据部门相关配置 big_date: name: 青岛市大数据发展管理局 diff --git a/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml b/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml index ab3dd13c..1c520273 100644 --- a/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml +++ b/renren-admin/src/main/resources/mapper/resource/ResourceDao.xml @@ -9,9 +9,14 @@ + + + + + @@ -32,9 +37,14 @@ + + + + + @@ -47,6 +57,10 @@ + + + + @@ -143,7 +157,6 @@ LEFT JOIN ( SELECT resource_id, COUNT(id) AS "collectCount" FROM tb_resource_collection WHERE 1 = 1 and del_flag = 0 GROUP BY resource_id ) trc ON tdr.id = trc.resource_id WHERE 1 = 1 - AND tdr.id = trs.resource_id AND tdr.del_flag = 0 AND tdr.type = #{type}