package com.jeeplus.modules.sg.service;

import com.jeeplus.modules.sg.entity.JkxlData;
import com.jeeplus.modules.sg.entity.RuleRatio;
import com.jeeplus.modules.sg.entity.TzData;
import com.jeeplus.modules.sg.entity.WbsProject;
import com.jeeplus.modules.sg.mapper.JkxlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class JkxlService {
    @Autowired
    private JkxlMapper jkxlMapper;


   public RuleRatio getValueByName(String ratioName){
       return jkxlMapper.getValue(ratioName);
   }

   public List<JkxlData> getList(String id){
       return jkxlMapper.getList(id);
   }

   public List<JkxlData> findList(String id){
       return jkxlMapper.findList(id);
   }

   @Transactional
   public void save(JkxlData jkxlData){
       jkxlMapper.save(jkxlData);
   }

    @Transactional
    public void updataDate(JkxlData jkxlData){
        jkxlMapper.updateDate(jkxlData);
    }

    @Transactional
   public void saveProject(WbsProject wbsProject){
       jkxlMapper.saveProject(wbsProject);
   }

   public List<TzData> getTzFee(TzData tzData){
       return jkxlMapper.getTzFee(tzData);
   }

    @Transactional
   public void  updateFee(TzData tzData){
       String type  = tzData.getType();
       if(type.equals("补增值税税率调整差额")){
           type = "1";
       } else {
           type = "2";
       }
       tzData.setType(type);
       tzData.setFee(0.00);
       jkxlMapper.updateTzFee(tzData);
   }

    @Transactional
    public void saveTzFee(double[] wbs,String id){
       TzData tzData = new TzData();
       TzData tzData1 = new TzData();
       tzData.setId(id);
       tzData1.setId(id);
       tzData.setType("1");
       tzData1.setType("2");
       tzData.setFee(wbs[0]);
       tzData1.setFee(wbs[1]);
       jkxlMapper.saveTzFee(tzData);
       jkxlMapper.saveTzFee(tzData1);
    }
}
