package com.dayou.service.impl;

import com.dayou.common.BaseEntity;
import com.dayou.dto.TaskRecordDTO;
import com.dayou.entity.Personal;
import com.dayou.entity.PersonalScene;
import com.dayou.mapper.PersonalSceneMapper;
import com.dayou.service.IPersonalSceneService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dayou.utils.LoginContext;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.dayou.utils.ExcelUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.ArrayList;
import org.springframework.transaction.annotation.Transactional;
import com.dayou.enums.BatchTaskTypeEnum;

/**
 * <p>
 * 个贷实勘表 服务实现类
 * </p>
 *
 * @author wucl
 * @since 2024-03-01
 */
@Service
public class PersonalSceneServiceImpl extends ServiceImpl<PersonalSceneMapper, PersonalScene> implements IPersonalSceneService {


    @Override
    @SuppressWarnings("unchecked")
    public Page<PersonalScene> selectPage(Page page,PersonalScene personalScene){
        return this.page(page, new QueryWrapper<PersonalScene>(personalScene));
    }


    @Override
    public PersonalScene detail(Long personalId){
        return this.getOne(new LambdaQueryWrapper<PersonalScene>().eq(PersonalScene::getPersonalId,personalId)
                .eq(BaseEntity::getDeleted,Boolean.FALSE));
    }

    @Override
    public Boolean add(PersonalScene personalScene){
        personalScene.setUserId(LoginContext.getCurrentUserId());
        return  this.save(personalScene);
    }

    @Override
    public Boolean update(PersonalScene personalScene){
        return  this.updateById(personalScene);
    }

    @Override
    public Boolean delete(Long id){
        //逻辑删除
        return this.removeById(id);
    }

    @Override
    public Boolean saveSceneInfo(TaskRecordDTO<PersonalScene> taskRecordDTO) {
        PersonalScene taskData = taskRecordDTO.getTaskData();
        taskData.setUserId(LoginContext.getCurrentUserId());
        return this.saveOrUpdate(taskData);
    }
}
