<commit_before><?php

namespace Zhiyi\Plus\Http\Controllers\APIs\V1;

use DB;
use Illuminate\Http\Request;
use Zhiyi\Plus\Models\CommonConfig;
use Zhiyi\Plus\Models\Conversation;
use Zhiyi\Plus\Models\Comment;
use Zhiyi\Plus\Models\Digg;
use Zhiyi\Plus\Http\Controllers\Controller;

class SystemController extends Controller
{
    /**
     * 获取扩展包安装状态
     *
     * @author bs<<EMAIL>>
     * @return [type] [description]
     */
    public function getComponentStatus()
    {
        $config = CommonConfig::select('namespace')->groupBy('namespace')->pluck('namespace')->toArray();

        $status = [
            'im' => in_array('im', $config),
        ];

        return response()->json(static::createJsonData([
            'status' => true,
            'data' => $status,
        ]))->setStatusCode(200);
    }

    /**
     * 获取扩展包配置信息.
     *
     * @author bs<<EMAIL>>
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function getComponentConfig(Request $request)
    {
        $configData = CommonConfig::where('namespace', $request->component)->select(['name', 'value'])->get();

        return response()->json(static::createJsonData([
            'status' => true,
            'data' => $configData,
        ]))->setStatusCode(200);
    }

    /**
     * 用户反馈.
     *
     * @author bs<<EMAIL>>
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function createFeedback(Request $request)
    {
        $feedback = new Conversation();
        $feedback->type = 'feedback';
        $feedback->content = $request->input('content');
        $feedback->user_id = $request->user()->id;
        $feedback->save();

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '反馈成功',
        ]))->setStatusCode(201);
    }

    /**
     * 获取用户的系统会话列表.
     *
     * @author bs<<EMAIL>>
     *
     * @return [type] [description]
     */
    public function getConversations(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $list = Conversation::where(function ($query) use ($uid) {
            $query->where(function ($query) use ($uid) {
                $query->where('type', 'system')->whereIn('to_user_id', [0, $uid]);
            })->orWhere(['type' => 'feedback', 'user_id' => 1]);
        })
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->orderBy('created_at', 'desc')
        ->take($limit)
        ->get();
        $datas = [];
        if (! $list->isEmpty()) {
            $datas = $list->toArray();
        }

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $datas,
        ]))->setStatusCode(200);
    }

    /**
     * 获取我收到的所有评论
     * 
     * @author bs<<EMAIL>>
     * 
     * @param  Request $request [description]
     * 
     * @return [type]           [description]
     */
    public function getMyComments(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $comment = Comment::where(function ($query) use ($uid) {
            $query->where('to_user_id', $uid)->orWhere('reply_to_user_id', $uid);
        })
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->take($limit)
        ->orderBy('id','desc')
        ->get()->toArray();
        foreach ($comment as $key => &$value) {
            $value['sourceInfo'] = DB::table($value['source_table'])->where('id', $value['source_id'])->first();
            $value['commentInfo'] = DB::table($value['comment_table'])->where('id', $value['comment_id'])->first();
        }
        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $comment,
        ]))->setStatusCode(200);
    }

    /**
     * 获取我收到的所有点赞
     * 
     * @author bs<<EMAIL>>
     * 
     * @param  Request $request [description]
     * 
     * @return [type]           [description]
     */
    public function getMyDiggs(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $digg = Digg::where('to_user_id', $uid)
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->take($limit)
        ->orderBy('id', 'desc')
        ->get()->toArray();
        foreach ($digg as $key => &$value) {
            $value['sourceInfo'] = DB::table($value['source_table'])->where('id', $value['source_id'])->first();
            $value['diggInfo'] = DB::table($value['digg_table'])->where('id', $value['digg_id'])->first();
        }
        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $digg,<commit_msg>Apply fixes from StyleCI<commit_after><?php

namespace Zhiyi\Plus\Http\Controllers\APIs\V1;

use DB;
use Zhiyi\Plus\Models\Digg;
use Illuminate\Http\Request;
use Zhiyi\Plus\Models\Comment;
use Zhiyi\Plus\Models\CommonConfig;
use Zhiyi\Plus\Models\Conversation;
use Zhiyi\Plus\Http\Controllers\Controller;

class SystemController extends Controller
{
    /**
     * 获取扩展包安装状态
     *
     * @author bs<<EMAIL>>
     * @return [type] [description]
     */
    public function getComponentStatus()
    {
        $config = CommonConfig::select('namespace')->groupBy('namespace')->pluck('namespace')->toArray();

        $status = [
            'im' => in_array('im', $config),
        ];

        return response()->json(static::createJsonData([
            'status' => true,
            'data' => $status,
        ]))->setStatusCode(200);
    }

    /**
     * 获取扩展包配置信息.
     *
     * @author bs<<EMAIL>>
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function getComponentConfig(Request $request)
    {
        $configData = CommonConfig::where('namespace', $request->component)->select(['name', 'value'])->get();

        return response()->json(static::createJsonData([
            'status' => true,
            'data' => $configData,
        ]))->setStatusCode(200);
    }

    /**
     * 用户反馈.
     *
     * @author bs<<EMAIL>>
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function createFeedback(Request $request)
    {
        $feedback = new Conversation();
        $feedback->type = 'feedback';
        $feedback->content = $request->input('content');
        $feedback->user_id = $request->user()->id;
        $feedback->save();

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '反馈成功',
        ]))->setStatusCode(201);
    }

    /**
     * 获取用户的系统会话列表.
     *
     * @author bs<<EMAIL>>
     *
     * @return [type] [description]
     */
    public function getConversations(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $list = Conversation::where(function ($query) use ($uid) {
            $query->where(function ($query) use ($uid) {
                $query->where('type', 'system')->whereIn('to_user_id', [0, $uid]);
            })->orWhere(['type' => 'feedback', 'user_id' => 1]);
        })
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->orderBy('created_at', 'desc')
        ->take($limit)
        ->get();
        $datas = [];
        if (! $list->isEmpty()) {
            $datas = $list->toArray();
        }

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $datas,
        ]))->setStatusCode(200);
    }

    /**
     * 获取我收到的所有评论.
     *
     * @author bs<<EMAIL>>
     *
     * @param  Request $request [description]
     *
     * @return [type]           [description]
     */
    public function getMyComments(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $comment = Comment::where(function ($query) use ($uid) {
            $query->where('to_user_id', $uid)->orWhere('reply_to_user_id', $uid);
        })
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->take($limit)
        ->orderBy('id', 'desc')
        ->get()->toArray();
        foreach ($comment as $key => &$value) {
            $value['sourceInfo'] = DB::table($value['source_table'])->where('id', $value['source_id'])->first();
            $value['commentInfo'] = DB::table($value['comment_table'])->where('id', $value['comment_id'])->first();
        }

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $comment,
        ]))->setStatusCode(200);
    }

    /**
     * 获取我收到的所有点赞.
     *
     * @author bs<<EMAIL>>
     *
     * @param  Request $request [description]
     *
     * @return [type]           [description]
     */
    public function getMyDiggs(Request $request)
    {
        $uid = $request->user()->id;
        $limit = $request->input('limit', 15);
        $max_id = $request->input('max_id', 0);
        $digg = Digg::where('to_user_id', $uid)
        ->where(function ($query) use ($max_id) {
            if ($max_id > 0) {
                $query->where('id', '<', $max_id);
            }
        })
        ->take($limit)
        ->orderBy('id', 'desc')
        ->get()->toArray();
        foreach ($digg as $key => &$value) {
            $value['sourceInfo'] = DB::table($value['source_table'])->where('id', $value['source_id'])->first();
            $value['diggInfo'] = DB::table($value['digg_table'])->where('id', $value['digg_id'])->first();
        }

        return response()->json(static::createJsonData([
            'status'  => true,
            'message' => '获取成功',
            'data'    => $digg,
{'fraction_non_alphanumeric': 0.19318816303740927, 'fraction_numerical': 0.005583472920156337, 'mean_word_length': 2.0574679943100995, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 211, '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': '5519829', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3435, 'n_words': 563}