package com.jkcredit.invoice.service.customer.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jkcredit.invoice.mapper.customer.CustomerOperMapper;
import com.jkcredit.invoice.mapper.user.UserMapper;
import com.jkcredit.invoice.model.entity.customer.CustomerOper;
import com.jkcredit.invoice.model.entity.user.User;
import com.jkcredit.invoice.service.customer.CustomerOperService;
import com.jkcredit.invoice.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service("customerOperService")
public class CustomerOperServiceImpl extends ServiceImpl<CustomerOperMapper,CustomerOper> implements CustomerOperService {
    @Autowired
    CustomerOperMapper customerOperMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public IPage findAllCustomerOper(Page page, CustomerOper customerOper) {
        return customerOperMapper.selectAllByPage(page,customerOper);
    }

    @Override
    public String saveCustomerOper(String customerName, int operType) {
        log.info("开始保存批次信息CustomerOperServiceImpl.saveCustomerOper:("+customerName+","+operType+")");
        //保存批次信息
        User user = userMapper.getUserByUserName(customerName);
        String batchNumber = "YD" + System.currentTimeMillis();
        CustomerOper customerOper = new CustomerOper();
        customerOper.setOperType(operType);
        customerOper.setCompany(user.getCompany());
        customerOper.setCreateTime(DateUtil.getCurrentDateStr());
        customerOper.setBatchNumber(batchNumber);
        customerOper.setCustomerPhone(user.getPhone());
        customerOper.setCustomerName(customerName);
        customerOperMapper.insert(customerOper);
        return batchNumber;
    }
}
