1.添加单据相关表的mongodb操作类

master
x_z 3 years ago
parent ba44eff5e3
commit efc758c860

@ -0,0 +1,146 @@
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.WarehouseEntity;
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.FilterWarehouseRequest;
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.Arrays;
import java.util.List;
@Component
public class CodesDao implements MongoBaseDao<WarehouseEntity, FilterWarehouseRequest> {
@Resource
private MongoTemplate mongoTemplate;
@Resource
private MongoPageHelper mongoPageHelper;
@Override
public PageResult<WarehouseEntity> pageQuery(Query query, FilterWarehouseRequest filterWarehouseRequest, int page, int size) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoPageHelper.pageQuery(query, WarehouseEntity.class, page, size, MongoDBName.NAME_CODE);
}
@Override
public List<WarehouseEntity> findList(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.find(query, WarehouseEntity.class, MongoDBName.NAME_CODE);
}
@Override
public WarehouseEntity findOne(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.findOne(query, WarehouseEntity.class, MongoDBName.NAME_CODE);
}
@Override
public void update(Query query, Update update, WarehouseEntity warehouseEntity) {
if (null == query) {
query = buildQuery(warehouseEntity);
}
if (null == update) {
update = buildUpdate(warehouseEntity);
}
mongoTemplate.updateMulti(query, update, WarehouseEntity.class, MongoDBName.NAME_CODE);
}
@Override
public void delete(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query) {
query = buildQuery(filterWarehouseRequest);
}
mongoTemplate.remove(query, WarehouseEntity.class, MongoDBName.NAME_CODE);
}
@Override
public long count(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.count(query, WarehouseEntity.class, MongoDBName.NAME_CODE);
}
@Override
public void insert(WarehouseEntity warehouseEntity) {
mongoTemplate.insert(warehouseEntity, MongoDBName.NAME_CODE);
}
@Override
public void insert(List<WarehouseEntity> records) {
mongoTemplate.insert(records, MongoDBName.NAME_CODE);
}
/**
* mongodb
*
* @param filterWarehouseRequest
* @return
*/
private Query buildQuery(FilterWarehouseRequest filterWarehouseRequest) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(FilterWarehouseRequest.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(filterWarehouseRequest, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
});
return query;
}
/**
* mongodb
*
* @param warehouseEntity
* @return
*/
private Query buildQuery(WarehouseEntity warehouseEntity) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(WarehouseEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(warehouseEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
});
return query;
}
/**
* mongodb
*
* @param warehouseEntity
* @return
*/
private Update buildUpdate(WarehouseEntity warehouseEntity) {
Update update = new Update();
Field[] fields = ReflectUtil.getFields(WarehouseEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(warehouseEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
update.set(field.getName(), fieldValue);
}
});
return update;
}
}

@ -0,0 +1,144 @@
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.WarehousetempEntity;
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.FilterWarehouseRequest;
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.Arrays;
import java.util.List;
@Component
public class CodesTempDao implements MongoBaseDao<WarehousetempEntity, FilterWarehouseRequest> {
@Resource
private MongoTemplate mongoTemplate;
@Resource
private MongoPageHelper mongoPageHelper;
public PageResult<WarehousetempEntity> pageQuery(Query query, FilterWarehouseRequest filterWarehouseRequest, int page, int size) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoPageHelper.pageQuery(query, WarehousetempEntity.class, page, size, MongoDBName.NAME_CODE_TEMP);
}
@Override
public List<WarehousetempEntity> findList(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.find(query, WarehousetempEntity.class, MongoDBName.NAME_CODE_TEMP);
}
@Override
public WarehousetempEntity findOne(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query && null != filterWarehouseRequest) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.findOne(query, WarehousetempEntity.class, MongoDBName.NAME_CODE_TEMP);
}
@Override
public void update(Query query, Update update, WarehousetempEntity WarehousetempEntity) {
if (null == query) {
query = buildQuery(WarehousetempEntity);
}
if (null == update) {
update = buildUpdate(WarehousetempEntity);
}
mongoTemplate.updateMulti(query, update, WarehousetempEntity.class, MongoDBName.NAME_CODE_TEMP);
}
@Override
public void delete(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query) {
query = buildQuery(filterWarehouseRequest);
}
mongoTemplate.remove(query, WarehousetempEntity.class, MongoDBName.NAME_CODE_TEMP);
}
@Override
public long count(Query query, FilterWarehouseRequest filterWarehouseRequest) {
if (null == query) {
query = buildQuery(filterWarehouseRequest);
}
return mongoTemplate.count(query, WarehousetempEntity.class, MongoDBName.NAME_CODE_TEMP);
}
@Override
public void insert(WarehousetempEntity WarehousetempEntity) {
mongoTemplate.insert(WarehousetempEntity, MongoDBName.NAME_CODE_TEMP);
}
@Override
public void insert(List<WarehousetempEntity> records) {
mongoTemplate.insert(records, MongoDBName.NAME_CODE_TEMP);
}
/**
* mongodb
*
* @param filterWarehouseRequest
* @return
*/
private Query buildQuery(FilterWarehouseRequest filterWarehouseRequest) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(FilterWarehouseRequest.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(filterWarehouseRequest, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
});
return query;
}
/**
* mongodb
*
* @param warehousetempEntity
* @return
*/
private Query buildQuery(WarehousetempEntity warehousetempEntity) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(WarehousetempEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(warehousetempEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
});
return query;
}
/**
* mongodb
*
* @param warehousetempEntity
* @return
*/
private Update buildUpdate(WarehousetempEntity warehousetempEntity) {
Update update = new Update();
Field[] fields = ReflectUtil.getFields(WarehousetempEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(warehousetempEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
update.set(field.getName(), fieldValue);
}
});
return update;
}
}

