Commit 92513729 authored by Shen's avatar Shen

1. 添加FieldMetaObjectHandler类,自动填充create_date字段

parent c3f9539c
......@@ -6,6 +6,7 @@ import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.common.utils.SubListForPageUtil;
import io.hmit.modules.serviceOrder.dao.PensionOrderDao;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
import io.hmit.modules.serviceOrder.entity.PensionOrderEntity;
......@@ -17,10 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* 订单表
......@@ -74,17 +73,20 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
result.addAll(list);
}
// page.setTotal(result.size());
Integer pageNum = Integer.parseInt(params.get("page").toString());
Integer pageSize = Integer.parseInt(params.get("limit").toString());
Integer count = result.size();
Integer pageNo = (pageNum - 1) * pageSize;
List<PensionOrderDTO> list2 ;
if (pageNo+pageSize > count) {
list2 = result.subList(pageNo,count );
}else {
list2 = result.subList(pageNo,pageNo+pageSize);
}
return getPageData(list2, result.size(), PensionOrderDTO.class);
// Integer pageNum = Integer.parseInt(params.get("page").toString());
// Integer pageSize = Integer.parseInt(params.get("limit").toString());
// Integer count = result.size();
// Integer pageNo = (pageNum - 1) * pageSize;
// List<PensionOrderDTO> list2 ;
// if (pageNo+pageSize > count) {
// list2 = result.subList(pageNo,count );
// }else {
// list2 = result.subList(pageNo,pageNo+pageSize);
// }
// return getPageData(list2, result.size(), PensionOrderDTO.class);
List<PensionOrderDTO> sortList = result.stream().sorted(Comparator.comparing(PensionOrderDTO::getCreateDate)).collect(Collectors.toList());
Collections.reverse(sortList);
return getPageData(SubListForPageUtil.getSubList(params, sortList), sortList.size(), PensionOrderDTO.class);
}
@Override
......
package io.hmit.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* 公共字段,自动填充值
*
* @author zsh 408538940@qq.com
*/
@Component
public class FieldMetaObjectHandler implements MetaObjectHandler {
private final static String CREATE_DATE = "createDate";
private final static String UPDATE_DATE = "updateDate";
@Override
public void insertFill(MetaObject metaObject) {
Date date = new Date();
//创建时间
setInsertFieldValByName(CREATE_DATE, date, metaObject);
//更新时间
setInsertFieldValByName(UPDATE_DATE, date, metaObject);
}
@Override
public void updateFill(MetaObject metaObject) {
//更新时间
setUpdateFieldValByName(UPDATE_DATE, new Date(), metaObject);
}
}
\ No newline at end of file
package io.hmit.modules.serviceOrder.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
......@@ -19,6 +23,11 @@ import java.util.Date;
public class PensionOrderEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId
private Long id;
/**
* 订单编号
*/
......@@ -120,5 +129,15 @@ public class PensionOrderEntity extends BaseEntity {
* 所属社区Id
*/
private Long communityId;
/**
* 创建者
*/
@TableField(fill = FieldFill.INSERT)
private Long creator;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createDate;
}
......@@ -135,7 +135,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
list.addAll(list2);
}
// page.setTotal(list.size());
List<PensionOrderDTO> sortList = list.stream().sorted(Comparator.comparing(PensionOrderDTO::getId)).collect(Collectors.toList());
List<PensionOrderDTO> sortList = list.stream().sorted(Comparator.comparing(PensionOrderDTO::getCreateDate)).collect(Collectors.toList());
Collections.reverse(sortList);
return getPageData(getSubList(params, sortList), sortList.size(), PensionOrderDTO.class);
}
......@@ -169,7 +169,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
result.addAll(list);
}
// page.setTotal(result.size());
List<PensionOrderDTO> sortList = result.stream().sorted(Comparator.comparing(PensionOrderDTO::getId)).collect(Collectors.toList());
List<PensionOrderDTO> sortList = result.stream().sorted(Comparator.comparing(PensionOrderDTO::getCreateDate)).collect(Collectors.toList());
Collections.reverse(sortList);
return getPageData(getSubList(params, sortList), sortList.size(), PensionOrderDTO.class);
}
......
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