feat:验证码(选择图形验证码)接口开发

This commit is contained in:
xiang
2025-09-04 23:06:30 +08:00
parent 95252f3775
commit c0080ddec7
19 changed files with 637 additions and 51 deletions

View File

@@ -0,0 +1,15 @@
package com.xiang.xservice.auth.api.dto.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CaptchaImageRequest {
private String username;
private Integer number;
}

View File

@@ -0,0 +1,24 @@
package com.xiang.xservice.auth.api.dto.resp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CaptchaDTO {
/**
* 图片验证码url集合
*/
private List<XCaptchaImageDTO> captchaCode;
/**
* 正确的图片id集合
*/
private List<Long> captchaIds;
private String questions;
private String captchaImageCode;
}

View File

@@ -0,0 +1,25 @@
package com.xiang.xservice.auth.api.dto.resp;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class XCaptchaImageDTO {
/**
* 主键id
*/
private Long id;
/**
* 类型id
*/
private Long typeId;
/**
* 图片地址url
*/
private String imageUrl;
}

View File

@@ -1,41 +0,0 @@
package com.xiang.xservice.auth.server.controller;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
import com.xiang.xservice.auth.service.service.CaptchaGenerateFactory;
import com.xiang.xservice.basic.common.resp.Result;
import com.xiang.xservice.basic.utils.RandomCodeUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequiredArgsConstructor
public class CaptchaImageController {
private final CaptchaGenerateFactory captchaGenerateFactory;
@PostMapping("/public/captchaImage")
public Result<String> getCaptchaImage() {
try {
String randomCode = RandomCodeUtils.getNumberRandomCode(1);
String captchaImage;
if (StringUtils.isBlank(randomCode)) {
captchaImage = captchaGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage();
} else {
try {
int i = Integer.parseInt(randomCode);
captchaImage = captchaGenerateFactory.get(i).getCaptchaImage();
} catch (Exception e) {
captchaImage = captchaGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage();
}
}
return Result.success(captchaImage);
} catch (Exception e) {
log.error("获取验证码失败", e);
}
return Result.error();
}
}

View File

@@ -0,0 +1,59 @@
package com.xiang.xservice.auth.server.controller;
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
import com.xiang.xservice.auth.service.service.ValidCodeGenerateFactory;
import com.xiang.xservice.basic.common.resp.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
@Slf4j
@RestController
@RequiredArgsConstructor
public class ValidationCodeController {
private final ValidCodeGenerateFactory validCodeGenerateFactory;
@PostMapping("/public/captchaImage")
public Result<CaptchaDTO> getCaptchaImage(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
try {
// String randomCode = RandomCodeUtils.getNumberRandomCode(1);
String randomCode = "1";
CaptchaDTO captchaImage;
if (StringUtils.isBlank(randomCode)) {
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
} else {
try {
int i = Integer.parseInt(randomCode);
captchaImage = validCodeGenerateFactory.get(i).getCaptchaImage(request);
} catch (Exception e) {
log.error("获取验证码失败,获取默认验证码", e);
captchaImage = validCodeGenerateFactory.get(CaptchaTypeEnum.NORMAL_CAPTCHA_IMAGE.getType()).getCaptchaImage(request);
}
}
return Result.success(captchaImage);
} catch (Exception e) {
log.error("获取验证码失败", e);
}
return Result.error();
}
@PostMapping("/public/getSmsCode")
public Result<Void> getSmsCode(@RequestBody @NotNull(message = "请求参数不能为空") @Valid CaptchaImageRequest request) {
try {
validCodeGenerateFactory.get(CaptchaTypeEnum.NUMBER_CAPTCHA_CODE.getType()).getCaptchaImage(request);
return Result.success();
} catch (Exception e) {
log.error("获取验证码失败", e);
}
return Result.error();
}
}

View File

@@ -3,4 +3,6 @@ package com.xiang.xservice.auth.service.constants;
public class RedisConstant { public class RedisConstant {
public static final String XS_PERMISSION_ROLE = "auth:permission:role"; public static final String XS_PERMISSION_ROLE = "auth:permission:role";
public static final String XS_SMS_CODE_KEY = "auth:sms:code:key:";
public static final String XS_CAPTCHA_CODE_KEY = "auth:captcha:code:key:";
} }

