package com.lz.modules.sys.service.app;

import com.baomidou.mybatisplus.extension.service.IService;
import com.lz.common.emun.WorkMsgTypeEnum;
import com.lz.common.utils.R;
import com.lz.modules.app.dto.ApprovalDto;
import com.lz.modules.app.dto.GraphicsStatisticalDto;
import com.lz.modules.app.dto.RecordDetailDto;
import com.lz.modules.app.entity.DepartmentsEntity;
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
import com.lz.modules.app.entity.StaffEntity;
import com.lz.modules.app.req.ResultRecordReq;
import com.lz.modules.app.resp.OwnResultResp;
import com.lz.modules.app.utils.t.TwoTuple;
import com.lz.modules.flow.entity.Flow;
import com.lz.modules.flow.entity.FlowApprovalRole;
import com.lz.modules.flow.model.StaffRoleDto;
import com.lz.modules.performance.req.AssessDetailReq;
import com.lz.modules.performance.req.OwnResultReq;
import com.lz.modules.performance.res.ChartStatistical;
import com.lz.modules.sys.entity.SysUserEntity;
import com.lz.modules.sys.entity.app.ResultRecord;

import java.util.List;
import java.util.Map;

/**
* <p>
* 业绩记录表 服务类
* </p>
*
* @author quyixiao
* @since 2020-08-10
*/
public interface ResultRecordService extends IService<ResultRecord> {



	ResultRecord selectResultRecordById(Long id);


	Long insertResultRecord(ResultRecord resultRecord);


	int updateResultRecordById(ResultRecord resultRecord);


	int updateCoverResultRecordById(ResultRecord resultRecord);


	int deleteResultRecordById(Long id);
	int deleteResultRecordById2(Long id);

	R queryPage(ResultRecordReq params, SysUserEntity user);


	void deleteBatchIds(List<Long> asList);

    ResultRecord selectResultRecordByStaffId(Long userId);

    void updateFlowStaffIdRoleToNull(Long id,Integer status);

    R approval(Long resultRecordId, Long userId,Integer status,boolean flagEnd);

    List<ResultRecord> selectResultRecordByIds(List<Long> recordIds);

	TwoTuple getFlowInfo(Long staffId,Integer type);

	ResultRecord createResultRecord(Long userId, int type,Long roleId);

	ResultRecord initResult(Long staffId ,Integer recordType,Long roleId) ;

	R checkApproval(ResultRecord resultRecord,Long userId);

	int getDepartmentLevelIndex(List<Flow> list, int flowIndex);

    R commitApproval(ResultRecordReq req,Long userId);

	void sendWorkMSG(StaffEntity mySelf, StaffEntity toSelf, WorkMsgTypeEnum workMsgTypeEnum
			, Long recordResultId, int count);

	List<OwnResultResp> ownResult(OwnResultReq req);

	/**
	 * 人员等级排布
	 * @param monthTime
	 * @return
	 */
	List<GraphicsStatisticalDto> staffDistribution(String monthTime,List<String> staffIds);


	Map<String, List<DepartmentsEntity>> getStringListMap(List<DepartmentsEntity> tDepartments);

    ResultRecord selectResultRecordByStaffIdStatus(Long staffId, int status);

	R reject( ResultRecord resultRecord,Integer status);

	StaffEntity getApprovalStaff(ResultRecord resultRecord, String departmentLevel, List<StaffRoleDto> staffRoleDtos, Long roleId);

	DepartmentsStaffRelateEntity getLeaderDepartmentsStaffRelateEntity(Long staffId);

	ResultRecord selectLastResultRecordByStaffIdType(Long staffId, int type);

	ResultRecord selectCurrentMonthResultRecordByStaffIdType(Long staffId, int type);

	List<ResultRecord> selectResultRecordAllByStaffId(Long staffId);

	List<ChartStatistical> countNumByFlowProcess(Long startId,List<Long> evaluationIds,List<String> departmentIds);

	List<ChartStatistical> countNumByScoreLevel(Long startId,List<Long> evaluationIds,List<String> departmentIds);

	void batchDeleteByStaffIds(List<String> staffIds);

    R initFlowRecord(Long resultRecordId);

	R initFlowRecord(ResultRecord resultRecord, List<Flow> flows, List<FlowApprovalRole> flowApprovalRoles);

	R newApproval(ApprovalDto approvalDto) throws Exception;

	R newResultRecordList(RecordDetailDto recordDetailDto);

    ResultRecord selectLastResultRecordByUserId(Long userId);

	ResultRecord selectResultRecordByStaffIdAndStartId(Long userId, Long startId);

    List<ResultRecord> selectResultRecordsByStartId(Long startId);
	List<Long> selectResultRecordIdsByStartId(Long startId);

    R getResetData(RecordDetailDto recordDetailDto);

	/**
	 * clearFlag == 0 全清 1 部分清 2只清楚评分标志
	 *
	 * */
	R resetData(Long recordId, int clearFlag);

	List<Long> selectStaffIdsByFlowProcess(List<Integer> flowProcess);

}