package com.ruoyi.web.controller.api.csMember;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.cs.domain.CsEvaluate;
import com.ruoyi.cs.domain.CsResourceOrderApply;
import com.ruoyi.cs.service.ICsEvaluateService;
import com.ruoyi.cs.service.ICsResourceOrderApplyService;
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.annotation.Resource;

/**
 * @Desc 服务评价控制器类
 * @Author pdt
 * @Date 2025-02-06
 */
@RestController
@RequestMapping("/api/cs/csEvaluate")
public class ApiCsEvaluateController extends BaseController {

    @Resource
    private ICsEvaluateService csEvaluateService;

    @Resource
    private ICsResourceOrderApplyService resourceOrderApplyService;

    /**
     * 服务评价
     *
     * @param csEvaluate
     * @return
     */
    @PostMapping("/addEvaluate")
    public AjaxResult add(@RequestBody CsEvaluate csEvaluate) {
        int result = csEvaluateService.insertCsEvaluate(csEvaluate);
        if(result > 0){
            CsResourceOrderApply csResourceOrderApply = new CsResourceOrderApply();
            csResourceOrderApply.setApplyId(csEvaluate.getResId());
            csResourceOrderApply.setEvaluateStar(csEvaluate.getEvaluateStar());
            resourceOrderApplyService.updateCsResourceOrderApply(csResourceOrderApply);
            return success("评价成功");
        }
        return error("评价失败");
    }

}
