CommonInfo APP配置查询接口
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.sqx.modules.common.controller.app;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -59,7 +58,19 @@ public class AppCommonController {
|
||||
return commonService.findByTypeAndCondition(condition);
|
||||
}
|
||||
|
||||
@GetMapping("getAppUseKv")
|
||||
@ApiOperation("获取APP使用的KV数据")
|
||||
@ResponseBody
|
||||
public Result getAppUseKv() {
|
||||
return Result.success().put("data",commonService.findAppKv());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("cleanAppUseKv")
|
||||
@ApiOperation("清理APP使用的KV数据")
|
||||
@ResponseBody
|
||||
public Result clean() {
|
||||
commonService.cleanAppKv();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,5 +32,10 @@ public class CommonInfo implements Serializable {
|
||||
|
||||
private String conditionFrom;
|
||||
|
||||
/**
|
||||
* 是否在app中使用 1是,0否,默认0
|
||||
*/
|
||||
private Integer isAppUse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.sqx.modules.common.service;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.common.entity.CommonInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
@@ -40,4 +42,7 @@ public interface CommonInfoService {
|
||||
*/
|
||||
Result findByTypeAndCondition(String condition);
|
||||
|
||||
Map<Integer,String> findAppKv();
|
||||
|
||||
void cleanAppKv();
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.sqx.modules.common.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.common.dao.CommonInfoDao;
|
||||
@@ -7,14 +9,18 @@ import com.sqx.modules.common.entity.CommonInfo;
|
||||
import com.sqx.modules.common.service.CommonInfoService;
|
||||
import com.sqx.modules.course.service.CourseService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author fang
|
||||
@@ -29,6 +35,9 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private CacheManager cacheManager;
|
||||
|
||||
|
||||
@CacheEvict(key = "#commonInfo.id")
|
||||
@Override
|
||||
@@ -36,15 +45,15 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date now = new Date();
|
||||
commonInfo.setCreateAt(sdf.format(now));
|
||||
if(commonInfo.getType()==820){
|
||||
if (commonInfo.getType() == 820) {
|
||||
Result result = courseService.setDyNotifyUrl(commonInfo.getValue());
|
||||
String code = String.valueOf(result.get("code"));
|
||||
if(!"0".equals(code)){
|
||||
if (!"0".equals(code)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
commonInfoDao.updateById(commonInfo);
|
||||
|
||||
cleanAppKv();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@@ -57,6 +66,7 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
@Override
|
||||
public Result delete(long id) {
|
||||
commonInfoDao.deleteById(id);
|
||||
cleanAppKv();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@@ -64,18 +74,34 @@ public class CommonInfoServiceImpl extends ServiceImpl<CommonInfoDao, CommonInfo
|
||||
@Override
|
||||
public Result updateBody(CommonInfo commonInfo) {
|
||||
commonInfoDao.updateById(commonInfo);
|
||||
cleanAppKv();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result findByType(Integer type) {
|
||||
return Result.success().put("data",commonInfoDao.findOne(type));
|
||||
return Result.success().put("data", commonInfoDao.findOne(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result findByTypeAndCondition(String condition) {
|
||||
return Result.success().put("data",commonInfoDao.findByCondition(condition));
|
||||
return Result.success().put("data", commonInfoDao.findByCondition(condition));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable("commonInfoAppKv")
|
||||
public Map<Integer, String> findAppKv() {
|
||||
List<CommonInfo> list = commonInfoDao.selectList(Wrappers.<CommonInfo>lambdaQuery().eq(CommonInfo::getIsAppUse, 1).orderByAsc(CommonInfo::getType).orderByAsc(CommonInfo::getId));
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return new HashMap<>(0);
|
||||
}
|
||||
Map<Integer, String> data = list.stream().collect(Collectors.toMap(CommonInfo::getType, CommonInfo::getValue));
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAppKv() {
|
||||
cacheManager.getCache("commonInfoAppKv").clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user