|
|
|
@ -0,0 +1,165 @@
|
|
|
|
|
package com.glxp.udi.admin.mongo.dao;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
|
|
|
import com.glxp.udi.admin.entity.inout.OrderMdEntity;
|
|
|
|
|
import com.glxp.udi.admin.mongo.MongoDBName;
|
|
|
|
|
import com.glxp.udi.admin.mongo.dao.base.MongoBaseDao;
|
|
|
|
|
import com.glxp.udi.admin.mongo.utils.MongoPageHelper;
|
|
|
|
|
import com.glxp.udi.admin.mongo.utils.PageResult;
|
|
|
|
|
import com.glxp.udi.admin.req.inout.OrderFilterRequest;
|
|
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
|
import org.springframework.data.mongodb.core.query.Update;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 订单数据操作类
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
public class OrderDao implements MongoBaseDao<OrderMdEntity, OrderFilterRequest> {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
|
@Resource
|
|
|
|
|
private MongoPageHelper mongoPageHelper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<OrderMdEntity> pageQuery(Query query, OrderFilterRequest orderFilterRequest, int page, int size) {
|
|
|
|
|
if (null == query && orderFilterRequest != null) {
|
|
|
|
|
query = buildQuery(orderFilterRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoPageHelper.pageQuery(query, OrderMdEntity.class, page, size, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<OrderMdEntity> findList(Query query, OrderFilterRequest orderFilterRequest) {
|
|
|
|
|
if (null == query && null != orderFilterRequest) {
|
|
|
|
|
query = buildQuery(orderFilterRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.find(query, OrderMdEntity.class, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OrderMdEntity findOne(Query query, OrderFilterRequest orderFilterRequest) {
|
|
|
|
|
if (query == null && null != orderFilterRequest) {
|
|
|
|
|
query = buildQuery(orderFilterRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.findOne(query, OrderMdEntity.class, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Query query, Update update, OrderMdEntity orderMdEntity) {
|
|
|
|
|
if (null == query) {
|
|
|
|
|
query = buildQuery(orderMdEntity);
|
|
|
|
|
}
|
|
|
|
|
if (null == update) {
|
|
|
|
|
update = buildUpdate(orderMdEntity);
|
|
|
|
|
}
|
|
|
|
|
mongoTemplate.updateMulti(query, update, OrderMdEntity.class, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delete(Query query, OrderFilterRequest orderFilterRequest) {
|
|
|
|
|
if (null == query && null != orderFilterRequest) {
|
|
|
|
|
query = buildQuery(orderFilterRequest);
|
|
|
|
|
}
|
|
|
|
|
mongoTemplate.remove(query, OrderMdEntity.class, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long count(Query query, OrderFilterRequest orderFilterRequest) {
|
|
|
|
|
if (null == query && null != orderFilterRequest) {
|
|
|
|
|
query = buildQuery(orderFilterRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.count(query, OrderMdEntity.class, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void insert(OrderMdEntity orderMdEntity) {
|
|
|
|
|
mongoTemplate.insert(orderMdEntity, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void insert(List<OrderMdEntity> records) {
|
|
|
|
|
mongoTemplate.insert(records, MongoDBName.NAME_ORDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据查询参数实体构造mongodb查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param orderFilterRequest
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Query buildQuery(OrderFilterRequest orderFilterRequest) {
|
|
|
|
|
Query query = new Query();
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(OrderFilterRequest.class);
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(orderFilterRequest, field);
|
|
|
|
|
if (ObjectUtil.isNotNull(fieldValue)) {
|
|
|
|
|
if ("id".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("orderId").is(fieldValue));
|
|
|
|
|
} else if ("invCodes".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("locStorageCode").in(fieldValue));
|
|
|
|
|
} else if ("actDate".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("actDate").gte(fieldValue + " 00:00:00").andOperator(Criteria.where("actDate").lte(fieldValue + " 23:59:59")));
|
|
|
|
|
} else if ("isError".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("status").ne(fieldValue));
|
|
|
|
|
} else {
|
|
|
|
|
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ("receiveStatus".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("receiveStatus").ne(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据数据实体,构造mongodb查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param orderMdEntity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Query buildQuery(OrderMdEntity orderMdEntity) {
|
|
|
|
|
Query query = new Query();
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(OrderMdEntity.class);
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(orderMdEntity, field);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(fieldValue)) {
|
|
|
|
|
if ("id".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("_id").is(fieldValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据数据实体,构造mongodb查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param orderMdEntity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Update buildUpdate(OrderMdEntity orderMdEntity) {
|
|
|
|
|
Update update = new Update();
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(OrderMdEntity.class);
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(orderMdEntity, field);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(fieldValue)) {
|
|
|
|
|
if (!field.getName().equals("id") && !field.getName().equals("orderId")) {
|
|
|
|
|
update.set(field.getName(), fieldValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return update;
|
|
|
|
|
}
|
|
|
|
|
}
|