package com.dk.mdm.service.mst;

import com.dk.common.response.ResponseResultUtil;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.model.pojo.mst.RoleSensitive;
import com.dk.mdm.model.pojo.mst.SettingValue;
import com.dk.mdm.mapper.mst.SettingValueMapper;
import com.dk.common.service.BaseService;
import com.dk.common.mapper.BaseMapper;
import com.dk.mdm.model.vo.mst.RoleVo;
import com.dk.mdm.model.vo.mst.SettingValueVO;
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;

@Service
@Transactional
public class SettingValueService extends BaseService<SettingValue> {

    @Override
    public BaseMapper<SettingValue> getRepository() {
        return settingValueMapper;
    }

    @Autowired
    private SettingValueMapper settingValueMapper;

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


    /**
     * @desc : 删除系统参数
     * @author : 姜永辉
     * @date : 2023/1/5 9:39
     */
    public ResponseResultVO<Boolean> deleteSettingValueId(Integer id) {
        SettingValue settingValue = new SettingValue();
        settingValue.setCpId(id);
        settingValueMapper.deleteSettingValueId(settingValue);
        return ResponseResultUtil.success() ;
    }

    /**
     * @desc : 批量修改系统参数
     * @author : 姜永辉
     * @date : 2023/1/5 9:39
     */
    @Transactional(
            rollbackFor = {Exception.class}
    )
    public ResponseResultVO<Boolean> updateBatch(SettingValueVO vo) {
        //删除历史功能权限
        deleteSettingValueId(vo.getCpId());
        if (vo.getSettingValueList() != null && vo.getSettingValueList().size() > 0) {
            //批量新建
            settingValueMapper.insertBatch(vo.getSettingValueList());
        }

        return ResponseResultUtil.success();
    }

}
