Browse Source

feat: 计划详情补充路线名称

master_tdsql
hxh 10 months ago
parent
commit
8b4b2bf992
  1. 440
      shuili-framework/src/main/java/com/shuili/common/core/redis/RedisCache.java
  2. 66
      shuili-framework/src/main/java/com/shuili/common/core/service/BaseService.java
  3. 3
      shuili-system/src/main/java/com/kms/yxgh/df/dto/DfCheckingPlanContentDto.java
  4. 3
      shuili-system/src/main/java/com/kms/yxgh/df/dto/DfPlanSearchDto.java
  5. 6
      shuili-system/src/main/java/com/kms/yxgh/df/dto/DfPlanSimpleDto.java
  6. 14
      shuili-system/src/main/java/com/kms/yxgh/df/mapper/DfPlanMapper.java
  7. 13
      shuili-system/src/main/java/com/kms/yxgh/df/service/DfPlanService.java

440
shuili-framework/src/main/java/com/shuili/common/core/redis/RedisCache.java

@ -18,227 +18,229 @@ import java.util.concurrent.TimeUnit;
*
* @author shuili
**/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@SuppressWarnings(value = {"unchecked", "rawtypes"})
@Component
public class RedisCache {
@Autowired
public RedisTemplate redisTemplate;
@Value("${shuili.nameKey}")
private String REDIS_PREFIX;
/**
* 缓存基本的对象IntegerString实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
*/
public <T> void setCacheObject(final String key, final T value) {
redisTemplate.opsForValue().set(REDIS_PREFIX+"_"+key, value);
}
/**
* 缓存基本的对象IntegerString实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
* @param timeout 时间
* @param timeUnit 时间颗粒度
*/
public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(REDIS_PREFIX+"_"+key, value, timeout, timeUnit);
}
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(REDIS_PREFIX+"_"+key, value, timeout, timeUnit);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @return true=设置成功false=设置失败
*/
public boolean expire(final String key, final long timeout) {
return expire(REDIS_PREFIX+"_"+key, timeout, TimeUnit.SECONDS);
}
/**
* 获取有效时间
*
* @param key
* @return
*/
public long getExpire(final String key) {
return redisTemplate.getExpire(REDIS_PREFIX+"_"+key);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @param unit 时间单位
* @return true=设置成功false=设置失败
*/
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
return redisTemplate.expire(REDIS_PREFIX+"_"+key, timeout, unit);
}
/**
* 获得缓存的基本对象
*
* @param key 缓存键值
* @return 缓存键值对应的数据
*/
public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(REDIS_PREFIX+"_"+key);
}
public <T> T getCacheObject(final String key,Class<T> c) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(REDIS_PREFIX+"_"+key);
}
/**
* 删除单个对象
*
* @param key
*/
public boolean deleteObject(final String key) {
return redisTemplate.delete(REDIS_PREFIX+"_"+key);
}
/**
* 删除集合对象
*
* @param collection 多个对象
* @return
*/
public long deleteObject(final Collection collection) {
return redisTemplate.delete(collection);
}
/**
* 缓存List数据
*
* @param key 缓存的键值
* @param dataList 待缓存的List数据
* @return 缓存的对象
*/
public <T> long setCacheList(final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(REDIS_PREFIX+"_"+key, dataList);
return count == null ? 0 : count;
}
/**
* 获得缓存的list对象
*
* @param key 缓存的键值
* @return 缓存键值对应的数据
*/
public <T> List<T> getCacheList(final String key) {
return redisTemplate.opsForList().range(REDIS_PREFIX+"_"+key, 0, -1);
}
/**
* 缓存Set
*
* @param key 缓存键值
* @param dataSet 缓存的数据
* @return 缓存数据的对象
*/
public <T> long setCacheSet(final String key, final Set<T> dataSet) {
@Autowired
public RedisTemplate redisTemplate;
@Value("${shuili.nameKey}")
private String REDIS_PREFIX;
/**
* 缓存基本的对象IntegerString实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
*/
public <T> void setCacheObject(final String key, final T value) {
redisTemplate.opsForValue().set(REDIS_PREFIX + "_" + key, value);
}
/**
* 缓存基本的对象IntegerString实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
* @param timeout 时间
* @param timeUnit 时间颗粒度
*/
public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(REDIS_PREFIX + "_" + key, value, timeout, timeUnit);
}
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(REDIS_PREFIX + "_" + key, value, timeout, timeUnit);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @return true=设置成功false=设置失败
*/
public boolean expire(final String key, final long timeout) {
return expire(REDIS_PREFIX + "_" + key, timeout, TimeUnit.SECONDS);
}
/**
* 获取有效时间
*
* @param key
* @return
*/
public long getExpire(final String key) {
return redisTemplate.getExpire(REDIS_PREFIX + "_" + key);
}
/**
* 设置有效时间
*
* @param key Redis键
* @param timeout 超时时间
* @param unit 时间单位
* @return true=设置成功false=设置失败
*/
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
return Boolean.TRUE.equals(redisTemplate.expire(REDIS_PREFIX + "_" + key, timeout, unit));
}
/**
* 获得缓存的基本对象
*
* @param key 缓存键值
* @return 缓存键值对应的数据
*/
public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(REDIS_PREFIX + "_" + key);
}
public <T> T getCacheObject(final String key, Class<T> c) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(REDIS_PREFIX + "_" + key);
}
/**
* 删除单个对象
*
* @param key
*/
public boolean deleteObject(final String key) {
return Boolean.TRUE.equals(redisTemplate.delete(REDIS_PREFIX + "_" + key));
}
/**
* 删除集合对象
*
* @param collection 多个对象
* @return
*/
public long deleteObject(final Collection collection) {
return redisTemplate.delete(collection);
}
/**
* 缓存List数据
*
* @param key 缓存的键值
* @param dataList 待缓存的List数据
* @return 缓存的对象
*/
public <T> long setCacheList(final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(REDIS_PREFIX + "_" + key, dataList);
return count == null ? 0 : count;
}
/**
* 获得缓存的list对象
*
* @param key 缓存的键值
* @return 缓存键值对应的数据
*/
public <T> List<T> getCacheList(final String key) {
return redisTemplate.opsForList().range(REDIS_PREFIX + "_" + key, 0, -1);
}
/**
* 缓存Set
*
* @param key 缓存键值
* @param dataSet 缓存的数据
* @return 缓存数据的对象
*/
public <T> long setCacheSet(final String key, final Set<T> dataSet) {
// redisTemplate.opsForSet()
Long count = redisTemplate.opsForSet().add(REDIS_PREFIX+"_"+key, dataSet);
return count == null ? 0 : count;
}
public <T> long setCacheSet(final String key, final Set<T> dataSet,int time,TimeUnit t) {
Long count = redisTemplate.opsForSet().add(REDIS_PREFIX+"_"+key, dataSet,time,t);
return count == null ? 0 : count;
}
/**
* 获得缓存的set
*
* @param key
* @return
*/
public <T> Set<T> getCacheSet(final String key) {
return redisTemplate.opsForSet().members(REDIS_PREFIX+"_"+key);
}
/**
* 缓存Map
*
* @param key
* @param dataMap
*/
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) {
redisTemplate.opsForHash().putAll(REDIS_PREFIX+"_"+key, dataMap);
}
}
/**
* 获得缓存的Map
*
* @param key
* @return
*/
public <T> Map<String, T> getCacheMap(final String key) {
return redisTemplate.opsForHash().entries(REDIS_PREFIX+"_"+key);
}
/**
* 往Hash中存入数据
*
* @param key Redis键
* @param hKey Hash键
* @param value
*/
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
redisTemplate.opsForHash().put(REDIS_PREFIX+"_"+key, hKey, value);
}
/**
* 获取Hash中的数据
*
* @param key Redis键
* @param hKey Hash键
* @return Hash中的对象
*/
public <T> T getCacheMapValue(final String key, final String hKey) {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(REDIS_PREFIX+"_"+key, hKey);
}
/**
* 获取多个Hash中的数据
*
* @param key Redis键
* @param hKeys Hash键集合
* @return Hash对象集合
*/
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(REDIS_PREFIX+"_"+key, hKeys);
}
/**
* 获得缓存的基本对象列表
*
* @param pattern 字符串前缀
* @return 对象列表
*/
public Collection<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
public boolean hasKey(String key) {
return redisTemplate.hasKey(REDIS_PREFIX+"_"+key);
}
Long count = redisTemplate.opsForSet().add(REDIS_PREFIX + "_" + key, dataSet);
return count == null ? 0 : count;
}
public <T> long setCacheSet(final String key, final Set<T> dataSet, int time, TimeUnit t) {
Long count = redisTemplate.opsForSet().add(REDIS_PREFIX + "_" + key, dataSet, time, t);
return count == null ? 0 : count;
}
/**
* 获得缓存的set
*
* @param key
* @return
*/
public <T> Set<T> getCacheSet(final String key) {
return redisTemplate.opsForSet().members(REDIS_PREFIX + "_" + key);
}
/**
* 缓存Map
*
* @param key
* @param dataMap
*/
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) {
redisTemplate.opsForHash().putAll(REDIS_PREFIX + "_" + key, dataMap);
}
}
/**
* 获得缓存的Map
*
* @param key
* @return
*/
public <T> Map<String, T> getCacheMap(final String key) {
return redisTemplate.opsForHash().entries(REDIS_PREFIX + "_" + key);
}
/**
* 往Hash中存入数据
*
* @param key Redis键
* @param hKey Hash键
* @param value
*/
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
redisTemplate.opsForHash().put(REDIS_PREFIX + "_" + key, hKey, value);
}
/**
* 获取Hash中的数据
*
* @param key Redis键
* @param hKey Hash键
* @return Hash中的对象
*/
public <T> T getCacheMapValue(final String key, final String hKey) {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(REDIS_PREFIX + "_" + key, hKey);
}
/**
* 获取多个Hash中的数据
*
* @param key Redis键
* @param hKeys Hash键集合
* @return Hash对象集合
*/
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(REDIS_PREFIX + "_" + key, hKeys);
}
/**
* 获得缓存的基本对象列表
*
* @param pattern 字符串前缀
* @return 对象列表
*/
public Collection<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
public boolean hasKey(String key) {
return Boolean.TRUE.equals(redisTemplate.hasKey(REDIS_PREFIX + "_" + key));
}
}

