package com.yanzhu.jh.project.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.enums.PublicStateEnum;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.jh.project.mapper.SurProjectInsuranceMapper;
import com.yanzhu.jh.project.domain.SurProjectInsurance;
import com.yanzhu.jh.project.service.ISurProjectInsuranceService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目保险Service业务层处理
 * 
 * @author JiangYuQi
 * @date 2023-08-16
 */
@Service
public class SurProjectInsuranceServiceImpl implements ISurProjectInsuranceService 
{
    @Autowired
    private SurProjectInsuranceMapper surProjectInsuranceMapper;

    /**
     * 查询项目保险
     * 
     * @param id 项目保险主键
     * @return 项目保险
     */
    @Override
    public SurProjectInsurance selectSurProjectInsuranceById(Long id)
    {
        return surProjectInsuranceMapper.selectSurProjectInsuranceById(id);
    }

    /**
     * 查询项目保险列表
     * 
     * @param surProjectInsurance 项目保险
     * @return 项目保险
     */
    @Override
    public List<SurProjectInsurance> selectSurProjectInsuranceList(SurProjectInsurance surProjectInsurance)
    {
        return surProjectInsuranceMapper.selectSurProjectInsuranceList(surProjectInsurance);
    }

    /**
     * 查询项目保险列表
     *
     * @param surProjectInsurance 项目保险
     * @return 项目保险
     */
    @Override
    public List<SurProjectInsurance> selectSurProjectInsuranceListv2(SurProjectInsurance surProjectInsurance)
    {
        return surProjectInsuranceMapper.selectSurProjectInsuranceListv2(surProjectInsurance);
    }

    /**
     * 查询大屏保险统计列表
     *
     * @param surProjectInsurance 项目保险
     * @return map集合
     */
    @Override
    public List<Map<String,Object>> selectBgscreenInsuranceList(SurProjectInsurance surProjectInsurance){
        return surProjectInsuranceMapper.selectBgscreenInsuranceList(surProjectInsurance);
    }

    /**
     * 新增项目保险
     * 
     * @param surProjectInsurance 项目保险
     * @return 结果
     */
    @Override
    @Transactional
    public int insertSurProjectInsurance(SurProjectInsurance surProjectInsurance)
    {
        surProjectInsurance.setCreateBy(SecurityUtils.getUsername());
        surProjectInsurance.setCreateTime(DateUtils.getNowDate());
        surProjectInsurance.setInsuranceState(PublicStateEnum.YES.getCode());
        surProjectInsurance.setIsDel(PublicStateEnum.OK.getCode());
        surProjectInsurance.setIsDel("0");
        int res = -1;
        //效验保险是否已办理
        int total = surProjectInsuranceMapper.findInsuranceByParams(surProjectInsurance);
        if(total>0){
            return res;
        }
        return surProjectInsuranceMapper.insertSurProjectInsurance(surProjectInsurance);
    }

    /**
     * 修改项目保险
     * 
     * @param surProjectInsurance 项目保险
     * @return 结果
     */
    @Override
    public int updateSurProjectInsurance(SurProjectInsurance surProjectInsurance)
    {
        surProjectInsurance.setUpdateBy(SecurityUtils.getUsername());
        surProjectInsurance.setUpdateTime(DateUtils.getNowDate());
        return surProjectInsuranceMapper.updateSurProjectInsurance(surProjectInsurance);
    }

    /**
     * 批量删除项目保险
     * 
     * @param ids 需要删除的项目保险主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectInsuranceByIds(Long[] ids)
    {
        return surProjectInsuranceMapper.deleteSurProjectInsuranceByIds(ids);
    }

    /**
     * 删除项目保险信息
     * 
     * @param id 项目保险主键
     * @return 结果
     */
    @Override
    public int deleteSurProjectInsuranceById(Long id)
    {
        return surProjectInsuranceMapper.deleteSurProjectInsuranceById(id);
    }

    /**
     * 按项目获取保险信息
     * @param projectId
     * @return
     */
    @Override
    public List<SurProjectInsurance> selectProjectInsuranceListByProjectId(Long projectId) {
        return surProjectInsuranceMapper.selectProjectInsuranceListByProjectId(projectId);
    }
}
