|
@@ -1,11 +1,26 @@
|
|
package com.zhentao.service.impl;
|
|
package com.zhentao.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.zhentao.conment.SnowflakeIdWorker;
|
|
|
|
+import com.zhentao.dto.Orders1Dto;
|
|
|
|
+import com.zhentao.mapper.OrdersTimeMapper;
|
|
|
|
+import com.zhentao.mapper.YouhuiqMapper;
|
|
import com.zhentao.pojo.Orders1;
|
|
import com.zhentao.pojo.Orders1;
|
|
|
|
+import com.zhentao.pojo.OrdersTime;
|
|
|
|
+import com.zhentao.pojo.Youhuiq;
|
|
import com.zhentao.service.Orders1Service;
|
|
import com.zhentao.service.Orders1Service;
|
|
import com.zhentao.mapper.Orders1Mapper;
|
|
import com.zhentao.mapper.Orders1Mapper;
|
|
|
|
+import com.zhentao.vo.Result;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author lzy
|
|
* @author lzy
|
|
* @description 针对表【orders1】的数据库操作Service实现
|
|
* @description 针对表【orders1】的数据库操作Service实现
|
|
@@ -15,6 +30,59 @@ import org.springframework.stereotype.Service;
|
|
public class Orders1ServiceImpl extends ServiceImpl<Orders1Mapper, Orders1>
|
|
public class Orders1ServiceImpl extends ServiceImpl<Orders1Mapper, Orders1>
|
|
implements Orders1Service{
|
|
implements Orders1Service{
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private OrdersTimeMapper ordersTimeMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private YouhuiqMapper youhuiqMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result Add(Orders1Dto orders1Dto, Long uid) {
|
|
|
|
+ SnowflakeIdWorker snowflakeIdWorker=new SnowflakeIdWorker(1,1);
|
|
|
|
+ List<OrdersTime> ordersTimes = orders1Dto.getOrdersTimes();
|
|
|
|
+ Map<Long,OrdersTime> map=new HashMap<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Orders1 orders1=new Orders1();
|
|
|
|
+ orders1.setId(snowflakeIdWorker.nextId());
|
|
|
|
+ orders1.setOrderName("15633"+snowflakeIdWorker.nextId()+"846541465113");
|
|
|
|
+ orders1.setUserId(uid);
|
|
|
|
+ this.baseMapper.insert(orders1);
|
|
|
|
+ BigDecimal a=BigDecimal.ZERO;
|
|
|
|
+ for (OrdersTime ordersTime:ordersTimes){
|
|
|
|
+ map.put(ordersTime.getShopId(),ordersTime);
|
|
|
|
+ SnowflakeIdWorker snowflakeIdWorker1=new SnowflakeIdWorker(1,1);
|
|
|
|
+ long l = snowflakeIdWorker1.nextId();
|
|
|
|
+ OrdersTime ordersTime1 = map.get(ordersTime.getShopId());
|
|
|
|
+ BigDecimal bigDecimal =ordersTime.getJiage().multiply(BigDecimal.valueOf(ordersTime1.getCount()));
|
|
|
|
+ ordersTime1.setXiao(bigDecimal);
|
|
|
|
+ a=a.add(bigDecimal);
|
|
|
|
+ ordersTime1.setId(l);
|
|
|
|
+ ordersTime1.setOrdersId(orders1.getId());
|
|
|
|
+ ordersTimeMapper.insert(ordersTime1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ System.err.println(a);
|
|
|
|
+ Youhuiq userId = youhuiqMapper.selectOne(new QueryWrapper<Youhuiq>().eq("user_id", uid));
|
|
|
|
+ System.err.println(userId);
|
|
|
|
+ BigDecimal subtract = a.subtract(userId.getJine());
|
|
|
|
+
|
|
|
|
+ orders1.setZhong(a);
|
|
|
|
+ orders1.setYouhui(userId.getJine());
|
|
|
|
+ orders1.setShi(subtract);
|
|
|
|
+ this.baseMapper.updateById(orders1);
|
|
|
|
+
|
|
|
|
+ List<OrdersTime> orderName = ordersTimeMapper.selectList(new QueryWrapper<OrdersTime>().eq("orders_id", orders1.getId()));
|
|
|
|
+
|
|
|
|
+ orders1.setOrdersTimes(orderName);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return Result.OK(orders1,"添加成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|