package com.lgx8.gateway.member.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.lgx8.common.util.SendSms;
import com.lgx8.gateway.dao.ICardDao;
import com.lgx8.gateway.entities.Card;
import com.lgx8.right.entities.RunTimeUser;
/**
* Servlet implementation class BatchCreateCardServlet
*/
public class BatchCreateCardServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BatchCreateCardServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RunTimeUser rtUser = RunTimeUser.getRunTimeUser(request);
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ICardDao cardDao = (ICardDao) ac.getBean("cardDao");
Integer count = Integer.parseInt(request.getParameter("count"));
String card = request.getParameter("card");
Double score = Double.parseDouble(request.getParameter("score"));
String mobile = request.getParameter("mobile");
String email = request.getParameter("email");
long car3 = Long.parseLong(card);
Card temp = null;
for(int i=1;i<=count;i++,car3++)
{
//生成卡号且卡号唯一
String car = car3+"";
temp = cardDao.createUserByCard(car.toUpperCase(), score, rtUser.getUsertype(), 1l, rtUser.getOrganizationid(), rtUser, rtUser,count==1?mobile:null,count==1?email:null);
}
if(count == 1 &&(mobile != null && !"".equals(mobile)) && temp != null)
{
//当开卡成功后发短信到手机尊敬的会员您的乐共享登录名13036780222,卡/号818800010022密/码abc123,请登录www.lgx8.com【乐共享】
String content = "您的乐共享卡号是:"+temp.getId()+",密码是:"+temp.getPassword() + ",请登录后继续完善帐号信息。";
SendSms.sendSms(mobile, content);
}
try {
PrintWriter out = response.getWriter();
out.println("1");
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}