package com.fdkankan.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.common.util.NumberUtils;
import com.fdkankan.order.entity.CommerceOrder;
import com.fdkankan.order.mapper.ICommerceOrderMapper;
import com.fdkankan.order.service.ICommerceOrderService;
import com.fdkankan.order.vo.ResponseCommerceOrder;
import com.fdkankan.user.request.RequestCommerceOrder;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 商业订单表（八目相机） 服务实现类
 * </p>
 *
 * @author 
 * @since 2021-12-24
 */
@Service
public class CommerceOrderServiceImpl extends ServiceImpl<ICommerceOrderMapper, CommerceOrder> implements ICommerceOrderService {

    @Override
    public ResponseCommerceOrder saveByOrderParam(Long userId, RequestCommerceOrder order, BigDecimal price) {
        BigDecimal total = price.multiply(new BigDecimal(order.getCount()));
        CommerceOrder commerceOrderEntity = new CommerceOrder();
        commerceOrderEntity.setOrderSn(NumberUtils.getOrderSn());
        commerceOrderEntity.setAmount(total);
        commerceOrderEntity.setPayType(order.getPayType());
        commerceOrderEntity.setPayStatus(-1);
        commerceOrderEntity.setUserId(userId);
        commerceOrderEntity.setCommerceType(order.getCommerceType());
        commerceOrderEntity.setCount(order.getCount());
        commerceOrderEntity.setCameraId(order.getCameraId());
        commerceOrderEntity.setAbroad(order.getAbroad());
        this.save(commerceOrderEntity);
        ResponseCommerceOrder commerceOrder = new ResponseCommerceOrder();
        BeanUtils.copyProperties(commerceOrderEntity, commerceOrder);
        return commerceOrder;
    }
}
