package com.dk.mdm.service.mst;

import com.dk.common.response.ResponseResultUtil;
import com.dk.common.response.ResponseResultVO;
import com.dk.common.model.pojo.mst.StaffRight;
import com.dk.mdm.mapper.mst.StaffRightMapper;
import com.dk.common.service.BaseService;
import com.dk.common.mapper.BaseMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author : 姜永辉
 * @desc : 获取员工权限
 * @date : 2024/2/26 10:36
 */
@Service
public class StaffRightService extends BaseService<StaffRight> {

    @Override
    public BaseMapper<StaffRight> getRepository() {
        return staffRightMapper;
    }

    @Autowired
    private StaffRightMapper staffRightMapper;

    /**
     * @desc : 获取员工权限
     * @author : 姜永辉
     * @date : 2024/2/26 10:36
     */
    public ResponseResultVO<Map<String, Object>> getStaffRight(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = staffRightMapper.getStaffRight(param);
        Map<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("list", list);
        return ResponseResultUtil.success(objectObjectHashMap);
    }


    /**
     * @desc : 保存员工权限
     * @author : 姜永辉
     * @date : 2024/2/26 10:36
     */
    @Transactional(rollbackFor = {Exception.class})
    public ResponseResultVO<?> saveStaffRight(List<StaffRight> staffRightList) {
        staffRightMapper.insertBatch(staffRightList);
        return ResponseResultUtil.success();
    }

    public ResponseResultVO<Boolean> delete(String id) {
        return  ResponseResultUtil.success(staffRightMapper.deleteById(new StaffRight().setStaffId(id)) > 0) ;
    }

    /**
     * @desc   : WEB获取员工权限
     * @author : 常皓宁
     * @date   : 2024/3/6 13:16
     */
    public ResponseResultVO<Map<String, Object>> getStaffRightWeb(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = staffRightMapper.getStaffRightWeb(param);
        Map<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("list", list);
        return ResponseResultUtil.success(objectObjectHashMap);
    }

}
