package com.ghy.worker.service.impl;

import java.util.List;
import com.ghy.common.utils.DateUtils;
import com.ghy.system.domain.SysArea;
import com.ghy.system.service.ISysAreaService;
import org.springframework.stereotype.Service;
import com.ghy.worker.mapper.WorkerCertificationMapper;
import com.ghy.worker.domain.WorkerCertification;
import com.ghy.worker.service.IWorkerCertificationService;
import com.ghy.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 师傅实名审核Service业务层处理
 *
 * @author clunt
 * @date 2022-07-07
 */
@Service
public class WorkerCertificationServiceImpl implements IWorkerCertificationService
{
    @Resource
    private WorkerCertificationMapper workerCertificationMapper;

    @Resource
    private ISysAreaService sysAreaService;

    /**
     * 查询师傅实名审核
     *
     * @param workerCertificationId 师傅实名审核主键
     * @return 师傅实名审核
     */
    @Override
    public WorkerCertification selectWorkerCertificationByWorkerCertificationId(String workerCertificationId)
    {
        return workerCertificationMapper.selectWorkerCertificationByWorkerCertificationId(workerCertificationId);
    }

    /**
     * 查询师傅实名审核列表
     *
     * @param workerCertification 师傅实名审核
     * @return 师傅实名审核
     */
    @Override
    public List<WorkerCertification> selectWorkerCertificationList(WorkerCertification workerCertification)
    {
        List<WorkerCertification> workerCertifications = workerCertificationMapper.selectWorkerCertificationList(workerCertification);
        workerCertifications.forEach(model->{
            if(model.getCompanyProvinceId() != null){
                SysArea area = sysAreaService.selectById(model.getCompanyProvinceId());
                if(area != null){
                    model.setCompanyProvinceName(area.getAreaName());
                }
            }
            if(model.getCompanyCityId() != null){
                SysArea area = sysAreaService.selectById(model.getCompanyCityId());
                if(area != null){
                    model.setCompanyCityName(area.getAreaName());
                }
            }
            if(model.getCompanyCountryId() != null){
                SysArea area = sysAreaService.selectById(model.getCompanyCountryId());
                if(area != null){
                    model.setCompanyCountryName(area.getAreaName());
                }
            }
        });
        return workerCertifications;
    }

    /**
     * 新增师傅实名审核
     *
     * @param workerCertification 师傅实名审核
     * @return 结果
     */
    @Override
    public int insertWorkerCertification(WorkerCertification workerCertification)
    {
        workerCertification.setCreateTime(DateUtils.getNowDate());
        return workerCertificationMapper.insertWorkerCertification(workerCertification);
    }

    /**
     * 修改师傅实名审核
     *
     * @param workerCertification 师傅实名审核
     * @return 结果
     */
    @Override
    public int updateWorkerCertification(WorkerCertification workerCertification)
    {
        workerCertification.setUpdateTime(DateUtils.getNowDate());
        return workerCertificationMapper.updateWorkerCertification(workerCertification);
    }

    /**
     * 批量删除师傅实名审核
     *
     * @param workerCertificationIds 需要删除的师傅实名审核主键
     * @return 结果
     */
    @Override
    public int deleteWorkerCertificationByWorkerCertificationIds(String workerCertificationIds)
    {
        return workerCertificationMapper.deleteWorkerCertificationByWorkerCertificationIds(Convert.toStrArray(workerCertificationIds));
    }

    /**
     * 删除师傅实名审核信息
     *
     * @param workerCertificationId 师傅实名审核主键
     * @return 结果
     */
    @Override
    public int deleteWorkerCertificationByWorkerCertificationId(String workerCertificationId)
    {
        return workerCertificationMapper.deleteWorkerCertificationByWorkerCertificationId(workerCertificationId);
    }

    @Override
    public WorkerCertification selectByWorkerId(Long workerId) {
        return workerCertificationMapper.selectByWorkerId(workerId);
    }

    @Override
    public int deleteCertificationByWorkerId(Long workerId) {
        return workerCertificationMapper.deleteCertificationByWorkerId(workerId);
    }

    @Override
    public int changeStatus(String ids, Integer status) {
        return workerCertificationMapper.changeStatus(ids, status);
    }
}
