Controller层
@ApiOperation(value = "任务列表")
@RequestMapping(value = "/taskList", method = RequestMethod.GET)
public PaginationVO taskList(PaginationVO<ProductCommentCrawlTask> pageInfo, String searchValue, ProductCommentCrawlTask product) throws Exception {
return productCommentService.productCommentCrawlTaskList(pageInfo, searchValue, product);
}
Service层
@Override
public PaginationVO productCommentCrawlTaskList(PaginationVO<ProductCommentCrawlTask> pageInfo, String searchValue, ProductCommentCrawlTask comment) throws Exception {
Map<String, Object> paramMap = MapUtil.beansToMap(comment);
paramMap.put("searchValue", searchValue);
Long totalCount = productCommentDao.countByMap(paramMap);
List<ProductCommentCrawlTask> list = new ArrayList<>();
if (!totalCount.equals(0L)) {
PageHelper.startPage(pageInfo.getPage(), pageInfo.getPageSize());
list = productCommentDao.listCommentCrawlByMap(paramMap);
}
return new PaginationVO<>(pageInfo.getPage(), pageInfo.getPageSize(), totalCount, list);
}
Dao层
Long countByMap(Map<String, Object> params);
List<ProductCommentCrawlTask> listCommentCrawlByMap(Map<String, Object> paramMap);
Mapper
<sql id="baseColumns">
id, product_id, sku, product_title, product_url, product_image, target_product_id, target_product_url, target_platform, creator_id,
creator, create_time, updater_id, updater, update_time, status, message, push_status
</sql>
<sql id="baseInsertColumns">
product_id, sku, product_title, product_url, product_image, target_product_id, target_product_url, target_platform, creator_id,
creator, create_time, updater_id, updater, update_time, status, message, push_status
</sql>
<sql id="queryByMapSql">
<where>
<if test="sku != null and sku !=''">sku=#{sku}</if>
<if test="productId != null and productId !=''">and product_id=#{productId}</if>
<if test="productTitle != null and productTitle !=''">and product_title=#{productTitle}</if>
<if test="productUrl != null and productUrl != ''">and product_url=#{productUrl}</if>
<if test="productImage != null and productImage != ''">and product_image=#{productImage}</if>
<if test="targetProductId != null and targetProductId !=''">and target_product_id=#{targetProductId}</if>
<if test="targetPlatform != null and targetPlatform !='' ">and target_platform=#{targetPlatform}</if>
<if test="targetProductUrl != null and targetProductUrl != ''">and target_product_url=#{targetProductUrl}
</if>
<if test="creatorId != null and creatorId != ''">and creator_id=#{creatorId}</if>
<if test="creator != null and creator !=''">and creator=#{creator}</if>
<if test="createTime != null">and create_time=#{createTime}</if>
<if test="updateTime !=null ">and update_time=#{updateTime}</if>
<if test="updaterId != null and updaterId !=''">and updater_id=#{updaterId}</if>
<if test="updater != null and updater != ''">and updater=#{updater}</if>
<if test="status != null ">and status=#{status}</if>
<if test="pushStatus != null ">and push_status=#{pushStatus}</if>
<if test="searchValue != null and searchValue != ''">
AND (
product_title LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR target_product_id LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR product_url LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR target_platform LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR sku LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR target_product_url LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
OR product_id LIKE CONCAT('%', CONCAT(#{searchValue},'%'))
)
</if>
</where>
</sql>
<select id="countByMap" resultType="java.lang.Long">
select count(1) from zjz_comment_crawl_task
<include refid="queryByMapSql"/>
</select>
<select id="listCommentCrawlByMap" resultMap="baseResultMap">
select
<include refid="baseColumns"/>
from zjz_comment_crawl_task
<include refid="queryByMapSql"/>
<include refid="defaultOrderSql"/>
</select>
util类
import java.io.Serializable;
import java.util.Collection;
/**
*
* <p>
* 分页实体VO类:
* </p>
*/
@SuppressWarnings({ "serial", "unused" })
public class PaginationVO<T> implements Serializable, Cloneable {
private int pageSize = 20; // 每页显示的行数,默认20条
private int page = 1; // 当前页号,默认第一页
private long totalPages; // 总页数
private long total; // 记录数
private String sort;
private String direction;
private Collection<T> data; // 数据
public PaginationVO() {
}
public PaginationVO(Collection<T> data) {
this.data = data;
}
public PaginationVO(Integer page, Integer pageSize) {
this.page = page == null ? this.page : page;
this.pageSize = pageSize == null ? this.pageSize : pageSize;
}
public PaginationVO(Integer page, Integer pageSize, Long total,
Collection<T> data) {
this(page, pageSize);
this.total = total == null ? 0 : total;
this.data = data;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public void setData(Collection<T> data) {
this.data = data;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public long getTotalPages() {
return (this.total % this.pageSize == 0) ? this.total
/ this.pageSize : this.total / this.pageSize + 1;
}
public void setTotalPages(long totalPages) {
this.totalPages = totalPages;
}
public String getSort() {
return sort;
}
public void setSort(String sort) {
this.sort = sort;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
public Collection<T> getData() {
return data;
}
}
package com.efe.ms.common.util;
import com.alibaba.fastjson.JSONObject;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
/**
* Map工具类
*
*/
public class MapUtil {
/**
* javaBean 转 Map
*
* @param object
* 需要转换的javabean
* @return 转换结果map
* @throws Exception
*/
@SuppressWarnings("rawtypes")
public static Map<String, Object> beanToMap(Object object) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Class cls = object.getClass();
Field[] fields = cls.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
map.put(field.getName(), field.get(object));
}
return map;
}
@SuppressWarnings("rawtypes")
public static Map<String, String> beanToStringMap(Object object) throws Exception {
Map<String, String> map = new HashMap<>();
Class cls = object.getClass();
Field[] fields = cls.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
map.put(field.getName(), field.get(object) == null ? null : field.get(object).toString());
}
return map;
}
public static Map<String, Object> beansToMap(Object... objects)
throws Exception {
final Map<String, Object> map = new HashMap<String, Object>();
if (objects == null) {
return map;
}
for (Object obj : objects) {
map.putAll(beanToMap(obj));
}
return filterNullValueKeys(map);
}
private static Map<String, Object> filterNullValueKeys(Map<String, Object> map) {
if (map != null) {
Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
Entry<String, Object> obj = null;
while(iterator.hasNext()){
obj = iterator.next();
if(obj.getKey() == null || obj.getValue() == null){
iterator.remove();
}
}
}
return map;
}
/**
*
* @param map
* 需要转换的map
* @param cls
* 目标javaBean的类对象
* @return 目标类object
* @throws Exception
*/
public static <T> T mapToBean(Map<String, Object> map, Class<T> cls)
throws Exception {
T ins = cls.newInstance();
for (String key : map.keySet()) {
Field temField = cls.getDeclaredField(key);
temField.setAccessible(true);
temField.set(ins, map.get(key));
}
return ins;
}
public static Map<String, String> convertJSON2Map(JSONObject jo) {
Map<String, String> map = new HashMap<String, String>();
Iterator<java.util.Map.Entry<String, Object>> ite = jo.entrySet().iterator();
Map.Entry<String, Object> entry = null;
while (ite.hasNext()) {
entry = ite.next();
map.put(entry.getKey(), entry.getValue() == null ? "" : entry.getValue().toString());
}
return map;
}
}
实体类
@Data
public class ProductCommentCrawlTask extends BaseModel {
private String productId;
private String sku;
private String productTitle;
private String productUrl;
private String productImage;
private String targetProductId;
private String targetProductUrl;
private String targetPlatform;
private String creatorId;
private String creator;
private String updaterId;
private String updater;
private Short status;
private String message;
}