package com.xzx.gc.order.service; import cn.hutool.core.util.StrUtil; import com.xzx.gc.common.utils.IdUtils; import com.xzx.gc.entity.AddressInfo; import com.xzx.gc.entity.JhyOrder; import com.xzx.gc.entity.JhyOrderItems; import com.xzx.gc.entity.SysEnvironmentalInfo; import com.xzx.gc.order.dto.AddJhyOrderDto; import com.xzx.gc.order.mapper.AddressMapper; import com.xzx.gc.order.mapper.JhyOrderItemsMapper; import com.xzx.gc.order.mapper.JhyOrderMapper; import com.xzx.gc.order.mapper.SysEnvironmentalInfoMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @Slf4j @Service @Transactional public class JhyOrderService { @Autowired private JhyOrderMapper jhyOrderMapper; @Autowired private AddressMapper addressMapper; @Autowired private SysEnvironmentalInfoMapper environmentalInfoMapper; @Autowired private JhyOrderItemsMapper jhyOrderItemsMapper; @Autowired private IdUtils idUtils; public void addJhyOrder(AddJhyOrderDto orderDto) { String orderNo = idUtils.generate("JW", 10); JhyOrder jhyOrder = new JhyOrder(); AddressInfo addressInfo = addressMapper.selectByPrimaryKey(orderDto.getAddressId()); jhyOrder.setOrderNo(orderNo); jhyOrder.setArea(addressInfo.getAddressArea()); jhyOrder.setAddress(addressInfo.getAddress()); jhyOrder.setUsername(addressInfo.getRelaName()); jhyOrder.setPhone(addressInfo.getMobilePhone()); jhyOrder.setLongitude(addressInfo.getLongitude()); jhyOrder.setLatitude(addressInfo.getLatitude()); jhyOrder.setReserveDate(orderDto.getReserveDate()); jhyOrder.setReserveTime(orderDto.getReserveTime()); jhyOrder.setWeight(orderDto.getWeight()); jhyOrder.setStatus(JhyOrder.ORDER_STATUS_WAITING); jhyOrder.setCreatedTime(new Date()); jhyOrderMapper.insert(jhyOrder); long[] typeIds = StrUtil.splitToLong(orderDto.getTypeIds(), ","); for (long typeId : typeIds) { SysEnvironmentalInfo environmentalInfo = environmentalInfoMapper.selectByPrimaryKey(typeId); JhyOrderItems item = new JhyOrderItems(); item.setOrderId(jhyOrder.getId()); item.setPicture(environmentalInfo.getPicture()); item.setItemType(typeId); item.setTitle(environmentalInfo.getTitle()); item.setPrice(new BigDecimal(environmentalInfo.getPrice())); jhyOrderItemsMapper.insert(item); } } }