Merge remote-tracking branch 'origin/master'

This commit is contained in:
wangliwen 2022-04-25 19:59:56 +08:00
commit a551408bc7
13 changed files with 226 additions and 117 deletions

View File

@ -15,6 +15,7 @@ import io.renren.modules.category.service.CategoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,12 +27,11 @@ import java.util.List;
@Api(tags="编目管理") @Api(tags="编目管理")
public class CategoryController { public class CategoryController {
@Value("${resource.devModelFilePath}")
private String devModelFilePath;
@Autowired @Autowired
private CategoryService categoryService; private CategoryService categoryService;
/**
* 查询顶级分类
* @return
*/
@GetMapping("/getTopCategory") @GetMapping("/getTopCategory")
@ApiOperation("获取一级分类") @ApiOperation("获取一级分类")
public Result getTopCategory() { public Result getTopCategory() {
@ -58,20 +58,19 @@ public class CategoryController {
@PostMapping("/insert") @PostMapping("/insert")
@ApiOperation("保存") @ApiOperation("保存")
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = Exception.class)
public Object insert(@RequestBody CategoryDTO categoryDTO) { public Object insert(@RequestBody CategoryDTO categoryDTO) {
//效验数据 //效验数据
ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(categoryDTO, AddGroup.class, DefaultGroup.class);
categoryDTO.setDelFlag(0); categoryDTO.setDelFlag(0);
categoryService.save(categoryDTO);
//若为一级分类增加文件夹 //若为一级分类增加文件夹
//if (ObjectUtil.isNull(categoryDTO.getPid())) { if (ObjectUtil.isNull(categoryDTO.getPid())) {
// File file = new File("D:\\新建文件夹\\resource\\" + categoryDTO.getName()); File file = new File(devModelFilePath + categoryDTO.getName());
// file.mkdirs(); if (file.mkdirs()) {
// if (file.mkdirs()) { throw new RuntimeException("创建文件夹失败!");
// throw new RuntimeException("创建文件夹失败!"); }
// } }
//} categoryService.save(categoryDTO);
return new Result(); return new Result();
} }

View File

@ -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<String>().error(e.getMessage());
}
}
}

View File

@ -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;
}

View File

@ -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("获取开发指南成功!!!");
}
}

View File

