package io.renren.modules.business.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.business.entity.BusinessCommentsEntity;
import io.renren.modules.business.service.BusinessCommentsService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 记录评论信息
 *
 * @author jiaqiao
 * @email jiaqiao@163.com
 * @date 2022-08-09 10:59:44
 */
@RestController
@RequestMapping("business/businesscomments")
public class BusinessCommentsController {
    @Autowired
    private BusinessCommentsService businessCommentsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = businessCommentsService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据立项id获取所有的评论信息
     */
    @RequestMapping("/getListByProjectId/{projectId}")
    public R wxList(@PathVariable("projectId") String projectId){
        List<BusinessCommentsEntity> list = businessCommentsService.getListByProjectId(projectId);
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		BusinessCommentsEntity businessComments = businessCommentsService.getById(id);
        return R.ok().put("businessComments", businessComments);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BusinessCommentsEntity businessComments){
        SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal();//获取当前登录人信息
        businessComments.setCommentsPersonId(user.getUserId());
		businessCommentsService.save(businessComments);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BusinessCommentsEntity businessComments){
		businessCommentsService.updateById(businessComments);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		businessCommentsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
