You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
6.1 KiB

3 years ago
package com.dsideal.FengHuang.TouPiao.Controller;
3 years ago
import com.alibaba.fastjson.JSONObject;
import com.aspose.cells.Workbook;
3 years ago
import com.dsideal.FengHuang.Interceptor.IsLoginInterface;
import com.dsideal.FengHuang.TouPiao.Model.TouPiaoModel;
import com.dsideal.FengHuang.Util.CommonUtil;
3 years ago
import com.dsideal.FengHuang.Util.ExcelExportUtil;
import com.dsideal.FengHuang.Util.FileUtil;
3 years ago
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
3 years ago
import com.jfinal.kit.Kv;
3 years ago
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
3 years ago
import com.jfinal.plugin.activerecord.Db;
3 years ago
import com.jfinal.plugin.activerecord.Page;
3 years ago
import com.jfinal.plugin.activerecord.Record;
3 years ago
import com.jfinal.plugin.activerecord.SqlPara;
3 years ago
3 years ago
import java.io.File;
3 years ago
import java.util.ArrayList;
3 years ago
import java.util.List;
3 years ago
import java.util.UUID;
3 years ago
@SuppressWarnings("unchecked")
public class TouPiaoController extends Controller {
TouPiaoModel tm = new TouPiaoModel();
/**
*
*
* 2022-12-11
3 years ago
*
* http://10.10.11.124:9000/FengHuang/TouPiao/getHouXuanRenList?type_id=1
*
* http://10.10.11.124:9000/FengHuang/TouPiao/getHouXuanRenList?type_id=2
3 years ago
*/
@Before({GET.class})
@IsLoginInterface({})
public void getHouXuanRenList(int type_id) {
List<Record> list = tm.getHouXuanRenList(type_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
3 years ago
3 years ago
/*
3 years ago
,
3 years ago
http://10.10.11.124:9000/FengHuang/TouPiao/getTouPiaoRenInfo
*/
3 years ago
@Before({GET.class})
@IsLoginInterface({})
public void getTouPiaoRenInfo() {
String toupiaoren_tel = getCookie("toupiaoren_tel");
3 years ago
Record record = tm.getTouPiaoRenInfo(toupiaoren_tel);
renderJson(record);
}
@Before({POST.class})
@IsLoginInterface({})
public void save(String gaoji, String zhongji) {
String toupiaoren_tel = getCookie("toupiaoren_tel");
3 years ago
if (tm.haveFinishTouPiao(toupiaoren_tel)) {
Kv kv = Kv.create();
kv.put("success", false);
3 years ago
kv.put("message", "您已经投票完成,不能重复投票!");
3 years ago
renderJson(kv);
return;
}
3 years ago
//检查中级是不是2个高级是不是2个
3 years ago
String[] gaojiArray = gaoji.split(",");
String[] zhongjiArray = zhongji.split(",");
3 years ago
if (gaojiArray.length != 2) {
3 years ago
Kv kv = Kv.create();
kv.set("success", false);
3 years ago
kv.set("message", "本次投票高级只能投2人!");
3 years ago
renderJson(kv);
return;
}
if (zhongjiArray.length != 2) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "本次投票中级只能投2人!");
renderJson(kv);
return;
}
tm.save(toupiaoren_tel, gaojiArray, zhongjiArray);
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "投票成功 !");
renderJson(kv);
3 years ago
}
3 years ago
3 years ago
/*
http://10.10.11.124:9000/FengHuang/TouPiao/TongJi?houxuanren_type_id=1
*/
public void TongJi(int houxuanren_type_id) {
3 years ago
List<Record> list = tm.TongJi(houxuanren_type_id);
3 years ago
renderJson(CommonUtil.renderJsonForLayUI(list));
3 years ago
}
3 years ago
/*
3 years ago
http://10.10.11.124:9000/FengHuang/TouPiao/getTouPiaoRenSummary
3 years ago
*/
3 years ago
public void getTouPiaoRenSummary() {
List<Record> list1 = tm.getYingTouPiaoRenSummary();
List<Record> list2 = tm.getYiTouPiaoRenSummary();
List<Record> res = new ArrayList<>();
for (Record r1 : list1)
for (Record r2 : list2) {
if (r1.getInt("toupiaoren_type_id") == r2.getInt("toupiaoren_type_id")) {
Record r3 = new Record();
r3.set("toupiaoren_type_id", r1.getInt("toupiaoren_type_id"));
r3.set("ying_count", r1.getInt("c"));
r3.set("yi_count", r2.getInt("c"));
res.add(r3);
}
}
renderJson(CommonUtil.renderJsonForLayUI(res));
3 years ago
}
/*
excel
http://10.10.11.124:9000/FengHuang/TouPiao/exportExcel
*/
public void exportExcel() throws Exception {
//模板文件
String excelPath = PathKit.getRootClassPath() + PropKit.get("excelExportTemplatePathSuffix").replace("\\", "/");
String filePath = excelPath + "TouPiaoSummaryGaoJi.json";
//转成 json对象
JSONObject jo = FileUtil.readJsonFile(filePath);
//导出
Page<Record> rs = new Page<>();
List<Record> list1 = tm.TongJi(1);
rs.setList(list1);
rs.setPageNumber(1);
rs.setPageSize(list1.size());
rs.setTotalRow(list1.size());
String file1 = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
ExcelExportUtil.export(rs, jo, file1);
//中级导出
filePath = excelPath + "TouPiaoSummaryZhongJi.json";
//转成 json对象
jo = FileUtil.readJsonFile(filePath);
//导出
rs = new Page<>();
List<Record> list2 = tm.TongJi(2);
rs.setList(list2);
rs.setPageNumber(1);
rs.setPageSize(list2.size());
rs.setTotalRow(list2.size());
String file2 = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
ExcelExportUtil.export(rs, jo, file2);
ExcelExportUtil.getLicense();
Workbook SourceBook1 = new Workbook(file1);
Workbook SourceBook2 = new Workbook(file2);
SourceBook1.combine(SourceBook2);
String file3 = excelPath + "excelTemp/" + UUID.randomUUID().toString().toUpperCase() + ".xls";
SourceBook1.save(file3);
//提供下载
String filename = "投票结果.xls";
renderFile(new File(file3), filename);
}
3 years ago
}