|
|
|
@ -2,7 +2,7 @@ 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.ErpOrderEntity;
|
|
|
|
|
import com.glxp.udi.admin.entity.inout.OrderDetailEntity;
|
|
|
|
|
import com.glxp.udi.admin.mongo.MongoDBName;
|
|
|
|
|
import com.glxp.udi.admin.mongo.dao.base.MongoBaseDao;
|
|
|
|
|
import com.glxp.udi.admin.mongo.utils.MongoPageHelper;
|
|
|
|
@ -20,7 +20,7 @@ import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
|
public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrderRequest> {
|
|
|
|
|
public class OrderDetailDao implements MongoBaseDao<OrderDetailEntity, FilterErpOrderRequest> {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
|
@ -29,38 +29,38 @@ public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<ErpOrderEntity> pageQuery(Query query, FilterErpOrderRequest filterErpOrderRequest, int page, int size) {
|
|
|
|
|
public PageResult<OrderDetailEntity> pageQuery(Query query, FilterErpOrderRequest filterErpOrderRequest, int page, int size) {
|
|
|
|
|
if (null == query && null != filterErpOrderRequest) {
|
|
|
|
|
query = buildQuery(filterErpOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoPageHelper.pageQuery(query, ErpOrderEntity.class, size, page, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
return mongoPageHelper.pageQuery(query, OrderDetailEntity.class, size, page, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpOrderEntity> findList(Query query, FilterErpOrderRequest filterErpOrderRequest) {
|
|
|
|
|
public List<OrderDetailEntity> findList(Query query, FilterErpOrderRequest filterErpOrderRequest) {
|
|
|
|
|
if (null == query && null != filterErpOrderRequest) {
|
|
|
|
|
query = buildQuery(filterErpOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.find(query, ErpOrderEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
return mongoTemplate.find(query, OrderDetailEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ErpOrderEntity findOne(Query query, FilterErpOrderRequest filterErpOrderRequest) {
|
|
|
|
|
public OrderDetailEntity findOne(Query query, FilterErpOrderRequest filterErpOrderRequest) {
|
|
|
|
|
if (null == query && null != filterErpOrderRequest) {
|
|
|
|
|
query = buildQuery(filterErpOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.findOne(query, ErpOrderEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
return mongoTemplate.findOne(query, OrderDetailEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update(Query query, Update update, ErpOrderEntity erpOrderEntity) {
|
|
|
|
|
public void update(Query query, Update update, OrderDetailEntity orderDetailEntity) {
|
|
|
|
|
if (null == query) {
|
|
|
|
|
query = buildQuery(erpOrderEntity);
|
|
|
|
|
query = buildQuery(orderDetailEntity);
|
|
|
|
|
}
|
|
|
|
|
if (null == update) {
|
|
|
|
|
update = buildUpdate(erpOrderEntity);
|
|
|
|
|
update = buildUpdate(orderDetailEntity);
|
|
|
|
|
}
|
|
|
|
|
mongoTemplate.updateMulti(query, update, ErpOrderEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
mongoTemplate.updateMulti(query, update, OrderDetailEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -68,7 +68,7 @@ public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrd
|
|
|
|
|
if (null == query) {
|
|
|
|
|
query = buildQuery(filterErpOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
mongoTemplate.remove(query, ErpOrderEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
mongoTemplate.remove(query, OrderDetailEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -76,16 +76,16 @@ public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrd
|
|
|
|
|
if (null == query) {
|
|
|
|
|
query = buildQuery(filterErpOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
return mongoTemplate.count(query, ErpOrderEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
return mongoTemplate.count(query, OrderDetailEntity.class, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void insert(ErpOrderEntity erpOrderEntity) {
|
|
|
|
|
mongoTemplate.insert(erpOrderEntity, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
public void insert(OrderDetailEntity orderDetailEntity) {
|
|
|
|
|
mongoTemplate.insert(orderDetailEntity, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void insert(List<ErpOrderEntity> records) {
|
|
|
|
|
public void insert(List<OrderDetailEntity> records) {
|
|
|
|
|
mongoTemplate.insert(records, MongoDBName.NAME_ORDER_DETAIL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -115,14 +115,14 @@ public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrd
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据详情实体,构造mongodb查询条件
|
|
|
|
|
*
|
|
|
|
|
* @param erpOrderEntity
|
|
|
|
|
* @param orderDetailEntity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Query buildQuery(ErpOrderEntity erpOrderEntity) {
|
|
|
|
|
private Query buildQuery(OrderDetailEntity orderDetailEntity) {
|
|
|
|
|
Query query = new Query();
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(ErpOrderEntity.class);
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(OrderDetailEntity.class);
|
|
|
|
|
Arrays.stream(fields).forEach(field -> {
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(erpOrderEntity, field);
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(orderDetailEntity, field);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(fieldValue)) {
|
|
|
|
|
if ("orderId".equals(field.getName())) {
|
|
|
|
|
query.addCriteria(Criteria.where("orderIdFk").is(fieldValue));
|
|
|
|
@ -137,14 +137,14 @@ public class OrderDetailDao implements MongoBaseDao<ErpOrderEntity, FilterErpOrd
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据详情实体,构造更新条件
|
|
|
|
|
*
|
|
|
|
|
* @param erpOrderEntity
|
|
|
|
|
* @param orderDetailEntity
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Update buildUpdate(ErpOrderEntity erpOrderEntity) {
|
|
|
|
|
private Update buildUpdate(OrderDetailEntity orderDetailEntity) {
|
|
|
|
|
Update update = new Update();
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(ErpOrderEntity.class);
|
|
|
|
|
Field[] fields = ReflectUtil.getFields(OrderDetailEntity.class);
|
|
|
|
|
Arrays.stream(fields).forEach(field -> {
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(erpOrderEntity, field);
|
|
|
|
|
Object fieldValue = ReflectUtil.getFieldValue(orderDetailEntity, field);
|
|
|
|
|
if (ObjectUtil.isNotEmpty(fieldValue)) {
|
|
|
|
|
if (!"orderId".equals(field.getName()) && !"orderIdFk".equals(field.getName())) {
|
|
|
|
|
update.set(field.getName(), fieldValue);
|
|
|
|
|