var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const logCtl = system.getObject("web.common.oplogCtl");
const md5 = require("MD5");
const uuidv4 = require('uuid/v4');

var cacheBaseComp = null;
class PatentAnalysisCtl extends CtlBase {
  constructor() {
    super("report", CtlBase.getServiceName(PatentAnalysisCtl));
    this.redisClient = system.getObject("util.redisClient");
  }

  async save(body, query, req, res) {
    let technology_name = this.trim(body.technology_name);
    let data_file = this.trim(body.data_file);
    if (!technology_name) {
      return system.getResult(null, "请填写技术名称");
    }
    if (!data_file) {
      return system.getResult(null, "请上传文件");
    }

    try {
      // let exists = this.service.findOne({technology_name: technology_name});
      // if (exists) {
      //   return system.getResult(null, `${technology_name}名称重复`);
      // }
      let obj = {
        autoIncrement: true,
        technology_name: technology_name,
        data_file: data_file,
        status: 1,
      };
      obj = await this.service.create(obj);
      return system.getResultSuccess();
    } catch (error) {
      console.log(error);
      return system.getResultFail(500, "接口异常：" + error.stack);
    }
  }

  async page(body, query, req, res) {
    try {
      let page = await this.service.pageByCondition(body);
      return page;
    } catch (error) {
      console.log(error);
      return system.getResultFail(500, "接口异常：" + error.stack);
    }
  }
}
module.exports = PatentAnalysisCtl;