View File

@@ -0,0 +1,17 @@
package com.xiang.xservice.auth.service.convert;
import com.xiang.xservice.auth.api.dto.resp.XCaptchaImageDTO;
import com.xiang.xservice.auth.service.entity.XCaptchaImage;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper(componentModel = "spring")
public interface XCaptchaImageConvert {
XDeptConvert INSTANCE = Mappers.getMapper(XDeptConvert.class);
XCaptchaImageDTO toDTO(XCaptchaImage captchaImage);
List<XCaptchaImageDTO> toDTOList(List<XCaptchaImage> captchaImage);
}

View File

@@ -0,0 +1,57 @@
package com.xiang.xservice.auth.service.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class XCaptchaImage implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
private Long id;
/**
* 类型id
*/
private Long typeId;
/**
* 图片地址url
*/
private String imageUrl;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 创建人
*/
private String createBy;
/**
* 是否删除0否 1
*/
private Integer delFlag;
/**
* 修改时间
*/
private LocalDateTime updateTime;
/**
* 修改人
*/
private String updateBy;
}

View File

@@ -0,0 +1,62 @@
package com.xiang.xservice.auth.service.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class XCaptchaType implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键id
*/
private Long id;
/**
* 图片类型
*/
private Integer imageType;
/**
* 类型名称
*/
private String typeName;
/**
* 状态0禁用1启用
*/
private Integer status;
/**
* 创建人
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 修改人
*/
private String updateBy;
/**
* 修改时间
*/
private LocalDateTime updateTime;
/**
* 删除标识(0未删除 1已删除)
*/
private Integer delFlag;
}

View File

