package com.hz.pm.api.todocenter.service.impl;

import com.hz.pm.api.todocenter.mapper.StatisticsMapper;
import com.hz.pm.api.todocenter.model.po.TodoCenterStatisticsPO;
import com.hz.pm.api.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(Long userId) {
        TodoCenterStatisticsPO res = new TodoCenterStatisticsPO();
        String userIdStr = String.valueOf(userId);
        TodoCenterListReqDTO req = new TodoCenterListReqDTO();
        req.setEmployeeCode(userIdStr);
        Integer todoCount = processTaskService.getTodoCount(req);
        res.setTodoNum(todoCount);

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

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

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

        return res;
    }
}
