package com.dsh.guns.modular.system.controller.code;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.dsh.course.feignClient.communityWorldCup.Model.WorldCupStore;
|
import com.dsh.course.feignClient.communityWorldCup.WorldCupClient;
|
import com.dsh.course.feignClient.communityWorldCup.Model.WorldCup;
|
import com.dsh.course.feignClient.communityWorldCup.Model.WorldCupListAll;
|
import com.dsh.course.feignClient.communityWorldCup.WorldCupStoreClient;
|
import com.dsh.course.feignClient.communityWorldCup.Model.RegisteredPersonnel;
|
import com.dsh.course.feignClient.competition.model.Competition;
|
import com.dsh.course.feignClient.competition.model.CompetitionUser;
|
import com.dsh.course.feignClient.competition.model.GetPeopleQuery;
|
import com.dsh.guns.core.util.ToolUtil;
|
import com.dsh.guns.modular.system.service.IStoreService;
|
import com.dsh.guns.modular.system.util.DateUtil;
|
import com.dsh.guns.modular.system.util.ExcelUtil;
|
import com.dsh.guns.modular.system.util.QRCodeUtils;
|
import com.dsh.guns.modular.system.util.ResultUtil;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.awt.image.BufferedImage;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipOutputStream;
|
|
/**
|
* @author zhibing.pu
|
* @Date 2024/3/2 10:40
|
*/
|
@Controller
|
@RequestMapping("/worldCup")
|
public class WorldCupController {
|
|
private String PREFIX = "/system/worldCup/";
|
|
@Resource
|
private WorldCupClient worldCupClient;
|
|
@Resource
|
private WorldCupStoreClient worldCupStoreClient;
|
|
@Autowired
|
private IStoreService storeService;
|
|
|
/**
|
* 跳转列表页
|
* @return
|
*/
|
@RequestMapping("")
|
public String showWorldCupList(){
|
return PREFIX + "worldCup.html";
|
}
|
|
/**
|
* 跳转到添加页
|
* @return
|
*/
|
@RequestMapping("/openAddWorldCup")
|
public String openAddWorldCup(){
|
return PREFIX + "worldCup_add.html";
|
}
|
|
|
@RequestMapping("/openEditWorldCup")
|
public String openEditWorldCup(Model model, Integer id){
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
WorldCup worldCup = worldCupClient.getWorldCupById(id);
|
model.addAttribute("item", worldCup);
|
model.addAttribute("startTime", sdf.format(worldCup.getStartTime()));
|
model.addAttribute("endTime", sdf.format(worldCup.getEndTime()));
|
model.addAttribute("registrationClosingTime", null != worldCup.getRegistrationClosingTime() ? sdf.format(worldCup.getRegistrationClosingTime()) : "");
|
List<WorldCupStore> worldCupStoreAllList = worldCupStoreClient.getWorldCupStoreAllList(id);
|
List<Integer> collect = worldCupStoreAllList.stream().map(WorldCupStore::getStoreId).collect(Collectors.toList());
|
List<Map<String, Object>> mapList = storeService.listStoreAllByIds(collect);
|
model.addAttribute("stores", JSON.toJSONString(mapList));
|
return PREFIX + "worldCup_edit.html";
|
}
|
|
|
@RequestMapping("/openInfoWorldCup")
|
public String openInfoWorldCup(Model model, Integer id){
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
WorldCup worldCup = worldCupClient.getWorldCupById(id);
|
model.addAttribute("item", worldCup);
|
model.addAttribute("startTime", sdf.format(worldCup.getStartTime()));
|
model.addAttribute("endTime", sdf.format(worldCup.getEndTime()));
|
model.addAttribute("registrationClosingTime", null != worldCup.getRegistrationClosingTime() ? sdf.format(worldCup.getRegistrationClosingTime()) : "");
|
List<WorldCupStore> worldCupStoreAllList = worldCupStoreClient.getWorldCupStoreAllList(id);
|
List<Integer> collect = worldCupStoreAllList.stream().map(WorldCupStore::getStoreId).collect(Collectors.toList());
|
List<Map<String, Object>> mapList = storeService.listStoreAllByIds(collect);
|
model.addAttribute("stores", JSON.toJSONString(mapList));
|
return PREFIX + "worldCup_info.html";
|
}
|
|
|
/**
|
* 跳转到已报名人员列表
|
* @param model
|
* @param id
|
* @return
|
*/
|
@RequestMapping("/openRegisteredPersonnel")
|
public String openRegisteredPersonnel(Model model, Integer id){
|
model.addAttribute("id", id);
|
return PREFIX + "registeredPersonnel.html";
|
}
|
|
|
|
/**
|
* 跳转到门店选择页面
|
* @return
|
*/
|
@RequestMapping("/openStore")
|
public String openStore(){
|
return PREFIX + "store.html";
|
}
|
|
|
|
|
|
/**
|
* 获取列表数据
|
* @param worldCupList
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/listAll")
|
public Object listAll(WorldCupListAll worldCupList){
|
return worldCupClient.getWorldCupListAll(worldCupList);
|
}
|
|
|
/**
|
* 添加社区世界杯
|
* @param worldCup
|
* @param stores
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/addWorldCup")
|
public ResultUtil addWorldCup(WorldCup worldCup, String stores){
|
if(worldCup.getStartTime().before(new Date())){
|
worldCup.setStatus(2);
|
}else{
|
worldCup.setStatus(1);
|
}
|
worldCup.setCreateTime(new Date());
|
worldCup.setMatchNumber(0);
|
Integer integer = worldCupClient.addWorldCup(worldCup);
|
if(null != integer){
|
JSONArray jsonArray = JSON.parseArray(stores);
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Integer id = jsonObject.getInteger("id");
|
WorldCupStore worldCupStore = new WorldCupStore();
|
worldCupStore.setStoreId(id);
|
worldCupStore.setWorldCupId(integer);
|
worldCupStore.setIsOpen(0);
|
worldCupStoreClient.addWorldCupStore(worldCupStore);
|
}
|
}
|
return ResultUtil.success();
|
}
|
|
|
|
/**
|
* 编辑社区世界杯
|
* @param worldCup
|
* @param stores
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/editWorldCup")
|
public ResultUtil editWorldCup(WorldCup worldCup, String stores){
|
WorldCup worldCup1 = worldCupClient.getWorldCupById(worldCup.getId());
|
if(worldCup1.getStartTime().before(DateUtil.getDate())){
|
return ResultUtil.error("赛事已开始,不能编辑");
|
}
|
Integer maxPeople = worldCup1.getMaxPeople();
|
int registeredNumber = worldCupClient.getRegisteredNumber(worldCup.getId());
|
if(maxPeople.compareTo(registeredNumber) < 0){
|
return ResultUtil.error("报名人数不能小于已报名人数");
|
}
|
if(worldCup.getStartTime().before(new Date())){
|
worldCup.setStatus(2);
|
}else{
|
worldCup.setStatus(1);
|
}
|
worldCupClient.editWorldCup(worldCup);
|
worldCupStoreClient.delWorldCupStore(worldCup.getId());
|
JSONArray jsonArray = JSON.parseArray(stores);
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Integer id = jsonObject.getInteger("id");
|
WorldCupStore worldCupStore = new WorldCupStore();
|
worldCupStore.setStoreId(id);
|
worldCupStore.setWorldCupId(worldCup.getId());
|
worldCupStore.setIsOpen(0);
|
worldCupStoreClient.addWorldCupStore(worldCupStore);
|
}
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 修改赛事状态
|
* @param id
|
* @param state
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/updateState")
|
public ResultUtil updateState(Integer id, Integer state){
|
WorldCup worldCup = new WorldCup();
|
worldCup.setId(id);
|
worldCup.setStatus(state);
|
worldCupClient.editWorldCup(worldCup);
|
//开始处理已支付的退费
|
worldCupClient.cancelWorldCupRefund(id);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取已报名人员列表
|
* @param registeredPersonnel
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/registeredPersonnel")
|
public Object registeredPersonnel(RegisteredPersonnel registeredPersonnel){
|
return worldCupClient.getRegisteredPersonnel(registeredPersonnel);
|
}
|
|
|
/**
|
* 下载二维码压缩包
|
* @param registeredPersonnel
|
* @param response
|
*/
|
@ResponseBody
|
@GetMapping("/downloadQRCodeZip")
|
public void downloadQRCodeZip(RegisteredPersonnel registeredPersonnel, HttpServletResponse response){
|
try {
|
registeredPersonnel.setOffset(0);
|
registeredPersonnel.setLimit(10000);
|
Map<String, Object> maps = worldCupClient.getRegisteredPersonnel(registeredPersonnel);
|
List<Map<String, Object>> list = (List<Map<String, Object>>)maps.get("rows");
|
response.setContentType("APPLICATION/OCTET-STREAM");
|
response.setHeader("Content-Disposition","attachment; filename=" + URLEncoder.encode("二维码", "UTF-8") + ".zip");
|
ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
|
for(Map<String, Object> map : list){
|
String id = map.get("id").toString();
|
String isStudent = map.get("isStudent").toString();
|
String name = map.get("name").toString();
|
QRCodeUtils.encode("{\"id\":" + id + ",\"isStudent\":" + isStudent + "}", name, "/usr/playpai/qrcode", false);
|
File file = new File("/usr/playpai/qrcode/" + name + ".jpg");
|
FileInputStream fileInputStream = new FileInputStream(file);
|
|
out.putNextEntry(new ZipEntry(name + ".jpg"));
|
int len = 0;
|
byte[] buf = new byte[1024];
|
while ((len = fileInputStream.read(buf, 0, 1024)) != -1) {
|
out.write(buf, 0, len);
|
}
|
fileInputStream.close();
|
}
|
out.finish();
|
out.close();
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 下载已报名人员
|
* @param registeredPersonnel
|
* @param response
|
*/
|
@ResponseBody
|
@GetMapping("/exportPersonnel")
|
public void exportPersonnel(RegisteredPersonnel registeredPersonnel, HttpServletResponse response){
|
try {
|
Date date = new Date();
|
DateFormat format = new SimpleDateFormat("yyyyMMdd");
|
String time1 = format.format(date);
|
String fileName ="已报名人员.xls";
|
String[] title = new String[] {"姓名","性别","年龄","联系电话","身份证号","状态"};
|
registeredPersonnel.setOffset(0);
|
registeredPersonnel.setLimit(10000);
|
Map<String, Object> maps = worldCupClient.getRegisteredPersonnel(registeredPersonnel);
|
List<Map<String, Object>> list = (List<Map<String, Object>>)maps.get("rows");
|
String[][] values = new String[list.size()][];
|
for (int i = 0; i < list.size(); i++) {
|
Map<String, Object> d = list.get(i);
|
values[i] = new String[title.length];
|
values[i][0] = d.get("name").toString();
|
values[i][1] = d.get("gender").toString();
|
values[i][2] = d.get("age").toString();
|
values[i][3] = d.get("phone").toString();
|
values[i][4] = d.get("idcard").toString();
|
Integer state1 = Integer.valueOf(d.get("state").toString());
|
if(1 == state1){
|
values[i][5] = "正常";
|
}else {
|
values[i][5] = "取消";
|
}
|
}
|
HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
|
ExcelUtil.setResponseHeader(response, fileName);
|
OutputStream os = response.getOutputStream();
|
wb.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|