package org.jeecg.modules.stm.rate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.stm.rate.entity.RateStd;
import org.jeecg.modules.stm.rate.mapper.RateStdMapper;
import org.jeecg.modules.stm.rate.service.IRateStdService;
import org.jeecg.modules.stm.rate.vo.RateStdOptionVo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.CollectionUtils;


import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 评分标准
 * @Author: jeecg-boot
 * @Date:   2023-09-21
 * @Version: V1.0
 */
@Service
public class RateStdServiceImpl extends ServiceImpl<RateStdMapper, RateStd> implements IRateStdService {

    @Override
    public List<RateStdOptionVo> rateStdOptionList(String rateKeyitemId) {

        QueryWrapper<RateStd> rateStdQueryWrapper  = new QueryWrapper<>();
        rateStdQueryWrapper.eq("rate_keyitem_id",rateKeyitemId);
        rateStdQueryWrapper.orderByAsc("val_index");
        List<RateStd> list  = this.list(rateStdQueryWrapper);

        if(CollectionUtils.isEmpty(list)){
            return new ArrayList<>();
        }
        List<RateStdOptionVo> data = new ArrayList<>();
        for(RateStd rmStdVal:list){
            RateStdOptionVo rateStdOptionVo = new RateStdOptionVo();
            rateStdOptionVo.setLabel(rmStdVal.getStdopt());
            rateStdOptionVo.setValue(rmStdVal.getId());
            rateStdOptionVo.setScore(rmStdVal.getValScore());
            rateStdOptionVo.setMinScore(rmStdVal.getValScoremin());
            rateStdOptionVo.setMaxScore(rmStdVal.getValScoremax());
            data.add(rateStdOptionVo);
        }
        return data;
    }

    @Override
    public List<RateStdOptionVo> pfrateStdOptionList(String rateKeyitemId) {
//（建议扣0.5-1分）
        String valmodel="得";
        QueryWrapper<RateStd> rateStdQueryWrapper  = new QueryWrapper<>();
        rateStdQueryWrapper.eq("rate_keyitem_id",rateKeyitemId);
        rateStdQueryWrapper.orderByAsc("val_index");
        List<RateStd> list  = this.list(rateStdQueryWrapper);

        if(CollectionUtils.isEmpty(list)){
            return new ArrayList<>();
        }
        List<RateStdOptionVo> data = new ArrayList<>();
        for(RateStd rmStdVal:list){
            RateStdOptionVo rateStdOptionVo = new RateStdOptionVo();

            rateStdOptionVo.setValue(rmStdVal.getId());
            rateStdOptionVo.setScore(rmStdVal.getValScore());
            rateStdOptionVo.setMinScore(rmStdVal.getValScoremin());
            rateStdOptionVo.setMaxScore(rmStdVal.getValScoremax());
            if(rmStdVal.getValScoremax()<0){
                valmodel="扣";
            }
            double ValScoremin = Math.abs(rmStdVal.getValScoremin());
            double ValScoremax = Math.abs(rmStdVal.getValScoremax());
            String valtitle = "(建议"+valmodel+ValScoremin+"-"+ValScoremax+"分)";

            rateStdOptionVo.setLabel(rmStdVal.getStdopt()+" "+valtitle);

            data.add(rateStdOptionVo);
        }
        return data;
    }

}
