package com.ideabobo.action;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.Resource;
import javax.swing.*;
import org.springframework.stereotype.Controller;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ideabobo.model.Address;
import com.ideabobo.model.Bill;
import com.ideabobo.model.Dingzuo;
import com.ideabobo.model.Good;
import com.ideabobo.model.Jifen;
import com.ideabobo.model.Line;
import com.ideabobo.model.Message;
import com.ideabobo.model.Posts;
import com.ideabobo.model.Replay;
import com.ideabobo.model.Shop;
import com.ideabobo.model.Tousu;
import com.ideabobo.model.User;
import com.ideabobo.model.Youhuijuan;
import com.ideabobo.model.Yzmessage;
import com.ideabobo.service.BaseService;
import com.ideabobo.service.BillService;
import com.ideabobo.service.DingzuoService;
import com.ideabobo.service.GoodService;
import com.ideabobo.service.NoticeService;
import com.ideabobo.service.ReplayService;
import com.ideabobo.service.RoomService;
import com.ideabobo.service.ShopService;
import com.ideabobo.service.TypeService;
import com.ideabobo.service.UserService;
import com.ideabobo.util.GetNowTime;
import com.ideabobo.util.HttpClientTools;
import com.ideabobo.util.IdeaAction;
import com.ideabobo.util.getui.Getui;
@Controller
public class WehallAction extends IdeaAction {
@Resource
private BaseService baseService;
@Resource
private BillService billService;
@Resource
private ShopService shopService;
@Resource
private GoodService goodService;
@Resource
private DingzuoService dingzuoService;
@Resource
private TypeService typeService;
@Resource
private UserService userService;
@Resource
private ReplayService replayService;
@Resource
private NoticeService noticeService;
@Resource
private RoomService roomService;
public Gson gson = new Gson();
private static final long serialVersionUID = -3218238026025256103L;
public String wehall(){
// String openid = request.getParameter("openid");
// session.put("openid", openid);
return SUCCESS;
}
public void login(){
String username = request.getParameter("username");
String passwd = request.getParameter("passwd");
User user = new User();
user.setPasswd(passwd);
user.setUsername(encodeGet(username));
User r = userService.find(user);
if(r!=null){
session.put("user", r);
renderJsonpObj(r);
}else{
renderJsonpString("fail");
}
}
public void checkSession(){
Object obj = session.get("user");
if(obj!=null){
renderJsonpObj(obj);
}else{
renderJsonpString("fail");
}
}
public void clearSession(){
session.clear();
}
public void checkUser(){
User u = new User();
String username = request.getParameter("username");
u.setUsername(username);
User r = userService.find(u);
if(r!=null){
renderJsonpString("fail");
}else{
renderJsonpString("success");
}
}
public void updateUser(){
String tel = request.getParameter("tel");
String qq = request.getParameter("qq");
String wechat = request.getParameter("wechat");
String email = request.getParameter("email");
String birth = request.getParameter("birth");
String sex = request.getParameter("sex");
String id = request.getParameter("id");
User user = userService.find(id);
user.setId(Integer.parseInt(id));
user.setTel(tel);
user.setWechat(wechat);
user.setQq(qq);
user.setEmail(email);
user.setBirth(birth);
user.setSex(encodeGet(sex));
user.setAddress(encodeGet(request.getParameter("address")));
userService.update(user);
renderJsonpObj(user);
}
public void changePasswd(){
String passwd = request.getParameter("passwd");
String id = request.getParameter("id");
User user = userService.find(id);
user.setPasswd(passwd);
userService.update(user);
renderJsonpString("success");
}
public void changePasswd2(){
String passwd = request.getParameter("passwd");
String tel = request.getParameter("ftel");
User user = (User) baseService.find("from User t where t.username='"+tel+"'");
if(user!=null){
user.setPasswd(passwd);
userService.update(user);
renderJsonpString("success");
}else{
renderJsonpString("-1");
}
}
public void register(){
User user = (User) getByRequest(new User(), true);
String roletype = "2";
user.setRoletype(roletype);
userService.save(user);
renderJsonpString("success");
}
public void register2(){
Shop shop = (Shop) getByRequest(new Shop(), true);
baseService.save(shop);
User user = new User();
String roletype = "3";
user.setRoletype(roletype);
user.setImg(shop.getImg());
user.setSid(shop.getId()+"");
user.setTel(shop.getTel());
user.setAddress(shop.getAddress());
user.setPasswd("111111");
user.setStatecn("待审核");
user.setUsername(shop.getSname());
userService.save(user);
renderJsonpString("success");
}
public void listShop(){
renderJsonpObj(shopService.list());
}
public void listGood(){
String type = request.getParameter("stype");
String sid = request.getParameter("sid");
String title = request.getParameter("stitle");
String sort = request.getParameter("order");
title = encodeGet(title);
String hql = "from Good t where 1=1";
if (type != null&& !"".equals(type)) {
hql+=" and t.typeid="+type;
}
if(sid != null&& !"".equals(sid)){
hql+=" and t.sid="+sid;
}
if(title != null&& !"".equals(title)){
hql+=" and t.gname='"+title+"'";
}
if(sort != null&& !"".equals(sort)){
hql+=" order by "+sort+" desc";
}else{
hql+=" order by xiaoliang desc";
}
/*ArrayList<Good> list = (ArrayList<Good>) goodService.queryObj(g);
Collections.sort(list);*/
renderJsonpObj(baseService.list(hql));
}
public void listType(){
renderJsonpObj(typeService.list());
}
public void saveDingzuo(){
Dingzuo dz = new Dingzuo();
dz.setRenshu(request.getParameter("renshu"));
dz.setXingming(encodeGet(request.getParameter("xingming")));
dz.setShouji(request.getParameter("shouji"));
dz.setShijian(request.getParameter("shijian"));
dz.setTodate(request.getParameter("todate"));
dz.setBeizhu(encodeGet(request.getParameter("beizhu")));
dz.setShopid(request.getParameter("shopid"));
dz.setShopname(encodeGet(request.getParameter("shopname")));
dz.setOpenid(request.getParameter("openid"));
dz.setNdate(GetNowTime.getNowTimeNian());
dingzuoService.save(dz);
renderJsonpString("提交成功!");
}
public void saveBill(){
Bill bill = (Bill) getByRequest(new Bill(), true);
bill.setNdate(GetNowTime.getNowTimeNian());
bill.setStatecn("未付款");
billService