package com.ideabobo.action;
import java.util.Date;
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.Bill;
import com.ideabobo.model.Dingzuo;
import com.ideabobo.model.Good;
import com.ideabobo.model.Message;
import com.ideabobo.model.Posts;
import com.ideabobo.model.Replay;
import com.ideabobo.model.User;
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.PostsService;
import com.ideabobo.service.ReplayService;
import com.ideabobo.service.ShopService;
import com.ideabobo.service.TypeService;
import com.ideabobo.service.UserService;
import com.ideabobo.util.GetNowTime;
import com.ideabobo.util.IdeaAction;
@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 PostsService postsService;
@Resource
private ReplayService replayService;
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){
renderJsonpObj(r);
}else{
renderJsonpString("fail");
}
}
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");
String address = request.getParameter("address");
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(address));
userService.update(user);
renderJsonpString("success");
}
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 register(){
User user = (User) getByRequest(new User(), true);
String roletype = "2";
user.setRoletype(roletype);
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 uid = request.getParameter("uid");
String statecn = request.getParameter("statecn");
String sex = request.getParameter("sex");
String level = request.getParameter("level");
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(uid != null&& !"".equals(uid)){
hql+=" and t.uid='"+uid+"'";
}
if(sex != null&& !"".equals(sex)){
sex = encodeGet(sex);
hql+=" and t.sex='"+sex+"'";
}
if(level != null&& !"".equals(level)){
hql+=" and t.level='"+level+"'";
}
if(statecn != null&& !"".equals(statecn)){
statecn = encodeGet(statecn);
hql+=" and t.statecn='"+statecn+"'";
}
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());
billService.save(bill);
renderJsonpString("提交成功!");
}
public void updateGoodStatecn(){
String id = request.getParameter("id");
Good g = (Good) baseService.find(Integer.parseInt(id), Good.class);
String statecn = request.getParameter("statecn");
statecn = encodeGet(statecn);
g.setStatecn(statecn);
baseService.update(g);
renderJsonpString("0");
}
public void saveBills(){
String bills = request.getParameter("bills");
bills = encodeGet(bills);
JsonParser parser = new JsonParser();
JsonArray blist = parser.parse(bills).getAsJsonArray();
for(int i=0;i<blist.size();i++){
JsonElement jo = blist.get(i);
JsonObject obj = (JsonObject) parser.parse(jo.toString());
Bill bill = new Bill();
bill.setTotal(obj.get("total").getAsString());
bill.setSid(obj.get("sid").getAsString());
bill.setShop(obj.get("shop").getAsString());
bill.setUid(obj.get("uid").getAsString());
bill.setUser(obj.get("user").getAsString());
bill.setNdate(GetNowTime.getNowTimeNian());
bill.setGids(obj.get("gids").getAsString());
bill.setGnames(obj.get("gnames").getAsString());
bill.setAddress(obj.get("address").getAsString());
bill.setTel(obj.get("tel").getAsString());
bill.setNote(obj.get("note").getAsString());
bill.setWay(obj.get("way").getAsString());
bill.setStatecn("进行中");
billService.save(bill);
}
renderJsonpString("提交成功!");
}