package com.sqx.modules.creditRecord.controller;


import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.creditRecord.entity.CreditRecord;
import com.sqx.modules.creditRecord.entity.CreditRecordEntity;
import com.sqx.modules.creditRecord.service.CreditRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 信用分记录表
 *
 * @since 2023-05-17
 */
@RestController
@Api(value = "信用分记录", tags = {"信用分记录"})
@RequestMapping("/app/creditRecord/")
public class AppCreditRecordController {

    @Autowired
    private CreditRecordService recordService;

    /**
     * 获取信用分记录
     *
     * @param page
     * @param limit
     * @param creditRecord
     * @return
     */
    @Login
    @GetMapping("getCreditRecordList")
    @ApiOperation("获取信用分记录")
    public Result getCreditRecordList(@RequestAttribute("userId")Long userId, Integer page, Integer limit, CreditRecord creditRecord) {
        creditRecord.setRiderUserId(userId);
        return Result.success().put("data", recordService.getCreditRecordList(page, limit, creditRecord));
    }

    /**
     * 获取信用分与上月对比数据
     * @param userId
     * @param isDriver
     * @return
     */
    @Login
    @GetMapping("getScore")
    @ApiOperation("获取信用分")
    public Result getScore(@RequestAttribute("userId") Long userId, Integer isDriver){
        CreditRecordEntity score = recordService.getScore(userId, isDriver);
        if (score.getDiff() >= 0){
            score.setSymbol("+");
        }else{
            score.setSymbol("");
        }
        return Result.success().put("data",score);
    }

    @Login
    @GetMapping("getFilledScore")
    @ApiOperation("获取信用分趋势")
    public Result getFilledScore(@RequestAttribute("userId") Long userId, Integer isDriver,Integer several){
        return Result.success().put("data",recordService.getFilledScore(userId,isDriver,several));
    }
}

