package com.sckw.contract.service;

import com.sckw.contract.dao.KwcContractLogisticsTrackMapper;
import com.sckw.contract.dao.KwcContractTradeMapper;
import com.sckw.contract.dao.KwcContractTradeTrackMapper;
import com.sckw.contract.model.entity.KwcContractLogisticsTrack;
import com.sckw.contract.model.entity.KwcContractTradeTrack;
import com.sckw.core.exception.SystemException;
import com.sckw.core.model.constant.Global;
import com.sckw.core.model.enums.ContractTrackEnum;
import com.sckw.core.utils.IdWorker;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.context.LoginUserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author PC
* @description 针对表【kwc_contract_trade_track(交易合同（采购合同/销售合同）-交易订单（采购订单/销售订单）)】的数据库操作Service实现
* @createDate 2023-07-13 13:36:19
*/
@Service
public class KwcContractTradeTrackService {

    @Autowired
    private KwcContractTradeTrackMapper kwcContractTradeTrackMapper;


    public void saveContractTradeTrack(Long contractId) {
        Date date = new Date();
        KwcContractTradeTrack kwcContractTradeTrack = new KwcContractTradeTrack();
        kwcContractTradeTrack.setId(new IdWorker(1L).nextId());
        kwcContractTradeTrack.setContractId(contractId);
        kwcContractTradeTrack.setType(ContractTrackEnum.SIGNING.getCode());
        kwcContractTradeTrack.setRemark("");
        kwcContractTradeTrack.setStatus(Global.NO);
        kwcContractTradeTrack.setCreateBy(LoginUserHolder.getUserId());
        kwcContractTradeTrack.setCreateTime(date);
        kwcContractTradeTrack.setUpdateBy(LoginUserHolder.getUserId());
        kwcContractTradeTrack.setUpdateTime(date);
        kwcContractTradeTrack.setDelFlag(Global.NO);
        if (kwcContractTradeTrackMapper.insert(kwcContractTradeTrack) <= 0) {
            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
        }
    }
}




