package com.sifang.modules.sunshine.settleSet.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.sunshine.settleSet.entity.CrmRewardsPunishWay;
import com.sifang.modules.sunshine.settleSet.entity.CrmRewardsPunishWayMsg;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.persistence.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RewardsPunishWayMsgDao extends BaseDao<CrmRewardsPunishWayMsg> {


    public void saveMsg(CrmRewardsPunishWay punishWay, User user){
        CrmRewardsPunishWayMsg wayMsg=new CrmRewardsPunishWayMsg();
        wayMsg.setRewardsId(punishWay.getId());
        wayMsg.setUpdateTime(punishWay.getUpdateTime());
        wayMsg.setUpdateBy(user.getId());
        wayMsg.setUpdateByName(user.getUserName());
        StringBuffer sb=new StringBuffer();
        if("1".equals(punishWay.getType())){
            sb.append(" 当月完成安装容量大于等于"+punishWay.getLowData()+"MW，");
            sb.append("小于"+punishWay.getHighData()+"MW，");
            sb.append("奖励当月安装量 * "+punishWay.getRatioData()+"元/W；");
            sb.append("当月完成安装容量大于等于"+punishWay.getMaxHighData()+"MW，");
            sb.append("奖励当月安装量 * "+punishWay.getMaxHighDataRadio()+"元/W；");
        }else if("2".equals(punishWay.getType())){
            sb.append(" 并网天数超过"+punishWay.getLowData()+"天（含"+punishWay.getLowData()+"天）少于"+punishWay.getHighData()+"天（含"+punishWay.getHighData()+"天），惩罚安装容量*"+punishWay.getRatioData()+"元/W；");
        }else if("3".equals(punishWay.getType())){
            sb.append(" 单户装机容量≤"+punishWay.getHighData()+"千瓦，基础结算价格每瓦减少"+punishWay.getRatioData()+"元 ");
        }
        /*sb.append("有效时间："+punishWay.getLowTime()+" 至 "+punishWay.getHighTime()+"。");*/
        wayMsg.setContent(sb.toString());
        save(wayMsg);
    }

    public List<Record> getChangeRecord(String id){
        return Db.find(" SELECT DATE_FORMAT(update_time,'%Y-%m-%d %H:%i') AS updateTime,content,update_by,update_by_name FROM `crm_rewards_punish_way_msg` WHERE rewards_id=? ",id);
    }
}