66
shuili-framework/src/main/java/com/shuili/common/core/service/BaseService.java

@ -21,61 +21,69 @@ import java.util.Objects;
/**
* 扩展其他的通用方法
*
* @param <T>
*/
public class BaseService<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T>{
public class BaseService<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> {
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
public IPage<T> selectPage(SearchParam<T> sp){
return getBaseMapper().selectPage(new Page<>(sp.getPageNum(),sp.getPageSize()), BeanToWrapper.getWrapper(sp));
public IPage<T> selectPage(SearchParam<T> sp) {
return getBaseMapper().selectPage(new Page<>(sp.getPageNum(), sp.getPageSize()), BeanToWrapper.getWrapper(sp));
}
public AjaxResult selectPage(T t){
public AjaxResult selectPage(T t) {
QueryWrapper<T> wrapper = BeanToWrapper.getWrapper(t);
BeanToWrapper.order(wrapper, t);
Page<Map<String, Object>> mapPage = getBaseMapper().selectMapsPage(new Page<>(t.getPageNum(), t.getPageSize()), wrapper);
AjaxResult success = AjaxResult.success();
success.put(AjaxResult.DATA_TAG,mapPage.getRecords());
success.put(AjaxResult.TOTAL,mapPage.getTotal());
success.put(AjaxResult.DATA_TAG, mapPage.getRecords());
success.put(AjaxResult.TOTAL, mapPage.getTotal());
return success;
}
/**
* 同步保存到缓存
*
* @param t
* @return
*/
public boolean saveWithRedis(T t){
public boolean saveWithRedis(T t) {
boolean save = super.save(t);
if(save){
redisCache.setCacheObject(getRedisKey()+t.getId(),t);
if (save) {
redisCache.setCacheObject(getRedisKey() + t.getId(), t);
}
return true;
}
/**
* 同步更新缓存
*
* @param t
* @return
*/
public boolean updateWithReids(T t){
public boolean updateWithReids(T t) {
boolean result = super.updateById(t);
if(result){
redisCache.setCacheObject(getRedisKey()+t.getId(),t);
if (result) {
redisCache.setCacheObject(getRedisKey() + t.getId(), t);
}
return result;
}
/**
* 从缓存中获取对应的数据
*
* @param id
* @return
*/
public T getWithRedis(Serializable id){
T cacheObject = redisCache.getCacheObject(getRedisKey()+id.toString(),getEntityClass());
if(Objects.isNull(cacheObject)){
public T getWithRedis(Serializable id) {
T cacheObject = redisCache.getCacheObject(getRedisKey() + id.toString(), getEntityClass());
if (Objects.isNull(cacheObject)) {
T byId = getById(id);
redisCache.setCacheObject(getRedisKey()+id.toString(),byId);
if (Objects.isNull(byId)) {
return null;
}
redisCache.setCacheObject(getRedisKey() + id, byId);
return byId;
}
return cacheObject;
@ -84,45 +92,49 @@ public class BaseService<M extends BaseMapper<T>, T extends BaseEntity> extends
/**
* 同步删除redis
*
* @return
*/
public boolean removeByIdWithRedis(Serializable id){
public boolean removeByIdWithRedis(Serializable id) {
boolean result = super.removeById(id);
if(result){ // 同步删除redis
redisCache.deleteObject(getRedisKey()+id.toString());
if (result) { // 同步删除redis
redisCache.deleteObject(getRedisKey() + id.toString());
}
return result;
}
/**
* 同步删除缓存
*
* @param ids
* @return
*/
public boolean removeWithRedis(Serializable[] ids){
public boolean removeWithRedis(Serializable[] ids) {
boolean result = removeByIds(Arrays.asList(ids));
if(result){
if (result) {
for (Serializable id : ids) {
redisCache.deleteObject(getRedisKey()+id.toString());
redisCache.deleteObject(getRedisKey() + id.toString());
}
}
return result;
}
public boolean removeWithRedis(List<Serializable> ids){
public boolean removeWithRedis(List<Serializable> ids) {
boolean result = removeByIds(ids);
if(result){
if (result) {
for (Serializable id : ids) {
redisCache.deleteObject(getRedisKey()+id.toString());
redisCache.deleteObject(getRedisKey() + id.toString());
}
}
return result;
}
/**
* 工程名+实体类+ id
*
* @return
*/
public String getRedisKey(){
return getEntityClass()+"_";
public String getRedisKey() {
return getEntityClass() + "_";
}
}

3
shuili-system/src/main/java/com/kms/yxgh/df/dto/DfCheckingPlanContentDto.java

@ -35,6 +35,9 @@ public class DfCheckingPlanContentDto {
@ApiModelProperty("巡查路线ID")
private String lineId;
@ApiModelProperty("巡查路线名称")
private String lineName;
/**
* 计划开始时间
*/

3
shuili-system/src/main/java/com/kms/yxgh/df/dto/DfPlanSearchDto.java

@ -17,6 +17,9 @@ public class DfPlanSearchDto {
private String name;
@ApiModelProperty(value = "状态")
private String status;
@ApiModelProperty(value = "记录状态")
private String recordStatus;
private String user;
@ApiModelProperty(value = "巡查人员id")
private List<String> userIds;
@ApiModelProperty(value = "开始时间")

6
shuili-system/src/main/java/com/kms/yxgh/df/dto/DfPlanSimpleDto.java

@ -44,6 +44,12 @@ public class DfPlanSimpleDto {
@ApiModelProperty("状态")
private String status;
@ApiModelProperty("记录状态")
private String recordStatus;
@ApiModelProperty("记录id")
private String recordId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("最近修改时间")
private Date updateTime;

14
shuili-system/src/main/java/com/kms/yxgh/df/mapper/DfPlanMapper.java

@ -31,7 +31,9 @@ public interface DfPlanMapper extends BaseMapper<DfPlan> {
"SELECT df.dike_name as dike_name, df.dike_code as dike_code, df.dike_type as dike_type, " +
"p.id, p.name, p.type plan_type, p.update_time as update_time, p.create_time as create_time, " +
"p.frequency, p.status, p.create_uid as createUid, " +
"(select count(1) from bs_sgc_df_xsjhxq su where su.plan_id = p.id) as item_count " +
"(select count(1) from bs_sgc_df_xsjhxq su where su.plan_id = p.id) as item_count ," +
"(select count(1) from bs_sgc_df_xsjhjl r where p.id = r.plan_id and r.create_uid = #{dto.user} and r.status = '1' order by r.create_time desc limit 1) as record_status, " +
"(select id from bs_sgc_df_xsjhjl r where p.id = r.plan_id and r.create_uid = #{dto.user} and r.status = '1' order by r.create_time desc limit 1) as record_id " +
"FROM bs_sgc_df_xsjh p " +
"Left JOIN att_dike_base df ON p.dike_code = df.dike_code and df.expr_date is null " +
"WHERE 1=1 " +
@ -50,6 +52,16 @@ public interface DfPlanMapper extends BaseMapper<DfPlan> {
"<if test='dto != null and dto.endTime != null'>" +
"AND p.end_date &lt;= #{dto.endTime} " +
"</if>" +
"<if test='dto != null and dto.recordStatus != null and dto.recordStatus == \"0\"'>" +
" and NOT EXISTS (" +
" SELECT plan_id FROM bs_sgc_df_xsjhjl od WHERE p.id = od.plan_id and od.create_uid = #{dto.user} and od.status = '1'" +
") " +
"</if>" +
"<if test='dto != null and dto.recordStatus != null and dto.recordStatus == \"1\"'>" +
" and EXISTS (" +
" SELECT plan_id FROM bs_sgc_df_xsjhjl od WHERE p.id = od.plan_id and od.create_uid = #{dto.user} and od.status = '1'" +
") " +
"</if>" +
"<if test='dto != null and dto.userIds != null and dto.userIds.size() > 0'>" +
"AND p.id in (select plan_id from bs_sgc_df_xsjhzx where operator_uid in " +
"<foreach collection='dto.userIds' item='item' open='(' separator=',' close=')'> " +

13
shuili-system/src/main/java/com/kms/yxgh/df/service/DfPlanService.java

@ -5,13 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kms.common.utils.UserUtils;
import com.kms.system.service.SysUserService;
import com.kms.yxgh.base.DfException;
import com.kms.yxgh.common.dto.OperatorDto;
import com.kms.yxgh.df.domain.DfCheckingPlanContent;
import com.kms.yxgh.df.domain.DfPlan;
import com.kms.yxgh.df.domain.DfPlanOperator;
import com.kms.yxgh.df.domain.DfRecord;
import com.kms.yxgh.df.domain.*;
import com.kms.yxgh.df.dto.DfCheckingPlanContentDto;
import com.kms.yxgh.df.dto.DfPlanDetailDto;
import com.kms.yxgh.df.dto.DfPlanSearchDto;
@ -21,10 +19,12 @@ import com.kms.yxgh.df.mapper.DfPlanMapper;
import com.kms.yxgh.df.mapper.DfRecordMapper;
import com.kms.yxgh.util.BeanCopyUtils;
import com.shuili.common.core.domain.SearchParam;
import com.shuili.common.core.domain.entity.SysUser;
import com.shuili.common.core.service.BaseService;
import com.shuili.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.data.util.Optionals;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -47,6 +47,7 @@ public class DfPlanService extends BaseService<DfPlanMapper, DfPlan> {
private final DfRecordMapper dfRecordMapper;
private final DfCheckingPlanContentService dfCheckingPlanContentService;
private final DfCheckingLineService dfCheckingLineService;
private final DfCheckingPlanContentMapper dfCheckingPlanContentMapper;
private final SysUserService userService;
private final DfPlanOperatorService dfPlanOperatorService;
@ -54,7 +55,8 @@ public class DfPlanService extends BaseService<DfPlanMapper, DfPlan> {
public IPage<DfPlanSimpleDto> search(SearchParam<DfPlanSearchDto> sp) {
Page<DfPlan> page = new Page<>(sp.getPageNum(), sp.getPageSize());
DfPlanSearchDto searchDto = sp.getData();
SysUser user = UserUtils.getUser();
searchDto.setUser(Optional.ofNullable(user).map(SysUser::getId).orElse(null));
IPage<DfPlanSimpleDto> result = this.getBaseMapper().search(page, searchDto);
result.getRecords().forEach(item -> {
item.setCreateName(userService.userName(item.getCreateUid()));
@ -235,6 +237,7 @@ public class DfPlanService extends BaseService<DfPlanMapper, DfPlan> {
private DfCheckingPlanContentDto toDto(DfCheckingPlanContent entity, Map<String, List<DfPlanOperator>> operatorMap) {
DfCheckingPlanContentDto dto = BeanCopyUtils.copy(entity, DfCheckingPlanContentDto.class);
if (dto != null) {
dto.setLineName(Optional.ofNullable(dfCheckingLineService.getWithRedis(dto.getLineId())).map(DfCheckingLine::getName).orElse(""));
dto.setOperator(operatorMap.getOrDefault(dto.getId(), Collections.emptyList()).stream()
.map(item -> {
OperatorDto operatorDto = new OperatorDto();

Loading…
Cancel
Save