package com.cyksj.web.controller.manage;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cyksj.dto.Result;
import com.cyksj.enums.GatewayResponse;
import com.cyksj.model.entity.UserComplaint;
import com.cyksj.model.views.UserComplaintView;
import com.cyksj.service.user.UserComplaintService;
import com.ejlchina.searcher.BeanSearcher;
import com.ejlchina.searcher.SearchResult;
import com.ejlchina.searcher.util.MapUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/*
 *项目名: netflix
 *文件名: CmsUserComplaintController
 *创建者: JavaZou
 *创建时间:2023/6/16 11:34
 */
@RestController
@RequestMapping("/manage/user/complaint")
@RequiredArgsConstructor
public class CmsUserComplaintController {
	private final UserComplaintService userComplaintService;

	private final BeanSearcher beanSearcher;

	private final HttpServletRequest request;

	/**
	 * 投诉列表
	 */
	@GetMapping("/get")
	public Result<SearchResult<UserComplaintView>> get() {
		SearchResult<UserComplaintView> search = beanSearcher.search(UserComplaintView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
	}

	/**
	 * 修改投诉状态
	 */
	@PutMapping("/put")
	public Result<String> updateUserComplaintStatus(@RequestBody UserComplaint userComplaint) {
		Long id = userComplaint.getId();
		UserComplaint.Status status = userComplaint.getStatus();
		userComplaintService.update(null, Wrappers.lambdaUpdate(UserComplaint.class)
				.set(UserComplaint::getStatus, status)
				.eq(UserComplaint::getId, id));
		return GatewayResponse.SUCCESS.newBuilder().toResult();
	}
}
