package com.zhongdao.jlr.business.service.impl;

import com.util.Vo;
import com.zhongdao.jlr.business.dao.SupplierDao;
import com.zhongdao.jlr.business.service.SupplierService;
import com.zhongdao.jlr.business.vo.Contract;
import com.zhongdao.jlr.business.vo.Destination;
import com.zhongdao.jlr.business.vo.Enterprise;
import com.zhongdao.jlr.pojo.JLRDestination;
import com.zhongdao.jlr.pojo.JLRSupplier;
import com.zhongdao.jlr.pojo.JLRUserContract;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service(value = "supplierServiceImpl")
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    SupplierDao dao;
    @Override
    public Vo getContractInfo(HttpServletRequest request,String name,String id) {
        return dao.getContractInfo(request,name,id);
    }

    @Override
    public List<Contract> getAssignContract(String id) {
        return dao.getAssignContract(id);
    }

    @Override
    public List<Destination> geAssignDestination(String id) {
        return dao.getAssignDestination(id);
    }

    @Override
    public List<Enterprise> geAssignEnterprise(String id) {
        return dao.getAssignEnterprise(id);
    }

    @Override
    public Vo getEnterpriseInfo(HttpServletRequest request,String name,String id) {
        return dao.getEnterpriseInfo(request,name,id);
    }

    @Override
    public Vo getDestination(HttpServletRequest request, String name,String id) {
        return dao.getDestination(request,name,id);
    }

    @Override
    public boolean insertContractInfo(Integer id, int[] ids) {
        //声明一个合同对象
        JLRUserContract jlrUserContract=new JLRUserContract();
        jlrUserContract.setJlr_user_id(id);
        //批量插入数据
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            jlrUserContract.setId(Integer.valueOf((System.currentTimeMillis() / 10 + "").substring(3)));
            jlrUserContract.setContract_id(ids[i]);
            boolean state=dao.insertContractInfo(jlrUserContract);
                if(state == false){
                    return false;
            }
        }
        return true;
    }


    @Override
    public boolean insertDestinationInfo(Integer id, int[] ids) {
        //声明一个合同对象
        JLRDestination jlrDestination=new JLRDestination();
        jlrDestination.setJlr_user_id(id);
        //批量插入数据
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            jlrDestination.setId(Integer.valueOf((System.currentTimeMillis() / 10 + "").substring(3)));
            jlrDestination.setContract_destination_id(ids[i]);
            boolean state=dao.insertDestinationInfo(jlrDestination);
            if(state == false){
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean insertEnterpriseInfo(Integer id, int[] ids) {
        //声明一个合同对象
        JLRSupplier jlrSupplier=new JLRSupplier();
        jlrSupplier.setJlr_user_id(id);
        //批量插入数据
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            jlrSupplier.setId(Integer.valueOf((System.currentTimeMillis() / 10 + "").substring(3)));
            jlrSupplier.setSupplier_id(ids[i]);
            boolean state=dao.insertEnterpriseInfo(jlrSupplier);
            if(state == false){
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean deleteEnterpriseInfo(Integer id, int[] ids) {
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            int sid=ids[i];
            boolean state=dao.deleteEnterpriseInfo(sid,id);
            if(state == false){
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean deleteContractInfo(Integer id, int[] ids) {
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            int cid=ids[i];
            boolean state=dao.deleteContractInfo(cid,id);
            if(state == false){
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean deleteDestinationInfo(Integer id, int[] ids) {
        for(int i=0;i<ids.length;i++) {
            //将数据放入对象里
            int did=ids[i];
            boolean state=dao.deleteDestinationInfo(did,id);
            if(state == false){
                return false;
            }
        }
        return true;
    }

    @Override
    public List<JLRUserContract> getDestinationInfo(String id) {
        return dao.getContract(id);
    }
}
