import {
  getAction,
  deleteAction,
  putAction,
  postAction,
  httpAction
} from '@/api/manage'
import Vue from 'vue'
import {
  UI_CACHE_DB_DICT_DATA
} from "@/store/mutation-types"

//角色管理
const addRole = (params) => postAction("/sys/role/add", params)
const editRole = (params) => putAction("/sys/role/edit", params)
const checkRoleCode = (params) => getAction("/sys/role/checkRoleCode", params)
const queryall = (params) => getAction("/sys/role/queryall", params)

//用户管理
const addUser = (params) => postAction("/sys/user/add", params)
const editUser = (params) => putAction("/sys/user/edit", params)
const queryUserRole = (params) => getAction("/sys/user/queryUserRole", params)
const getUserList = (params) => getAction("/sys/user/list", params)
const frozenBatch = (params) => putAction("/sys/user/frozenBatch", params)
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/sys/user/checkOnlyUser", params)
//改变密码
const changePassword = (params) => putAction("/sys/user/changePassword", params)

//权限管理
const addPermission = (params) => postAction("/sys/permission/add", params)
const editPermission = (params) => putAction("/sys/permission/edit", params)
const getPermissionList = (params) => getAction("/sys/permission/list", params)
const getSystemMenuList = (params) => getAction("/sys/permission/getSystemMenuList", params)
const getSystemSubmenu = (params) => getAction("/sys/permission/getSystemSubmenu", params)
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params) => getAction("/sys/permission/queryTreeList", params)
const queryTreeListForRole = (params) => getAction("/sys/role/queryTreeList", params)
const queryListAsync = (params) => getAction("/sys/permission/queryListAsync", params)
const queryRolePermission = (params) => getAction("/sys/permission/queryRolePermission", params)
const saveRolePermission = (params) => postAction("/sys/permission/saveRolePermission", params)
const queryPermissionsByUser = () => getAction("/sys/permission/getUserPermissionByToken")
const loadAllRoleIds = (params) => getAction("/sys/permission/loadAllRoleIds", params)
const getPermissionRuleList = (params) => getAction("/sys/permission/getPermRuleListByPermId", params)
const queryPermissionRule = (params) => getAction("/sys/permission/queryPermissionRule", params)

// 部门管理
const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params)
const queryDepartTreeSync = (params) => getAction("/sys/sysDepart/queryDepartTreeSync", params)
const queryIdTree = (params) => getAction("/sys/sysDepart/queryIdTree", params)
const queryParentName = (params) => getAction("/sys/sysDepart/queryParentName", params)
const searchByKeywords = (params) => getAction("/sys/sysDepart/searchBy", params)
const deleteByDepartId = (params) => deleteAction("/sys/sysDepart/delete", params)

//二级部门管理
const queryDepartPermission = (params) => getAction("/sys/permission/queryDepartPermission", params)
const saveDepartPermission = (params) => postAction("/sys/permission/saveDepartPermission", params)
const queryTreeListForDeptRole = (params) => getAction("/sys/sysDepartPermission/queryTreeListForDeptRole", params)
const queryDeptRolePermission = (params) => getAction("/sys/sysDepartPermission/queryDeptRolePermission", params)
const saveDeptRolePermission = (params) => postAction("/sys/sysDepartPermission/saveDeptRolePermission", params)
const queryMyDepartTreeList = (params) => getAction("/sys/sysDepart/queryMyDeptTreeList", params)

//日志管理
const deleteLog = (params) => deleteAction("/sys/log/delete", params)
const deleteLogList = (params) => deleteAction("/sys/log/deleteBatch", params)

//数据字典
const addDict = (params) => postAction("/sys/dict/add", params)
const editDict = (params) => putAction("/sys/dict/edit", params)
const treeList = (params) => getAction("/sys/dict/treeList", params)
const addDictItem = (params) => postAction("/sys/dictItem/add", params)
const editDictItem = (params) => putAction("/sys/dictItem/edit", params)

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params)
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]
    //console.log("-----------getDictItemsFromCache----------dictCode="+dictCode+"---- dictItems=",dictItems)
    return dictItems
  }
}

