Authored by ping

update

package com.yoho.unions.common.enums;
import org.apache.commons.lang.StringUtils;
/**
* 性别枚举
* @author ping.huang
*
*/
public enum SexEnum {
FEMALE("2", "f", "女"),
MALE("1", "m", "男");
private String code;
private String name;
private String name_ch;
public String getCode() {
return code;
}
public String getName() {
return name;
}
public String getName_ch() {
return name_ch;
}
private SexEnum(String code, String name, String name_ch) {
this.code = code;
this.name = name;
this.name_ch = name_ch;
}
/**
* 根据code,获取name
* @param code
* @return
*/
public static String getNameByCode(String code) {
if (StringUtils.isEmpty(code)) {
return null;
}
for (SexEnum e : values()) {
if (code.equals(e.getCode())) {
return e.getName();
}
}
return null;
}
/**
* 根据code,获取中文name
* @param code
* @return
*/
public static String getNameCHByCode(String code) {
if (StringUtils.isEmpty(code)) {
return null;
}
for (SexEnum e : values()) {
if (code.equals(e.getCode())) {
return e.getName_ch();
}
}
return null;
}
}
... ...
... ... @@ -20,6 +20,7 @@ import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.request.DrawRequestBO;
import com.yoho.service.model.union.response.DrawInfoResponseBO;
import com.yoho.service.model.user.other.response.DrawResponseBO;
import com.yoho.unions.common.enums.SexEnum;
import com.yoho.unions.common.utils.DateUtil;
import com.yoho.unions.common.utils.RandomUtil;
import com.yoho.unions.dal.IUserBaseDAO;
... ... @@ -78,6 +79,12 @@ public class DrawServiceImpl implements DrawService {
throw new ServiceException(ServiceError.USER_NOT_EXISTS);
}
//性别的值,只能是1或2
if (SexEnum.getNameByCode(request.getGender()) == null) {
log.warn("draw error gender is error with param is {}", request);
throw new ServiceException(ServiceError.PARAM_ERROR);
}
//通用的部分,男女都有
list.addAll(pDraw);
... ...