|
@@ -11,6 +11,7 @@ import com.leromro.common.core.domain.ListPermission;
|
|
|
import com.leromro.common.core.domain.R;
|
|
|
import com.leromro.common.core.domain.entity.SysDept;
|
|
|
import com.leromro.common.core.domain.entity.SysUser;
|
|
|
+import com.leromro.common.core.domain.model.LoginUser;
|
|
|
import com.leromro.common.exception.ServiceException;
|
|
|
import com.leromro.common.utils.GeoUtils;
|
|
|
import com.leromro.common.utils.SecurityUtils;
|
|
@@ -28,6 +29,7 @@ import com.leromro.core.utils.DateTimeUtil;
|
|
|
import com.leromro.core.utils.JsonParser;
|
|
|
import com.leromro.core.utils.NoUtil;
|
|
|
import com.leromro.system.mapper.SysDeptMapper;
|
|
|
+import com.leromro.system.mapper.SysUserMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -44,7 +46,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrders> implements IMainOrderService{
|
|
|
+public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrders> implements IMainOrderService {
|
|
|
@Autowired
|
|
|
private MainOrdersMapper mainOrdersMapper;
|
|
|
@Autowired
|
|
@@ -76,6 +78,8 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
private RedissonClient redissonClient;
|
|
|
@Autowired
|
|
|
private SysDeptMapper sysDeptMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private DeptRegionManagementMapper deptRegionManagementMapper;
|
|
@@ -90,12 +94,11 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
@Override
|
|
|
public List<MainOrdersVO> selectByUserId(String[] orderStatus, Long userId) {
|
|
|
|
|
|
- List<MainOrdersVO> ordersVOS = mainOrdersMapper.selectByUserId(orderStatus,userId);
|
|
|
- return ordersVOS;
|
|
|
+ List<MainOrdersVO> ordersVOS = mainOrdersMapper.selectByUserId(orderStatus, userId);
|
|
|
+ return ordersVOS;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* @param orderRequest
|
|
|
*/
|
|
@@ -106,7 +109,7 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
OrderPaymentVO vo = new OrderPaymentVO();
|
|
|
//订单信息
|
|
|
MainOrders orders = orderRequest.getOrders();
|
|
|
- if (SecurityUtils.getUserId().equals(orders.getVolunteerId())){
|
|
|
+ if (SecurityUtils.getUserId().equals(orders.getVolunteerId())) {
|
|
|
throw new RuntimeException("不可以给自己下单");
|
|
|
}
|
|
|
//由于前端传过来的不是有序的,所以我们要将工作时间进行排序
|
|
@@ -136,14 +139,14 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
orders.setServiceTotalPrice(totalPrice);
|
|
|
// 判断支付方式,余额扣减余额。 1 余额 2 微信
|
|
|
String seconderStatus;
|
|
|
- if (orders.getPaymentMethod().equals("1")){
|
|
|
+ if (orders.getPaymentMethod().equals("1")) {
|
|
|
// 查看余额够不够 修改用户余额表
|
|
|
ClientAccount clientAccount = clientAccountMapper.selectBalanceByuserID(userId);
|
|
|
BigDecimal balanceOld = clientAccount.getBalance();
|
|
|
BigDecimal newBalance = balanceOld.subtract(totalPrice);
|
|
|
- if (newBalance.compareTo(BigDecimal.ZERO) < 0){
|
|
|
+ if (newBalance.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new RuntimeException("余额不足,支付失败");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
BigDecimal balanceNew = balanceOld.subtract(totalPrice);
|
|
|
clientAccount.setBalance(balanceNew);
|
|
|
clientAccount.setUpdateTime(DateTimeUtil.getNowTime());
|
|
@@ -156,8 +159,8 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
ClientAccountChange clientAccountChange = ClientAccountChange.builder().userId(userId).changeType("0").sourceType("1").changeMoney(totalPrice).beforeBalance(balanceOld).afterBalance(newBalance).mainOrderId(orderId).build();
|
|
|
clientAccountChange.setCreateTime(DateTimeUtil.getNowTime1());
|
|
|
clientAccountChangeMapper.insert(clientAccountChange);
|
|
|
- }else if (orders.getPaymentMethod().equals("2")){
|
|
|
- /**微信支付 */
|
|
|
+ } else if (orders.getPaymentMethod().equals("2")) {
|
|
|
+ /**微信支付 */
|
|
|
//组装微信预下单参数
|
|
|
try {
|
|
|
seconderStatus = "1";
|
|
@@ -180,7 +183,7 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
vo.setSignType(result.getSignType());
|
|
|
vo.setPaySign(result.getPaySign());
|
|
|
log.info("【微信支付】预下单成功,结果={}", result);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("【微信支付】支付失败 原因={}", e.getMessage());
|
|
|
return R.fail("服务器繁忙,暂时无法下单,请稍后再试");
|
|
|
}
|
|
@@ -188,7 +191,7 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
//设置订单支付状态
|
|
|
orders.setOrderStatus("0");
|
|
|
seconderStatus = "0";
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException("支付方式错误");
|
|
|
}
|
|
|
//创建订单主表
|
|
@@ -196,7 +199,6 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
Address address = addressMapper.selectAddressByAddressId(orders.getAddressId());
|
|
|
|
|
|
|
|
|
-
|
|
|
//地址拼接信息+经纬度
|
|
|
String OrderAddress = String.join("",
|
|
|
Objects.toString(address.getProvinceName(), ""),
|
|
@@ -225,11 +227,11 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
orders.setServiceDuration(businessDurationMin);
|
|
|
//设置服务的开始与结束日期 以及开始与结束时间
|
|
|
orders.setServiceStartDate(workDateList.get(0).getWorkDate());
|
|
|
- orders.setServiceFinishDate(workDateList.get(workDateList.size()-1).getWorkDate());
|
|
|
- this.save(orders);
|
|
|
+ orders.setServiceFinishDate(workDateList.get(workDateList.size() - 1).getWorkDate());
|
|
|
+
|
|
|
|
|
|
//修改志愿者预约时间表
|
|
|
- VolunteerReservationTime reservationTime =VolunteerReservationTime.builder().volunteerId(orders.getVolunteerId()).clientId(userId).build();
|
|
|
+ VolunteerReservationTime reservationTime = VolunteerReservationTime.builder().volunteerId(orders.getVolunteerId()).clientId(userId).build();
|
|
|
reservationTime.setRemark(orders.getRemark());
|
|
|
List<VolunteerReservationTime> reservationTimes = new ArrayList<>();
|
|
|
|
|
@@ -245,60 +247,42 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
.outTradeNo(orderNo)
|
|
|
.build();
|
|
|
secondOrder.setRemark(orders.getRemark());
|
|
|
- //根据下单的收货地址,来设置分账比例 先查这个订单是否在电子围栏中
|
|
|
- //找到所有的部门的数据,然后把所有的数据遍历,并且统计出来
|
|
|
- //用的是新版的部门区域 但是获取分账比例还是从老的中获取
|
|
|
- /* List<DeptRegionManagement> deptRegionManagements = deptRegionManagementMapper.selectList(new LambdaQueryWrapper<DeptRegionManagement>().eq(DeptRegionManagement::getDelFlag, 2));
|
|
|
- List<Long> deptIdsList = deptRegionManagements.stream().map(DeptRegionManagement::getDeptId).collect(Collectors.toList());*/
|
|
|
-
|
|
|
- List<SysDept> sysDepts = sysDeptMapper.getAlldept();
|
|
|
-
|
|
|
- List<Long> deptIdList = new ArrayList<>();
|
|
|
- /*for (DeptRegionManagement deptRegionManagement : deptRegionManagements) {}*/
|
|
|
- for (SysDept sysDept : sysDepts) {
|
|
|
- //判断 服务中心分成比例
|
|
|
- //真的
|
|
|
- /* String pointList = sysDept.getPointList();
|
|
|
- boolean insidePolygon ;
|
|
|
- if (pointList != null){
|
|
|
- List<double[]> doubles = JsonParser.parseCoordinates(pointList);
|
|
|
- insidePolygon = GeoUtils.isInsidePolygon(Double.parseDouble(address.getLatitude()) , Double.parseDouble(address.getLongitude()), doubles);
|
|
|
- }else {
|
|
|
- insidePolygon = false;
|
|
|
- }
|
|
|
- if (insidePolygon){
|
|
|
- //如果是true 将这个地址的区域id添加到集合中
|
|
|
- deptIdList.add(sysDept.getDeptId());
|
|
|
- }//如果false 则什么都不变*/
|
|
|
- //区域公司的分成比例 因为没有区域公司,也不会有志愿者,所以这个区域公司一定会匹配上的
|
|
|
- if (sysDept.getDistrictCode()== null){
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (sysDept.getDistrictCode().equals(address.getDistrictCode()) && sysDept.getAreaType().equals("3")){
|
|
|
- secondOrder.setAreaDistributionRatio(sysDept.getDistributionRatio());
|
|
|
- secondOrder.setAreaDistributionId(sysDept.getDeptId());
|
|
|
- orders.setAreaDistributionId(sysDept.getDeptId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //根据匹配数量,修改数值,(开会说不用电子围栏)
|
|
|
- /* if (deptIdList.size()==1){
|
|
|
- //已分配到服务中心
|
|
|
- secondOrder.setAllotStatus("20");
|
|
|
- secondOrder.setServiceCenterId(deptIdList.get(0));
|
|
|
- //设置服务中心的分成比例
|
|
|
- sysDepts.forEach(sysDept -> {
|
|
|
- if (sysDept.getDeptId().equals(deptIdList.get(0)) && sysDept.getAreaType().equals("10")) {
|
|
|
+ //根据下单的收货地址,来设置分账比例 以及区域公司id
|
|
|
+ List<SysDept> sysDeptList = sysDeptMapper.getAlldept();
|
|
|
+ //如果推荐的服务中心id为空,那就根据收货地址来计算
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
|
|
|
+ SysDept areaDept = sysDeptList.stream()
|
|
|
+ .filter(sysDept ->
|
|
|
+ sysDept.getDistrictCode() != null && sysDept.getDistrictCode().equals(address.getDistrictCode())
|
|
|
+ && sysDept.getAreaType().equals("3")
|
|
|
+ )
|
|
|
+ .findFirst()
|
|
|
+ .orElseThrow(() -> new RuntimeException("此区域公司没有收货地址区域公司"));
|
|
|
+ //在订单中设置区域公司的信息
|
|
|
+ secondOrder.setAreaDistributionRatio(areaDept.getDistributionRatio());
|
|
|
+ secondOrder.setAreaDistributionId(areaDept.getDeptId());
|
|
|
+ orders.setAreaDistributionId(areaDept.getDeptId());
|
|
|
+ Long sysUserServiceCentreId = sysUser.getServiceCentreId();
|
|
|
+ if (sysUserServiceCentreId != null) {
|
|
|
+ for (SysDept sysDept : sysDeptList) {
|
|
|
+ if (sysDept.getDeptId().equals(sysUserServiceCentreId) && sysDept.getParentId().equals(areaDept.getDeptId())) {
|
|
|
+ //说明 推荐的服务中心id和所属的区域公司id和收货地址的区域公司的id相同,那就在订单中设置此服务中心id
|
|
|
+ orders.setServiceCenterId(sysUserServiceCentreId);
|
|
|
+ secondOrder.setServiceCenterId(sysUserServiceCentreId);
|
|
|
secondOrder.setServiceCentreDistributionRatio(sysDept.getDistributionRatio());
|
|
|
- secondOrder.setServiceCenterId(sysDept.getDeptId());
|
|
|
+ secondOrder.setAllotStatus("20");
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
+ }
|
|
|
} else {
|
|
|
+ secondOrder.setAllotStatus("10");
|
|
|
+ }
|
|
|
+ this.save(orders);
|
|
|
|
|
|
- }*/
|
|
|
+ /**/
|
|
|
+ // secondOrder.setServiceCentreDistributionRatio(sysDept.getDistributionRatio());
|
|
|
+ // secondOrder.setServiceCenterId(sysDept.getDeptId());
|
|
|
+ //根据匹配数量,修改数值,(开会说不用电子围栏)
|
|
|
|
|
|
- secondOrder.setAllotStatus("10");
|
|
|
List<SecondOrder> secondOrderList = new ArrayList<>();
|
|
|
|
|
|
|
|
@@ -314,25 +298,25 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
long secondOrderIdL = snowflake.nextId();
|
|
|
seconderIdList.add(secondOrderIdL);
|
|
|
SecondOrder secondOrder1 = new SecondOrder();
|
|
|
- BeanUtils.copyProperties(secondOrder,secondOrder1);
|
|
|
+ BeanUtils.copyProperties(secondOrder, secondOrder1);
|
|
|
secondOrder1.setWorkDate(workDate.getWorkDate());
|
|
|
secondOrder1.setWorkStartTime(workDate.getWorkStartTime());
|
|
|
- secondOrder1.setWorkEndTime(workDate.getWorkStartTime().plus(Duration.ofMinutes(orders.getServiceDuration()*orders.getSingleQuantity())));
|
|
|
+ secondOrder1.setWorkEndTime(workDate.getWorkStartTime().plus(Duration.ofMinutes(orders.getServiceDuration() * orders.getSingleQuantity())));
|
|
|
secondOrder1.setWorkNumber(number);
|
|
|
secondOrder1.setSecondOrderId(secondOrderIdL);
|
|
|
- String orderNoId = orderNo+"-"+number;
|
|
|
+ String orderNoId = orderNo + "-" + number;
|
|
|
secondOrder1.setOutTradeNo(orderNoId);
|
|
|
secondOrderList.add(secondOrder1);
|
|
|
|
|
|
//向志愿者预约时间表中添加数据
|
|
|
- int parts = (int) (businessDurationMin * singleQuantity /30);
|
|
|
- if (businessDurationMin % 30!=0){
|
|
|
+ int parts = (int) (businessDurationMin * singleQuantity / 30);
|
|
|
+ if (businessDurationMin % 30 != 0) {
|
|
|
parts++;
|
|
|
}
|
|
|
LocalTime workStartTime = workDate.getWorkStartTime();
|
|
|
for (int i = 0; i < parts; i++) {
|
|
|
VolunteerReservationTime reservationTime1 = new VolunteerReservationTime();
|
|
|
- BeanUtils.copyProperties(reservationTime,reservationTime1);
|
|
|
+ BeanUtils.copyProperties(reservationTime, reservationTime1);
|
|
|
reservationTime1.setReservationDate(workDate.getWorkDate());
|
|
|
reservationTime1.setReservationTime(workStartTime);
|
|
|
reservationTimes.add(reservationTime1);
|
|
@@ -348,8 +332,6 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
//新增志愿者订单小表N个 得修改这种
|
|
|
secondOrdersMapper.insertList(secondOrderList);
|
|
|
//新增志愿者预约时间表
|
|
@@ -358,9 +340,9 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
//修改志愿者排班日期表
|
|
|
workDateMapper.updateVolunteerWorkDatebyVolunteerId(volunteerWorkDates);
|
|
|
//调用方法,向平台流水中添加数据
|
|
|
- if(!orders.getOrderStatus().equals("0")){
|
|
|
+ if (!orders.getOrderStatus().equals("0")) {
|
|
|
// 0 是待支付,
|
|
|
- changePlatformFinance(seconderIdList,orders);
|
|
|
+ changePlatformFinance(seconderIdList, orders);
|
|
|
//异步推送消息给志愿者
|
|
|
conversationRecordService.sendSystemMsg(ConversationMsgDTO.builder()
|
|
|
.system(2).userId(orders.getVolunteerId()).volunteerId(orders.getVolunteerId())
|
|
@@ -374,10 +356,10 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
@Override
|
|
|
public List<webMainOrderListVO> webMainOrderList(WebMainOrdersDTO dto) {
|
|
|
//区分服务中心
|
|
|
- if (SecurityUtils.getAreaType().equals("4")){
|
|
|
+ if (SecurityUtils.getAreaType().equals("4")) {
|
|
|
dto.setDeptId(SecurityUtils.getDeptId());
|
|
|
}
|
|
|
- List<webMainOrderListVO> vos = baseMapper.webMainOrderList(new ListPermission(MainOrders.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT) ,dto);
|
|
|
+ List<webMainOrderListVO> vos = baseMapper.webMainOrderList(new ListPermission(MainOrders.class, CommonConstants.CHECK_PROVINCE_CITY_DISTRICT), dto);
|
|
|
return vos;
|
|
|
}
|
|
|
|
|
@@ -399,16 +381,16 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
return webMainOrderInfoVO;
|
|
|
}
|
|
|
|
|
|
- public void changePlatformFinance ( List<Long> seconderIdList,MainOrders orders){
|
|
|
+ public void changePlatformFinance(List<Long> seconderIdList, MainOrders orders) {
|
|
|
//创建平台流水模板 按照小订单,单价*件数 = 小订单价格 = 一条平台流水变动
|
|
|
- PlatformFinance platformFinance = PlatformFinance.builder().changeMoney(orders.getServiceOnePrice().multiply(BigDecimal.valueOf(orders.getSingleQuantity()))).changeType(1).moneyType(1)
|
|
|
+ PlatformFinance platformFinance = PlatformFinance.builder().changeMoney(orders.getServiceOnePrice().multiply(BigDecimal.valueOf(orders.getSingleQuantity()))).changeType(1).moneyType(1)
|
|
|
.sourceType(1).volunteerId(orders.getVolunteerId()).build();
|
|
|
platformFinance.setCreateTime(DateTimeUtil.getNowTime());
|
|
|
List<PlatformFinance> platformFinanceList = new ArrayList<>();
|
|
|
for (Long seconderId : seconderIdList) {
|
|
|
//向平台流水中添加数据
|
|
|
PlatformFinance platformFinance1 = new PlatformFinance();
|
|
|
- BeanUtils.copyProperties(platformFinance,platformFinance1);
|
|
|
+ BeanUtils.copyProperties(platformFinance, platformFinance1);
|
|
|
platformFinance1.setSecondOrderId(seconderId);
|
|
|
platformFinanceList.add(platformFinance1);
|
|
|
}
|