文章广告
This commit is contained in:
parent
bdd597895e
commit
ed4113968c
|
|
@ -1,22 +1,21 @@
|
|||
package com.ruoyi.content.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.content.domain.CmsArticleAdInfo;
|
||||
import com.ruoyi.content.service.ICmsArticleAdInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.content.domain.CmsArticleAdInfo;
|
||||
import com.ruoyi.content.service.ICmsArticleAdInfoService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文章广告Controller
|
||||
*
|
||||
|
|
@ -72,7 +71,7 @@ public class AdvertisementController extends BaseController {
|
|||
* 新增保存文章广告
|
||||
*/
|
||||
@Log(title = "文章广告", businessType = BusinessType.INSERT)
|
||||
@RequestMapping("/add")
|
||||
@PostMapping("/add")
|
||||
@ResponseBody
|
||||
public AjaxResult addSave(@RequestParam("addImg") MultipartFile[] files, CmsArticleAdInfo cmsArticleAdInfo) {
|
||||
MultipartFile file = files[0];
|
||||
|
|
@ -95,8 +94,12 @@ public class AdvertisementController extends BaseController {
|
|||
@Log(title = "文章广告", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
@ResponseBody
|
||||
public AjaxResult editSave(CmsArticleAdInfo cmsArticleAdInfo) {
|
||||
return toAjax(cmsArticleAdInfoService.updateCmsArticleAdInfo(cmsArticleAdInfo));
|
||||
public AjaxResult editSave(@RequestParam("addImg") MultipartFile[] files, CmsArticleAdInfo cmsArticleAdInfo) {
|
||||
MultipartFile file = null;
|
||||
if (files != null && files.length > 0) {
|
||||
file = files[0];
|
||||
}
|
||||
return toAjax(cmsArticleAdInfoService.updateCmsArticleAdInfo(file, cmsArticleAdInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ruoyi.content.exception;
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*
|
||||
* @author zhanghe
|
||||
*/
|
||||
public class BusinessException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -717870860504034613L;
|
||||
|
||||
public BusinessException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public BusinessException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ruoyi.content.exception;
|
||||
|
||||
/**
|
||||
* 参数异常
|
||||
*
|
||||
* @author zhanghe
|
||||
*
|
||||
*/
|
||||
public class ParameterException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -796008340044578794L;
|
||||
|
||||
public ParameterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParameterException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,4 +61,6 @@ public interface CmsArticleAdInfoMapper {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteCmsArticleAdInfoByIds(String[] adIds);
|
||||
|
||||
CmsArticleAdInfo selectByPrimaryKey(Integer adId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,784 @@
|
|||
package com.ruoyi.content.redis;
|
||||
|
||||
import com.ruoyi.content.exception.ParameterException;
|
||||
import com.ruoyi.content.utils.JsonUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.BoundValueOperations;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* redis操作类
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
public class RedisManager {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(RedisManager.class);
|
||||
|
||||
private static String DEFAULT_CHARSET = "UTF-8";
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 获取过期时间
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public long ttl(String key) {
|
||||
return redisTemplate.getExpire(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放set集合
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 存放集合内容(字符串数组)
|
||||
*/
|
||||
public Long saveSet(String key, String... value) {
|
||||
try {
|
||||
|
||||
return redisTemplate.opsForSet().add(key, value);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的saveSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放Zset集合
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 存放集合内容(字符串数组)
|
||||
*/
|
||||
public boolean saveZSet(String key, String value) {
|
||||
try {
|
||||
double score = System.currentTimeMillis();
|
||||
return redisTemplate.opsForZSet().add(key, value, score);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的savezSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除在Redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 要删除的set集合中的值
|
||||
* @return
|
||||
*/
|
||||
public Long deleteSet(String key, String value) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().remove(key, value);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的deleteSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除在Redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 要删除的set集合中的值
|
||||
* @return
|
||||
*/
|
||||
public Long deleteZSet(String key, String value) {
|
||||
try {
|
||||
return redisTemplate.opsForZSet().remove(key, value);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的deleteSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存放在redis中的set集合
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public Set<String> querySet(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的querySet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存放在redis中的ZSet集合
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param min 最小分
|
||||
* @param max 最大分
|
||||
* @param offset 开始坐标
|
||||
* @param count 显示长度
|
||||
* @return
|
||||
*/
|
||||
public Set<String> queryZSet(String key, double min, double max, long offset, long count) {
|
||||
try {
|
||||
return redisTemplate.opsForZSet().rangeByScore(key, min, max, offset, count);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的querySet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 倒序获取存放在redis中的ZSet集合
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param min 最小分
|
||||
* @param max 最大分
|
||||
* @param offset 开始坐标
|
||||
* @param count 显示长度
|
||||
* @return
|
||||
*/
|
||||
public Set<String> reverseQueryZSet(String key, double min, double max, long offset, long count) {
|
||||
try {
|
||||
return redisTemplate.opsForZSet().reverseRangeByScore(key, min, max, offset, count);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的querySet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存放在redis中的zSet集合的成员数
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public Long zSetCount(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForZSet().size(key);
|
||||
} catch (Exception e) {
|
||||
logger.info("操作redis的zSetCount方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放信息,支持覆盖
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 存放值
|
||||
* @return
|
||||
*/
|
||||
public boolean save(String key, String value) {
|
||||
return save(key, value, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放信息,支持覆盖
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 存放值
|
||||
* @param time 过期时间,单位秒
|
||||
* @return
|
||||
*/
|
||||
public boolean save(String key, String value, long time) {
|
||||
byte[] values = null;
|
||||
try {
|
||||
values = value.getBytes(DEFAULT_CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.info("保存时,value转换utf-8编码异常,key【{}】,value【{}】", key, value);
|
||||
throw new ParameterException("保存时,value转换utf-8编码异常,key{" + key + "},value{" + value + "}");
|
||||
}
|
||||
return save(key.getBytes(), values, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存放信息,支持覆盖、过期时间
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param value 存放值
|
||||
* @param time 过期时间,单位秒
|
||||
* @return
|
||||
*/
|
||||
public boolean save(final byte[] key, final byte[] value, final long time) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
connection.set(key, value);
|
||||
if (time > 0) {
|
||||
connection.expire(key, time);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的save方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存放在redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public String query(String key) {
|
||||
byte[] value = qurey(key.getBytes());
|
||||
if (value == null) {
|
||||
logger.info("根据【{}】获取值【{}】", key, value);
|
||||
return "";
|
||||
} else {
|
||||
try {
|
||||
return new String(value, DEFAULT_CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.info("操作Redis的query方法出现异常!,value转换utf-8编码异常,key【{}】,value【{}】", key, value);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存放在redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public byte[] qurey(final byte[] key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<byte[]>() {
|
||||
@Override
|
||||
public byte[] doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.get(key);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的qurey方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取与字段中存储的键哈希相关联的值
|
||||
*
|
||||
* @param key
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
public String hQuery(String key, String field) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<String>() {
|
||||
@Override
|
||||
public String doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
byte[] value = connection.hGet(key.getBytes(), field.getBytes());
|
||||
return value.toString();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的queryKeys方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询匹配的所有KEY
|
||||
*
|
||||
* @param pattern
|
||||
* @return
|
||||
*/
|
||||
public List<String> queryKeys(String pattern) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<List<String>>() {
|
||||
@Override
|
||||
public List<String> doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
Set<byte[]> value = connection.keys(pattern.getBytes());
|
||||
if (value != null && !value.isEmpty()) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (byte[] v : value) {
|
||||
try {
|
||||
values.add(new String(v, DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的queryKeys方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断键值是否存在
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public boolean exists(String key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.exists(key.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的exists方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断键值是否存在
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public boolean exists(final byte[] key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.exists(key);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的exists方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊查詢所有的key,模糊查询 (key*)
|
||||
*
|
||||
* @param keys
|
||||
* @return
|
||||
*/
|
||||
public Set<byte[]> queryByVague(final String keys) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.keys(keys.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的queryByVague方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除在redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public Long delete(final String key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.del(key.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的delete方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除在redis中的值
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public Long delete(final byte[] key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.del(key);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的delete方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除在redis中的值
|
||||
*
|
||||
* @param keys 存放key
|
||||
* @return
|
||||
*/
|
||||
public Long delete(final Set<byte[]> keys) {
|
||||
long count = 0;
|
||||
for (byte[] key : keys) {
|
||||
count = count + delete(key);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量获取redis中的值,支持数字
|
||||
*
|
||||
* @param key 存放key
|
||||
* @param incrementValue 增量值
|
||||
* @return
|
||||
*/
|
||||
public Long increment(String key, long incrementValue) {
|
||||
try {
|
||||
BoundValueOperations<String, String> bo = redisTemplate.boundValueOps(key);
|
||||
if (bo == null) {
|
||||
return 0L;
|
||||
} else {
|
||||
return bo.increment(incrementValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的increment方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量获取redis中的值,每次增长1
|
||||
*
|
||||
* @param key 存放key
|
||||
* @return
|
||||
*/
|
||||
public Long increment(String key) {
|
||||
try {
|
||||
BoundValueOperations<String, String> bo = redisTemplate.boundValueOps(key);
|
||||
if (bo == null) {
|
||||
return 0L;
|
||||
} else {
|
||||
return bo.increment(1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的increment方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空redis 所有数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean flushDB() {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
connection.flushDb();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的flushDB方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis从List头部存储数据
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return 当前List的长度
|
||||
*/
|
||||
public Long lpush(String key, String value) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.lPush(key.getBytes(), value.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的lpush方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis从List尾部提取数据
|
||||
*
|
||||
* @param key
|
||||
* @return value
|
||||
*/
|
||||
public String rPop(String key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<String>() {
|
||||
@Override
|
||||
public String doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
byte[] re = connection.rPop(key.getBytes());
|
||||
String value = "";
|
||||
if (re != null && re.length > 0) {
|
||||
try {
|
||||
value = new String(re, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的rPop方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取List的长度
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Long lLen(String key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.lLen(key.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的lLen方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储在哈希表中指定字段的值
|
||||
*
|
||||
* @param key
|
||||
* @param field 哈希表的字段名
|
||||
* @return
|
||||
*/
|
||||
public String hGet(String key, String field) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<String>() {
|
||||
@Override
|
||||
public String doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
String result = "";
|
||||
byte[] values = connection.hGet(key.getBytes(), field.getBytes());
|
||||
if (values == null) {
|
||||
return result;
|
||||
} else {
|
||||
try {
|
||||
result = new String(values, DEFAULT_CHARSET);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的hGet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储在哈希表中指定字段的值加上增量
|
||||
*
|
||||
* @param key
|
||||
* @param field 哈希表的字段名
|
||||
* @param delta 增量
|
||||
* @return
|
||||
*/
|
||||
public Long updateHset(String key, String field, Long delta) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
Long hLong = 0L;
|
||||
try {
|
||||
hLong = connection.hIncrBy(key.getBytes(), field.getBytes(DEFAULT_CHARSET), delta);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return hLong;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的updateHset方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在哈希表中指定 KEY的所有字段和值
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> hGetAll(String key) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
Map<byte[], byte[]> values = connection.hGetAll(key.getBytes());
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
if (values != null && !values.isEmpty()) {
|
||||
Set<byte[]> keys = values.keySet();
|
||||
if (keys != null && !keys.isEmpty()) {
|
||||
for (byte[] key : keys) {
|
||||
try {
|
||||
map.put(new String(key, DEFAULT_CHARSET), new String(values.get(key), DEFAULT_CHARSET));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.info("Redis提取哈希表, key【{}】, value【{}】", key, JsonUtil.objectToJackson(map));
|
||||
return map;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的hGetAll方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将哈希表 key 中的字段 field 的值设为 value
|
||||
*
|
||||
* @param key 键
|
||||
* @param field 哈希的字段名
|
||||
* @param value 哈希的值
|
||||
* @return
|
||||
*/
|
||||
public Boolean hSet(String key, String field, String value, Long time) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
try {
|
||||
connection.hSet(key.getBytes(), field.getBytes(DEFAULT_CHARSET), value.getBytes(DEFAULT_CHARSET));
|
||||
if (time > 0) {
|
||||
connection.expire(key.getBytes(), time);
|
||||
}
|
||||
return true;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的hSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同时将多个 field-value (域-值)对设置到哈希表 key 中
|
||||
*
|
||||
* @param key
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
public Boolean hMSet(String key, Map<String, String> map, long time) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Boolean>() {
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
Boolean result = false;
|
||||
try {
|
||||
Map<byte[], byte[]> hashes = new HashMap<byte[], byte[]>();
|
||||
if (map != null && !map.isEmpty()) {
|
||||
Set<String> setKeys = map.keySet();
|
||||
if (setKeys != null && !setKeys.isEmpty()) {
|
||||
for (String skey : setKeys) {
|
||||
hashes.put(skey.getBytes(DEFAULT_CHARSET), map.get(skey).getBytes(DEFAULT_CHARSET));
|
||||
}
|
||||
}
|
||||
}
|
||||
connection.hMSet(key.getBytes(), hashes);
|
||||
if (time > 0) {
|
||||
connection.expire(key.getBytes(), time);
|
||||
}
|
||||
result = true;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("插入哈希表,key【{}】, value【{}】, 操作结果【{}】", key, JsonUtil.objectToJackson(map), result);
|
||||
return result;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的hMSet方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个哈希表字段
|
||||
*
|
||||
* @param key
|
||||
* @param field 哈希表字段
|
||||
* @return
|
||||
*/
|
||||
public Long hDel(String key, String field) {
|
||||
try {
|
||||
return redisTemplate.execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.hDel(key.getBytes(), field.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.info("操作Redis的hDel方法出现异常!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,10 +40,11 @@ public interface ICmsArticleAdInfoService {
|
|||
/**
|
||||
* 修改文章广告
|
||||
*
|
||||
* @param file 广告图片
|
||||
* @param cmsArticleAdInfo 文章广告
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateCmsArticleAdInfo(CmsArticleAdInfo cmsArticleAdInfo);
|
||||
public int updateCmsArticleAdInfo(MultipartFile file, CmsArticleAdInfo cmsArticleAdInfo);
|
||||
|
||||
/**
|
||||
* 批量删除文章广告
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.ruoyi.common.utils.DateUtils;
|
|||
import com.ruoyi.content.constants.PropertiesConstants;
|
||||
import com.ruoyi.content.domain.CmsArticleAdInfo;
|
||||
import com.ruoyi.content.mapper.CmsArticleAdInfoMapper;
|
||||
import com.ruoyi.content.redis.RedisManager;
|
||||
import com.ruoyi.content.service.ICmsArticleAdInfoService;
|
||||
import com.ruoyi.content.utils.OSSUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -29,6 +30,8 @@ public class CmsArticleAdInfoServiceImpl implements ICmsArticleAdInfoService {
|
|||
|
||||
@Autowired
|
||||
private CmsArticleAdInfoMapper cmsArticleAdInfoMapper;
|
||||
@Autowired
|
||||
private RedisManager redisManager;
|
||||
|
||||
/**
|
||||
* 查询文章广告
|
||||
|
|
@ -99,13 +102,44 @@ public class CmsArticleAdInfoServiceImpl implements ICmsArticleAdInfoService {
|
|||
/**
|
||||
* 修改文章广告
|
||||
*
|
||||
* @param file 广告图片
|
||||
* @param cmsArticleAdInfo 文章广告
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateCmsArticleAdInfo(CmsArticleAdInfo cmsArticleAdInfo) {
|
||||
cmsArticleAdInfo.setUpdateTime(DateUtils.getDate());
|
||||
return cmsArticleAdInfoMapper.updateCmsArticleAdInfo(cmsArticleAdInfo);
|
||||
public int updateCmsArticleAdInfo(MultipartFile file, CmsArticleAdInfo cmsArticleAdInfo) {
|
||||
if (!file.isEmpty()) {
|
||||
String fileName = file.getOriginalFilename();// 文件名
|
||||
String ext = fileName.substring(fileName.lastIndexOf("."), fileName.length());// 文件后缀
|
||||
String fileTime = DateUtils.getMillisecond();
|
||||
fileName = PropertiesConstants.AD_IMG_PATH + fileTime + ext;// OSS保存路径
|
||||
String flag = null;
|
||||
try {
|
||||
flag = OSSUtil.uploadFileByInputStream(PropertiesConstants.OSSENDPOINT, PropertiesConstants.OSSID, PropertiesConstants.OSSKEY,
|
||||
PropertiesConstants.BUCKETNAME, file.getInputStream(), PropertiesConstants.OSSPATH + fileName);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("上传阿里云失败!", e);
|
||||
}
|
||||
if (null == flag || flag.equals("false")) {
|
||||
LOGGER.info("广告图片上传oss失败");
|
||||
return 0;
|
||||
} else {
|
||||
cmsArticleAdInfo.setAdImageUrl(PropertiesConstants.OSS_URL + PropertiesConstants.OSSPATH + fileName);
|
||||
}
|
||||
}
|
||||
String date = DateUtils.getDate();
|
||||
String time = DateUtils.getTimeNow();
|
||||
cmsArticleAdInfo.setAdLinkUrl(cmsArticleAdInfo.getAdLinkUrl() + "(");
|
||||
cmsArticleAdInfo.setUpdateDate(date);
|
||||
cmsArticleAdInfo.setUpdateTime(time);
|
||||
cmsArticleAdInfo.setUpdateUser("company");
|
||||
if (cmsArticleAdInfoMapper.updateCmsArticleAdInfo(cmsArticleAdInfo) > 0) {
|
||||
redisManager.delete("articleAdInfo_id" + cmsArticleAdInfo.getAdId());
|
||||
} else {
|
||||
LOGGER.info("编辑广告失败");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -116,7 +150,16 @@ public class CmsArticleAdInfoServiceImpl implements ICmsArticleAdInfoService {
|
|||
*/
|
||||
@Override
|
||||
public int deleteCmsArticleAdInfoByIds(String ids) {
|
||||
return cmsArticleAdInfoMapper.deleteCmsArticleAdInfoByIds(Convert.toStrArray(ids));
|
||||
String[] arrId = ids.split(",");
|
||||
for (String id : arrId) {
|
||||
CmsArticleAdInfo delType = cmsArticleAdInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (delType != null) {
|
||||
redisManager.delete("articleAdInfo_id" + id);
|
||||
redisManager.delete("article_ad_typeList_" + delType.getAdType());
|
||||
cmsArticleAdInfoMapper.deleteCmsArticleAdInfoById(Long.valueOf(id));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,291 @@
|
|||
package com.ruoyi.content.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFilter;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser.Feature;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
||||
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
|
||||
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
|
||||
import com.ruoyi.content.exception.BusinessException;
|
||||
import com.ruoyi.content.exception.ParameterException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class JsonUtil {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(JsonUtil.class);
|
||||
|
||||
private static ObjectMapper jacksonMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 把json字符串转换为JavaBean (1)普通对象转换:toJson(Student) (2)List转换:toJson(List)
|
||||
* (3)Map转换:toJson(Map) 我们发现不管什么类型,都可以直接传入这个方法
|
||||
* <p>
|
||||
* /** 将Object对象转换成json串,原始方法
|
||||
*
|
||||
* @param object Java对象
|
||||
* @return
|
||||
*/
|
||||
public static String objectToJson(Object object) {
|
||||
try {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
return jacksonMapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Object对象转换成json串,把null换成""
|
||||
*
|
||||
* @param object Java对象
|
||||
* @return
|
||||
*/
|
||||
public static String objectToJackson(Object object) {
|
||||
ObjectMappingCustomer jacksonMapper = new ObjectMappingCustomer();
|
||||
try {
|
||||
return jacksonMapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Object对象转换成json串,自动去掉null和""的字段
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
public static String objectToJacksonNotNull(Object object) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||
try {
|
||||
return jacksonMapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把json字符串转换为JavaBean对象
|
||||
*
|
||||
* @param json 字符串
|
||||
* @param object Java对象类型
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T jackson2Object(String json, Class<?> object) {
|
||||
T t = null;
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
try {
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
t = (T) jacksonMapper.readValue(json, object);
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("把json字符串转换为JavaBean对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("jackson转化对象失败");
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("把json字符串转换为JavaBean对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("jackson转化对象失败");
|
||||
} catch (IOException e) {
|
||||
logger.error("把json字符串转换为JavaBean对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("jackson转化对象失败");
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把Json转成Map
|
||||
*
|
||||
* @param json JSON字符串
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Map jackson2Map(String json) {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
try {
|
||||
jacksonMapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
return jacksonMapper.readValue(json, Map.class);
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("把Json转成Map异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("把Json转成Map失败");
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("把Json转成Map异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("把Json转成Map失败");
|
||||
} catch (IOException e) {
|
||||
logger.error("把Json转成Map异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("把Json转成Map失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换集合对象
|
||||
*
|
||||
* @param json json数据
|
||||
* @param obj java对象类型
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T JsonToList(String json, Class<?> obj) {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
List<T> lst = null;
|
||||
try {
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
lst = (List<T>) jacksonMapper.readValue(json, getCollectionType(List.class, obj));
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
} catch (IOException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
}
|
||||
return (T) lst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换集合对象
|
||||
*
|
||||
* @param json
|
||||
* @param objectList 集合类型
|
||||
* @param obj java对象类型
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T JsonToCollectionType(String json, Class<?> objectList, Class<?> obj) {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
List<T> lst = null;
|
||||
try {
|
||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
lst = (List<T>) jacksonMapper.readValue(json, getCollectionType(objectList, obj));
|
||||
} catch (JsonParseException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
} catch (JsonMappingException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
} catch (IOException e) {
|
||||
logger.error("转换集合对象异常", e);
|
||||
logger.info("传入JSON:" + json);
|
||||
throw new ParameterException("转换集合对象失败");
|
||||
}
|
||||
return (T) lst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取泛型的Collection Type
|
||||
*
|
||||
* @param collectionClass 泛型的Collection
|
||||
* @param elementClasses 元素类
|
||||
* @return JavaType Java类型
|
||||
* @since 1.0
|
||||
*/
|
||||
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
return jacksonMapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法json节点
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static JsonNode createJsonNode() throws Exception {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
return jacksonMapper.createObjectNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法json节点
|
||||
*
|
||||
* @param data
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws @throws Exception
|
||||
*/
|
||||
public static JsonNode getJsonNode(String data) throws IOException {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
return jacksonMapper.readTree(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转换位Json
|
||||
*
|
||||
* @param object
|
||||
* @param properties
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public static String objectToJackson(Object object, Set<String> properties) throws BusinessException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
FilterProvider filters = new SimpleFilterProvider().addFilter("headFilter",
|
||||
SimpleBeanPropertyFilter.serializeAllExcept(properties));
|
||||
mapper.setFilterProvider(filters);
|
||||
mapper.addMixIn(object.getClass(), HeadFilterMixIn.class);
|
||||
try {
|
||||
return mapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new BusinessException("jackson转化异常");
|
||||
}
|
||||
}
|
||||
|
||||
public static String jsonNode2String(Map<String, String> map) throws IOException {
|
||||
if (jacksonMapper == null) {
|
||||
jacksonMapper = new ObjectMapper();
|
||||
}
|
||||
JsonNodeFactory factory = new JsonNodeFactory(false);
|
||||
ObjectNode objectNode = factory.objectNode();
|
||||
for (Entry<String, String> entry : map.entrySet()) {
|
||||
objectNode.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return jacksonMapper.writeValueAsString(objectNode);
|
||||
}
|
||||
|
||||
@JsonFilter("headFilter")
|
||||
private static interface HeadFilterMixIn {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.ruoyi.content.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
/**
|
||||
* Jackson处理类,处理null字符串
|
||||
*
|
||||
* @author zhanghe
|
||||
*/
|
||||
public class ObjectMappingCustomer extends ObjectMapper {
|
||||
|
||||
private static final long serialVersionUID = -1066355039918898238L;
|
||||
|
||||
public ObjectMappingCustomer() {
|
||||
super();
|
||||
// 空值处理为空串
|
||||
this.getSerializerProvider().setNullValueSerializer(new JsonSerializer<Object>() {
|
||||
@Override
|
||||
public void serialize(Object value, JsonGenerator jg, SerializerProvider sp)
|
||||
throws IOException, JsonProcessingException {
|
||||
jg.writeString("");
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,27 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.content.mapper.CmsArticleAdInfoMapper">
|
||||
|
||||
|
||||
<resultMap type="CmsArticleAdInfo" id="CmsArticleAdInfoResult">
|
||||
<result property="adId" column="AD_ID" />
|
||||
<result property="companyId" column="COMPANY_ID" />
|
||||
<result property="adType" column="AD_TYPE" />
|
||||
<result property="adTypeName" column="AD_TYPE_NAME" />
|
||||
<result property="adLinkUrl" column="AD_LINK_URL" />
|
||||
<result property="adTitle" column="AD_TITLE" />
|
||||
<result property="adName" column="AD_NAME" />
|
||||
<result property="adSummary" column="AD_SUMMARY" />
|
||||
<result property="adColorType" column="AD_COLOR_TYPE" />
|
||||
<result property="adImageUrl" column="AD_IMAGE_URL" />
|
||||
<result property="adState" column="AD_STATE" />
|
||||
<result property="createDate" column="CREATE_DATE" />
|
||||
<result property="createTime" column="CREATE_TIME" />
|
||||
<result property="createUser" column="CREATE_USER" />
|
||||
<result property="updateUser" column="UPDATE_USER" />
|
||||
<result property="updateDate" column="UPDATE_DATE" />
|
||||
<result property="updateTime" column="UPDATE_TIME" />
|
||||
<result property="adId" column="AD_ID"/>
|
||||
<result property="companyId" column="COMPANY_ID"/>
|
||||
<result property="adType" column="AD_TYPE"/>
|
||||
<result property="adTypeName" column="AD_TYPE_NAME"/>
|
||||
<result property="adLinkUrl" column="AD_LINK_URL"/>
|
||||
<result property="adTitle" column="AD_TITLE"/>
|
||||
<result property="adName" column="AD_NAME"/>
|
||||
<result property="adSummary" column="AD_SUMMARY"/>
|
||||
<result property="adColorType" column="AD_COLOR_TYPE"/>
|
||||
<result property="adImageUrl" column="AD_IMAGE_URL"/>
|
||||
<result property="adState" column="AD_STATE"/>
|
||||
<result property="createDate" column="CREATE_DATE"/>
|
||||
<result property="createTime" column="CREATE_TIME"/>
|
||||
<result property="createUser" column="CREATE_USER"/>
|
||||
<result property="updateUser" column="UPDATE_USER"/>
|
||||
<result property="updateDate" column="UPDATE_DATE"/>
|
||||
<result property="updateTime" column="UPDATE_TIME"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectCmsArticleAdInfoVo">
|
||||
|
|
@ -30,32 +30,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="selectCmsArticleAdInfoList" parameterType="CmsArticleAdInfo" resultMap="CmsArticleAdInfoResult">
|
||||
<include refid="selectCmsArticleAdInfoVo"/>
|
||||
<where>
|
||||
<if test="companyId != null and companyId != ''"> and COMPANY_ID = #{companyId}</if>
|
||||
<if test="adType != null and adType != ''"> and AD_TYPE = #{adType}</if>
|
||||
<if test="adTypeName != null and adTypeName != ''"> and AD_TYPE_NAME like concat('%', #{adTypeName}, '%')</if>
|
||||
<if test="adLinkUrl != null and adLinkUrl != ''"> and AD_LINK_URL = #{adLinkUrl}</if>
|
||||
<if test="adTitle != null and adTitle != ''"> and AD_TITLE like concat('%', #{adTitle}, '%')</if>
|
||||
<if test="adName != null and adName != ''"> and AD_NAME like concat('%', #{adName}, '%')</if>
|
||||
<if test="adSummary != null and adSummary != ''"> and AD_SUMMARY = #{adSummary}</if>
|
||||
<if test="adColorType != null and adColorType != ''"> and AD_COLOR_TYPE = #{adColorType}</if>
|
||||
<if test="adImageUrl != null and adImageUrl != ''"> and AD_IMAGE_URL = #{adImageUrl}</if>
|
||||
<if test="adState != null and adState != ''"> and AD_STATE = #{adState}</if>
|
||||
<if test="createDate != null and createDate != ''"> and CREATE_DATE = #{createDate}</if>
|
||||
<if test="createTime != null and createTime != ''"> and CREATE_TIME = #{createTime}</if>
|
||||
<if test="createUser != null and createUser != ''"> and CREATE_USER = #{createUser}</if>
|
||||
<if test="updateUser != null and updateUser != ''"> and UPDATE_USER = #{updateUser}</if>
|
||||
<if test="updateDate != null and updateDate != ''"> and UPDATE_DATE = #{updateDate}</if>
|
||||
<if test="updateTime != null and updateTime != ''"> and UPDATE_TIME = #{updateTime}</if>
|
||||
<where>
|
||||
<if test="companyId != null and companyId != ''">and COMPANY_ID = #{companyId}</if>
|
||||
<if test="adType != null and adType != ''">and AD_TYPE = #{adType}</if>
|
||||
<if test="adTypeName != null and adTypeName != ''">and AD_TYPE_NAME like concat('%', #{adTypeName}, '%')
|
||||
</if>
|
||||
<if test="adLinkUrl != null and adLinkUrl != ''">and AD_LINK_URL = #{adLinkUrl}</if>
|
||||
<if test="adTitle != null and adTitle != ''">and AD_TITLE like concat('%', #{adTitle}, '%')</if>
|
||||
<if test="adName != null and adName != ''">and AD_NAME like concat('%', #{adName}, '%')</if>
|
||||
<if test="adSummary != null and adSummary != ''">and AD_SUMMARY = #{adSummary}</if>
|
||||
<if test="adColorType != null and adColorType != ''">and AD_COLOR_TYPE = #{adColorType}</if>
|
||||
<if test="adImageUrl != null and adImageUrl != ''">and AD_IMAGE_URL = #{adImageUrl}</if>
|
||||
<if test="adState != null and adState != ''">and AD_STATE = #{adState}</if>
|
||||
<if test="createDate != null and createDate != ''">and CREATE_DATE = #{createDate}</if>
|
||||
<if test="createTime != null and createTime != ''">and CREATE_TIME = #{createTime}</if>
|
||||
<if test="createUser != null and createUser != ''">and CREATE_USER = #{createUser}</if>
|
||||
<if test="updateUser != null and updateUser != ''">and UPDATE_USER = #{updateUser}</if>
|
||||
<if test="updateDate != null and updateDate != ''">and UPDATE_DATE = #{updateDate}</if>
|
||||
<if test="updateTime != null and updateTime != ''">and UPDATE_TIME = #{updateTime}</if>
|
||||
</where>
|
||||
order by CREATE_DATE DESC,CREATE_TIME DESC, UPDATE_DATE DESC,UPDATE_TIME DESC
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectCmsArticleAdInfoById" parameterType="Long" resultMap="CmsArticleAdInfoResult">
|
||||
<include refid="selectCmsArticleAdInfoVo"/>
|
||||
where AD_ID = #{adId}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertCmsArticleAdInfo" parameterType="CmsArticleAdInfo" useGeneratedKeys="true" keyProperty="adId">
|
||||
insert into cms_article_ad_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
|
@ -75,7 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateUser != null">UPDATE_USER,</if>
|
||||
<if test="updateDate != null">UPDATE_DATE,</if>
|
||||
<if test="updateTime != null">UPDATE_TIME,</if>
|
||||
</trim>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="companyId != null">#{companyId},</if>
|
||||
<if test="adType != null">#{adType},</if>
|
||||
|
|
@ -93,7 +94,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="updateUser != null">#{updateUser},</if>
|
||||
<if test="updateDate != null">#{updateDate},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateCmsArticleAdInfo" parameterType="CmsArticleAdInfo">
|
||||
|
|
@ -124,10 +125,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</delete>
|
||||
|
||||
<delete id="deleteCmsArticleAdInfoByIds" parameterType="String">
|
||||
delete from cms_article_ad_info where AD_ID in
|
||||
delete from cms_article_ad_info where AD_ID in
|
||||
<foreach item="adId" collection="array" open="(" separator="," close=")">
|
||||
#{adId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.ruoyi.content.domain.CmsArticleAdInfo">
|
||||
<id column="AD_ID" property="adId" jdbcType="INTEGER"/>
|
||||
<result column="COMPANY_ID" property="companyId" jdbcType="VARCHAR"/>
|
||||
<result column="AD_TYPE" property="adType" jdbcType="VARCHAR"/>
|
||||
<result column="AD_TYPE_NAME" property="adTypeName" jdbcType="VARCHAR"/>
|
||||
<result column="AD_LINK_URL" property="adLinkUrl" jdbcType="VARCHAR"/>
|
||||
<result column="AD_TITLE" property="adTitle" jdbcType="VARCHAR"/>
|
||||
<result column="AD_NAME" property="adName" jdbcType="VARCHAR"/>
|
||||
<result column="AD_SUMMARY" property="adSummary" jdbcType="VARCHAR"/>
|
||||
<result column="AD_COLOR_TYPE" property="adColorType" jdbcType="VARCHAR"/>
|
||||
<result column="AD_IMAGE_URL" property="adImageUrl" jdbcType="VARCHAR"/>
|
||||
<result column="AD_STATE" property="adState" jdbcType="VARCHAR"/>
|
||||
<result column="CREATE_DATE" property="createDate" jdbcType="VARCHAR"/>
|
||||
<result column="CREATE_TIME" property="createTime" jdbcType="VARCHAR"/>
|
||||
<result column="CREATE_USER" property="createUser" jdbcType="VARCHAR"/>
|
||||
<result column="UPDATE_USER" property="updateUser" jdbcType="VARCHAR"/>
|
||||
<result column="UPDATE_DATE" property="updateDate" jdbcType="VARCHAR"/>
|
||||
<result column="UPDATE_TIME" property="updateTime" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
AD_ID, COMPANY_ID, AD_TYPE, AD_TYPE_NAME, AD_LINK_URL, AD_TITLE, AD_NAME, AD_SUMMARY,
|
||||
AD_COLOR_TYPE, AD_IMAGE_URL, AD_STATE, CREATE_DATE, CREATE_TIME, CREATE_USER, UPDATE_USER,
|
||||
UPDATE_DATE, UPDATE_TIME
|
||||
</sql>
|
||||
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from article_ad_info
|
||||
where AD_ID = #{adId,jdbcType=INTEGER}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -98,18 +98,18 @@
|
|||
}
|
||||
|
||||
var fileoptions = {
|
||||
showUpload : false,
|
||||
showRemove : true,
|
||||
language : 'zh',
|
||||
allowedPreviewTypes : [ 'image' ],
|
||||
allowedFileExtensions : [ 'jpg', 'png', 'gif' ],
|
||||
maxFileSize : 0,
|
||||
autoReplace : true,// 是否自动替换图片
|
||||
uploadAsync : false,// 异步上传
|
||||
maxFileCount : 1,
|
||||
maxFilesNum : 1,
|
||||
dropZoneEnabled : false,
|
||||
showPreview : true,
|
||||
showUpload: false,
|
||||
showRemove: true,
|
||||
language: 'zh',
|
||||
allowedPreviewTypes: ['image'],
|
||||
allowedFileExtensions: ['jpg', 'png', 'gif'],
|
||||
maxFileSize: 0,
|
||||
autoReplace: true,// 是否自动替换图片
|
||||
uploadAsync: false,// 异步上传
|
||||
maxFileCount: 1,
|
||||
maxFilesNum: 1,
|
||||
dropZoneEnabled: false,
|
||||
showPreview: true,
|
||||
msgUploadThreshold : '上传中',
|
||||
msgUploadEnd : '完成'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
|
||||
<head>
|
||||
<th:block th:include="include :: header('文章广告列表')" />
|
||||
<th:block th:include="include :: header('文章广告列表')"/>
|
||||
</head>
|
||||
<style>
|
||||
.article-table-img {
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
display: block;
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
.article-color {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
|
|
@ -18,53 +19,55 @@
|
|||
}
|
||||
</style>
|
||||
<body class="gray-bg">
|
||||
<div class="container-div">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 search-collapse">
|
||||
<form id="formId">
|
||||
<div class="select-list">
|
||||
<ul>
|
||||
<li>
|
||||
<label>广告标题:</label>
|
||||
<input type="text" name="adTitle"/>
|
||||
</li>
|
||||
<li>
|
||||
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i> 搜索</a>
|
||||
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container-div">
|
||||
<div class="row">
|
||||
<div class="col-sm-12 search-collapse">
|
||||
<form id="formId">
|
||||
<div class="select-list">
|
||||
<ul>
|
||||
<li>
|
||||
<label>广告标题:</label>
|
||||
<input type="text" name="adTitle"/>
|
||||
</li>
|
||||
<li>
|
||||
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
|
||||
class="fa fa-search"></i> 搜索</a>
|
||||
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
|
||||
class="fa fa-refresh"></i> 重置</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="btn-group-sm" id="toolbar" role="group">
|
||||
<a class="btn btn-success" onclick="$.operate.add()">
|
||||
<i class="fa fa-plus"></i> 添加
|
||||
</a>
|
||||
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
|
||||
<i class="fa fa-remove"></i> 删除
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-12 select-table table-striped">
|
||||
<table id="bootstrap-table"></table>
|
||||
</div>
|
||||
<div class="btn-group-sm" id="toolbar" role="group">
|
||||
<a class="btn btn-success" onclick="$.operate.add()">
|
||||
<i class="fa fa-plus"></i> 添加
|
||||
</a>
|
||||
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
|
||||
<i class="fa fa-remove"></i> 删除
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-12 select-table table-striped">
|
||||
<table id="bootstrap-table"></table>
|
||||
</div>
|
||||
</div>
|
||||
<th:block th:include="include :: footer" />
|
||||
<script th:inline="javascript">
|
||||
var prefix = ctx + "content/adverts";
|
||||
</div>
|
||||
<th:block th:include="include :: footer"/>
|
||||
<script th:inline="javascript">
|
||||
var prefix = ctx + "content/adverts";
|
||||
|
||||
$(function() {
|
||||
var options = {
|
||||
url: prefix + "/list",
|
||||
createUrl: prefix + "/add",
|
||||
updateUrl: prefix + "/edit/{id}",
|
||||
removeUrl: prefix + "/remove",
|
||||
exportUrl: prefix + "/export",
|
||||
modalName: "文章广告",
|
||||
columns: [{
|
||||
checkbox: true
|
||||
},
|
||||
$(function () {
|
||||
var options = {
|
||||
url: prefix + "/list",
|
||||
createUrl: prefix + "/add",
|
||||
updateUrl: prefix + "/edit/{id}",
|
||||
removeUrl: prefix + "/remove",
|
||||
exportUrl: prefix + "/export",
|
||||
modalName: "文章广告",
|
||||
columns: [{
|
||||
checkbox: true
|
||||
},
|
||||
{
|
||||
field: 'adId',
|
||||
title: '',
|
||||
|
|
@ -85,9 +88,9 @@
|
|||
{
|
||||
field: 'adLinkUrl',
|
||||
title: '跳转地址',
|
||||
formatter: function(value, row, index) {
|
||||
formatter: function (value, row, index) {
|
||||
var actions = [];
|
||||
actions.push('<a class="btn btn-xs" href="javascript:void(0)" onclick="$.modal.msg(\''+row.adLinkUrl+'\');" ><i class="fa"></i>展示</a> ');
|
||||
actions.push('<a class="btn btn-xs" href="javascript:void(0)" onclick="$.modal.msg(\'' + row.adLinkUrl + '\');" ><i class="fa"></i>展示</a> ');
|
||||
return actions.join('');
|
||||
}
|
||||
},
|
||||
|
|
@ -100,7 +103,7 @@
|
|||
{
|
||||
field: 'adColorType',
|
||||
title: '背景颜色',
|
||||
formatter: function(value, row, index) {
|
||||
formatter: function (value, row, index) {
|
||||
var actions = [];
|
||||
if (row.adColorType === '1') {
|
||||
actions.push('<div class="article-color" style="background-color: #67c5ab"></div>');
|
||||
|
|
@ -119,25 +122,25 @@
|
|||
title: '广告图片',
|
||||
width: '10',
|
||||
widthUnit: 'px',
|
||||
formatter: function(value, row, index) {
|
||||
formatter: function (value, row, index) {
|
||||
var actions = [];
|
||||
actions.push('<img class="article-table-img" src="'+row.adImageUrl+'" ></img> ');
|
||||
actions.push('<img class="article-table-img" src="' + row.adImageUrl + '" ></img> ');
|
||||
return actions.join('');
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
formatter: function(value, row, index) {
|
||||
formatter: function (value, row, index) {
|
||||
var actions = [];
|
||||
actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.adId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
|
||||
actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.adId + '\')"><i class="fa fa-remove"></i>删除</a>');
|
||||
return actions.join('');
|
||||
}
|
||||
}]
|
||||
};
|
||||
$.table.init(options);
|
||||
});
|
||||
</script>
|
||||
};
|
||||
$.table.init(options);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,116 +1,172 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
|
||||
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<th:block th:include="include :: header('修改文章广告')" />
|
||||
<th:block th:include="include :: header('修改文章广告')"/>
|
||||
</head>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-adverts-edit" th:object="${cmsArticleAdInfo}">
|
||||
<input name="adId" th:field="*{adId}" type="hidden">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">公司id:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="companyId" th:field="*{companyId}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告类型:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="adType" class="form-control m-b">
|
||||
<option value="">所有</option>
|
||||
</select>
|
||||
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告类型名:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adTypeName" th:field="*{adTypeName}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告跳转地址:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adLinkUrl" th:field="*{adLinkUrl}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告标题:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adTitle" th:field="*{adTitle}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adName" th:field="*{adName}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告简介:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adSummary" th:field="*{adSummary}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告背景颜色:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="adColorType" class="form-control m-b">
|
||||
<option value="">所有</option>
|
||||
</select>
|
||||
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告图片地址:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adImageUrl" th:field="*{adImageUrl}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告状态 0:展示 1:不可用:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adState" th:field="*{adState}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="createDate" th:field="*{createDate}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">广告创建者:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="createUser" th:field="*{createUser}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="updateUser" th:field="*{updateUser}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="updateDate" th:field="*{updateDate}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<th:block th:include="include :: footer" />
|
||||
<script th:inline="javascript">
|
||||
var prefix = ctx + "content/adverts";
|
||||
$("#form-adverts-edit").validate({
|
||||
focusCleanup: true
|
||||
});
|
||||
<style>
|
||||
.lab {
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
display: inline-block;
|
||||
border-radius: 20%;
|
||||
margin-bottom: 0px;
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
$.operate.save(prefix + "/edit", $('#form-adverts-edit').serialize());
|
||||
}
|
||||
.addColor {
|
||||
|
||||
}
|
||||
</style>
|
||||
<body class="white-bg">
|
||||
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
||||
<form class="form-horizontal m" id="form-adverts-edit" th:object="${cmsArticleAdInfo}">
|
||||
<input name="adId" th:id="adId" th:field="*{adId}" type="hidden">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">广告标题:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adTitle" th:field="*{adTitle}" th:id="adTitle" class="form-control" type="text" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">广告名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adName" th:field="*{adName}" th:id="adName" class="form-control" type="text" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">广告类型:</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="adType" th:field="*{adType}" th:id="adType" class="form-control" onchange="chooseAdType()"
|
||||
required>
|
||||
<option value="1">名片</option>
|
||||
<option value="2">招募</option>
|
||||
<option value="3">增员</option>
|
||||
<option value="4">产品</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" th:hidden="true">
|
||||
<input name="adTypeName" th:field="*{adTypeName}" th:id="adTypeName" class="form-control" type="text">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">跳转地址:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adLinkUrl" th:field="*{adLinkUrl}" th:id="adLinkUrl" class="form-control" type="text"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">简介:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="adSummary" th:field="*{adSummary}" th:id="adSummary" class="form-control" type="text"
|
||||
required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">广告背景颜色:</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="radio" class="addColor" id="addColor_a" th:name="adColorType" value="1"
|
||||
th:checked="*{adColorType} eq '1'">
|
||||
<label class="lab" style="background-color: #67c5ab"></label>
|
||||
<input type="radio" class="addColor" id="addColor_b" th:name="adColorType" value="2"
|
||||
th:checked="*{adColorType} eq '2'">
|
||||
<label class="lab" style="background-color: #b6d882"></label>
|
||||
<input type="radio" class="addColor" id="addColor_c" th:name="adColorType" value="3"
|
||||
th:checked="*{adColorType} eq '3'">
|
||||
<label class="lab" style="background-color: #f88f81"></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label is-required">广告图片地址:</label>
|
||||
<div class="col-sm-1">
|
||||
<img id="imgContent" th:src="*{adImageUrl}" style="width: 50px;height: 50px;">
|
||||
</div>
|
||||
<label class="col-sm-3 control-label">新图片:</label>
|
||||
<div class="col-sm-1">
|
||||
<img id="editImgContent" style="width: 50px;height: 50px;">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">上传新图:</label>
|
||||
<div class="col-sm-7">
|
||||
<input type="file" class="file projectfile" id="editImg" name="editImg">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<th:block th:include="include :: footer"/>
|
||||
<link th:href="@{/css/fileinput.min.css}" rel="stylesheet"/>
|
||||
<script th:src="@{/js/fileinput.min.js}"></script>
|
||||
<script th:src="@{/js/fileinput_locale_zh.js}"></script>
|
||||
<script th:inline="javascript">
|
||||
var prefix = ctx + "content/adverts";
|
||||
|
||||
function chooseAdType() {
|
||||
$('#adTypeName').val($("#adType option:selected").text());
|
||||
}
|
||||
|
||||
$("#form-adverts-edit").validate({
|
||||
focusCleanup: true
|
||||
});
|
||||
|
||||
var fileoptions = {
|
||||
showUpload: false,
|
||||
showRemove: true,
|
||||
language: 'zh',
|
||||
allowedPreviewTypes: ['image'],
|
||||
allowedFileExtensions: ['jpg', 'png', 'gif'],
|
||||
maxFileSize: 0,
|
||||
autoReplace: true,// 是否自动替换图片
|
||||
uploadAsync: false,// 异步上传
|
||||
maxFileCount: 1,
|
||||
maxFilesNum: 1,
|
||||
dropZoneEnabled: false,
|
||||
showPreview: true,
|
||||
msgUploadThreshold: '上传中',
|
||||
msgUploadEnd: '完成'
|
||||
}
|
||||
|
||||
$("#editImg").fileinput(fileoptions).on("change", function (event) {
|
||||
$(".file-preview").css("display", "none");
|
||||
}).on("filebatchselected", function (event, files) {
|
||||
$("#editImgContent").attr("src", $(".file-preview-image.kv-preview-data").attr('src'));
|
||||
}).on("filecleared", function (event) {
|
||||
$("#editImgContent").removeAttr("src");
|
||||
});
|
||||
|
||||
|
||||
function submitHandler() {
|
||||
if ($.validate.form()) {
|
||||
var data = new FormData();
|
||||
data.append('adId', $("#adId").val());
|
||||
data.append('adTitle', $("#adTitle").val());
|
||||
data.append('adName', $("#adName").val());
|
||||
data.append('adType', $("#adType").val());
|
||||
data.append('adTypeName', $("#adTypeName").val());
|
||||
data.append('adLinkUrl', $("#adLinkUrl").val());
|
||||
data.append('adSummary', $("#adSummary").val());
|
||||
data.append('adColorType',$("input[name='adColorType']:checked").val());
|
||||
data.append('addImg', $("#editImg")[0].files[0]);
|
||||
$.ajax({
|
||||
url : prefix + "/edit",
|
||||
data : data,
|
||||
dataType : "json",
|
||||
type : "post",
|
||||
processData: false,//不需要对数据进行处理
|
||||
contentType:false,
|
||||
cache : false,
|
||||
success : function(result) {
|
||||
$.operate.successCallback(result);
|
||||
},
|
||||
error : function(textStatus, e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue