package com.dayou.service.impl;

import com.dayou.common.BaseEntity;
import com.dayou.entity.WorkRecordTransfer;
import com.dayou.entity.WorkTaskRecord;
import com.dayou.mapper.WorkRecordTransferMapper;
import com.dayou.service.IWorkRecordTransferService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dayou.service.workflow.IWorkTaskRecordService;
import com.dayou.utils.LoginContext;
import org.springframework.beans.factory.annotation.Autowired;
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-04-30
 */
@Service
public class WorkRecordTransferServiceImpl extends ServiceImpl<WorkRecordTransferMapper, WorkRecordTransfer> implements IWorkRecordTransferService {

    @Autowired
    private IWorkTaskRecordService workTaskRecordService;

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


    @Override
    public WorkRecordTransfer detail(Long id){
        return this.getById(id);
    }

    @Override
    @Transactional
    public Boolean add(WorkRecordTransfer workRecordTransfer){
        workTaskRecordService.update(new LambdaUpdateWrapper<WorkTaskRecord>().set(WorkTaskRecord::getHandlerId,workRecordTransfer.getToId())
                .eq(BaseEntity::getId,workRecordTransfer.getRecordId()));
        workRecordTransfer.setFromId(LoginContext.getCurrentUserId());
        return  this.save(workRecordTransfer);
    }

    @Override
    public Boolean update(WorkRecordTransfer workRecordTransfer){
        return  this.updateById(workRecordTransfer);
    }

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