package com.happy.dao.impl;

import com.happy.Until.UUIDUtil;
import com.happy.dao.BookingComplaintProgressDao;
import com.happy.service.BookingComplaintProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("BookingComplaintProgressDao")
public class BookingComplaintProgressImplDao implements BookingComplaintProgressDao {

    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
        return namedParameterJdbcTemplate;
    }

    public void setNamedParameterJdbcTemplate(
            NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }

    @Override
    public int insert(String complaintId, String createId, String createDate, String modifyDate, String progressType) {
        String sql = "INSERT INTO booking_complaint_progress (id, complaint_id, progress_type, create_id,create_date,modify_date,status) " +
                "VALUES (:id, :complaint_id, :progress_type, :create_id, :create_date, :modify_date, :status)";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("complaint_id",complaintId);
        sps.addValue("progress_type",progressType);
        sps.addValue("create_id",createId);
        sps.addValue("create_date",createDate);
        sps.addValue("modify_date",modifyDate);
        sps.addValue("status",1);
        sps.addValue("id", UUIDUtil.generateID());
        int num = 0;
        try{
            num = namedParameterJdbcTemplate.update(sql, sps);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return num;

    }

    /**
     * 投诉完成添加
     * @param complaintId
     * @param createId
     * @param createDate
     * @param modifyDate
     * @return
     */
    @Override
    public int resolutionComplaint(String complaintId, String createId, String createDate, String modifyDate) {
        String sql = "INSERT INTO booking_complaint_progress (id, complaint_id, progress_type, create_id,create_date,modify_date,status) VALUES (:id, :complaint_id, :progress_type, :create_id,:create_date,:modify_date,:status)";
        MapSqlParameterSource sps = new MapSqlParameterSource();
        sps.addValue("complaint_id",complaintId);
        sps.addValue("progress_type",3);
        sps.addValue("create_id",createId);
        sps.addValue("create_date",createDate);
        sps.addValue("modify_date",modifyDate);
        sps.addValue("status",1);
        sps.addValue("id", UUIDUtil.generateID());
        int num = 0;
        try{
            num = namedParameterJdbcTemplate.update(sql, sps);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return num;
    }

}