@ -39,9 +39,6 @@ import java.util.Map;
@Api(tags = "资源表") @Api(tags = "资源表")
public class ResourceController { public class ResourceController {
@Value("${resource.devModelFilePath}")
private String devModelFilePath;
@Autowired @Autowired
private ResourceService resourceService; private ResourceService resourceService;
@ -157,55 +154,6 @@ public class ResourceController {
return new Result(); 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<String>().error(e.getMessage());
}
}
/* /*
@GetMapping("export") @GetMapping("export")
@ApiOperation("导出") @ApiOperation("导出")

View File

@ -40,11 +40,17 @@ public class ResourceDTO implements Serializable {
private String deptContacts; private String deptContacts;
@ApiModelProperty(value = "联系电话") @ApiModelProperty(value = "联系电话")
private String deptPhone; private String deptPhone;
@ApiModelProperty(value = "共享类型")
private String shareType;
@ApiModelProperty(value = "共享方式")
private String shareMode;
@ApiModelProperty(value = "共享条件")
private String shareCondition;
@ApiModelProperty(value = "地区编码") @ApiModelProperty(value = "地区编码")
private Long districtId; private Long districtId;
@ApiModelProperty(value = "访问量") @ApiModelProperty(value = "访问量")
private Long visits; private Long visits;
@ApiModelProperty(value = "删除标志0:正常1:已删除9其他") @ApiModelProperty(value = "删除标志0:正常1:已删除;2:待审核3:审核中;9其他")
private Integer delFlag; private Integer delFlag;
@ApiModelProperty(value = "创建人") @ApiModelProperty(value = "创建人")
private Long creator; private Long creator;
@ -65,6 +71,13 @@ public class ResourceDTO implements Serializable {
@ApiModelProperty(value = "备用字段") @ApiModelProperty(value = "备用字段")
private String note5; private String note5;
@ApiModelProperty(value = "部门名称")
private String deptName;
@ApiModelProperty(value = "收藏标志")
private String isCollect;
@ApiModelProperty(value = "评分")
private Long score;
@ApiModelProperty(value = "属性信息") @ApiModelProperty(value = "属性信息")
private List<AttrEntity> infoList; private List<AttrEntity> infoList;

View File

@ -61,6 +61,18 @@ public class ResourceEntity extends BaseEntity {
*/ */
private String deptPhone; private String deptPhone;
/** /**
* 共享类型
*/
private String shareType;
/**
* 共享方式
*/
private String shareMode;
/**
* 共享条件
*/
private String shareCondition;
/**
* 地区编码 * 地区编码
*/ */
private Long districtId; private Long districtId;

View File

@ -32,8 +32,6 @@ public interface ResourceService extends CrudService<ResourceEntity, ResourceDTO
Object selectTotal(); Object selectTotal();
void getDevelopmentFile(HttpServletRequest request, HttpServletResponse response) throws Exception;
Object selectNewest(JSONObject jsonObject); Object selectNewest(JSONObject jsonObject);
Object selectMostPopular(JSONObject jsonObject); Object selectMostPopular(JSONObject jsonObject);

View File

@ -48,10 +48,6 @@ import java.util.Map;
@Service @Service
public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEntity, ResourceDTO> implements ResourceService { public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEntity, ResourceDTO> implements ResourceService {
@Value("${resource.devModelFilePath}")
private String delModelFilePath;
@Value("${resource.root_url}")
private String root_url;
@Autowired @Autowired
private SysDeptService sysDeptService; private SysDeptService sysDeptService;
@ -144,6 +140,10 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
ResourceDTO resourceDTO = JSON.toJavaObject(jsonObject, ResourceDTO.class); ResourceDTO resourceDTO = JSON.toJavaObject(jsonObject, ResourceDTO.class);
Integer pageNum = jsonObject.getInteger("pageNum"); Integer pageNum = jsonObject.getInteger("pageNum");
Integer pageSize = jsonObject.getInteger("pageSize"); Integer pageSize = jsonObject.getInteger("pageSize");
//默认按上架时间降序排列
String orderField = StringUtils.isNotBlank(jsonObject.getString("orderField")) ? "create_time" : jsonObject.getString("orderField");
String orderType = StringUtils.isNotBlank(jsonObject.getString("orderType")) ? "DESC" : jsonObject.getString("orderType");
boolean orderASC = /*orderType.equals("ASC") ? true : */false;
Page<ResourceDTO> resultPage = new Page<>(pageNum, pageSize); Page<ResourceDTO> resultPage = new Page<>(pageNum, pageSize);
if (resourceDTO.getInfoList().isEmpty()) { if (resourceDTO.getInfoList().isEmpty()) {
Page<ResourceEntity> page = new Page(pageNum, pageSize); Page<ResourceEntity> page = new Page(pageNum, pageSize);
@ -152,7 +152,8 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
.like(StringUtils.isNotBlank(resourceDTO.getName()), "name", resourceDTO.getName()) .like(StringUtils.isNotBlank(resourceDTO.getName()), "name", resourceDTO.getName())
.eq(ObjectUtil.isNotNull(resourceDTO.getDistrictId()), "district_id", resourceDTO.getDistrictId()) .eq(ObjectUtil.isNotNull(resourceDTO.getDistrictId()), "district_id", resourceDTO.getDistrictId())
.eq(ObjectUtil.isNotNull(resourceDTO.getDeptId()), "dept_id", resourceDTO.getDeptId()) .eq(ObjectUtil.isNotNull(resourceDTO.getDeptId()), "dept_id", resourceDTO.getDeptId())
.eq("type", resourceDTO.getType()); .eq("type", resourceDTO.getType())
.orderBy(true, orderASC, orderField);
Page<ResourceEntity> entityPage = resourceDao.selectPage(page, queryWrapper); Page<ResourceEntity> entityPage = resourceDao.selectPage(page, queryWrapper);
ArrayList<ResourceDTO> list = new ArrayList<>(); ArrayList<ResourceDTO> list = new ArrayList<>();
entityPage.getRecords().forEach(item -> { entityPage.getRecords().forEach(item -> {
@ -202,45 +203,6 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
return resultMap; return resultMap;
} }
@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("获取开发指南成功!!!");
}
@Override @Override
public Object selectNewest(JSONObject jsonObject) { public Object selectNewest(JSONObject jsonObject) {
@ -256,9 +218,15 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override @Override
public Object selectMostPopular(JSONObject jsonObject) { public Object selectMostPopular(JSONObject jsonObject) {
IPage<ResourceDTO> page = new Page<>(jsonObject.getIntValue("pageNum"), jsonObject.getIntValue("pageSize"));
Map<String, Object> selectMap = JSON.toJavaObject(jsonObject, Map.class); Map<String, Object> selectMap = JSON.toJavaObject(jsonObject, Map.class);
List<ResourceDTO> resourceDTOS = resourceDao.selectMostPopular(selectMap); List<ResourceDTO> resourceDTOS = resourceDao.selectMostPopular(selectMap);
return resourceDTOS; page.setRecords(resourceDTOS);
QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("del_flag", 0).eq("type", jsonObject.getString("type"));
Integer count = resourceDao.selectCount(queryWrapper);
page.setTotal(count);
return page;
} }
@Override @Override

View File

@ -55,7 +55,7 @@ spring:
resource: resource:
root_url: 15.2.21.238 root_url: 15.2.21.238
path: /home/yth/files/ path: /home/yth/files/
devModelFilePath: /home/yth/files/resource devModelFilePath: /home/yth/files/devModelFile
# 大数据部门相关配置 # 大数据部门相关配置
big_date: big_date:
name: 青岛市大数据发展管理局 name: 青岛市大数据发展管理局

View File

@ -38,7 +38,7 @@ spring:
resource: resource:
root_url: 15.2.21.238 root_url: 15.2.21.238
path: /data/services/nengli/files/ path: /data/services/nengli/files/
devModelFilePath: /data/services/nengli/files/resource devModelFilePath: /data/services/nengli/files/devModelFile
# 大数据部门相关配置 # 大数据部门相关配置
big_date: big_date:
name: 青岛市大数据发展管理局 name: 青岛市大数据发展管理局

View File

@ -39,7 +39,7 @@ spring:
resource: resource:
root_url: 15.2.21.238 root_url: 15.2.21.238
path: /home/yth/files/ path: /home/yth/files/
devModelFilePath: /home/yth/files/resource devModelFilePath: /home/yth/files/devModelFile
# 大数据部门相关配置 # 大数据部门相关配置
big_date: big_date:
name: 青岛市大数据发展管理局 name: 青岛市大数据发展管理局

View File

@ -9,9 +9,14 @@
<result property="name" column="name"/> <result property="name" column="name"/>
<result property="description" column="description"/> <result property="description" column="description"/>
<result property="link" column="link"/> <result property="link" column="link"/>
<result property="apiUrl" column="api_url"/>
<result property="groupId" column="group_id"/>
<result property="deptId" column="dept_id"/> <result property="deptId" column="dept_id"/>
<result property="deptContacts" column="dept_contacts"/> <result property="deptContacts" column="dept_contacts"/>
<result property="deptPhone" column="dept_phone"/> <result property="deptPhone" column="dept_phone"/>
<result property="shareType" column="share_type"/>
<result property="shareMode" column="share_mode"/>
<result property="shareCondition" column="share_condition"/>
<result property="districtId" column="district_id"/> <result property="districtId" column="district_id"/>
<result property="visits" column="visits"/> <result property="visits" column="visits"/>
<result property="delFlag" column="del_flag"/> <result property="delFlag" column="del_flag"/>
@ -32,9 +37,14 @@
<result property="name" column="name"/> <result property="name" column="name"/>
<result property="description" column="description"/> <result property="description" column="description"/>
<result property="link" column="link"/> <result property="link" column="link"/>
<result property="apiUrl" column="api_url"/>
<result property="groupId" column="group_id"/>
<result property="deptId" column="dept_id"/> <result property="deptId" column="dept_id"/>
<result property="deptContacts" column="dept_contacts"/> <result property="deptContacts" column="dept_contacts"/>
<result property="deptPhone" column="dept_phone"/> <result property="deptPhone" column="dept_phone"/>
<result property="shareType" column="share_type"/>
<result property="shareMode" column="share_mode"/>
<result property="shareCondition" column="share_condition"/>
<result property="districtId" column="district_id"/> <result property="districtId" column="district_id"/>
<result property="visits" column="visits"/> <result property="visits" column="visits"/>
<result property="delFlag" column="del_flag"/> <result property="delFlag" column="del_flag"/>
@ -47,6 +57,10 @@
<result property="note3" column="note3"/> <result property="note3" column="note3"/>
<result property="note4" column="note4"/> <result property="note4" column="note4"/>
<result property="note5" column="note5"/> <result property="note5" column="note5"/>
<!-- 自定义字段 -->
<result property="deptName" column="dept_name"/>
<result property="isCollect" column="is_collect"/>
<result property="score" column="score"/>
<collection property="infoList" javaType="List" ofType="attrEntity"> <collection property="infoList" javaType="List" ofType="attrEntity">
<result property="id" column="id"/> <result property="id" column="id"/>
<result property="dataResourceId" column="data_resource_id"/> <result property="dataResourceId" column="data_resource_id"/>
@ -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 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 WHERE
1 = 1 1 = 1
AND tdr.id = trs.resource_id
AND tdr.del_flag = 0 AND tdr.del_flag = 0
<if test="type != null and type != ''"> <if test="type != null and type != ''">
AND tdr.type = #{type} AND tdr.type = #{type}