//系统通告
const doReleaseData = (params) => getAction("/sys/annountCement/doReleaseData", params)
const doReovkeData = (params) => getAction("/sys/annountCement/doReovkeData", params)
//获取系统访问量
const getLoginfo = (params) => getAction("/sys/loginfo", params)
const getVisitInfo = (params) => getAction("/sys/visitInfo", params)

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/sys/user/queryUserByDepId", params)

// 重复校验
const duplicateCheck = (params) => getAction("/sys/duplicate/check", params)
// 加载分类字典
const loadCategoryData = (params) => getAction("/sys/category/loadAllData", params)
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend", params)
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`

//获取模板
const getTemplateList = (params) => getAction("/warning/template/getList", params)
//删除模板
const deleteTemplate = (params) => deleteAction("/warning/template/delete", params)
//获取图表以及配置树
const getChartTreeList = (params) => getAction("/warning/template/getChartTreeList", params)
const addTemplate = (params) => postAction("/warning/template/add", params)
//新增曲线道
const addTrack = (params) => postAction("/warning/track/add", params)
//曲线拖动
const moveLine = (params) => postAction("/warning/track/moveLine", params)
//删除曲线道
const deleteTrack = (params) => deleteAction("/warning/track/delete", params)
//新增曲线
const addLine = (params) => postAction("/warning/configure/add", params)
//删除曲线
const deleteLine = (params) => deleteAction("/warning/configure/delete", params)
//修改模板
const editTemplate = (params) => putAction("/warning/template/edit", params)
//修改曲线道
const editTrack = (params) => putAction("/warning/track/edit", params)
//修改曲线道
const editLine = (params) => putAction("/warning/configure/edit", params)
//新增曲线道
const addByDirection = (params) => postAction("/warning/track/addByDirection", params)
// //获取曲线数据
//const getDataByTime = (params) => getAction("/warning/ltd/getList", params)
// //获取所有时间数据
// const getAllDate = (params) => getAction("/warning/ltd/getAllDate", params)
// //新接口获取数据
// const getJwssList = (params) => getAction("/warning/ltd/getJwssList", params)
// //获取最新的日期
// const getDate = (params) => getAction("/warning/ltd/getDate", params)
const getMotionByTime = (params) => getAction("/RealTimeZj/getMotion", params)

const getDataByTime = (params) => getAction("/RealTimeZj/getList", params)
const getAllDate= (params) => getAction("/RealTimeZj/getAllDate",params)
const getJwssList = (params)=> etAction("/RealTimeZj/getJwssList",params)
const getDate =(params)=> getAction("/RealTimeZj/getDate",params)
const getRecalculateList =(params)=> getAction("/recalculate/getList",params)
//获取钻井液数据
const getZjyData = (params) => getAction("/warning/zjycs/getList", params)
//获取钻井液数据
const getZjyLtdData = (params) => getAction("/warning/zjycs/getLtd", params)
//获取钻井液所有时间数据
const getZjyAllData = (params) => getAction("/warning/zjycs/getAllDate", params)
//获取复杂情况数据
const getFzqkData = (params) => getAction("/warning/fzqk/Calculate", params)
//获取工程预警数据
const getAnalyse = (params, timeout = 30) => getAction("/engineer/warnResult/getGcyjResetList", params, timeout)
// 数据源重复校验
const duplicateCheckDataSource = (params) => getAction("/warning/configure/doDuplicateCheck", params)
//编辑报警信息备注
const editWarning = (params) => postAction("/focusJh/warningUpdate", params)
//重新填充aFocusWarn中的工程预警报警，手动调用，可删除
const refillWarning = (params) => getAction("/focusJh/refillAFocusWarn", params)
//重新填充aFocusWarn中的工程预警报警，手动调用，可删除
const refillWarningDay = (params) => getAction("/engineer/warnResult/refillAFocusWarnDay", params)



// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}

export {
  // imgView,
  // doMian,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  getTemplateList,
  getChartTreeList,
  addTemplate,
  addTrack,
  addLine,
  deleteTemplate,
  deleteTrack,
  deleteLine,
  editTemplate,
  editTrack,
  editLine,
  moveLine,
  addByDirection,
  getDataByTime,
  getAllDate,
  getDate,
  getZjyData,
  getFzqkData,
  getAnalyse,
  duplicateCheckDataSource,
  editWarning,
  getZjyLtdData,
  getZjyAllData,
  getJwssList,
  refillWarning,
  refillWarningDay,
  getRecalculateList,
  getMotionByTime
}



