package com.ag.demo;

import com.ag.base.BaseService;
import com.ag.base.DefaultBussniessImpl;
import com.ag.demo.entity.QrcodeInfo;
import com.ag.util.UUIDUtil;
import com.alibaba.fastjson.JSON;
import com.wb.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yangxh on 2022/3/24.
 */
@Service
public class QRCodeDemo extends BaseService {
    @Autowired
    private DefaultBussniessImpl bizDao;

    public void saveQrInfo(org.json.JSONObject reqParam, HttpServletResponse response, HttpServletRequest request){
        QrcodeInfo info = new QrcodeInfo();
        info.setId(UUIDUtil.getUUID());
        info.setTitle(reqParam.getString("DESCRIPTION"));
        info.setContext(reqParam.getString("NOTES"));
        info.setKeyword(reqParam.getString("keyword"));
        info.setUrl("http://localhost:7002/m?xwl=agtesth/tstudent");
        super.setSaveUser(reqParam, info);
        bizDao.save(info);
        try {
            WebUtil.send(response, info.getId());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public void findQrInfo(org.json.JSONObject reqParam, HttpServletResponse response, HttpServletRequest request){
        QrcodeInfo info = new QrcodeInfo();
        info.setId(reqParam.getString("id"));
        info = (QrcodeInfo)bizDao.findById(info, QrcodeInfo.class, "ID");
        try {
            WebUtil.send(response, JSON.toJSONString(info));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
