import CollectTaskAPI from '../../api/restApis/CollectTaskAPI'
import HelperUtil from '../../utils/HelperUtil'
import {PERFORM_TASK_KEY} from '../../utils/constantCollection'

// 静态方法
let staticMethods = {
  /**
   * @Description  : 获取所有
   * @author       : ls
   * @date         : 2020/4/27 16:39
   * @param        :
   * @return       :
   */
  getAllCollectTaskCollection: function () {
    return CollectTaskAPI.getCollectTaskCollection().then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, PERFORM_TASK_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 创建采集任务
   * @author       : ls
   * @date         : 2020/4/27 16:47
   * @param        :
   * @return       :
   */
  createCollectTask: function (colTask) {
    return CollectTaskAPI.postAddCollectTask(colTask).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : shanchuzhibiao
   * @author       : ls
   * @date         : 2020/4/27 9:46
   * @param        :
   * @return       :
   */
  deleteCollectTask: function (delList) {
    return CollectTaskAPI.deleteDeleteCollectTask(delList).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : xiugai
   * @author       : ls
   * @date         : 2020/4/27 16:48
   * @param        :
   * @return       :
   */
  updateCollectTask: function (colTask) {
    return CollectTaskAPI.putModifyCollectTask(colTask).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },

  /**
   * @Description  : 条件查询
   * @author       : ls
   * @date         : 2020/4/27 10:08
   * @param        :
   * @return       :
   */
  queryCollectTask: function (conditionSet) {
    return CollectTaskAPI.putConditionQueryCollectTask(conditionSet).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, PERFORM_TASK_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 启用
   * @author       : ls
   * @date         : 2020/4/29 16:13
   * @param        :
   * @return       :
   */
  startCollectTask: function (val) {
    return CollectTaskAPI.putStartCollectTask(val).then(result => {
      if (result.data.result) {
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 分页查询
   * @author       : ls
   * @date         : 2020/5/26 15:00
   * @param        :
   * @return       :
   */
  queryCollectTaskListPaging: function (beginItem, endItem, selectList) {
    return CollectTaskAPI.queryCollectTaskPaging(beginItem, endItem, selectList).then(result => {
      if (result.data.result) {
        return HelperUtil.arrayToObject(result.data.returnValue, PERFORM_TASK_KEY)
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  },
  /**
   * @Description  : 查询总数
   * @author       : ls
   * @date         : 2020/5/26 15:04
   * @param        :
   * @return       :
   */
  getCollectTaskTotalCounts: function (selectList) {
    return CollectTaskAPI.getCollectTaskCounts(selectList).then(result => {
      if (result.data.result) {
        return result.data.returnValue
      } else {
        return HelperUtil.returnPromiseRejectObj(result)
      }
    })
  }
}

function CollectTaskService () {
  return Object.freeze(Object.assign(
    {
    },
    staticMethods
  ))
}
// inject static methods
Object.assign(CollectTaskService, staticMethods)
export default CollectTaskService
