第十二周总结

package web;

import com.google.gson.Gson;
import entity.TCorpStock;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.MyDataSoureUtils;

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 java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/gqjg")
public class gqjg extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String id = request.getParameter("id");
List<TCorpStock> tCorpStockList = new ArrayList<>();
try {
tCorpStockList = getTcorpStock(id);
} catch (SQLException e) {
e.printStackTrace();
}
response.getWriter().write(new Gson().toJson(tCorpStockList));
}

private List<TCorpStock> getTcorpStock(String id) throws SQLException {
QueryRunner qr = new QueryRunner(MyDataSoureUtils.getDataSource());
String sql = "select * from t_corp_stock where id in (select sub_id from t_m_corp_corp_stock where id = ?)";
List<TCorpStock> query = qr.query(sql, new BeanListHandler<TCorpStock>(TCorpStock.class), id);
return query;
}
}
package web;

import com.google.gson.Gson;
import entity.ChartData;
import entity.LinkeData;
import entity.TCorpStock;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import utils.MyDataSoureUtils;

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 java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/qytp")
public class qytp extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String id = request.getParameter("id");
String companyName = request.getParameter("companyName");
List<TCorpStock> tCorpStockList = new ArrayList<>();
List<ChartData> chartDataList = new ArrayList<>();
List<LinkeData> linkeDataList = new ArrayList<>();
List<Object> dbr = new ArrayList<>();
try {
tCorpStockList = getTcorpStock(id);
dbr = getGG(id);
} catch (SQLException e) {
e.printStackTrace();
}
initData(chartDataList,linkeDataList,companyName);
for (TCorpStock tCorpStock : tCorpStockList) {
ChartData temp = new ChartData();
LinkeData link = new LinkeData();
temp.setCategory(2);
temp.setDes(tCorpStock.getSTOCK_NAME());
temp.setName(tCorpStock.getSTOCK_NAME());
temp.setSymbolSize(40);
link.setSource("股东");
link.setTarget(tCorpStock.getSTOCK_NAME());
link.setDes("1");
link.setName("linke");
chartDataList.add(temp);
linkeDataList.add(link);
}

for (Object object : dbr) {
String name = (String) object;
ChartData temp = new ChartData();
LinkeData link = new LinkeData();
temp.setCategory(2);
temp.setDes(name);
temp.setName(name);
temp.setSymbolSize(40);
link.setSource("法定代表人");
link.setTarget(name);
link.setDes("1");
link.setName("linke");
chartDataList.add(temp);
linkeDataList.add(link);
}

List<Object> data = new ArrayList<>();
data.addAll(chartDataList);
data.addAll(linkeDataList);
response.getWriter().write(new Gson().toJson(data));
}

private void initData(List<ChartData> chartDataList, List<LinkeData> linkeDataList, String companyName) {
ChartData gdData = new ChartData();
LinkeData linkGd = new LinkeData();
gdData.setCategory(1);
gdData.setDes("股东");
gdData.setName("股东");
gdData.setSymbolSize(60);
linkGd.setSource(companyName);
linkGd.setTarget("股东");
linkGd.setDes("1");
linkGd.setName("linke");
chartDataList.add(gdData);
linkeDataList.add(linkGd);

ChartData company = new ChartData();
company.setCategory(0);
company.setDes(companyName);
company.setName(companyName);
company.setSymbolSize(80);
chartDataList.add(company);


ChartData TzData = new ChartData();
LinkeData linkTz = new LinkeData();
TzData.setCategory(1);
TzData.setDes("法定代表人");
TzData.setName("法定代表人");
TzData.setSymbolSize(60);
linkTz.setSource(companyName);
linkTz.setTarget("法定代表人");
linkTz.setDes("1");
linkTz.setName("linke");
chartDataList.add(TzData);
linkeDataList.add(linkTz);


}

//查股东
private List<TCorpStock> getTcorpStock(String id) throws SQLException {
QueryRunner qr = new QueryRunner(MyDataSoureUtils.getDataSource());
String sql = "select * from t_corp_stock where id in (select sub_id from t_m_corp_corp_stock where id = ?)";
List<TCorpStock> query = qr.query(sql, new BeanListHandler<TCorpStock>(TCorpStock.class), id);
return query;
}

//查高管
private List<Object> getGG(String id) throws SQLException {
QueryRunner qr = new QueryRunner(MyDataSoureUtils.getDataSource());
String sql = "select person_name from t_corp_pertains where id in (select sub_id from t_m_corp_corp_pertains where id = ?)";
List<Object> query = qr.query(sql, new ColumnListHandler(), id);
return query;
}
}
原文地址:https://www.cnblogs.com/sunhongbin/p/14211138.html