提交 2fbfce0c 编写于 作者: wenhao.qin's avatar wenhao.qin

代码参数校验优化

上级 47b7f3ef
流水线 #42909 已失败 于阶段
...@@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -6,6 +6,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import javax.validation.constraints.Max;
/** /**
* @Author qinwh * @Author qinwh
* @Date 2022/3/1 20:27 * @Date 2022/3/1 20:27
...@@ -13,11 +15,17 @@ import org.hibernate.validator.constraints.NotBlank; ...@@ -13,11 +15,17 @@ import org.hibernate.validator.constraints.NotBlank;
@Data @Data
@ApiModel @ApiModel
public class HospitalRoleDetailReq { public class HospitalRoleDetailReq {
@ApiModelProperty("角色id") @ApiModelProperty("角色id")
private Long id; private Long id;
@ApiModelProperty("角色name")
@ApiModelProperty("角色名称")
@NotBlank(message = "角色名称不能为空") @NotBlank(message = "角色名称不能为空")
@Max(value = 16, message = "角色名称长度≤16字符")
private String name; private String name;
@ApiModelProperty("角色描述") @ApiModelProperty("角色描述")
@Max(value = 100, message = "描述长度≤100字符")
private String remark; private String remark;
} }
...@@ -7,12 +7,10 @@ import com.pica.cloud.foundation.utils.utils.ValidateUtils; ...@@ -7,12 +7,10 @@ import com.pica.cloud.foundation.utils.utils.ValidateUtils;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.NonNull;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.NotBlank;
import javax.validation.constraints.Max; import java.util.Objects;
import javax.validation.constraints.Pattern; import java.util.regex.Pattern;
/** /**
...@@ -60,9 +58,6 @@ public class HospitalSaasUserReq { ...@@ -60,9 +58,6 @@ public class HospitalSaasUserReq {
if (StringUtils.isBlank(this.password)) { if (StringUtils.isBlank(this.password)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "密码不能为空"); throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "密码不能为空");
} }
// if (null == this.roleId) {
// throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "角色id不能为空");
// }
if (this.name.length() > 16) { if (this.name.length() > 16) {
throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "姓名长度必须≤16字符!"); throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "姓名长度必须≤16字符!");
} }
...@@ -75,5 +70,12 @@ public class HospitalSaasUserReq { ...@@ -75,5 +70,12 @@ public class HospitalSaasUserReq {
if (null == this.sourceType) { if (null == this.sourceType) {
throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "资源类型不能为空!"); throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "资源类型不能为空!");
} }
if (!Pattern.matches("^[A-Za-z0-9]{5,10}$", this.password)) {
throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "密码需由6-10位字母或数字组成!");
}
if (Objects.nonNull(this.comment) && this.comment.length() > 100) {
throw new PicaWarnException(AccountExceptionEnum.PICA_NOT_EMPTY.getCode(), "备注长度须≤100字符");
}
} }
} }
...@@ -32,14 +32,19 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService { ...@@ -32,14 +32,19 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService {
@Override @Override
public int insertAndModify(HospitalRoleDetailReq req, PicaUser user) { public int insertAndModify(HospitalRoleDetailReq req, PicaUser user) {
if (Objects.nonNull(req.getId()) && (req.getId() == 1 || req.getId() == 2 || req.getId() == 3)) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), "该角色无法删除");
}
int num; int num;
PermissionRole role = new PermissionRole(); PermissionRole role = new PermissionRole();
role.setRoleName(req.getName()); role.setRoleName(req.getName());
PermissionRole byNameCode = permissionRoleMapper.selectByNameCode(role); PermissionRole byNameCode = permissionRoleMapper.selectByNameCode(role);
if (null != byNameCode) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), "该角色重复");
}
if (null != req.getId()) { if (null != req.getId()) {
if (null != byNameCode && !byNameCode.getId().equals(req.getId())) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getMessage());
}
role.setId(req.getId()); role.setId(req.getId());
role.setRoleName(req.getName()); role.setRoleName(req.getName());
role.setRemark(req.getRemark()); role.setRemark(req.getRemark());
...@@ -47,9 +52,6 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService { ...@@ -47,9 +52,6 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService {
role.setModifiedTime(new Date()); role.setModifiedTime(new Date());
num = permissionRoleMapper.updateByPrimaryKeySelective(role); num = permissionRoleMapper.updateByPrimaryKeySelective(role);
} else { } else {
if (null != byNameCode) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getMessage());
}
role.setRoleCode("saas_admin" + CommonUtil.getRandom(10)); role.setRoleCode("saas_admin" + CommonUtil.getRandom(10));
role.setRemark(req.getRemark()); role.setRemark(req.getRemark());
role.setCreatedId(Long.valueOf(user.getId())); role.setCreatedId(Long.valueOf(user.getId()));
...@@ -81,6 +83,14 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService { ...@@ -81,6 +83,14 @@ public class HospitalSaasRoleServiceImpl implements HospitalSaasRoleService {
@Override @Override
@Transactional @Transactional
public int delete(Long id, PicaUser user) { public int delete(Long id, PicaUser user) {
if (id == null || id == 0L) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), "请输入角色id");
}
if (id == 1 || id == 2 || id == 3) {
throw new PicaWarnException(AccountExceptionEnum.PAT_ACCT_HAS_EXIST.getCode(), "该角色无法删除");
}
Map<String, Object> map = new HashMap<>(3); Map<String, Object> map = new HashMap<>(3);
map.put("id", id); map.put("id", id);
map.put("modifiedId", user.getId()); map.put("modifiedId", user.getId());
......
...@@ -198,21 +198,22 @@ ...@@ -198,21 +198,22 @@
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from permission_role from permission_role
where delete_flag = 1 where delete_flag = 1
<if test="roleCode != null"> <if test="roleCode != null and roleCode != '' ">
and role_code = #{roleCode} and role_code = #{roleCode}
</if> </if>
<if test="roleName != null"> <if test="roleName != null and roleName != '' ">
and role_name = #{roleName} and role_name = #{roleName}
</if> </if>
</select> </select>
<select id="selectByDoctorId" resultMap="BaseResultMap" parameterType="java.util.Map"> <select id="selectByDoctorId" resultMap="BaseResultMap" parameterType="java.util.Map">
select select r.role_code as roleCode,
r.role_code as roleCode, r.role_name as roleName r.role_name as roleName
from from permission_doctor_role dr
permission_doctor_role dr JOIN permission_role r on dr.role_id = r.id
JOIN permission_role r on dr.role_id = r.id WHERE dr.delete_flag = 1
WHERE and dr.doctor_id = 1
dr.delete_flag = 1 and dr.doctor_id = 1 AND dr.hospital_id = 2 and r.delete_flag = 1 AND dr.hospital_id = 2
and r.delete_flag = 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册