package com.qy.worksheetsystem.service.impl;

import com.qy.worksheetsystem.model.mapper.ProjectMapper;
import com.qy.worksheetsystem.service.ProjectPersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qingwu
 * @date 2024/12/5
 * @apiNote
 */
@Slf4j
@Service
public class ProjectPersonServiceImpl implements ProjectPersonService {

    @Resource
    private ProjectMapper projectMapper;

    @Override
    public List<Map<String, String>> getProjectRoleList() {
        return projectMapper.getProjectRoleList();
    }

    @Override
    public List<Map<String, String>> getProjectListByState(String state, String dateTime, String personNumber) {
        return projectMapper.getProjectListByState(state, dateTime, personNumber);
    }

    @Override
    public List<Map<String, String>> getProjectManagementByState(String state, String dateTime) {
        return projectMapper.getProjectManagementByState(state, dateTime);
    }

    @Override
    public List<Map<String, Object>> getMemberManagementInfoByPerobjectId(String perobjectId) {
        List<Map<String, Object>> list = projectMapper.getMemberManagementInfoByPerobjectId(perobjectId);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = list.get(i);
            map.put("isDisable", 1);
            if ("项目经理".equals(map.get("projectRoleName"))) {
                map.put("isDisable", 0);
            }
        }
        return list;
        //return projectMapper.getMemberManagementInfoByPerobjectId(perobjectId);
    }

    @Override
    public List<Map<String, String>> getPersonAll() {
        return projectMapper.getPersonAll();
    }

    @Override
    public int updateStateByPersonIdAndPerobject(boolean state, String personID, String projectID) {
        String status = "1";
        if (!state) {
            status = "0";
        }
        return projectMapper.updateStateByPersonIdAndPerobject(status, personID, projectID);
    }

    @Override
    public String getMemberManagementID() {
        return projectMapper.getMemberManagementID();
    }

    @Override
    public String getPersonIdBYNumber(String number) {
        return projectMapper.getPersonIdBYNumber(number);
    }

    @Override
    public List<Map<String, String>> getProjectManagementInfoBYId(String id) {
        return projectMapper.getProjectManagementInfoBYId(id);
    }

    @Override
    public Map addProjectPerson(Map<String, Object> mapParam) {
        Map map = new HashMap();
        int insertNum = projectMapper.addProjectPerson(mapParam);
        if (insertNum != 1) {
            map.put("code", "500");
            map.put("status", insertNum);
            map.put("msg", "新增失败");
        } else {
            map.put("code", "200");
            map.put("status", insertNum);
            map.put("msg", "新增成功");
        }
        return map;
    }

    @Override
    public List<Map<String, String>> getManagementByNumber(String number) {
        return projectMapper.getManagementByNumber(number);
    }

    @Override
    public Map<String, String> getPerson(String personID) {
        return projectMapper.getPerson(personID);
    }
}
