<commit_before>import {query} from '../models/db_connection';
import { pagination, getLinuxTimeStamp} from '../uitil';
import moment from 'moment';

/**
 * 获取游记列表
 * @param {*} ctx 
 * @param {*} next 
 */
const list = async (ctx, next) => {
  const params = ctx.request.body;
  const {limit, pageIndex, type, admin_id} = params;
  const sql = 'select * from hw_travel_note where type=? and admin_id=? ORDER BY id desc limit ?,?';
  let data = await query(sql, [type, admin_id, (pageIndex-1)*limit, limit]);
  let count = await query('select count(*) as count from hw_travel_note where type=? and admin_id=?', [type, admin_id]);
  ctx.body = Object.assign({code: 0, message: 'success', 'data': data}, pagination(limit, pageIndex, count[0].count));
}

/**
 * 添加， 后台
 * @param {*} ctx
 * @param {*} next
 */
const add = async(ctx, next) => {
  const params = ctx.request.body;
  const {title, desc, link_url, image_url, author, view_count, start_date, type, admin_id} = params;

  const sql = `INSERT into hw_travel_note VALUES(
              NULL,'${title}','${desc}', '${link_url}', '${image_url}', '${author}', '${view_count}', '${start_date}', 
              '${type}', admin_id='${admin_id}' '${getLinuxTimeStamp()}'
          )`;
  var data = await query(sql);
  console.log('insert hw_travel_note:', data);
  ctx.body = {code: 0, message:'保存成功', data}

}


/**
 * 更新 管理后台使用
 * @param {*} ctx
 * @param {*} next
 */
const update = async(ctx, next) => {
  const params = ctx.request.body;
  const {id, title, desc, link_url, image_url, author, view_count, start_date, type,
    admin_id, created_at} = params;
  const sql = `update hw_travel_note set title='${title}', desc='${desc}', link_url='${link_url}', image_url='${image_url}',
  author='${author}', view_count='${view_count}',
              start_date='${start_date}', type='${type}', admin_id=${admin_id}, created_at='${created_at}' where id=${id}`;
  console.log('update hw_travel_note sql:', sql);
  const res = await query(sql);
  ctx.body = {code: 0, message: 'success', data: res}
}




/**
 * 获取列表,管理后台使用
 * @param {*} ctx
 * @param {*} next
 */
const list_search = async (ctx, next) => {
  const params = ctx.request.body
  const {admin_id, id, title, author, limit, pageIndex, type} = params
  const where = {}

  if (id) {
    where['id'] = id;
  }

  if (title) {
    where['title'] = title;
  }

  if (author) {
    where['author'] = author;<commit_msg>process note<commit_after>import {query} from '../models/db_connection';
import { pagination, getLinuxTimeStamp} from '../uitil';
import moment from 'moment';

/**
 * 获取游记列表
 * @param {*} ctx 
 * @param {*} next 
 */
const list = async (ctx, next) => {
  const params = ctx.request.body;
  const {limit, pageIndex, type, admin_id} = params;
  const sql = 'select * from hw_travel_note where type=? and admin_id=? ORDER BY id desc limit ?,?';
  let data = await query(sql, [type, admin_id, (pageIndex-1)*limit, limit]);
  let count = await query('select count(*) as count from hw_travel_note where type=? and admin_id=?', [type, admin_id]);
  ctx.body = Object.assign({code: 0, message: 'success', 'data': data}, pagination(limit, pageIndex, count[0].count));
}

/**
 * 添加， 后台
 * @param {*} ctx
 * @param {*} next
 */
const add = async(ctx, next) => {
  const params = ctx.request.body;
  const {title, desc, link_url, image_url, author, view_count, start_date, type, admin_id} = params;

  const sql = `INSERT into hw_travel_note VALUES(
              NULL,'${title}','${desc}', '${link_url}', '${image_url}', '${author}', '${view_count}', '${start_date}', 
              '${type}', '${admin_id}', '${getLinuxTimeStamp()}'
          )`;
  console.log('add hw_travel_note sql', sql);
  const data = await query(sql);
  // console.log('insert hw_travel_note:', data);
  ctx.body = {code: 0, message:'保存成功', data}

}


/**
 * 更新 管理后台使用
 * @param {*} ctx
 * @param {*} next
 */
const update = async(ctx, next) => {
  const params = ctx.request.body;
  const {id, title, desc, link_url, image_url, author, view_count, start_date, type,
    admin_id, created_at} = params;
  const sql = `update hw_travel_note set title='${title}', \`desc\`='${desc}', link_url='${link_url}', image_url='${image_url}',
  author='${author}', view_count='${view_count}',
              start_date='${start_date}', type='${type}', admin_id=${admin_id}, created_at='${created_at}' where id=${id}`;
  console.log('update hw_travel_note sql:', sql);
  const res = await query(sql);
  ctx.body = {code: 0, message: 'success', data: res}
}




/**
 * 获取列表,管理后台使用
 * @param {*} ctx
 * @param {*} next
 */
const list_search = async (ctx, next) => {
  const params = ctx.request.body
  const {admin_id, id, title, author, limit, pageIndex, type} = params
  const where = {}

  if (id) {
    where['id'] = id;
  }

  if (title) {
    where['title'] = title;
  }

  if (author) {
    where['author'] = author;
{'fraction_non_alphanumeric': 0.19293589220089832, 'fraction_numerical': 0.002041649652919559, 'mean_word_length': 3.9989795918367346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6592774', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1767, 'n_words': 452}