| | |
| | | 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") |