提交修改
This commit is contained in:
parent
0b25695a47
commit
b55a0b829c
@ -51,4 +51,9 @@ public interface VvProductPropertyDao extends BaseMapper<VvProductPropertyEntity
|
||||
|
||||
|
||||
List<VvProductPropertyEntity> selectProductPropertyByIds(@IN List<Long> id);
|
||||
|
||||
|
||||
|
||||
@OrderBy(value={VvProductPropertyEntity.default_sort}, type={OrderType.ASC})
|
||||
List<VvProductPropertyEntity> selectVvProductPropertyByProductIdList(@IN List<Long> productId);
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
package com.heyu.api.data.utils;
|
||||
|
||||
import com.heyu.api.common.LBiFunction0;
|
||||
import com.heyu.api.common.test.AriseUser;
|
||||
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.lang.invoke.SerializedLambda;
|
||||
@ -137,10 +137,10 @@ public class SanUtils {
|
||||
|
||||
public static <T, R, V> Map<R, List<V>> groupByFiled2MapList(List<V> values, LBiFunction0<T, R> function) {
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
return new HashMap<>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
Map<R, List<V>> listmap = new HashMap<>();
|
||||
Map<R, List<V>> listmap = new LinkedHashMap<>();
|
||||
Method method = getMethod(function);
|
||||
try {
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
@ -166,6 +166,7 @@ public class SanUtils {
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
Method method = getMethod(function);
|
||||
for (V value : values) {
|
||||
R r = (R) method.invoke(value);
|
||||
@ -203,12 +204,11 @@ public class SanUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T,P , V,R> Map<P,R> groupAndSum(LBiFunction0<T, P> groupKeyFunction,List<V> values,LBiFunction0<T, R> function) {
|
||||
Map<P,MethodSumDTO> map = new HashMap<>();
|
||||
public static <T, P, V, R> Map<P, R> groupAndSum(LBiFunction0<T, P> groupKeyFunction, List<V> values, LBiFunction0<T, R> function) {
|
||||
Map<P, MethodSumDTO> map = new LinkedHashMap<>();
|
||||
try {
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
return new HashMap<>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
for (V value : values) {
|
||||
Method groupKeyMethod = getMethod(groupKeyFunction);
|
||||
@ -220,8 +220,8 @@ public class SanUtils {
|
||||
if (r != null) {
|
||||
BigDecimal bigDecimalR = NumberUtils.objToBigDecimalDefault(r, BigDecimal.ZERO);
|
||||
MethodSumDTO methodSumDTO = map.get(p);
|
||||
if(methodSumDTO == null){
|
||||
methodSumDTO = new MethodSumDTO();
|
||||
if (methodSumDTO == null) {
|
||||
methodSumDTO = new MethodSumDTO();
|
||||
}
|
||||
methodSumDTO.getItemList().add(bigDecimalR);
|
||||
methodSumDTO.setMethod(method);
|
||||
@ -231,7 +231,7 @@ public class SanUtils {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<P, R> result = new HashMap<>();
|
||||
Map<P, R> result = new LinkedHashMap<>();
|
||||
for (Map.Entry<P, MethodSumDTO> entry : map.entrySet()) {
|
||||
|
||||
MethodSumDTO methodSumDTO = entry.getValue();
|
||||
@ -282,9 +282,9 @@ public class SanUtils {
|
||||
}
|
||||
|
||||
public static <T, V, R> Map<R, V> groupMerge2Map(LBiFunction0<T, R> groupByFunction, List<V> values, LBiFunction0<T, ? extends Object>... functionArray) {
|
||||
Map<R, List<V>> mapData = new HashMap<>();
|
||||
Map<R, List<V>> mapData = new LinkedHashMap<>();
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
return new HashMap<>();
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
for (V value : values) {
|
||||
try {
|
||||
@ -304,7 +304,7 @@ public class SanUtils {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Map<R, V> result = new HashMap<>();
|
||||
Map<R, V> result = new LinkedHashMap<>();
|
||||
if (!mapData.isEmpty()) {
|
||||
for (Map.Entry<R, List<V>> map : mapData.entrySet()) {
|
||||
List<V> list = map.getValue();
|
||||
@ -318,8 +318,6 @@ public class SanUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static <T, V> V merge(List<V> values, LBiFunction0<T, ? extends Object>... functionArray) {
|
||||
try {
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
@ -385,15 +383,15 @@ public class SanUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void getAllDeclaredMethods(List<Method> list ,Class<?> clazz) {
|
||||
if(clazz==Object.class){
|
||||
return ;
|
||||
public static void getAllDeclaredMethods(List<Method> list, Class<?> clazz) {
|
||||
if (clazz == Object.class) {
|
||||
return;
|
||||
}
|
||||
Method methods[] = clazz.getDeclaredMethods();
|
||||
for (Method m : methods) {
|
||||
list.add(m);
|
||||
}
|
||||
getAllDeclaredMethods(list,clazz.getSuperclass());
|
||||
getAllDeclaredMethods(list, clazz.getSuperclass());
|
||||
}
|
||||
|
||||
|
||||
@ -427,7 +425,7 @@ public class SanUtils {
|
||||
String methodName = serializedLambda.getImplMethodName();
|
||||
String className = serializedLambda.getImplClass().replace("/", ".");
|
||||
Class<?> clazz = Class.forName(className);
|
||||
List<Method> methodList= new ArrayList<>();
|
||||
List<Method> methodList = new ArrayList<>();
|
||||
getAllDeclaredMethods(methodList, clazz);
|
||||
for (Method m : methodList) {
|
||||
if (m.getName().equals(methodName)) {
|
||||
@ -465,7 +463,6 @@ public class SanUtils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static Method getRealMethod(List<Method> methods, Class paramClazz) {
|
||||
for (Method method : methods) {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
@ -648,170 +645,4 @@ public class SanUtils {
|
||||
}
|
||||
|
||||
|
||||
public static <T, R, V> List<R> parallel2List(List<V> params, LBiFunction0<T, R> function) {
|
||||
|
||||
List<R> list = new ArrayList<>();
|
||||
|
||||
|
||||
Map<String, Future<R>> map = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
V v = params.get(i);
|
||||
Future<R> countFuture = threadPool.submit(getAsynCallable(function, v));
|
||||
|
||||
|
||||
map.put(i + "", countFuture);
|
||||
}
|
||||
|
||||
|
||||
Map<String, R> agentResult = new HashMap<>();
|
||||
|
||||
map.forEach((key, future) -> Optional.ofNullable(get(future)).ifPresent(osResp -> {
|
||||
agentResult.put(key, osResp);
|
||||
}));
|
||||
for (Map.Entry<String, R> entry : agentResult.entrySet()) {
|
||||
list.add(entry.getValue());
|
||||
}
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static <T, R, V, K> Map<K, R> parallel2Map(List<V> params, LBiFunction0<T, R> function, LBiFunction0<T, K> functionKey) {
|
||||
Map<K, Future<R>> map = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
V v = params.get(i);
|
||||
|
||||
Future<R> countFuture = threadPool.submit(getAsynCallable(function, v));
|
||||
|
||||
K key = null;
|
||||
|
||||
Object object = getKeyDeValue(v);
|
||||
|
||||
Method method = getMethod(functionKey);
|
||||
|
||||
method.setAccessible(true);
|
||||
|
||||
try {
|
||||
int modifiers = method.getModifiers();
|
||||
if (Modifier.isStatic(modifiers)) {
|
||||
key = (K) method.invoke(null, object);
|
||||
} else {
|
||||
key = (K) method.invoke(object);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
map.put(key, countFuture);
|
||||
}
|
||||
|
||||
Map<K, R> agentResult = new HashMap<>();
|
||||
|
||||
map.forEach((key, future) -> Optional.ofNullable(get(future)).ifPresent(osResp -> {
|
||||
agentResult.put(key, osResp);
|
||||
}));
|
||||
|
||||
return agentResult;
|
||||
|
||||
}
|
||||
|
||||
private static Object getKeyDeValue(Object v) {
|
||||
if (v instanceof Map) {
|
||||
for (Map.Entry<?, ?> entry : ((Map<?, ?>) v).entrySet()) {
|
||||
return getKeyDeValue(entry.getValue());
|
||||
}
|
||||
} else if (v instanceof List) {
|
||||
return getKeyDeValue(((List<?>) v).get(0));
|
||||
} else if (!isBasicDataTypes(v.getClass())) {
|
||||
return v;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static <T, P, R, E> Callable getAsynCallable(LBiFunction0<T, R> function0, P value) {
|
||||
return new Callable<R>() {
|
||||
@Override
|
||||
public R call() throws Exception {
|
||||
|
||||
Object object = null;
|
||||
try {
|
||||
Method method = getMethod(function0);
|
||||
|
||||
int modifiers = method.getModifiers();
|
||||
|
||||
if (Modifier.isStatic(modifiers)) {
|
||||
|
||||
object = method.invoke(null, value);
|
||||
|
||||
} else {
|
||||
object = method.invoke(value);
|
||||
}
|
||||
|
||||
return (R) object;
|
||||
} catch (Exception e) {
|
||||
log.error("线程池异常", e);
|
||||
} finally {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static Callable getAsynRun(Runnable runnable) {
|
||||
return new Callable() {
|
||||
@Override
|
||||
public R call() throws Exception {
|
||||
|
||||
Object object = null;
|
||||
try {
|
||||
runnable.run();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("线程池异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static AsynRunDTO build(Runnable... target) {
|
||||
Map<String, Future<R>> map = new HashMap<>();
|
||||
for (int i = 0; i < target.length; i++) {
|
||||
Runnable v = target[i];
|
||||
Future<R> countFuture = threadPool.submit(getAsynRun(v));
|
||||
map.put(i + "", countFuture);
|
||||
}
|
||||
|
||||
AsynRunDTO asynRunDTO = new AsynRunDTO();
|
||||
asynRunDTO.setMap(map);
|
||||
return asynRunDTO;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
build(
|
||||
() -> {
|
||||
System.out.println("1");
|
||||
},
|
||||
() -> {
|
||||
System.out.println("2");
|
||||
}
|
||||
).run();
|
||||
}
|
||||
|
||||
|
||||
public static AriseUser getName(AriseUser ariseUser) {
|
||||
|
||||
return ariseUser;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -101,6 +101,10 @@ public class AppOrderController {
|
||||
@Autowired
|
||||
private ReverseOrderService reverseOrderService;
|
||||
|
||||
@Autowired
|
||||
private VvProductPropertyDao vvProductPropertyDao;
|
||||
|
||||
|
||||
/***
|
||||
* https://api.1024api.com/api-interface/app/order/list
|
||||
*
|
||||
@ -167,13 +171,16 @@ public class AppOrderController {
|
||||
@RequestMapping("/add")
|
||||
public R add(@RequestBody VvTradeOrderDTO vvOrderRequest) {
|
||||
List<VvTradeOrderLineEntity> vvTradeOrderLineEntityList = new ArrayList<>();
|
||||
List<Long> skuIds = SanUtils.getFieldList( vvOrderRequest.getVvTradeOrderLineDTOList(),VvTradeOrderLineDTO::getSkuId);
|
||||
|
||||
List<Long> skuIds = SanUtils.getFieldList(vvOrderRequest.getVvTradeOrderLineDTOList(), VvTradeOrderLineDTO::getSkuId);
|
||||
List<VvSkuPropertyValueEntity> vvSkuPropertyValueList = vvSkuPropertyValueDao.selectVvSkuPropertyValueBySkuIds(skuIds);
|
||||
Map<Long, VvTradeOrderLineDTO> vvTradeOrderLineMap = SanUtils.groupByFiled2Map(vvOrderRequest.getVvTradeOrderLineDTOList(), VvTradeOrderLineDTO::getSkuId);
|
||||
|
||||
|
||||
List<VvSkuEntity> vvSkuEntities = vvSkuDao.selectVvSkuBySkuIds(skuIds);
|
||||
for (VvSkuEntity vvSkuEntity : vvSkuEntities) {
|
||||
VvTradeOrderLineDTO vvTradeOrderLineDTO = vvTradeOrderLineMap.get(vvSkuEntity.getId());
|
||||
// 如果库存少于 0 ,则显示库存不足
|
||||
if (vvSkuEntity.getStock() <= 0) {
|
||||
if (vvSkuEntity.getStock() - vvTradeOrderLineDTO.getNum() < 0) {
|
||||
OrderSkuDTO orderSkuDTO = new OrderSkuDTO();
|
||||
orderSkuDTO.setSkuId(vvSkuEntity.getId());
|
||||
orderSkuDTO.setMessage("库存不足");
|
||||
@ -181,26 +188,38 @@ public class AppOrderController {
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, VvSkuEntity> skuEntityMap = SanUtils.groupByFiled2Map(vvSkuEntities,VvSkuEntity::getId);
|
||||
Map<Long, VvSkuEntity> skuEntityMap = SanUtils.groupByFiled2Map(vvSkuEntities, VvSkuEntity::getId);
|
||||
|
||||
Map<Long, List<VvSkuPropertyValueEntity>> vvSkuPropertyValueMap = SanUtils.groupByFiled2MapList(vvSkuPropertyValueList, VvSkuPropertyValueEntity::getSkuId);
|
||||
|
||||
List<Long> productIdList = SanUtils.field2Set2List(vvSkuEntities,VvSkuEntity::getProductId);
|
||||
List<VvProductEntity> vvProductList = vvProductDao.selectVvProductByProductIds(productIdList);
|
||||
|
||||
Map<Long, VvProductEntity> vvProductMap = SanUtils.groupByFiled2Map(vvProductList,VvProductEntity::getId);
|
||||
VvBuyerAddressEntity vvBuyerAddress = vvBuyerAddressDao.selectVvBuyerAddressById(vvOrderRequest.getBuyerAddressId());
|
||||
|
||||
|
||||
List<VvProductPropertyEntity> vvProductPropertyEntities = vvProductPropertyDao.selectVvProductPropertyByProductIdList(productIdList);
|
||||
Map<Long,List<VvProductPropertyEntity>> vvProductPropertyMap = SanUtils.groupByFiled2MapList(vvProductPropertyEntities,VvProductPropertyEntity::getProductId);
|
||||
|
||||
for (VvTradeOrderLineDTO vvTradeOrderLineDTO : vvOrderRequest.getVvTradeOrderLineDTOList()) {
|
||||
VvSkuEntity vvSkuEntity = skuEntityMap.get(vvTradeOrderLineDTO.getSkuId());
|
||||
|
||||
List<VvSkuPropertyValueEntity> vvSkuPropertyValueEntities = vvSkuPropertyValueMap.get(vvTradeOrderLineDTO.getSkuId());
|
||||
VvProductEntity vvProduct = vvProductMap.get(vvSkuEntity.getProductId());
|
||||
List<PropertyNameValue> propertyNameValues = new ArrayList<>();
|
||||
|
||||
for (VvSkuPropertyValueEntity vvSkuPropertyValueEntity : vvSkuPropertyValueEntities) {
|
||||
Map<String, VvSkuPropertyValueEntity> vvSkuPropertyValueItemMap = SanUtils.groupByFiled2Map(vvSkuPropertyValueEntities, VvSkuPropertyValueEntity::getProductPropertyName);
|
||||
// 对商品属性进行排序
|
||||
List<VvProductPropertyEntity> vvProductPropertyList = vvProductPropertyMap.get(vvSkuEntity.getProductId());
|
||||
for (VvProductPropertyEntity vvProductPropertyEntity : vvProductPropertyList) {
|
||||
VvSkuPropertyValueEntity vvSkuPropertyValueEntity = vvSkuPropertyValueItemMap.get(vvProductPropertyEntity.getProductPropertyName());
|
||||
PropertyNameValue propertyNameValue = new PropertyNameValue();
|
||||
propertyNameValue.setPropertyName(vvSkuPropertyValueEntity.getProductPropertyName());
|
||||
propertyNameValue.setPropertyValue(vvSkuPropertyValueEntity.getProductPropertyValue());
|
||||
propertyNameValues.add(propertyNameValue);
|
||||
}
|
||||
|
||||
for (int i = 0; i < vvTradeOrderLineDTO.getNum(); i++) {
|
||||
VvTradeOrderLineEntity vvTradeOrderLineEntity = new VvTradeOrderLineEntity();
|
||||
vvTradeOrderLineEntity.setSkuId(vvTradeOrderLineDTO.getSkuId());
|
||||
@ -219,9 +238,11 @@ public class AppOrderController {
|
||||
vvTradeOrderLineEntity.setSkuInfo(JSON.toJSONString(propertyNameValues));
|
||||
vvTradeOrderLineEntity.setCreateTimestamp(System.currentTimeMillis());
|
||||
vvTradeOrderLineEntity.setModifyTimestamp(System.currentTimeMillis());
|
||||
vvTradeOrderLineEntity.setContry(vvBuyerAddress.getContry());
|
||||
vvTradeOrderLineEntity.setProvince(vvBuyerAddress.getProvince());
|
||||
vvTradeOrderLineEntity.setCity(vvBuyerAddress.getCity());
|
||||
vvTradeOrderLineEntity.setDistrict(vvBuyerAddress.getDistrict());
|
||||
vvTradeOrderLineEntity.setBuyerDetailAddress(vvBuyerAddress.getDetail());
|
||||
vvTradeOrderLineEntity.setStatus(OrderStatusEnums.create.getStatus());
|
||||
vvTradeOrderLineEntity.setBuyerId(vvOrderRequest.getBuyerId());
|
||||
vvTradeOrderLineEntity.setBuyerAddressId(vvOrderRequest.getBuyerAddressId());
|
||||
@ -232,6 +253,7 @@ public class AppOrderController {
|
||||
}
|
||||
|
||||
VvTradeOrderEntity vvTradeOrderEntity = new VvTradeOrderEntity();
|
||||
|
||||
VvBuyerEntity vvBuyerEntity = vvBuyerDao.selectVvBuyerById(vvOrderRequest.getBuyerId());
|
||||
//创建时间
|
||||
vvTradeOrderEntity.setCreateTime(new Date());
|
||||
@ -272,6 +294,11 @@ public class AppOrderController {
|
||||
vvProductDao.updateShowSaleCountAndSaleCount(map.getValue(), map.getValue(), map.getKey());
|
||||
}
|
||||
|
||||
|
||||
if(true){
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
DirectAPIv3JsapiPrepayResponse jsapiPrepayResponse = jsapiPrepay.prePay(vvTradeOrderEntity.getId(),
|
||||
BigDecimalUtil.multiply(vvTradeOrderEntity.getPayAmount(), new BigDecimal(100)).longValue(),
|
||||
vvBuyerEntity.getOpenid()
|
||||
@ -307,6 +334,7 @@ public class AppOrderController {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
WxPayVO vo = new WxPayVO();
|
||||
Long timeStamp = System.currentTimeMillis() / 1000;
|
||||
String nonceStr = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 32);
|
||||
@ -324,6 +352,7 @@ public class AppOrderController {
|
||||
vo.setMchid(mchid);
|
||||
vo.setPaySign(sign);
|
||||
vo.setPrepayId("prepay_id=" + prepay_id);
|
||||
|
||||
return R.ok().setData(vo);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user