@ -0,0 +1,182 @@
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.InvProductEntity;
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.inventory.FilterInvProductRequest;
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.Arrays;
import java.util.List;
import java.util.regex.Pattern;
@Component
public class InvProductDao implements MongoBaseDao<InvProductEntity, FilterInvProductRequest> {
@Resource
private MongoTemplate mongoTemplate;
@Resource
private MongoPageHelper mongoPageHelper;
@Override
public PageResult<InvProductEntity> pageQuery(Query query, FilterInvProductRequest filterInvProductRequest, int page, int size) {
if (null == query && null != filterInvProductRequest) {
query = buildQuery(filterInvProductRequest);
}
return mongoPageHelper.pageQuery(query, InvProductEntity.class, page, size, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public List<InvProductEntity> findList(Query query, FilterInvProductRequest filterInvProductRequest) {
if (null == query && null != filterInvProductRequest) {
query = buildQuery(filterInvProductRequest);
}
return mongoTemplate.find(query, InvProductEntity.class, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public InvProductEntity findOne(Query query, FilterInvProductRequest filterInvProductRequest) {
if (null == query && null != filterInvProductRequest) {
query = buildQuery(filterInvProductRequest);
}
return mongoTemplate.findOne(query, InvProductEntity.class, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public void update(Query query, Update update, InvProductEntity invProductEntity) {
if (null == query) {
query = buildQuery(invProductEntity);
}
if (null == update) {
update = buildUpdate(invProductEntity);
}
mongoTemplate.updateMulti(query, update, InvProductEntity.class, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public void delete(Query query, FilterInvProductRequest filterInvProductRequest) {
if (null == query && null != filterInvProductRequest) {
query = buildQuery(filterInvProductRequest);
}
mongoTemplate.remove(query, InvProductEntity.class, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public long count(Query query, FilterInvProductRequest filterInvProductRequest) {
if (null == query && null != filterInvProductRequest) {
query = buildQuery(filterInvProductRequest);
}
return mongoTemplate.count(query, InvProductEntity.class, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public void insert(InvProductEntity invProductEntity) {
mongoTemplate.insert(invProductEntity, MongoDBName.NAME_INV_PRODUCT);
}
@Override
public void insert(List<InvProductEntity> records) {
mongoTemplate.insert(records, MongoDBName.NAME_INV_PRODUCT);
}
/**
* mongodb
*
* @param filterInvProductRequest
* @return
*/
private Query buildQuery(FilterInvProductRequest filterInvProductRequest) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(FilterInvProductRequest.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(filterInvProductRequest, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
switch (field.getName()) {
case "uuids":
query.addCriteria(Criteria.where("relIdFk").in(fieldValue));
break;
case "invCodes":
query.addCriteria(Criteria.where("locStorageCode").in(fieldValue));
break;
case "cpmctymc": {
Pattern pattern = Pattern.compile("^.*" + fieldValue + ".*$");
query.addCriteria(Criteria.where("productsName").regex(pattern));
break;
}
case "zczbhhzbapzbh": {
Pattern pattern = Pattern.compile("^.*" + fieldValue + ".*$");
query.addCriteria(Criteria.where("zczbhhzbapzbh").regex(pattern));
break;
}
case "manufactory": {
Pattern pattern = Pattern.compile("^.*" + fieldValue + ".*$");
query.addCriteria(Criteria.where("manufactory").regex(pattern));
break;
}
case "ggxh": {
Pattern pattern = Pattern.compile("^.*" + fieldValue + ".*$");
query.addCriteria(Criteria.where("ggxh").regex(pattern));
break;
}
default:
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
break;
}
}
});
return query;
}
/**
* mongodb
*
* @param invProductEntity
* @return
*/
private Query buildQuery(InvProductEntity invProductEntity) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(InvProductEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(invProductEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
if ("id".equals(field.getName())) {
query.addCriteria(Criteria.where("_id").is(fieldValue));
} else {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
}
});
return query;
}
/**
* mongodb
*
* @param invProductEntity
* @return
*/
private Update buildUpdate(InvProductEntity invProductEntity) {
Update update = new Update();
Field[] fields = ReflectUtil.getFields(InvProductEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(invProductEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
if (!"id".equals(field.getName())) {
update.set(field.getName(), fieldValue);
}
}
});
return update;
}
}

@ -0,0 +1,156 @@
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.InvProductDetailEntity;
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.FilterInvProductDetailRequest;
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.Arrays;
import java.util.List;
@Component
public class InvProductDetailDao implements MongoBaseDao<InvProductDetailEntity, FilterInvProductDetailRequest> {
@Resource
private MongoTemplate mongoTemplate;
@Resource
private MongoPageHelper mongoPageHelper;
@Override
public PageResult<InvProductDetailEntity> pageQuery(Query query, FilterInvProductDetailRequest filterInvProductDetailRequest, int page, int size) {
if (null == query && null != filterInvProductDetailRequest) {
query = buildQuery(filterInvProductDetailRequest);
}
return mongoPageHelper.pageQuery(query, InvProductDetailEntity.class, page, size, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public List<InvProductDetailEntity> findList(Query query, FilterInvProductDetailRequest filterInvProductDetailRequest) {
if (null == query && null != filterInvProductDetailRequest) {
query = buildQuery(filterInvProductDetailRequest);
}
return mongoTemplate.find(query, InvProductDetailEntity.class, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public InvProductDetailEntity findOne(Query query, FilterInvProductDetailRequest filterInvProductDetailRequest) {
if (null == query && null != filterInvProductDetailRequest) {
query = buildQuery(filterInvProductDetailRequest);
}
return mongoTemplate.findOne(query, InvProductDetailEntity.class, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public void update(Query query, Update update, InvProductDetailEntity invProductDetailEntity) {
if (null == query) {
query = buildQuery(invProductDetailEntity);
}
if (null == update) {
update = buildUpdate(invProductDetailEntity);
}
mongoTemplate.updateMulti(query, update, InvProductDetailEntity.class, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public void delete(Query query, FilterInvProductDetailRequest filterInvProductDetailRequest) {
if (null == query && null != filterInvProductDetailRequest) {
buildQuery(filterInvProductDetailRequest);
}
mongoTemplate.remove(query, InvProductDetailEntity.class, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public long count(Query query, FilterInvProductDetailRequest filterInvProductDetailRequest) {
if (null == query && null != filterInvProductDetailRequest) {
buildQuery(filterInvProductDetailRequest);
}
return mongoTemplate.count(query, InvProductDetailEntity.class, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public void insert(InvProductDetailEntity invProductDetailEntity) {
mongoTemplate.insert(invProductDetailEntity, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
@Override
public void insert(List<InvProductDetailEntity> records) {
mongoTemplate.insert(records, MongoDBName.NAME_INV_PRODUCT_DETAIL);
}
/**
* mongodb
*
* @param filterInvProductDetailRequest
* @return
*/
private Query buildQuery(FilterInvProductDetailRequest filterInvProductDetailRequest) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(FilterInvProductDetailRequest.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(filterInvProductDetailRequest, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
if ("invCodes".equals(field.getName())) {
query.addCriteria(Criteria.where("locStorageCode").in(fieldValue));
} else {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
}
});
return query;
}
/**
* mongodb
*
* @param invProductDetailEntity
* @return
*/
private Query buildQuery(InvProductDetailEntity invProductDetailEntity) {
Query query = new Query();
Field[] fields = ReflectUtil.getFields(InvProductDetailEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(invProductDetailEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
if ("id".equals(field.getName())) {
query.addCriteria(Criteria.where("_id").is(fieldValue));
} else {
query.addCriteria(Criteria.where(field.getName()).is(fieldValue));
}
}
});
return query;
}
/**
* mongodb
*
* @param invProductDetailEntity
* @return
*/
private Update buildUpdate(InvProductDetailEntity invProductDetailEntity) {
Update update = new Update();
Field[] fields = ReflectUtil.getFields(InvProductDetailEntity.class);
Arrays.stream(fields).forEach(field -> {
Object fieldValue = ReflectUtil.getFieldValue(invProductDetailEntity, field);
if (ObjectUtil.isNotEmpty(fieldValue)) {
if (!"id".equals(field.getName())) {
update.set(field.getName(), fieldValue);
}
}
});
return update;
}
}
Loading…
Cancel
Save