Commit e9253ddc authored by yaobaizheng's avatar yaobaizheng

默认图修改

parent 11fbfe28
package com.postcard.service.config.other;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.postcard.service.config.anno.BusinessType;
import com.postcard.service.enums.BusinessTypeEnum;
import com.postcard.service.enums.DefaultImgUrlEnum;
import com.postcard.service.enums.DevelopmentStatusEnum;
import com.postcard.service.enums.ParkStatusEnum;
......@@ -17,16 +12,12 @@ import com.postcard.service.moudle.development.vo.DevelopmentPageVo;
import com.postcard.service.moudle.land.vo.LandPageVo;
import com.postcard.service.moudle.park.vo.ParkCarrierVo;
import com.postcard.service.moudle.park.vo.ParkPageVo;
import lombok.NoArgsConstructor;
import com.postcard.service.moudle.system.service.SysDefaultImgurlService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import com.postcard.service.moudle.system.service.SysDictDataService;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @Author:yaobaizheng
......@@ -35,41 +26,27 @@ import java.util.Map;
*/
@Component
public class DefaultImgUrl extends JsonSerializer<String> {
private SysDictDataService sysDictDataService = SpringUtil.getBean( SysDictDataService.class);
private DefaultImgUrl() {
JSONObject jsonObject = this.sysDictDataService.listByCodes(DefaultImgUrlEnum.DEFAULT_KEY.getName());
JSONArray dictType = jsonObject.getJSONArray(DefaultImgUrlEnum.DEFAULT_KEY.getName());
for (int i = 0; i < dictType.size(); i++) {
JSONObject obj = dictType.getJSONObject(i);
map.put(obj.getStr(DefaultImgUrlEnum.DICT_DATA_LABEL.getName()),obj.getStr(DefaultImgUrlEnum.DICT_DATA_VALUE.getName()));
}
@Autowired
private SysDefaultImgurlService sysDefaultImgurlService;
public DefaultImgUrl(){
this.sysDefaultImgurlService = SpringUtil.getBean(SysDefaultImgurlService.class);
}
private static Map<String, String> map= new HashMap<>();
/*public DefaultImgUrl(@Autowired SysDefaultImgurlService sysDefaultImgurlService){
this.sysDefaultImgurlService = sysDefaultImgurlService;
}*/
@Override
public void serialize(
String imgUrl, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
// Object currentValue = jsonGenerator.getCurrentValue();
// Class<?> aClass1 = currentValue.getClass();
// Object annotationValue = AnnotationUtil.getAnnotationValue(aClass1, BusinessType.class);
// BusinessTypeEnum businessTypeEnum = BusinessTypeEnum.valueOf(annotationValue.toString());
public void serialize(String imgUrl, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)throws IOException {
if(StringUtils.isNotBlank(imgUrl)){
jsonGenerator.writeString(imgUrl);
}else{
if (jsonGenerator.getCurrentValue() instanceof DevelopmentPageVo ) {
if (jsonGenerator.getCurrentValue() instanceof DevelopmentPageVo) {
DevelopmentPageVo developmentPageVo= (DevelopmentPageVo)jsonGenerator.getCurrentValue();
if(DevelopmentStatusEnum.STATUS_YRZ.getCode().equals(developmentPageVo.getStatus())){
imgUrl = map.get(DefaultImgUrlEnum.DEVELOPMENT_PZZ_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.DEVELOPMENT_PZZ_LIST_YQZD.getCode());
}
if(DevelopmentStatusEnum.STATUS_DRZ.getCode().equals(developmentPageVo.getStatus())){
imgUrl = map.get(DefaultImgUrlEnum.DEVELOPMENT_ZMZ_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.DEVELOPMENT_ZMZ_LIST_YQZD.getCode());
}
}
......@@ -77,21 +54,20 @@ public class DefaultImgUrl extends JsonSerializer<String> {
if (jsonGenerator.getCurrentValue() instanceof ParkPageVo) {
ParkPageVo parkPageVo= (ParkPageVo)jsonGenerator.getCurrentValue();
if(ParkStatusEnum.STATUS_YRZ.getCode().equals(parkPageVo.getStatus())){
imgUrl = map.get(DefaultImgUrlEnum.PARK_PZZ_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.PARK_PZZ_LIST_YQZD.getCode());
}
if(ParkStatusEnum.STATUS_DRZ.getCode().equals(parkPageVo.getStatus())){
imgUrl = map.get(DefaultImgUrlEnum.PARK_ZMZ_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.PARK_ZMZ_LIST_YQZD.getCode());
}
}
if (jsonGenerator.getCurrentValue() instanceof LandPageVo) {
imgUrl = map.get(DefaultImgUrlEnum.LAND_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.LAND_LIST_YQZD.getCode());
}
if (jsonGenerator.getCurrentValue() instanceof CarrierPageVo || jsonGenerator.getCurrentValue() instanceof ParkCarrierVo) {
imgUrl = map.get(DefaultImgUrlEnum.CARRIR_LIST.getName());
imgUrl = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.CARRIR_LIST_YQZD.getCode());
}
jsonGenerator.writeString(imgUrl);
}
}
......
package com.postcard.service.config.other;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
......@@ -13,15 +11,12 @@ import com.postcard.service.moudle.carrier.vo.CarrierDetailVo;
import com.postcard.service.moudle.development.vo.DevelopmentDetailVo;
import com.postcard.service.moudle.land.vo.LandDetailVo;
import com.postcard.service.moudle.park.vo.ParkDetailVo;
import com.postcard.service.moudle.system.service.SysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import com.postcard.service.moudle.system.service.SysDefaultImgurlService;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author:yaobaizheng
......@@ -31,22 +26,14 @@ import java.util.Map;
@Component
public class DefaultImgUrlList extends JsonSerializer<List<String>> {
private SysDictDataService sysDictDataService = SpringUtil.getBean( SysDictDataService.class);
private static Map<String, String> map= new HashMap<>();
private SysDefaultImgurlService sysDefaultImgurlService;
public DefaultImgUrlList(){
JSONObject jsonObject = this.sysDictDataService.listByCodes(DefaultImgUrlEnum.DEFAULT_KEY.getName());
JSONArray dictType = jsonObject.getJSONArray(DefaultImgUrlEnum.DEFAULT_KEY.getName());
for (int i = 0; i < dictType.size(); i++) {
JSONObject obj = dictType.getJSONObject(i);
map.put(obj.getStr(DefaultImgUrlEnum.DICT_DATA_LABEL.getName()),obj.getStr(DefaultImgUrlEnum.DICT_DATA_VALUE.getName()));
}
this.sysDefaultImgurlService = SpringUtil.getBean(SysDefaultImgurlService.class);
}
@Override
public void serialize(
List<String> imgUrlList, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
throws IOException {
if(!CollectionUtils.isEmpty(imgUrlList)){
jsonGenerator.writeArray(imgUrlList.toArray(new String[imgUrlList.size()]),0,imgUrlList.size());
}else{
......@@ -54,27 +41,27 @@ public class DefaultImgUrlList extends JsonSerializer<List<String>> {
if (jsonGenerator.getCurrentValue() instanceof DevelopmentDetailVo) {
DevelopmentDetailVo developmentDetailVo= (DevelopmentDetailVo)jsonGenerator.getCurrentValue();
if(DevelopmentStatusEnum.STATUS_YRZ.getCode().equals(developmentDetailVo.getStatus())){
imgs[0] = map.get(DefaultImgUrlEnum.DEVELOPMENT_PZZ_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.DEVELOPMENT_PZZ_DEATIL_YQZD.getCode());
}
if(DevelopmentStatusEnum.STATUS_DRZ.getCode().equals(developmentDetailVo.getStatus())){
imgs[0] = map.get(DefaultImgUrlEnum.DEVELOPMENT_ZMZ_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.DEVELOPMENT_ZMZ_DEATIL_YQZD.getCode());
}
}
if (jsonGenerator.getCurrentValue() instanceof ParkDetailVo) {
ParkDetailVo parkPageVo= (ParkDetailVo)jsonGenerator.getCurrentValue();
if(ParkStatusEnum.STATUS_YRZ.getCode().equals(parkPageVo.getStatus())){
imgs[0] = map.get(DefaultImgUrlEnum.PARK_PZZ_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.PARK_PZZ_DEATIL_YQZD.getCode());
}
if(ParkStatusEnum.STATUS_DRZ.getCode().equals(parkPageVo.getStatus())){
imgs[0] = map.get(DefaultImgUrlEnum.PARK_ZMZ_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.PARK_ZMZ_DEATIL_YQZD.getCode());
}
}
if (jsonGenerator.getCurrentValue() instanceof LandDetailVo) {
imgs[0] = map.get(DefaultImgUrlEnum.LAND_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.LAND_DEATIL_YQZD.getCode());
}
if (jsonGenerator.getCurrentValue() instanceof CarrierDetailVo) {
imgs[0] = map.get(DefaultImgUrlEnum.CARRIR_DEATIL.getName());
imgs[0] = this.sysDefaultImgurlService.getDefaultImgUrl(DefaultImgUrlEnum.CARRIR_DEATIL_YQZD.getCode());
}
jsonGenerator.writeArray(imgs,0,imgs.length);
}
......
package com.postcard.service.enums;
public enum DefaultImgUrlEnum {
DEFAULT_KEY("default_img_url"),
DICT_DATA_LABEL("dictLabel"),
DICT_DATA_VALUE("dictValue"),
DEVELOPMENT_PZZ_DEATIL("开发区拍摄中详情"),
DEVELOPMENT_ZMZ_DEATIL("开发区招募中详情"),
PARK_PZZ_DEATIL("产业园拍摄中详情"),
PARK_ZMZ_DEATIL("产业园招募中详情"),
LAND_DEATIL("土地拍摄中详情"),
CARRIR_DEATIL("载体拍摄中详情"),
DEFAULT_KEY("default_img_url","redis中hashkey"),
DEVELOPMENT_PZZ_DEATIL_YQZD("DEVELOPMENT_PZZ_DEATIL_YQZD","开发区拍摄中详情"),
DEVELOPMENT_ZMZ_DEATIL_YQZD("DEVELOPMENT_ZMZ_DEATIL_YQZD","开发区招募中详情"),
PARK_PZZ_DEATIL_YQZD("PARK_PZZ_DEATIL_YQZD","产业园拍摄中详情"),
PARK_ZMZ_DEATIL_YQZD("PARK_ZMZ_DEATIL_YQZD","产业园招募中详情"),
LAND_DEATIL_YQZD("LAND_DEATIL_YQZD","土地拍摄中详情"),
CARRIR_DEATIL_YQZD("CARRIR_DEATIL_YQZD","载体拍摄中详情"),
DEVELOPMENT_PZZ_LIST("开发区拍摄中列表"),
DEVELOPMENT_ZMZ_LIST("开发区招募中列表"),
PARK_PZZ_LIST("产业园拍摄中列表"),
PARK_ZMZ_LIST("产业园招募中列表"),
LAND_LIST("土地拍摄中列表"),
CARRIR_LIST("载体拍摄中列表"),
DEVELOPMENT_PZZ_LIST_YQZD("DEVELOPMENT_PZZ_LIST_YQZD","开发区拍摄中列表"),
DEVELOPMENT_ZMZ_LIST_YQZD("DEVELOPMENT_ZMZ_LIST_YQZD","开发区招募中列表"),
PARK_PZZ_LIST_YQZD("PARK_PZZ_LIST_YQZD","产业园拍摄中列表"),
PARK_ZMZ_LIST_YQZD("PARK_ZMZ_LIST_YQZD","产业园招募中列表"),
LAND_LIST_YQZD("LAND_LIST_YQZD","土地拍摄中列表"),
CARRIR_LIST_YQZD("CARRIR_LIST_YQZD","载体拍摄中列表")
;
private String name;
private final String code;
private final String name;
DefaultImgUrlEnum(String name) {
DefaultImgUrlEnum(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.postcard.service.moudle.system.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
*
* @TableName sys_default_imgurl
*/
@TableName(value ="sys_default_imgurl")
@Data
public class SysDefaultImgurl implements Serializable {
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Integer id;
/**
* 默认图地址
*/
private String imgUrl;
/**
* 描述信息
*/
private String description;
/**
* 系统类型
*/
private Integer systemType;
/**
* 业务类型
*/
private Integer bussinessType;
/**
* 唯一标识
*/
private String keyType;
/**
* 是否启用(0:否 1:是)
*/
private Integer status;
/**
* 乐观锁
*/
private Integer version;
/**
* 创建人
*/
private String createBy;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
package com.postcard.service.moudle.system.mapper;
import com.postcard.service.moudle.system.entity.SysDefaultImgurl;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author 26996
* @description 针对表【sys_default_imgurl】的数据库操作Mapper
* @createDate 2023-12-29 13:59:23
* @Entity com.postcard.service.moudle.system.entity.SysDefaultImgurl
*/
public interface SysDefaultImgurlMapper extends BaseMapper<SysDefaultImgurl> {
}
package com.postcard.service.moudle.system.service;
import com.postcard.service.moudle.system.entity.SysDefaultImgurl;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Map;
/**
* @author 26996
* @description 针对表【sys_default_imgurl】的数据库操作Service
* @createDate 2023-12-29 13:59:23
*/
public interface SysDefaultImgurlService extends IService<SysDefaultImgurl> {
/**
* 根据key来获取默认图
* @param key 拼接规则 sys_default_imgurl.system_type+bussiness_type+key_type
* @return SysDefaultImgurl
*/
String getDefaultImgUrl(String key);
Map<String, String> getAllDefaultImgUrl();
}
package com.postcard.service.moudle.system.service.impl;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.postcard.service.constant.RedisConstants;
import com.postcard.service.enums.DefaultImgUrlEnum;
import com.postcard.service.enums.StatusEnum;
import com.postcard.service.moudle.system.entity.SysDefaultImgurl;
import com.postcard.service.moudle.system.service.SysDefaultImgurlService;
import com.postcard.service.moudle.system.mapper.SysDefaultImgurlMapper;
import com.postcard.service.util.redis.RedisUtil;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 26996
* @description 针对表【sys_default_imgurl】的数据库操作Service实现
* @createDate 2023-12-29 13:59:23
*/
@Service
public class SysDefaultImgurlServiceImpl extends ServiceImpl<SysDefaultImgurlMapper, SysDefaultImgurl>
implements SysDefaultImgurlService{
/**
* 根据key来获取默认图
* @param key 拼接规则 sys_default_imgurl.system_type+bussiness_type+key_type
* @return SysDefaultImgurl
*/
@Override
public String getDefaultImgUrl(String key) {
Map<String, String> map = this.getAllDefaultImgUrl();
String sysDefaultImgurl = map.get(key);
if(sysDefaultImgurl == null){
RedisUtil.delHashKey(RedisConstants.DICT_DATA, DefaultImgUrlEnum.DEFAULT_KEY.getCode());
map = this.getAllDefaultImgUrl();
sysDefaultImgurl = map.get(key);
}
return sysDefaultImgurl;
}
@Override
public Map<String, String> getAllDefaultImgUrl() {
Object value= RedisUtil.hGet(RedisConstants.DICT_DATA, DefaultImgUrlEnum.DEFAULT_KEY.getCode());
Map<String, String> result=new HashMap<>();
if(ObjectUtils.isNotEmpty(value)){
List<SysDefaultImgurl> list = JSONUtil.toList(JSONUtil.toJsonStr(value), SysDefaultImgurl.class);
list.forEach(data->{
result.put(data.getKeyType(),data.getImgUrl());
});
}else {
LambdaQueryWrapper<SysDefaultImgurl> lambdaQueryWrapper=new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(SysDefaultImgurl::getStatus, StatusEnum.ENABLE.getCode());
List<SysDefaultImgurl> list = this.list(lambdaQueryWrapper);
if(!CollectionUtils.isEmpty(list)){
RedisUtil.hPut(RedisConstants.DICT_DATA, DefaultImgUrlEnum.DEFAULT_KEY.getCode(), JSONUtil.toJsonStr(list));
}
list.forEach(data->{
result.put(data.getKeyType(),data.getImgUrl());
});
}
return result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment