package cn.ezhizao.project.business.salary.service.impl;

import cn.ezhizao.project.business.salary.domain.BizFinancialSalaryDetail;
import cn.ezhizao.project.business.salary.domain.BizFinancialSalaryDetailEmployee;
import cn.ezhizao.project.business.salary.mapper.BizFinancialSalaryDetailMapper;
import cn.ezhizao.project.business.salary.service.IBizFinancialSalaryDetailEmployeeService;
import cn.ezhizao.project.business.salary.service.IBizFinancialSalaryDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工资报工信息Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-16
 */
@Service
public class BizFinancialSalaryDetailServiceImpl  extends ServiceImpl<BizFinancialSalaryDetailMapper, BizFinancialSalaryDetail> implements IBizFinancialSalaryDetailService
{
    @Resource
    private BizFinancialSalaryDetailMapper bizFinancialSalaryDetailMapper;
    @Resource
    private IBizFinancialSalaryDetailEmployeeService bizFinancialSalaryDetailEmployeeService;

    /**
     * 查询工资报工信息列表
     *
     * @param bizFinancialSalaryDetail 工资报工信息
     * @return 工资报工信息
     */
    @Override
    public List<BizFinancialSalaryDetail> getList(BizFinancialSalaryDetail bizFinancialSalaryDetail)
    {
        return bizFinancialSalaryDetailMapper.getList(bizFinancialSalaryDetail);
    }

    /**
     * 物理删除
     * @param bizFinancialSalaryDetail
     * @return 删除结果
     */
    @Override
    public int physicalDelete(BizFinancialSalaryDetail bizFinancialSalaryDetail){ return bizFinancialSalaryDetailMapper.physicalDelete(bizFinancialSalaryDetail); };

    @Override
    public boolean save(BizFinancialSalaryDetail bizFinancialSalaryDetail) {
        boolean status = super.save(bizFinancialSalaryDetail);
        List<BizFinancialSalaryDetailEmployee> employees = bizFinancialSalaryDetail.getDetails();
        employees.forEach(l -> {
            l.setFinancialSalaryDetailId(bizFinancialSalaryDetail.getId());
            l.setCompanyId(bizFinancialSalaryDetail.getCompanyId());
            l.setFinancialSalaryId(bizFinancialSalaryDetail.getFinancialSalaryId());
        });
        status = status && (employees.isEmpty() || bizFinancialSalaryDetailEmployeeService.saveBatch(employees));
        return status;
    }

    @Override
    public boolean updateById(BizFinancialSalaryDetail bizFinancialSalaryDetail) {
        boolean status = super.updateById(bizFinancialSalaryDetail);
        BizFinancialSalaryDetailEmployee delCondition = new BizFinancialSalaryDetailEmployee();
        delCondition.setFinancialSalaryDetailId(bizFinancialSalaryDetail.getId());
        bizFinancialSalaryDetailEmployeeService.physicalDelete(delCondition);
        List<BizFinancialSalaryDetailEmployee> employees = bizFinancialSalaryDetail.getDetails();
        employees.forEach(l -> {
            l.setFinancialSalaryDetailId(bizFinancialSalaryDetail.getId());
            l.setCompanyId(bizFinancialSalaryDetail.getCompanyId());
            l.setFinancialSalaryId(bizFinancialSalaryDetail.getFinancialSalaryId());
        });
        status = status && (employees.isEmpty() || bizFinancialSalaryDetailEmployeeService.saveBatch(employees));
        return status;
    }

}
