package cn.iocoder.yudao.module.inspection.service.impl;

import cn.iocoder.yudao.module.inspection.entity.ProjectRoyalty;
import cn.iocoder.yudao.module.inspection.mapper.ProjectRoyaltyMapper;
import cn.iocoder.yudao.module.inspection.service.AppInspectionPartnerService;
import cn.iocoder.yudao.module.inspection.service.ProjectRoyaltyService;
import cn.iocoder.yudao.module.inspection.vo.ProjectRoyaltySaveReqVO;
import cn.iocoder.yudao.module.shop.entity.ShopMallPartners;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import java.util.List;

/**
 * 检测项目子表（项目提成） Service 实现类
 *
 * @author 若依
 */
@Service
@Validated
public class ProjectRoyaltyServiceImpl extends ServiceImpl<ProjectRoyaltyMapper, ProjectRoyalty> implements ProjectRoyaltyService {

    @Resource
    private ProjectRoyaltyMapper projectRoyaltyMapper;
    @Autowired
    @Lazy
    private AppInspectionPartnerService appInspectionPartnerService;

    @Override
    public Long createProjectRoyalty(ProjectRoyaltySaveReqVO createReqVO) {
        // 插入
        ProjectRoyalty projectRoyalty = BeanUtils.toBean(createReqVO, ProjectRoyalty.class);
        projectRoyaltyMapper.insert(projectRoyalty);
        // 返回
        return projectRoyalty.getId();
    }

    /**
     * 批量创建检测项目子表（项目提成）
     *
     * @param createReq 创建信息
     */
    @Override
    public void batchInsertProjectRoyalty(List<ProjectRoyalty> createReq) {
        projectRoyaltyMapper.insertBatch(createReq);
    }

    /**
     * 根据项目id删除检测项目子表（项目提成）
     *
     * @param projectId
     */
    @Override
    public void deleteInsertProjectRoyalty(String projectId) {
        projectRoyaltyMapper.deleteByProjectId(projectId);
    }

    /**
     * 根据项目id查询检测项目子表（项目提成）
     *
     * @param projectId
     * @return
     */
    @Override
    public List<ProjectRoyalty> getProjectRoyaltyList(String projectId) {
        try {
            ShopMallPartners one = appInspectionPartnerService.shopInfoByUserId();
            return baseMapper.selectListByProjrctId(projectId, one.getPartnerId().toString());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 批量更新检测项目子表（项目提成）
     *
     * @param createReq
     */
    @Override
    public void updtaBatch(List<ProjectRoyalty> createReq) {
        projectRoyaltyMapper.updtaBatch(createReq);
    }

//    @Override
//    public void updateProjectRoyalty(ProjectRoyaltySaveReqVO updateReqVO) {
//        // 校验存在
//        validateProjectRoyaltyExists(updateReqVO.getId());
//        // 更新
//        ProjectRoyalty updateObj = BeanUtils.toBean(updateReqVO, ProjectRoyalty.class);
//        projectRoyaltyMapper.updateById(updateObj);
//    }
//
//    @Override
//    public void deleteProjectRoyalty(Long id) {
//        // 校验存在
//        validateProjectRoyaltyExists(id);
//        // 删除
//        projectRoyaltyMapper.deleteById(id);
//    }
//
//
//    @Override
//    public ProjectRoyalty getProjectRoyalty(Long id) {
//        return projectRoyaltyMapper.selectById(id);
//    }


}