package com.ningdatech.pmapi.todocenter.service.impl;

import com.ningdatech.pmapi.todocenter.mapper.StatisticsMapper;
import com.ningdatech.pmapi.todocenter.model.po.TodoCenterStatisticsPO;
import com.ningdatech.pmapi.todocenter.service.StatisticsService;
import com.wflow.workflow.bean.dto.TodoCenterListReqDTO;
import com.wflow.workflow.service.ProcessTaskService;
import lombok.AllArgsConstructor;
import org.flowable.engine.TaskService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Classname StatisticsService
 * @Description
 * @Date 2023/3/20 11:20
 * @Author PoffyZhang
 */
@Service
@AllArgsConstructor
public class StatisticsServiceImpl implements StatisticsService {

    private final StatisticsMapper mapper;

    private final ProcessTaskService processTaskService;

    private final TaskService taskService;

    @Override
    public TodoCenterStatisticsPO getStatistics(String employeeCode) {
        TodoCenterStatisticsPO res = new TodoCenterStatisticsPO();

        TodoCenterListReqDTO req = new TodoCenterListReqDTO();
        req.setEmployeeCode(employeeCode);
        Integer todoCount = processTaskService.getTodoCount(req);
        res.setTodoNum(todoCount);

        Integer idoCount = processTaskService.getUserIdoCount(req);
        res.setIdoNum(idoCount);

        TodoCenterStatisticsPO submit = mapper.mysubmitNum(employeeCode);
        if(Objects.nonNull(submit)){
            res.setMysubmitNum(submit.getMysubmitNum());
        }

        TodoCenterStatisticsPO ccMe = mapper.ccNums(employeeCode);
        if(Objects.nonNull(ccMe)){
            res.setCcmeNum(ccMe.getCcmeNum());
        }

        return res;
    }
}
