package com.ho.business.controller;

import com.ho.business.entity.HisCurveRelate;
import com.ho.business.service.HisCurveRelateService;
import com.ho.business.vo.req.modelType.ModelTypeQueryReq;
import com.ho.business.vo.req.point.HisPointReqVo;
import com.ho.common.tools.annotation.LogAnnotation;
import com.ho.common.tools.annotation.NotSportEnOperation;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.constant.ContextConstant;
import com.ho.common.tools.constant.RedisKeyConstant;
import com.ho.common.tools.entity.SimpleUser;
import com.ho.common.tools.exception.DataResult;
import com.ho.common.tools.service.RedisService;
import com.ho.common.tools.util.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author gyan
 * @desc: 曲线相关衍生功能
 * @DateTime: 2023/6/20 10:38
 */
@RestController
@RequestMapping(ContextConstant.BUSINESS + "hisCurveRelate")
@Api(tags = "业务模块-曲线相关衍生功能")
public class HisCurveRelateController {
    @Autowired
    RedisService redisService;

    @Autowired
    HisCurveRelateService hisCurveRelateService;

    //新增（批量）HttpServletRequest request
    @PostMapping("add")
    @ApiOperation(value = "新增历史曲线字典模板")
    @LogAnnotation(title = "业务模块-曲线相关衍生功能", action = "新增")
    //@TokenIgnore
    @NotSportEnOperation
    public DataResult add(@RequestBody @Valid HisPointReqVo hisPointReqVo, HttpServletRequest request) {
        String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
        SimpleUser user = redisService.getSimpleUserByToken(token);
        hisCurveRelateService.add(hisPointReqVo, user);
        return DataResult.success();
    }

    //查询
    @PostMapping("pageSelectAll")
    @ApiOperation(value = "查询全部数据")
    public DataResult pageSelectAll(@RequestBody ModelTypeQueryReq vo, HttpServletRequest request) {
        String token = request.getHeader(RedisKeyConstant.User.ACCESS_TOKEN);
        SimpleUser user = redisService.getSimpleUserByToken(token);
        vo.setUserId(user.getUserId());
        vo.setLang(request.getHeader(CommonConstant.LANG));
        PageResult<HisCurveRelate> list = hisCurveRelateService.pageSelectAll(vo);
        return DataResult.success(list);
    }

    //删除
    @PostMapping("delete")
    @ApiOperation(value = "删除")
    @LogAnnotation(title = "业务模块-曲线相关衍生功能", action = "删除")
    public DataResult deleteRateTemplate(@RequestBody HisCurveRelate hisCurveRelate)
    {
        return DataResult.success(hisCurveRelateService.delete(hisCurveRelate.getModelId()));
    }
}
