package sist.servlet;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import sist.bean.FwptPagingBean;
import sist.bean.NewsPaging;
import sist.bean.PatentPage;
import sist.bean.SupplyPagingBean;
import sist.bean.kjcgPagingBean;
import sist.bean.qyxqPagingBean;
import sist.bean.zcfgPagingBean;
import sist.bean.zjxxPagingBean;
import sist.dao.gmjjDao;
import sist.dao.jssslyDao;
import sist.dao.jstxxsDao;
import sist.dao.ssgxjslbDao;
import sist.dao.zyzddxDao;
import sist.domain.Fwpt;
import sist.domain.JSGJBean;
import sist.domain.NewsBean;
import sist.domain.Patent;
import sist.domain.cgal;
import sist.domain.cgzhxm;
import sist.domain.gmjj;
import sist.domain.jsssly;
import sist.domain.jstxxs;
import sist.domain.jsxq;
import sist.domain.kjcg;
import sist.domain.ssgxjslb;
import sist.domain.zcfg;
import sist.domain.zjxx;
import sist.domain.zyzddx;
import sist.factory.BasicFactory;
import sist.service.FwptService;
import sist.service.JSGJService;
import sist.service.NewsService;
import sist.service.PatentService;
import sist.service.cgalService;
import sist.service.cgzhxmService;
import sist.service.kjcgService;
import sist.service.qyxqService;
import sist.service.zcfgService;
import sist.service.zjxxService;
import sist.utils.Constant;
import sist.utils.StringUtil;
import sist.utils.URLUtil;
/**
* Servlet implementation class xxjsServlet
*/
@WebServlet("/back/xxjs/xxjsServlet")
public class xxjsServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private BasicFactory factory = BasicFactory.getFactory();
private PatentService service;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String method = request.getParameter("method");
if ("searchNews".equals(method)) {
searchNews(request, response);
} else if ("getNewsById".equals(method)) {
getNewsById(request, response);
} else if ("searchXuqiu".equals(method)) {
searchXuqiu(request, response);
} else if ("searchJishu".equals(method)) {
searchJishu(request, response);
} else if ("getSupplyById".equals(method)) {
getSupplyById(request, response);
} else if ("searchChengguo".equals(method)) {
searchChengguo(request, response);
} else if ("searchZhuanli".equals(method)) {
searchZhuanli(request, response);
} else if ("getZhuanliById".equals(method)) {
getZhuanliById(request, response);
} else if ("searchZhuanJia".equals(method)) {
searchZhuanJia(request, response);
} else if ("searchZhengce".equals(method)) {
searchZhengce(request, response);
} else if ("searchPingtai".equals(method)) {
searchPingtai(request, response);
} else if ("getPingTaiByKmAndMc".equals(method)) {
getPingTaiByKmAndMc(request, response);
} else if ("getChengguoById".equals(method)) {
getChengguoById(request, response);
} else if ("getXuqiuById".equals(method)) {
getXuqiuById(request, response);
} else if ("getZhengceById".equals(method)) {
getZhengceById(request, response);
}else if("getZhuanjiaById".equals(method)){
getZhuanjiaById(request,response);
}
}
private void getZhuanjiaById(HttpServletRequest request, HttpServletResponse response) {
int id = StringUtil.StringToInt(request.getParameter("id"));
zjxxService zs = BasicFactory.getFactory().getService(zjxxService.class);
try {
zjxx z = zs.getById(id);
request.setAttribute(Constant.ZJXXBEAN, z);
request.getRequestDispatcher("detailZhuanjia.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
private void getZhengceById(HttpServletRequest request, HttpServletResponse response) {
int id = StringUtil.StringToInt(request.getParameter("id"));
zcfgService zs = BasicFactory.getFactory().getService(zcfgService.class);
zcfg z = null;
try {
z = zs.getById(id);
} catch (Exception e) {
e.printStackTrace();
}
zyzddxDao d = BasicFactory.getFactory().getDao(zyzddxDao.class);
try {
List<zyzddx> list = d.getAll();
request.setAttribute(Constant.ZYZDDX, list);
} catch (Exception e1) {
e1.printStackTrace();
}
request.setAttribute(Constant.ZCFGBEAN, z);
try {
request.getRequestDispatcher("detailZhengce.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
private void getXuqiuById(HttpServletRequest request, HttpServletResponse response) {
int id = StringUtil.StringToInt(request.getParameter("id"));
qyxqService qs = BasicFactory.getFactory().getService(qyxqService.class);
jssslyDao jd = BasicFactory.getFactory().getDao(jssslyDao.class);
try {
jsxq js = qs.getInfo(id);
System.out.println("获取 id是" + id + "的信息成功");
request.setAttribute(Constant.JSXQBEAN, js);
List<jsssly> list = jd.getAll();
request.setAttribute(Constant.JSSSLY, list);
request.getRequestDispatcher("detailXuqiu.jsp").forward(request, response);
} catch (Exception e) {
System.out.println("获取信息失败,id是" + id);
e.printStackTrace();
}
}
private void getChengguoById(HttpServletRequest request, HttpServletResponse response) {
int id = StringUtil.StringToInt(request.getParameter("id"));
kjcgService ks = BasicFactory.getFactory().getService(kjcgService.class);
kjcg k = null;
try {
k = ks.getById(id);
} catch (Exception e) {
e.printStackTrace();
}
if (k != null) {
if (k.getKm().equals("成果转化项目")) {
cgzhxmService cs = BasicFactory.getFactory().getService(cgzhxmService.class);
cgzhxm c = null;
try {
c = cs.getByMc(k.getMc());
} catch (Exception e) {
e.printStackTrace();
}
if (!"".equals(c.getYyhy())) {
gmjjDao gd = BasicFactory.getFactory().getDao(gmjjDao.class);
gmjj g;
try {
g = gd.getByCode(c.getYyhy());
request.setAttribute(Constant.YYHY, g.getTitle());
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取技术所属领域信息和成果体现形式信息
getlbAndLy(request, response);
request.setAttribute(Constant.CGZHXMBEAN, c);
try {
request.getRequestDispatcher("detailChengguo.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
} else if (k.getKm().equals("成功案例")) {
cgalService cs = BasicFactory.getFactory().getService(cgalService.class);
try {
cgal c = cs.getByMc(k.getMc());
request.setAttribute(Constant.CGALBEAN, c);
} catch (Exception e) {
e.printStackTrace();
}
try {
request.getRequestDispatcher("detailAnli.jsp").forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 获取平台信息
*
* @param request
* @param response
*/
private void getPingTaiByKmAndMc(HttpServletRequest request, HttpServletResponse response) {
String mc = request.getParameter("mc");
String km = request.getParameter("km");
System.out.println(mc + " " + km);
FwptService fs = BasicFactory.getFactory().getService(FwptService.class);
try {
Fwpt f = fs.getByKmAndMc(km, mc);
request.setAttribute(Constant.FWPTBEAN, f);
System.out.println(f.toString());
request.getRequestDispatcher("detailPingtai.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 找平台
*
* @param request
* @param response
*/
private void searchPingtai(HttpServletRequest request, HttpServletResponse response) {
FwptPagingBean page = new FwptPagingBean();
int msg = StringUtil.StringToInt(