master
parent
5b3a61e706
commit
3c630c05c6
|
@ -23,6 +23,10 @@
|
|||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -68,6 +68,7 @@ public class ResourceInfo {
|
|||
/**
|
||||
* 为精确查询情况赋值
|
||||
*/
|
||||
|
||||
public void setFlag(ResourceReq req) {
|
||||
this.flag = this.getTitle().equals(req.getTitle())
|
||||
&& this.getPissn().equals(req.getPissn())
|
||||
|
|
|
@ -2,8 +2,11 @@ package com.muyu.resource.domain.resp;
|
|||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.muyu.common.core.annotation.Excel;
|
||||
import com.muyu.resource.domain.ResourceInfo;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: ResourceInfo
|
||||
|
@ -18,6 +21,8 @@ import lombok.*;
|
|||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ResourceInfoResp {
|
||||
// 序号
|
||||
private Integer id;
|
||||
/*
|
||||
* 题名
|
||||
*/
|
||||
|
@ -84,7 +89,9 @@ public class ResourceInfoResp {
|
|||
@Excel(name = "语种")
|
||||
private String language;
|
||||
|
||||
private List<ResourceInfo> resourceInfoList;
|
||||
|
||||
private Integer code = 0;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public class ResourceController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
public Result<PageResult<ResourceInfoResp>> upload(@RequestParam("file") MultipartFile file) {
|
||||
return Result.success(service.upload(file));
|
||||
public Result<Boolean> upload(@RequestParam("file") MultipartFile file) {
|
||||
return Result.success(service.upload(file), "上传成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
|||
*/
|
||||
|
||||
public interface ResourceService{
|
||||
PageResult<ResourceInfoResp> upload(MultipartFile file);
|
||||
Boolean upload(MultipartFile file);
|
||||
|
||||
List<ResourceInfo> findResourceByPissn(ResourceReq req);
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ import javax.annotation.Resource;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.resource.domain.result.PageResult;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.muyu.resource.domain.ResourceInfo;
|
||||
import com.muyu.resource.domain.req.ResourceReq;
|
||||
import com.muyu.resource.domain.resp.ResourceInfoResp;
|
||||
|
@ -38,18 +36,17 @@ public class ResourceServiceImpl implements ResourceService {
|
|||
@Resource
|
||||
private ResourceMapper mapper;
|
||||
@Resource
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
private RedisTemplate<String,Object> redisTemplate;
|
||||
|
||||
private static Integer on = 1;
|
||||
@Override
|
||||
public PageResult<ResourceInfoResp> upload(MultipartFile file) {
|
||||
public Boolean upload(MultipartFile file) {
|
||||
ExcelUtils<ResourceInfoResp> excelUtils = new ExcelUtils<>(ResourceInfoResp.class);
|
||||
try {
|
||||
PageHelper.startPage(1, 10);
|
||||
// 调用导入方法
|
||||
List<ResourceInfoResp> respList = excelUtils.importExcel(null, file);
|
||||
redisTemplate.opsForValue().set("list",JSONObject.toJSONString(respList),1,TimeUnit.HOURS);
|
||||
PageInfo<ResourceInfoResp> pageInfo = new PageInfo<>(respList);
|
||||
return PageResult.toPageResult(pageInfo.getTotal(), pageInfo.getList());
|
||||
redisTemplate.opsForValue().set("list",respList,1,TimeUnit.HOURS);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -57,28 +54,26 @@ public class ResourceServiceImpl implements ResourceService {
|
|||
|
||||
@Override
|
||||
public List<ResourceInfo> findResourceByPissn(ResourceReq req) {
|
||||
String resString = redisTemplate.opsForValue().get(req.toString());
|
||||
if (StringUtils.isNotEmpty(resString)){
|
||||
return JSONObject.parseObject(resString, List.class);
|
||||
}
|
||||
List<ResourceInfo> resourceInfos = mapper.findResourceByPissn(req);
|
||||
resourceInfos.forEach(resourceInfo -> resourceInfo.setFlag(req));
|
||||
redisTemplate.opsForValue().set(req.toString(), JSONObject.toJSONString(resourceInfos),1, TimeUnit.HOURS);
|
||||
redisTemplate.opsForValue().set("ResourceReq:"+req.toString(), resourceInfos,1, TimeUnit.HOURS);
|
||||
return resourceInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ResourceInfoResp> list(Integer pageNum) {
|
||||
String resString = redisTemplate.opsForValue().get("list");
|
||||
if (StringUtils.isNotEmpty(resString)){
|
||||
List<ResourceInfoResp> respList = JSONObject.parseObject(resString, List.class);
|
||||
Object o = redisTemplate.opsForValue().get("list");
|
||||
if (o!=null){
|
||||
List<ResourceInfoResp> respListAll = (List<ResourceInfoResp>) o;
|
||||
int index = (pageNum-1)*10;
|
||||
int toIndex = (pageNum-1)*10+10;
|
||||
if (toIndex>respList.size()){
|
||||
int toIndex = index+10;
|
||||
if (toIndex>respListAll.size()){
|
||||
return null;
|
||||
}
|
||||
return PageResult.toPageResult(respList.size(),
|
||||
respList.subList(index,toIndex));
|
||||
List<ResourceInfoResp> respList = respListAll.subList(index, toIndex);
|
||||
respList.forEach(resourceInfoResp -> resourceInfoResp.setId(on++));
|
||||
on = 1;
|
||||
return PageResult.toPageResult(respListAll.size(), respList);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue