| | |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.WebDataBinder; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.web.bind.annotation.InitBinder; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | import javax.jws.soap.SOAPBinding; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.OutputStream; |
| | | import java.beans.PropertyEditorSupport; |
| | | import java.text.DateFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | private ICityService cityService; |
| | | |
| | | /** |
| | | * 导出赛事已报名用户列表 |
| | | * 兼容活动表单提交的日期时间格式。 |
| | | * |
| | | * @param binder Spring Web 数据绑定器 |
| | | */ |
| | | @InitBinder |
| | | public void initCompetitionDateBinder(WebDataBinder binder) { |
| | | binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { |
| | | @Override |
| | | public void setAsText(String text) throws IllegalArgumentException { |
| | | if (ToolUtil.isEmpty(text)) { |
| | | setValue(null); |
| | | return; |
| | | } |
| | | Date parsedDate = parseCompetitionDate(text); |
| | | if (parsedDate == null) { |
| | | throw new IllegalArgumentException("日期格式应为yyyy-MM-dd HH:mm或yyyy-MM-dd"); |
| | | } |
| | | setValue(parsedDate); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 将活动表单日期文本解析为日期对象。 |
| | | * |
| | | * @param value 日期文本 |
| | | * @return 解析后的日期;格式不匹配时返回 {@code null} |
| | | */ |
| | | private Date parseCompetitionDate(String value) { |
| | | String[] patterns = {"yyyy-MM-dd HH:mm", "yyyy-MM-dd"}; |
| | | for (String pattern : patterns) { |
| | | try { |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); |
| | | dateFormat.setLenient(false); |
| | | return dateFormat.parse(value); |
| | | } catch (ParseException ignored) { |
| | | // 尝试下一个约定格式。 |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 导出活动已报名用户列表 |
| | | */ |
| | | |
| | | @RequestMapping(value = "/export") |
| | |
| | | DateFormat format = new SimpleDateFormat("yyyyMMdd"); |
| | | String time1 = format.format(date); |
| | | String fileName =name+"报名信息.xls"; |
| | | String[] title = new String[] {"姓名","性别","联系电话","身份证号","状态"}; |
| | | String[] title = new String[] {"姓名","性别","注册电话","联系电话","身份证号","状态"}; |
| | | GetPeopleQuery query = new GetPeopleQuery(); |
| | | query.setId(id); |
| | | query.setState(state); |
| | | List<CompetitionUser> list = competitionClient.getPeoples(query); |
| | | // todo 临时处理 因为只能更新后台 |
| | | Page<CompetitionUser> page = competitionClient.getPeopleFromId1(new GetPeopleQuery(999, 0, id, state)); |
| | | List<CompetitionUser> list = page.getRecords(); |
| | | // List<CompetitionUser> list = competitionClient.getPeoples(query); |
| | | System.err.println("导出查询人员列表"+ list); |
| | | String[][] values = new String[list.size()][]; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CompetitionUser d = list.get(i); |
| | |
| | | }else { |
| | | values[i][1] = "未知"; |
| | | } |
| | | values[i][2] = d.getPhone(); |
| | | values[i][3] = d.getIdCard(); |
| | | values[i][2] = d.getRegisterPhone(); |
| | | |
| | | values[i][3] = d.getPhone(); |
| | | values[i][4] = d.getIdCard(); |
| | | Integer state1 = d.getState(); |
| | | if(1 == state1){ |
| | | values[i][4] = "正常"; |
| | | values[i][5] = "正常"; |
| | | }else if(2 == state1){ |
| | | values[i][4] = "冻结"; |
| | | values[i][5] = "正常"; |
| | | }else { |
| | | values[i][4] = "删除"; |
| | | values[i][5] = "已取消"; |
| | | } |
| | | } |
| | | HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null); |