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.

182 lines
6.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.FengHuang.TouPiao.Controller;
import com.alibaba.fastjson.JSONObject;
import com.aspose.cells.Workbook;
import com.dsideal.FengHuang.Interceptor.IsLoginInterface;
import com.dsideal.FengHuang.TouPiao.Model.TouPiaoModel;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.Util.ExcelExportUtil;
import com.dsideal.FengHuang.Util.FileUtil;
import com.dsideal.FengHuang.Util.IpUtil;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("unchecked")
public class TouPiaoController extends Controller {
TouPiaoModel tm = new TouPiaoModel();
/**
* 功能:获取侯选人名单
* 作者:黄海
* 日期2022-12-11
* 高级
* http://10.10.11.124:9000/FengHuang/TouPiao/getHouXuanRenList?type_id=1
* 中级
* http://10.10.11.124:9000/FengHuang/TouPiao/getHouXuanRenList?type_id=2
*/
@Before({GET.class})
@IsLoginInterface({})
public void getHouXuanRenList(int type_id) {
List<Record> list = tm.getHouXuanRenList(type_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/*
获取当前登录人员信息,比如姓名信息,身份信息(评委小组,还是群众)
http://10.10.11.124:9000/FengHuang/TouPiao/getTouPiaoRenInfo
*/
@Before({GET.class})
@IsLoginInterface({})
public void getTouPiaoRenInfo() {
String toupiaoren_tel = getCookie("toupiaoren_tel");
Record record = tm.getTouPiaoRenInfo(toupiaoren_tel);
renderJson(record);
}
@Before({POST.class})
@IsLoginInterface({})
public void save(String gaoji, String zhongji) {
String ip = IpUtil.getIpAddr(getRequest());
String toupiaoren_tel = getCookie("toupiaoren_tel");
if (tm.haveFinishTouPiao(toupiaoren_tel)) {
Kv kv = Kv.create();
kv.put("success", false);
kv.put("message", "您已经投票完成,不能重复投票!");
renderJson(kv);
return;
}
//检查中级是不是2个高级是不是2个
String[] gaojiArray = gaoji.split(",");
String[] zhongjiArray = zhongji.split(",");
if (gaojiArray.length != 2) {
Kv kv = Kv.create();
kv.set("success", false);
kv.set("message", "本次投票高级只能投2人!");
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, ip);
Kv kv = Kv.create();
kv.set("success", true);
kv.set("message", "投票成功 !");
renderJson(kv);
}
/*
统计信息
http://10.10.11.124:9000/FengHuang/TouPiao/TongJi?houxuanren_type_id=1
*/
public void TongJi(int houxuanren_type_id) {
List<Record> list = tm.TongJi(houxuanren_type_id);
renderJson(CommonUtil.renderJsonForLayUI(list));
}
/*
投票人数信息
http://10.10.11.124:9000/FengHuang/TouPiao/getTouPiaoRenSummary
*/
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));
}
/*
导出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);
}
/*
查看人员投票情况
http://10.10.11.124:9000/FengHuang/TouPiao/getTouPiaoInfo
*/
public void getTouPiaoInfo() {
List<Record> list = tm.getTouPiaoInfo();
renderJson(CommonUtil.renderJsonForLayUI(list));
}
}