package cn.pluss.platform.controller.user;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.entity.UserExtra;
import cn.pluss.platform.entity.UserMultipleRemark;
import cn.pluss.platform.user.UserExtraService;
import cn.pluss.platform.user.UserMultipleRemarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author DJH
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserExtraService userExtraService;

    @Autowired
    private UserMultipleRemarkService umrService;

    @PostMapping("/followUpSuccess")
    @ResponseBody
    public Result<?> followUpSuccess(Long userId) {
        userExtraService.followUpMark(userId);
        return ResultGenerator.genSuccessResult("操作成功", null);
    }

    @PostMapping("/followUpStart")
    @ResponseBody
    public Result<?> followUpStart(Long userId) {
        userExtraService.followUpStart(userId);
        return ResultGenerator.genSuccessResult("操作成功", null);
    }

    @PostMapping("/addFollowUpRecord")
    @ResponseBody
    public Result<?> addFollowUpRecord(Long userId, String remark) {
        UserMultipleRemark entity = new UserMultipleRemark();
        entity.setUserId(userId);
        entity.setCode(UserExtraService.FU);
        entity.setRemark(remark);
        umrService.save(entity);

        return ResultGenerator.genSuccessResult(entity);
    }

    @GetMapping("/followUpData")
    public String followUpListPage(Long userId, HttpServletRequest request) {
        request.setAttribute("userId", userId);
        return "user/userFollowList";
    }

    @GetMapping("/followUpDataList")
    @ResponseBody
    public Result<?> followUpPage(Page<UserMultipleRemark> page, UserMultipleRemark condition) {
        final Page<UserMultipleRemark> result = umrService.pageFollowDataList(page, condition.getUserId());
        return ResultGenerator.genSuccessResult(result);
    }
}
