import YchConstant from "../YchConstant";
import { getAction, deleteAction, putAction, postAction, httpAction } from '../manage'
import Vue from 'vue'
const UI_CACHE_DB_DICT_DATA = 'UI_CACHE_DB_DICT_DATA'
//角色管理
const addRole = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/role/add', params)
const editRole = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/role/edit', params)
const checkRoleCode = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/role/checkRoleCode', params)
const queryall = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/role/queryall', params)

//用户管理
const addUser = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/user/add', params)
const editUser = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/user/edit', params)
const editUserInfo = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/user/userInfoEdit', params)
export const getUserInfo = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/getUserInfo', params)
const queryUserRole = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/user/queryUserRole', params)
const getUserList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/user/list', params)
const frozenBatch = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/user/frozenBatch', params)
const queryUserRelation = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/user/queryUserRelation', params)
const queryUserNameByUserIds = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysOrg/queryUserNameByUserIds', params)
const queryDeptNameByDeptIds = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysOrg/queryDeptNameByDeptIds', params)
//验证用户是否存在
const checkOnlyUser = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/user/checkOnlyUser', params)
//改变密码
const changePassword = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/user/changePassword', params)

//权限管理
const addPermission = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/permission/add', params)
const editPermission = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/permission/edit', params)
const getPermissionList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/list', params)
const getSystemMenuList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/getSystemMenuList', params)
const getSystemSubmenu = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/getSystemSubmenu', params)
const getSystemSubmenuBatch = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/getSystemSubmenuBatch', params)

const queryTreeList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/queryTreeList', params)
const queryListAsync = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/queryListAsync', params)
const queryRolePermission = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/queryRolePermission', params)
const saveRolePermission = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/permission/saveRolePermission', params)
const queryPermissionsByUser = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/getUserPermissionByToken', params)
const loadAllRoleIds = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/loadAllRoleIds', params)
const getPermissionRuleList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/getPermRuleListByPermId', params)
const queryPermissionRule = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/queryPermissionRule', params)

//二级部门管理
const queryDepartPermission = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/permission/queryDepartPermission', params)
const saveDepartPermission = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/permission/saveDepartPermission', params)
const queryTreeListForDeptRole = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysDepartPermission/queryTreeListForDeptRole', params)
const queryDeptRolePermission = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysDepartPermission/queryDeptRolePermission', params)
const saveDeptRolePermission = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/sysDepartPermission/saveDeptRolePermission', params)

//日志管理
const deleteLog = (params) => deleteAction(YchConstant.PREFIX_SYSTEM + '/log/delete', params)
const deleteLogList = (params) => deleteAction(YchConstant.PREFIX_SYSTEM + '/log/deleteBatch', params)

//数据字典
const addDict = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/dict/add', params)
const editDict = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/dict/edit', params)
const treeList = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/dict/treeList', params)
const addDictItem = (params) => postAction(YchConstant.PREFIX_SYSTEM + '/dictItem/add', params)
const editDictItem = (params) => putAction(YchConstant.PREFIX_SYSTEM + '/dictItem/edit', params)

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(YchConstant.PREFIX_SYSTEM + `/dict/getDictItems/${code}`, params)
export const ajaxGetDictItemMap = (codes, params) => getAction(YchConstant.PREFIX_SYSTEM + `/dict/getDictItemMap/${codes}`, params)

// 通过Sql配置获取选项
export const ajaxGetSqlConfigItems = (code, params) => postAction(YchConstant.PREFIX_EFORM + `/engine/viewEngine/getSqlConfigItems?sqlCode=${code}`, params || {})

// 通过服务配置获取选项
export const ajaxGetHttpConfigItems = (code, params) => postAction(YchConstant.PREFIX_EFORM + `/engine/viewEngine/getHttpConfigItems?httpCode=${code}`, params || {})

// 通过Sql配置获取选项
export const ajaxGetSqlConfigItemsBatch = (sqlConfig) => postAction(YchConstant.PREFIX_EFORM + `/engine/viewEngine/getSqlConfigItemsBatch`, sqlConfig || {})

// 通过服务配置获取选项
export const ajaxGetHttpConfigItemsBatch = (httpConfig) => postAction(YchConstant.PREFIX_EFORM + `/engine/viewEngine/getHttpConfigItemsBatch`, httpConfig || {})

//从缓存中获取字典配置
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]
    return dictItems
  }
}

//系统通告
const doReleaseData = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/annountCement/doReleaseData', params)
const doReovkeData = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/annountCement/doReovkeData', params)
//获取系统访问量
const getLoginfo = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/log/loginfo', params)
const getVisitInfo = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/log/visitInfo', params)

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/user/queryUserByDepId', params)
// 重复校验
const duplicateCheck = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/duplicate/check', params)
// 加载分类字典
const loadCategoryData = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/category/loadAllData', params)
const checkRuleByCode = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/checkRule/checkByCode', params)
//我的通告
const getUserNoticeInfo = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysAnnouncementSend/getMyAnnouncementSend', params)
//岗位管理
const queryAllJob = (params) => getAction(YchConstant.PREFIX_SYSTEM + '/sysJob/queryall', params)

//应用市场
const queryMarketList = (url) => getAction(url + YchConstant.PREFIX_SAAS + '/market/queryMarketList', {})
const queryMarketGroupList = (url) => getAction(url + YchConstant.PREFIX_SAAS + '/market/queryMarketGroupList', {})
const installationApp = (params) => postAction(YchConstant.PREFIX_EFORM + '/manage/market/installation', params)
const updateApp = (params) => putAction(YchConstant.PREFIX_EFORM + '/manage/market/update', params)
const queryAppList = () => getAction(YchConstant.PREFIX_EFORM + '/manage/market/queryAppList', {})

//个性化设置
const getCustomVaueByTypeAndDataId = (params) =>getAction(YchConstant.PREFIX_SYSTEM + '/sysCustom/getCustomVaueByTypeAndDataId', params)
const saveCustomWithDataId = (params)=>postAction(YchConstant.PREFIX_SYSTEM + '/sysCustom/saveCustomWithDataId', params)
export {
  queryAllJob,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  editUserInfo,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  queryUserRelation,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  getUserNoticeInfo,
  getDictItemsFromCache,
  queryUserNameByUserIds,
  queryDeptNameByDeptIds,
  queryMarketList,
  queryMarketGroupList,
  installationApp,
  updateApp,
  queryAppList,
  getCustomVaueByTypeAndDataId,
  saveCustomWithDataId
}



