package com.sxl.controller.admin;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.sxl.controller.MyController;
import com.sxl.util.StringHelper;
@Controller("appController")
@RequestMapping(value = "/app")
public class AppController extends MyController {
@RequestMapping(value = "/index")
public String frame(Model model, HttpServletRequest request)
throws Exception {
String sql = "select a.* from t_exam a where status='进行中'";
String ppp = request.getParameter("ppp");
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/index";
}
@RequestMapping(value = "/djs")
public String djs(Model model, HttpServletRequest request)
throws Exception {
return "/app/djs";
}
@RequestMapping(value = "/kc")
public String kc(Model model, HttpServletRequest request,Long id)
throws Exception {
String sql = "select a.* from t_exam a where id=" + id;
Map map = db.queryForMap(sql);
request.setAttribute("map", map);
return "/app/kc";
}
@RequestMapping(value = "/zsd")
public String zsd(Model model, HttpServletRequest request,Long examId)
throws Exception {
List list = db.queryForList("select * from t_zsd where examId="+examId);
request.setAttribute("list", list);
return "/app/zsd";
}
@RequestMapping(value = "/login")
public String login(Model model, HttpServletRequest request)
throws Exception {
return "/app/login";
}
@RequestMapping(value = "/register")
public String register(Model model, HttpServletRequest request)
throws Exception {
System.out.println("112312312");
return "/app/register";
}
@RequestMapping(value = "/detail")
public String detail(Model model, HttpServletRequest request, Long id)
throws Exception {
String sql = "select a.* from t_exam a where id=" + id;
Map map = db.queryForMap(sql);
request.setAttribute("map", map);
return "/app/detail";
}
@RequestMapping(value = "/begin")
public String begin(Model model, HttpServletRequest request, Long id)
throws Exception {
Map customer = getCustomer(request);
if (customer != null && customer.size() > 0) {
} else {
return "redirect:/app/login.html";
}
String sql="select * from t_exam where id=?";
Map map = db.queryForMap(sql,new Object[]{id});
model.addAttribute("map", map);
sql="select b.* from t_examlist a left join t_examtm b on a.examtmId=b.id where examId="+id+" ";
sql+=" order by id desc";
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/begin";
}
@RequestMapping(value = "/minedt")
public String minedt(Model model, HttpServletRequest request)
throws Exception {
String sql = "select max(v3) v3, batchId, examName,count(1) counts, " +
"sum(case when da=answer then 1 else 0 end) rights from t_examanswer a where customerId="+getCustomer(request).get("id")+" group by batchId, examName";
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/minedt";
}
@RequestMapping(value = "/xsdt")
public String xsdt(Model model, HttpServletRequest request)
throws Exception {
String sql = "select max(v3) v3, batchId, examName,count(1) counts, " +
"sum(case when da=answer then 1 else 0 end) rights from t_examanswer a where 1=1 group by batchId, examName";
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/xsdt";
}
@RequestMapping(value = "/minedtshow")
public String minedtshow(Model model, HttpServletRequest request,String batchId)
throws Exception {
String sql = "select * from t_examanswer where batchId='"+batchId+"' and 1=1";
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/minedtshow";
}
@RequestMapping(value = "/wdsc")
public String wdsc(Model model, HttpServletRequest request,String id)
throws Exception {
String sql = "select * from t_examtm a where exists(select 1 from t_sc b where b.examtmId=a.id and customerId="+getCustomer(request).get("id")+")";
List list = db.queryForList(sql);
System.out.println(list);
request.setAttribute("list", list);
return "/app/wdsc";
}
@RequestMapping(value = "/examSave")
public ResponseEntity<String> examSave(Model model,HttpServletRequest request,Long id,String flag
,String examName,String skbj,String skxq,String tm[],String da[],String answer[],String[] types) throws Exception{
int result = 0;
int v1all=0;
int v2all=0;
for (int i = 0; i < types.length; i++) {
if("1".equals(types[i])){
if(da[i].equals(answer[i])){
v1all+=2;
}
}else if("2".equals(types[i])){
if(da[i].equals(answer[i])){
v2all+=2;
}
}
}
String batchId = System.currentTimeMillis()+"";
String sql="insert into t_examanswer(batchId,customerId,examName,insertDate,tm,da,answer,v1,v2,v3,skbj,skxq,types,examId,v1all,v2all) values(?,?,?,now(),?,?,?,?,?,?,?,?,?,?,?,?)";
for (int i = 0; i < tm.length; i++) {
int v1=0;
int v2=0;
if("1".equals(types[i])){
if(da[i].equals(answer[i])){
v1=2;
}
}else if("2".equals(types[i])){
if(da[i].equals(answer[i])){
v2=2;
}
}
db.update(sql, new Object[]{batchId,getCustomer(request).get("id"),examName,tm[i],da[i],answer[i],v1,v2,0,skbj,skxq,types[i],id,v1all,v2all});
}
return renderData(true,"操作成功",null);
}
@RequestMapping(value = "/isin")
public ResponseEntity<String> isin(Model model,HttpServletRequest request,Long id,String flag
,String examName,String tm[],String da[],String answer[]) throws Exception{
Map customer = getCustomer(request);
if (customer != null && customer.size() > 0) {
} else {
return renderData(false,"1",null);
}
String sql="select count(1) from t_examanswer where customerId="+getCustomer(request).get("id")+" and examName='"+examName+"'";
int count = db.queryForInt(sql);
if(count>0){
return renderData(false,"2",null);
}else{
return renderData(true,"操作成功",null);
}
}
@RequestMapping(value = "/myOrder")
public String myOrder(Model model, HttpServletRequest request)
throws Exception {
String sql = "select a.*,(select max(name) from t_customer b where a.customerId=b.id) name from t_order a where 1=1 ";
if (1 == 1) {
sql += "and customerId=" + getCustomer(request).get("id") + " ";
}
sql += " order by id desc";
List list = db.queryForList(sql);
request.setAttribute("orderList", list);
System.out.println("############");
return "/app/myOrder";
}
@RequestMapping(value = "/addShopcar")
public ResponseEntity<String> addShopcar(Model model,
HttpServletRequest request, Long id, Integer num) throws Exception {
int result = 0;
// 判断该用户是否
String sql = "select * from t_shopcar where productId=? and customerId=?";
Map map = db.queryForMap(sql, new Object[] { id.toString(),
getCustomer(request).get("id").toString() });
if (map != null && map.size() > 0) {
sql = "update t_shopcar set productId=?,num=num+" + num
+ " where id=?";
result = db.update(sql, new Object[] { id, map.get("id") });
} else {
sql = "insert into t_shopcar(productId,num,customerId) values(?,?,?)";
result = db.update(sql, new Object[] { id, num,
getCustomer(request).get("id").toString() });
}
if (result == 1) {
return renderData(true, "操作成功", null);
} el