@@ -7,8 +7,9 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum CaptchaTypeEnum { public enum CaptchaTypeEnum {
NORMAL_CAPTCHA_IMAGE(1, "图形验证码"), NUMBER_CAPTCHA_CODE(-1, "数字验证码"),
NORMAL_CAPTCHA_IMAGE(0, "图形验证码"),
IMAGE_CAPTCHA_CHOOSE(1, "图形选择验证码")
; ;
private final Integer type; private final Integer type;

View File

@@ -0,0 +1,15 @@
package com.xiang.xservice.auth.service.repository.mapper;
import com.xiang.xservice.auth.service.entity.XCaptchaImage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Mapper
public interface XCaptchaImageMapper {
List<XCaptchaImage> getByTypeId(@Param("typeId") Long typeId);
}

View File

@@ -0,0 +1,16 @@
package com.xiang.xservice.auth.service.repository.mapper;
import com.xiang.xservice.auth.service.entity.XCaptchaType;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@Mapper
public interface XCaptchaTypeMapper {
List<XCaptchaType> getCaptchaTypeList(XCaptchaType xCaptchaType);
List<XCaptchaType> getAllAvailableCaptchaTypeList();
}

View File

@@ -1,10 +1,12 @@
package com.xiang.xservice.auth.service.service; package com.xiang.xservice.auth.service.service;
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum; import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
public interface ICaptchaService { public interface ICaptchaService {
String getCaptchaImage(); CaptchaDTO getCaptchaImage(CaptchaImageRequest request);
CaptchaTypeEnum getCaptchaType(); CaptchaTypeEnum getCaptchaType();
} }

View File

@@ -9,11 +9,11 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
@Component @Component
public class CaptchaGenerateFactory { public class ValidCodeGenerateFactory {
private final Map<Integer, ICaptchaService> strategies = Maps.newConcurrentMap(); private final Map<Integer, ICaptchaService> strategies = Maps.newConcurrentMap();
public CaptchaGenerateFactory(List<ICaptchaService> strategyList) { public ValidCodeGenerateFactory(List<ICaptchaService> strategyList) {
for (ICaptchaService captchaService : strategyList) { for (ICaptchaService captchaService : strategyList) {
strategies.put(captchaService.getCaptchaType().getType(), captchaService); strategies.put(captchaService.getCaptchaType().getType(), captchaService);
} }

View File

@@ -0,0 +1,75 @@
package com.xiang.xservice.auth.service.service.impl.captcha;
import com.google.common.collect.Lists;
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
import com.xiang.xservice.auth.service.convert.XCaptchaImageConvert;
import com.xiang.xservice.auth.service.entity.XCaptchaImage;
import com.xiang.xservice.auth.service.entity.XCaptchaType;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
import com.xiang.xservice.auth.service.repository.mapper.XCaptchaImageMapper;
import com.xiang.xservice.auth.service.repository.mapper.XCaptchaTypeMapper;
import com.xiang.xservice.auth.service.service.ICaptchaService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class ImageChooseCaptcha implements ICaptchaService {
private final XCaptchaTypeMapper captchaTypeMapper;
private final XCaptchaImageMapper captchaImageMapper;
private final XCaptchaImageConvert captchaImageConvert;
@Override
public CaptchaDTO getCaptchaImage(CaptchaImageRequest request) {
CaptchaDTO captchaDTO = new CaptchaDTO();
List<XCaptchaType> typeList = captchaTypeMapper.getAllAvailableCaptchaTypeList();
Map<Long, XCaptchaType> typeMap = typeList.stream().collect(Collectors.toMap(XCaptchaType::getId, Function.identity(), (a, b) -> a));
if (CollectionUtils.isNotEmpty(typeList)) {
List<Long> types = new java.util.ArrayList<>(typeList.stream().map(XCaptchaType::getId).distinct().toList());
Collections.shuffle(types);
List<XCaptchaImage> result = Lists.newArrayList();
// 第一组
Long type = types.get(0);
XCaptchaType captchaType = typeMap.get(type);
String question = "请选择所有" + captchaType.getTypeName();
// 问题
captchaDTO.setQuestions(question);
List<XCaptchaImage> captchaImages = buildCaptchaMap(type, result);
List<Long> captchaIds = captchaImages.stream().map(XCaptchaImage::getId).toList();
// 正确的图片id集合
captchaDTO.setCaptchaIds(captchaIds);
type = types.get(1);
buildCaptchaMap(type, result);
type = types.get(2);
buildCaptchaMap(type, result);
Collections.shuffle(result);
// 所有的验证码集合
captchaDTO.setCaptchaCode(captchaImageConvert.toDTOList(result));
}
return captchaDTO;
}
private List<XCaptchaImage> buildCaptchaMap(Long type, List<XCaptchaImage> result) {
List<XCaptchaImage> images = captchaImageMapper.getByTypeId(type);
Collections.shuffle(images);
images = images.subList(0, 2);
result.addAll(images);
return images;
}
@Override
public CaptchaTypeEnum getCaptchaType() {
return CaptchaTypeEnum.IMAGE_CAPTCHA_CHOOSE;
}
}

View File

@@ -1,5 +1,8 @@
package com.xiang.xservice.auth.service.service.impl.captcha; package com.xiang.xservice.auth.service.service.impl.captcha;
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
import com.xiang.xservice.auth.service.constants.RedisConstant;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum; import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
import com.xiang.xservice.auth.service.service.ICaptchaService; import com.xiang.xservice.auth.service.service.ICaptchaService;
import com.xiang.xservice.basic.utils.RandomCodeUtils; import com.xiang.xservice.basic.utils.RandomCodeUtils;
@@ -15,6 +18,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Base64; import java.util.Base64;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
@Service @Service
@@ -27,11 +31,10 @@ public class NormalCaptchaImage implements ICaptchaService {
private static final int WIDTH = 160;// 宽 private static final int WIDTH = 160;// 宽
private static final int HEIGHT = 40;// 高 private static final int HEIGHT = 40;// 高
private static final int LINE_SIZE = 30;// 干扰线数量 private static final int LINE_SIZE = 30;// 干扰线数量
private static final int STRING_NUMBER = 4;//随机产生字符的个数
@Override @Override
public String getCaptchaImage() { public CaptchaDTO getCaptchaImage(CaptchaImageRequest request) {
// BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类 // BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_BGR); BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_BGR);
Graphics g = image.getGraphics(); Graphics g = image.getGraphics();
@@ -44,11 +47,13 @@ public class NormalCaptchaImage implements ICaptchaService {
drawLine(g); drawLine(g);
} }
String randomCode = ""; String randomCode = "";
CaptchaDTO captchaDTO = new CaptchaDTO();
// 绘制随机字符 // 绘制随机字符
for (int i = 0; i < STRING_NUMBER; i++) { for (int i = 0; i < request.getNumber(); i++) {
randomCode = drawString(g, randomCode, i); randomCode = drawString(g, randomCode, i);
} }
log.info("生成的随机验证码:{}", randomCode); log.info("生成的随机验证码:{}", randomCode);
redisService.set(RedisConstant.XS_CAPTCHA_CODE_KEY + request.getUsername(), randomCode, 5, TimeUnit.MINUTES);
g.dispose(); g.dispose();
String base64String = ""; String base64String = "";
@@ -60,11 +65,12 @@ public class NormalCaptchaImage implements ICaptchaService {
byte[] bytes = bos.toByteArray(); byte[] bytes = bos.toByteArray();
Base64.Encoder encoder = Base64.getEncoder(); Base64.Encoder encoder = Base64.getEncoder();
base64String = encoder.encodeToString(bytes); base64String = encoder.encodeToString(bytes);
return base64String; captchaDTO.setCaptchaImageCode(base64String);
return captchaDTO;
} catch (IOException e) { } catch (IOException e) {
log.error("IO异常验证码异常", e); log.error("IO异常验证码异常", e);
} }
return base64String; return captchaDTO;
} }
@Override @Override

View File

@@ -0,0 +1,33 @@
package com.xiang.xservice.auth.service.service.impl.captcha;
import com.xiang.xservice.auth.api.dto.req.CaptchaImageRequest;
import com.xiang.xservice.auth.api.dto.resp.CaptchaDTO;
import com.xiang.xservice.auth.service.constants.RedisConstant;
import com.xiang.xservice.auth.service.enums.CaptchaTypeEnum;
import com.xiang.xservice.auth.service.service.ICaptchaService;
import com.xiang.xservice.basic.utils.RandomCodeUtils;
import com.xiang.xservice.cache.service.IRedisService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@Service
@RequiredArgsConstructor
public class NumberCaptchaCode implements ICaptchaService {
private final IRedisService redisService;
@Override
public CaptchaDTO getCaptchaImage(CaptchaImageRequest request) {
String randomCode = RandomCodeUtils.getMixtureRandomCode(request.getNumber());
redisService.set(RedisConstant.XS_SMS_CODE_KEY + request.getUsername(), randomCode, 5, TimeUnit.MINUTES);
CaptchaDTO captchaDTO = new CaptchaDTO();
captchaDTO.setCaptchaImageCode(randomCode);
return captchaDTO;
}
@Override
public CaptchaTypeEnum getCaptchaType() {
return CaptchaTypeEnum.NUMBER_CAPTCHA_CODE;
}
}

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XCaptchaImageMapper">
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XCaptchaImage" >
<result column="id" property="id" />
<result column="type_id" property="typeId" />
<result column="image_url" property="imageUrl" />
<result column="create_time" property="createTime" />
<result column="create_by" property="createBy" />
<result column="del_flag" property="delFlag" />
<result column="update_time" property="updateTime" />
<result column="update_by" property="updateBy" />
</resultMap>
<sql id="Base_Column_List">
id,
type_id,
image_url,
create_time,
create_by,
del_flag,
update_time,
update_by
</sql>
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XCaptchaImage">
INSERT INTO x_captcha_image
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="null != typeId ">
type_id,
</if>
<if test="null != imageUrl and '' != imageUrl">
image_url,
</if>
<if test="null != createTime ">
create_time,
</if>
<if test="null != createBy and '' != createBy">
create_by,
</if>
<if test="null != delFlag ">
del_flag,
</if>
<if test="null != updateTime ">
update_time,
</if>
<if test="null != updateBy and '' != updateBy">
update_by
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="null != typeId ">
#{typeId},
</if>
<if test="null != imageUrl and '' != imageUrl">
#{imageUrl},
</if>
<if test="null != createTime ">
#{createTime},
</if>
<if test="null != createBy and '' != createBy">
#{createBy},
</if>
<if test="null != delFlag ">
#{delFlag},
</if>
<if test="null != updateTime ">
#{updateTime},
</if>
<if test="null != updateBy and '' != updateBy">
#{updateBy}
</if>
</trim>
</insert>
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XCaptchaImage">
UPDATE x_captcha_image
<set>
<if test="null != typeId ">type_id = #{typeId},</if>
<if test="null != imageUrl and '' != imageUrl">image_url = #{imageUrl},</if>
<if test="null != createTime ">create_time = #{createTime},</if>
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
<if test="null != delFlag ">del_flag = #{delFlag},</if>
<if test="null != updateTime ">update_time = #{updateTime},</if>
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy}</if>
</set>
WHERE id = #{id}
</update>
<select id="getByTypeId" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from x_captcha_image where del_flag = 0 and type_id = #{typeId}
</select>
</mapper>

View File

@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XCaptchaTypeMapper">
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XCaptchaType" >
<result column="id" property="id" />
<result column="image_type" property="imageType" />
<result column="type_name" property="typeName" />
<result column="status" property="status" />
<result column="create_by" property="createBy" />
<result column="create_time" property="createTime" />
<result column="update_by" property="updateBy" />
<result column="update_time" property="updateTime" />
<result column="del_flag" property="delFlag" />
</resultMap>
<sql id="Base_Column_List">
id,
image_type,
type_name,
status,
create_by,
create_time,
update_by,
update_time,
del_flag
</sql>
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XCaptchaType">
INSERT INTO x_captcha_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="null != imageType ">
image_type,
</if>
<if test="null != typeName and '' != typeName">
type_name,
</if>
<if test="null != status ">
status,
</if>
<if test="null != createBy and '' != createBy">
create_by,
</if>
<if test="null != createTime ">
create_time,
</if>
<if test="null != updateBy and '' != updateBy">
update_by,
</if>
<if test="null != updateTime ">
update_time,
</if>
<if test="null != delFlag ">
del_flag
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="null != imageType ">
#{imageType},
</if>
<if test="null != typeName and '' != typeName">
#{typeName},
</if>
<if test="null != status ">
#{status},
</if>
<if test="null != createBy and '' != createBy">
#{createBy},
</if>
<if test="null != createTime ">
#{createTime},
</if>
<if test="null != updateBy and '' != updateBy">
#{updateBy},
</if>
<if test="null != updateTime ">
#{updateTime},
</if>
<if test="null != delFlag ">
#{delFlag}
</if>
</trim>
</insert>
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XCaptchaType">
UPDATE x_captcha_type
<set>
<if test="null != imageType ">image_type = #{imageType},</if>
<if test="null != typeName and '' != typeName">type_name = #{typeName},</if>
<if test="null != status ">status = #{status},</if>
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
<if test="null != createTime ">create_time = #{createTime},</if>
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
<if test="null != updateTime ">update_time = #{updateTime},</if>
<if test="null != delFlag ">del_flag = #{delFlag}</if>
</set>
WHERE id = #{id}
</update>
<select id="getCaptchaTypeList" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from x_captcha_type
<trim prefix="AND">
<where>
status = 1 and del_flag = 0
<if test="imageType != null">and image_type = #{imageType}</if>
<if test="typeName != null and typeName != ''">and type_name = #{typeName}</if>
</where>
</trim>
</select>
<select id="getAllAvailableCaptchaTypeList" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from x_captcha_type
where status = 1 and del_flag = 0
<trim prefix="AND">
<if test="imageType != null">and image_type = #{imageType}</if>
<if test="typeName != null and typeName != ''">and type_name = #{typeName}</if>
</trim>
</select>
</mapper>