Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
| | |
| | | <artifactId>commons-codec</artifactId> |
| | | <version>1.15</version> |
| | | </dependency> |
| | | |
| | | <!-- 图片验证码 --> |
| | | <dependency> |
| | | <groupId>com.github.penggle</groupId> |
| | | <artifactId>kaptcha</artifactId> |
| | | <version>2.3.2</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
New file |
| | |
| | | package com.dy.pipIrrGlobal.daoBa; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaCaptcha; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 10:58 |
| | | * @LastEditTime 2024-09-11 10:58 |
| | | * @Description |
| | | */ |
| | | |
| | | @Mapper |
| | | public interface BaCaptchaMapper extends BaseMapper { |
| | | int deleteByPrimaryKey(Long id); |
| | | |
| | | int insert(BaCaptcha record); |
| | | |
| | | int insertSelective(BaCaptcha record); |
| | | |
| | | BaCaptcha selectByPrimaryKey(Long id); |
| | | |
| | | int updateByPrimaryKeySelective(BaCaptcha record); |
| | | |
| | | int updateByPrimaryKey(BaCaptcha record); |
| | | |
| | | /** |
| | | * 依据验证码token获取验证字符 |
| | | * @param token |
| | | * @return |
| | | */ |
| | | Map getCodeByToken(String token); |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrGlobal.pojoBa; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 10:58 |
| | | * @LastEditTime 2024-09-11 10:58 |
| | | * @Description |
| | | */ |
| | | |
| | | import com.alibaba.fastjson2.annotation.JSONField; |
| | | import com.alibaba.fastjson2.writer.ObjectWriterImplToString; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.dy.common.po.BaseEntity; |
| | | import jakarta.validation.constraints.NotBlank; |
| | | import lombok.*; |
| | | |
| | | /** |
| | | * 图形验证记录表 |
| | | */ |
| | | |
| | | @TableName(value = "ba_captcha", autoResultMap = true) |
| | | @Data |
| | | @Builder |
| | | @ToString |
| | | @NoArgsConstructor |
| | | @AllArgsConstructor |
| | | public class BaCaptcha implements BaseEntity { |
| | | public static final long serialVersionUID = 202409111103001L; |
| | | |
| | | /** |
| | | * 主键 |
| | | */ |
| | | @JSONField(serializeUsing = ObjectWriterImplToString.class) |
| | | @TableId(type = IdType.INPUT) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 验证码token |
| | | */ |
| | | @NotBlank(message = "验证码token不能为空") |
| | | private String token; |
| | | |
| | | /** |
| | | * 验证字符 |
| | | */ |
| | | @NotBlank(message = "验证字符不能为空") |
| | | private String code; |
| | | |
| | | /** |
| | | * 过期时间 |
| | | */ |
| | | @JSONField(serializeUsing = ObjectWriterImplToString.class) |
| | | private Long expiration; |
| | | } |
| | |
| | | */ |
| | | |
| | | @Data |
| | | @JsonPropertyOrder({"cardNum", "cashierId", "villageId", "clientNum", "districtTitle", "clientName", "phone", "operateType", "tradeAmount", "waterCost", "cardCost", "gift", "refundAmount", "paymentName", "tradeTime"}) |
| | | @JsonPropertyOrder({"orderNumber", "clientName", "cardNum", "idCard", "clientNum", "phone", "operateType", "tradeAmount", "waterCost", "cardCost", "gift", "refundAmount", "money", "paymentName", "tradeTime", "cashierId", "cardState", "districtTitle", "villageId"}) |
| | | @HeadRowHeight(30) |
| | | @ContentRowHeight(20) |
| | | public class VoTradeDetails implements BaseEntity { |
| | | private static final long serialVersionUID = 202402012040001L; |
| | | |
| | | /** |
| | | * 水卡编号 |
| | | * 订单号 |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | private Long cardNum; |
| | | |
| | | /** |
| | | * 收银员ID |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ExcelIgnore |
| | | private Long cashierId; |
| | | |
| | | /** |
| | | * 村庄ID |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ExcelIgnore |
| | | private Long villageId; |
| | | |
| | | /** |
| | | * 农户编号 |
| | | */ |
| | | @ExcelIgnore |
| | | private String clientNum; |
| | | |
| | | /** |
| | | * 村庄名称 |
| | | */ |
| | | @ExcelProperty(value = {"${title}", "村庄名称"}) |
| | | @ColumnWidth(20) |
| | | private String districtTitle; |
| | | @ColumnWidth(25) |
| | | private String orderNumber; |
| | | |
| | | /** |
| | | * 农户姓名 |
| | |
| | | @ExcelProperty(value = {"${title}", "农户姓名"}) |
| | | @ColumnWidth(15) |
| | | private String clientName; |
| | | |
| | | /** |
| | | * 水卡编号 |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ColumnWidth(15) |
| | | private Long cardNum; |
| | | |
| | | /** |
| | | * 身份证号 |
| | | */ |
| | | @ColumnWidth(15) |
| | | private String idCard; |
| | | |
| | | /** |
| | | * 农户编号 |
| | | */ |
| | | //@ExcelIgnore |
| | | @ColumnWidth(15) |
| | | private String clientNum; |
| | | |
| | | /** |
| | | * 联系电话 |
| | |
| | | private Double refundAmount; |
| | | |
| | | /** |
| | | * 余额 |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ColumnWidth(15) |
| | | private Long money; |
| | | |
| | | /** |
| | | * 付款方式 |
| | | */ |
| | | @ExcelProperty(value = {"${title}", "付款方式"}) |
| | |
| | | @ColumnWidth(20) |
| | | private Date tradeTime; |
| | | |
| | | /** |
| | | * 收银员ID |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ExcelIgnore |
| | | private Long cashierId; |
| | | |
| | | /** |
| | | * 卡片状态 |
| | | */ |
| | | @ColumnWidth(15) |
| | | private String cardState; |
| | | |
| | | /** |
| | | * 村庄名称 |
| | | */ |
| | | @ExcelProperty(value = {"${title}", "村庄名称"}) |
| | | @ColumnWidth(20) |
| | | private String districtTitle; |
| | | |
| | | /** |
| | | * 村庄ID |
| | | */ |
| | | @JSONField(serializeUsing= ObjectWriterImplToString.class) |
| | | @ExcelIgnore |
| | | private Long villageId; |
| | | } |
| | |
| | | * 身份证号 |
| | | */ |
| | | private String idCard; |
| | | |
| | | /** |
| | | * 开阀次数 |
| | | */ |
| | | private Integer openCount; |
| | | } |
| | |
| | | - /sso/sso |
| | | - /remote/comRes/receive |
| | | - /wx/comRes/receive |
| | | - /app/captcha/get |
| | | #自动统计配置,自动统计定时任务会每天定时进行 |
| | | auto-statistics: |
| | | startHour: 0 #开始小时 0 |
New file |
| | |
| | | <?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.dy.pipIrrGlobal.daoBa.BaCaptchaMapper"> |
| | | <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoBa.BaCaptcha"> |
| | | <!--@mbg.generated--> |
| | | <!--@Table ba_captcha--> |
| | | <id column="id" jdbcType="BIGINT" property="id" /> |
| | | <result column="token" jdbcType="VARCHAR" property="token" /> |
| | | <result column="code" jdbcType="VARCHAR" property="code" /> |
| | | <result column="expiration" jdbcType="BIGINT" property="expiration" /> |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | <!--@mbg.generated--> |
| | | id, token, code, expiration |
| | | </sql> |
| | | <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> |
| | | <!--@mbg.generated--> |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from ba_captcha |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </select> |
| | | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
| | | <!--@mbg.generated--> |
| | | delete from ba_captcha |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </delete> |
| | | <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoBa.BaCaptcha"> |
| | | <!--@mbg.generated--> |
| | | insert into ba_captcha (id, token, code, |
| | | expiration) |
| | | values (#{id,jdbcType=BIGINT}, #{token,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, |
| | | #{expiration,jdbcType=BIGINT}) |
| | | </insert> |
| | | <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaCaptcha"> |
| | | <!--@mbg.generated--> |
| | | insert into ba_captcha |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null"> |
| | | id, |
| | | </if> |
| | | <if test="token != null"> |
| | | token, |
| | | </if> |
| | | <if test="code != null"> |
| | | code, |
| | | </if> |
| | | <if test="expiration != null"> |
| | | expiration, |
| | | </if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="id != null"> |
| | | #{id,jdbcType=BIGINT}, |
| | | </if> |
| | | <if test="token != null"> |
| | | #{token,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="code != null"> |
| | | #{code,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="expiration != null"> |
| | | #{expiration,jdbcType=BIGINT}, |
| | | </if> |
| | | </trim> |
| | | </insert> |
| | | <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoBa.BaCaptcha"> |
| | | <!--@mbg.generated--> |
| | | update ba_captcha |
| | | <set> |
| | | <if test="token != null"> |
| | | token = #{token,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="code != null"> |
| | | code = #{code,jdbcType=VARCHAR}, |
| | | </if> |
| | | <if test="expiration != null"> |
| | | expiration = #{expiration,jdbcType=BIGINT}, |
| | | </if> |
| | | </set> |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoBa.BaCaptcha"> |
| | | <!--@mbg.generated--> |
| | | update ba_captcha |
| | | set token = #{token,jdbcType=VARCHAR}, |
| | | code = #{code,jdbcType=VARCHAR}, |
| | | expiration = #{expiration,jdbcType=BIGINT} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | |
| | | <!--依据验证码token获取验证字符--> |
| | | <select id="getCodeByToken" resultType="java.util.Map"> |
| | | SELECT code, expiration FROM ba_captcha WHERE token = #{token} |
| | | </select> |
| | | </mapper> |
| | |
| | | <if test="intakeId != null and intakeId >0"> |
| | | AND oh.intake_id = #{intakeId} |
| | | </if> |
| | | <if test = "intakeName != null and intakeName !=''"> |
| | | AND inta.name LIKE CONCAT('%',#{intakeName},'%') |
| | | <if test = "intakeName != null and intakeNum !=''"> |
| | | AND inta.name LIKE CONCAT('%',#{intakeNum},'%') |
| | | </if> |
| | | <if test = "rtuAddr != null and rtuAddr !=''"> |
| | | AND oh.rtu_addr LIKE CONCAT('%',#{rtuAddr},'%') |
| | |
| | | cli.clientNum, |
| | | CONCAT(cli.districtTitle, cli.address) AS address, |
| | | cli.phone, |
| | | cli.idCard |
| | | cli.idCard, |
| | | (SELECT COUNT(*) |
| | | FROM rm_open_close_valve_history his |
| | | <where> |
| | | his.client_id = cli.id |
| | | <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''"> |
| | | AND his.op_dt BETWEEN #{timeStart} AND #{timeStop} |
| | | </if> |
| | | </where>) AS openCount |
| | | FROM se_client cli |
| | | <where> |
| | | <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != '' and openCount != null"> |
| | |
| | | cli.clientNum, |
| | | CONCAT(cli.districtTitle, cli.address) AS address, |
| | | cli.phone, |
| | | cli.idCard |
| | | cli.idCard, |
| | | (SELECT COUNT(*) |
| | | FROM rm_open_close_valve_history his |
| | | <where> |
| | | his.client_id = cli.id |
| | | <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != ''"> |
| | | AND his.op_dt BETWEEN #{timeStart} AND #{timeStop} |
| | | </if> |
| | | </where>) AS openCount |
| | | FROM se_client cli |
| | | <where> |
| | | <if test="timeStart != null and timeStart != '' and timeStop != null and timeStop != '' and openCount != null"> |
New file |
| | |
| | | package com.dy.pipIrrApp.captcha; |
| | | |
| | | import com.dy.common.multiDataSource.DataSourceContext; |
| | | import com.dy.pipIrrApp.captcha.dto.CaptchaDomain; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaCaptcha; |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.io.IOException; |
| | | import java.util.Calendar; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 13:45 |
| | | * @LastEditTime 2024-09-11 13:45 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(path="captcha") |
| | | public class CaptchaCtrl { |
| | | @Autowired |
| | | private CaptchaSV captchaSV; |
| | | |
| | | /** |
| | | * 获取验证码 |
| | | * @param type,图片类型:char-文本,math-一位数算式,math2-两位数算式 |
| | | * @return |
| | | */ |
| | | @GetMapping("/get") |
| | | @ResponseBody |
| | | public CaptchaDomain getCaptcha(HttpServletRequest request, @RequestParam(value = "type", required = false, defaultValue = "char") String type) { |
| | | // 配置数据源 |
| | | HttpServletRequest httpRequest = (HttpServletRequest) request; |
| | | String wxDataSourceName = httpRequest.getHeader("tag"); |
| | | if(wxDataSourceName != null && wxDataSourceName.trim().length() > 0){ |
| | | log.info("微信开发,设置数据源名称为:" + wxDataSourceName); |
| | | //把组织单位标签作为数据源名称 |
| | | DataSourceContext.set(wxDataSourceName); |
| | | } else { |
| | | log.info("用户未选择数据源"); |
| | | } |
| | | |
| | | // 生成验证码实体 |
| | | CaptchaDomain captchaDomain = captchaSV.createGoogleCaptcha(type); |
| | | if (null != captchaDomain) { |
| | | |
| | | // 验证码保存至redis |
| | | // redisUtils.set(captchaDomain.getToken(), captchaDomain.getCode(), 300L); |
| | | |
| | | // 验证码保存至session |
| | | //HttpSession session = (HttpSession) request.getSession(); |
| | | //session.setAttribute(captchaDomain.getToken(), captchaDomain.getCode()); |
| | | |
| | | /** |
| | | * 验证保存到数据库 |
| | | * 获取当前时间戳并延后3分钟 |
| | | */ |
| | | Long timestamp = System.currentTimeMillis(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(timestamp); |
| | | calendar.add(Calendar.SECOND, 180); |
| | | |
| | | BaCaptcha baCaptcha = new BaCaptcha(); |
| | | baCaptcha.setToken(captchaDomain.getToken()); |
| | | baCaptcha.setCode(captchaDomain.getCode()); |
| | | baCaptcha.setExpiration(calendar.getTimeInMillis()); |
| | | Long rec = captchaSV.addCaptcha(baCaptcha); |
| | | System.out.println("token: " + captchaDomain.getToken() + "; code: " + captchaDomain.getCode()); |
| | | |
| | | // 无用信息设空 |
| | | captchaDomain.setText(null); |
| | | captchaDomain.setCode(null); |
| | | // 返回前端信息 |
| | | return captchaDomain; |
| | | } else { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 直接输出图片 |
| | | * @param type,图片类型:char-文本,math-一位数算式,math2-两位数算式 |
| | | */ |
| | | @GetMapping("/get/image") |
| | | public void getCaptchaImage(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "type", required = false, defaultValue = "char") String type) { |
| | | CaptchaDomain captchaDomain = null; |
| | | |
| | | // 生成谷歌验证码实体 |
| | | captchaDomain = captchaSV.createGoogleCaptcha(type); |
| | | |
| | | // 验证码保存至redis |
| | | // redisUtils.set(captchaDomain.getToken(), captchaDomain.getCode(), 300L); |
| | | |
| | | // 验证码保存至session |
| | | //HttpSession session = (HttpSession) request.getSession(); |
| | | //session.setAttribute(captchaDomain.getToken(), captchaDomain.getCode()); |
| | | |
| | | /** |
| | | * 验证保存到数据库 |
| | | * 获取当前时间戳并延后3分钟 |
| | | */ |
| | | Long timestamp = System.currentTimeMillis(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(timestamp); |
| | | calendar.add(Calendar.SECOND, 180); |
| | | |
| | | BaCaptcha baCaptcha = new BaCaptcha(); |
| | | baCaptcha.setToken(captchaDomain.getToken()); |
| | | baCaptcha.setCode(captchaDomain.getCode()); |
| | | baCaptcha.setExpiration(calendar.getTimeInMillis()); |
| | | Long rec = captchaSV.addCaptcha(baCaptcha); |
| | | System.out.println("token: " + captchaDomain.getToken() + "; code: " + captchaDomain.getCode()); |
| | | |
| | | // 以文件流的形式,输出验证码图片 |
| | | ServletOutputStream out = null; |
| | | try { |
| | | response.setContentType("image/jpeg"); |
| | | out = response.getOutputStream(); |
| | | ImageIO.write(captchaDomain.getImage(), "jpg", out); |
| | | out.flush(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (out != null) { |
| | | out.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.captcha; |
| | | |
| | | import com.dy.pipIrrApp.captcha.dto.CaptchaDomain; |
| | | import com.dy.pipIrrGlobal.daoBa.BaCaptchaMapper; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaCaptcha; |
| | | import com.google.code.kaptcha.Producer; |
| | | import jakarta.annotation.Resource; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.util.Base64; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 13:46 |
| | | * @LastEditTime 2024-09-11 13:46 |
| | | * @Description |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class CaptchaSV { |
| | | @Autowired |
| | | private BaCaptchaMapper baCaptchaMapper; |
| | | |
| | | @Resource(name = "captchaProducer") |
| | | private Producer captchaProducer; |
| | | |
| | | @Resource(name = "captchaProducerMathOne") |
| | | private Producer captchaProducerMathOne; |
| | | |
| | | @Resource(name = "captchaProducerMathTwo") |
| | | private Producer captchaProducerMathTwo; |
| | | |
| | | private static final String TYPE_CHAR = "char"; |
| | | private static final String TYPE_MATH_ONE = "math"; |
| | | private static final String TYPE_MATH_TWO = "math2"; |
| | | |
| | | /** |
| | | * Kaptcha生成验证码实体 |
| | | * @param type,char - 字符(缺省) | math - 一位数算式 | math2 - 两位数算式 |
| | | * @return |
| | | */ |
| | | public CaptchaDomain createGoogleCaptcha(String type) { |
| | | // 定义验证码实体 |
| | | CaptchaDomain captchaDomain = new CaptchaDomain(); |
| | | // 一位数加减乘除 |
| | | if (TYPE_MATH_ONE.equals(type)) { |
| | | // 生成文本 |
| | | String producerText = captchaProducerMathOne.createText(); |
| | | // 设置验证码字符 |
| | | captchaDomain.setText(producerText.substring(0, producerText.indexOf("@"))); |
| | | // 设置验证码答案码 |
| | | captchaDomain.setCode(producerText.substring(producerText.indexOf("@") + 1)); |
| | | // 设置验证码图片 |
| | | captchaDomain.setImage(captchaProducerMathOne.createImage(captchaDomain.getText())); |
| | | } |
| | | // 两位数加减乘除 |
| | | else if (TYPE_MATH_TWO.equals(type)) { |
| | | String producerText = captchaProducerMathTwo.createText(); |
| | | captchaDomain.setText(producerText.substring(0, producerText.indexOf("@"))); |
| | | captchaDomain.setCode(producerText.substring(producerText.indexOf("@") + 1)); |
| | | captchaDomain.setImage(captchaProducerMathTwo.createImage(captchaDomain.getText())); |
| | | } |
| | | // 缺省情况:字符 |
| | | else { |
| | | captchaDomain.setText(captchaProducer.createText()); |
| | | captchaDomain.setCode(captchaDomain.getText()); |
| | | captchaDomain.setImage(captchaProducer.createImage(captchaDomain.getText())); |
| | | } |
| | | // 生成base64 |
| | | try { |
| | | // 定义字节数组输出流 |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | // 将图像以 jpg 的形式,写到字节数组输出流中 |
| | | ImageIO.write(captchaDomain.getImage(), "jpg", outputStream); |
| | | |
| | | // 写入base64格式 |
| | | captchaDomain.setBase64("data:image/jpg;base64," + Base64.getEncoder().encodeToString(outputStream.toByteArray())); |
| | | // 写入唯一Token |
| | | captchaDomain.setToken(UUID.randomUUID().toString()); |
| | | // 返回结果 |
| | | return captchaDomain; |
| | | } catch (Exception e) { |
| | | System.out.println(e.getMessage()); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加图片验证记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | | public Long addCaptcha(BaCaptcha po) { |
| | | baCaptchaMapper.insert(po); |
| | | return po.getId(); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.captcha.dto; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 13:46 |
| | | * @LastEditTime 2024-09-11 13:46 |
| | | * @Description |
| | | */ |
| | | |
| | | @JsonInclude(JsonInclude.Include.NON_NULL) |
| | | public class CaptchaDomain implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 验证码的Token |
| | | */ |
| | | private String token; |
| | | |
| | | /** |
| | | * 验证码的字符。返回的JSON,禁止返回给前端。 |
| | | */ |
| | | @JsonIgnore |
| | | private String text; |
| | | |
| | | /** |
| | | * 验证码的验证字符。比如算式的结果等。 |
| | | */ |
| | | @JsonIgnore |
| | | private String code; |
| | | |
| | | /** |
| | | * 验证码缓冲图像 |
| | | */ |
| | | @JsonIgnore |
| | | private BufferedImage image; |
| | | |
| | | /** |
| | | * 验证码图片的Base64字符串 |
| | | */ |
| | | private String base64; |
| | | |
| | | public String getToken() { |
| | | return token; |
| | | } |
| | | |
| | | public void setToken(String token) { |
| | | this.token = token; |
| | | } |
| | | |
| | | public String getText() { |
| | | return text; |
| | | } |
| | | |
| | | public void setText(String text) { |
| | | this.text = text; |
| | | } |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | public BufferedImage getImage() { |
| | | return image; |
| | | } |
| | | |
| | | public void setImage(BufferedImage image) { |
| | | this.image = image; |
| | | } |
| | | |
| | | public String getBase64() { |
| | | return base64; |
| | | } |
| | | |
| | | public void setBase64(String base64) { |
| | | this.base64 = base64; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "CaptchaDomain{" + |
| | | "token='" + token + '\'' + |
| | | ", text='" + text + '\'' + |
| | | ", code='" + code + '\'' + |
| | | ", image=" + image + |
| | | ", base64='" + base64 + '\'' + |
| | | '}'; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.config; |
| | | |
| | | import com.google.code.kaptcha.impl.DefaultKaptcha; |
| | | import com.google.code.kaptcha.util.Config; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 15:52 |
| | | * @LastEditTime 2024-09-11 15:52 |
| | | * @Description |
| | | */ |
| | | |
| | | @Configuration |
| | | public class KaptchaConfig { |
| | | /** |
| | | * 验证码配置默认配置 |
| | | * @return |
| | | */ |
| | | @Bean(name = "captchaProducer") |
| | | public DefaultKaptcha getKaptchaBean() { |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | Properties properties = new Properties(); |
| | | // 是否有边框。默认true,可选:yes,no |
| | | properties.setProperty("kaptcha.border", "yes"); |
| | | //设置图片边框颜色 |
| | | properties.setProperty("kaptcha.border.color", "green"); |
| | | // 验证码文本字符颜色。默认Color.BLACK |
| | | properties.setProperty("kaptcha.textproducer.font.color", "black"); |
| | | // 文字间隔 |
| | | properties.put("kaptcha.textproducer.char.space", "10"); |
| | | // 验证码图片宽度。默认200 |
| | | properties.setProperty("kaptcha.image.width", "160"); |
| | | // 验证码图片高度。默认50 |
| | | properties.setProperty("Kkaptcha.image.height", "60"); |
| | | // 验证码文本字符大小。默认40 |
| | | properties.setProperty("kaptcha.textproducer.font.size", "38"); |
| | | // KAPTCHA_SESSION_KEY |
| | | properties.setProperty("Kkaptcha.session.key", "kaptchaCode"); |
| | | // 验证码文本字符长度。默认5 |
| | | properties.setProperty("kaptcha.textproducer.char.length", "4"); |
| | | // 验证码文本字体样式。默认:new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) |
| | | properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier"); |
| | | // 干扰实现类 |
| | | properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise"); |
| | | // 图片样式。 |
| | | // 水纹:com.google.code.kaptcha.impl.WaterRipple |
| | | // 鱼眼:com.google.code.kaptcha.impl.FishEyeGimpy |
| | | // 阴影:com.google.code.kaptcha.impl.ShadowGimpy |
| | | properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple"); |
| | | Config config = new Config(properties); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | |
| | | /** |
| | | * 验证码数学题类配置(一位数加减乘除) |
| | | * @return 配置信息 |
| | | */ |
| | | @Bean(name = "captchaProducerMathOne") |
| | | public DefaultKaptcha getKaptchaBeanMathOne() { |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | Properties properties = commonConfig("com.dy.pipIrrApp.config.KaptchaMathOneTextCreator"); |
| | | Config config = new Config(properties); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | |
| | | /** |
| | | * 验证码数学题类配置(两位数的加减乘除) |
| | | * @return 配置信息 |
| | | */ |
| | | @Bean(name = "captchaProducerMathTwo") |
| | | public DefaultKaptcha getKaptchaBeanMathTwo() { |
| | | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
| | | Properties properties = commonConfig("com.dy.pipIrrApp.config.KaptchaMathTwoTextCreator"); |
| | | Config config = new Config(properties); |
| | | defaultKaptcha.setConfig(config); |
| | | return defaultKaptcha; |
| | | } |
| | | |
| | | /** |
| | | * 算式运算配置的公共配置类 |
| | | * @param textImpl 验证码文本生成器 |
| | | * @return 配置类 |
| | | */ |
| | | protected static Properties commonConfig(String textImpl) { |
| | | Properties properties = new Properties(); |
| | | // 是否有边框。默认为true,可设置:yes,no |
| | | properties.setProperty("kaptcha.border", "yes"); |
| | | // 边框颜色。默认:Color.BLACK |
| | | properties.setProperty("kaptcha.border.color", "105,179,90"); |
| | | // 验证码文本字符颜色。默认:Color.BLACK |
| | | properties.setProperty("kaptcha.textproducer.font.color", "blue"); |
| | | // 验证码图片宽度。默认:200 |
| | | properties.setProperty("kaptcha.image.width", "160"); |
| | | // 验证码图片高度。默认:50 |
| | | properties.setProperty("kaptcha.image.height", "60"); |
| | | // 验证码文本字符大小。默认:40 |
| | | properties.setProperty("kaptcha.textproducer.font.size", "35"); |
| | | // KAPTCHA_SESSION_KEY |
| | | properties.setProperty("kaptcha.session.key", "kaptchaCodeMath"); |
| | | // 验证码文本生成器 |
| | | properties.setProperty("kaptcha.textproducer.impl", textImpl); |
| | | // 验证码文本字符间距。默认:2 |
| | | properties.setProperty("kaptcha.textproducer.char.space", "6"); |
| | | // 验证码文本字符长度。默认:5 |
| | | properties.setProperty("kaptcha.textproducer.char.length", "6"); |
| | | // 验证码文本字体样式。默认:new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) |
| | | properties.setProperty("kaptcha.textproducer.font.names", "Arial,Courier"); |
| | | // 验证码噪点颜色。默认:Color.BLACK |
| | | properties.setProperty("kaptcha.noise.color", "white"); |
| | | // 干扰实现类 |
| | | properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise"); |
| | | // 图片样式。 |
| | | // 水纹:com.google.code.kaptcha.impl.WaterRipple |
| | | // 鱼眼:com.google.code.kaptcha.impl.FishEyeGimpy |
| | | // 阴影:com.google.code.kaptcha.impl.ShadowGimpy |
| | | properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.WaterRipple"); |
| | | // 返回生成的配置类 |
| | | return properties; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.config; |
| | | |
| | | import com.dy.pipIrrApp.util.CaptchaUtil; |
| | | import com.google.code.kaptcha.text.impl.DefaultTextCreator; |
| | | |
| | | import java.security.SecureRandom; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 15:51 |
| | | * @LastEditTime 2024-09-11 15:51 |
| | | * @Description |
| | | */ |
| | | |
| | | public class KaptchaMathOneTextCreator extends DefaultTextCreator { |
| | | @Override |
| | | public String getText() { |
| | | Random random = new SecureRandom(); |
| | | // 生成两个随机数,随机数范围:[0,10),并返回结果 |
| | | Map<String, String> result = CaptchaUtil.mathTextCreator(random.nextInt(10), random.nextInt(10)); |
| | | return result.get("resultString"); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.config; |
| | | |
| | | import com.dy.pipIrrApp.util.CaptchaUtil; |
| | | import com.google.code.kaptcha.text.impl.DefaultTextCreator; |
| | | |
| | | import java.security.SecureRandom; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 15:51 |
| | | * @LastEditTime 2024-09-11 15:51 |
| | | * @Description |
| | | */ |
| | | |
| | | public class KaptchaMathTwoTextCreator extends DefaultTextCreator { |
| | | @Override |
| | | public String getText() { |
| | | Random random = new SecureRandom(); |
| | | // 保存计算结果 |
| | | Map<String, String> result = CaptchaUtil.mathTextCreator(random.nextInt(100), random.nextInt(100)); |
| | | // 生成两个随机数,随机数范围:[0,100),并返回结果 |
| | | return result.get("resultString"); |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrApp.util; |
| | | |
| | | import java.security.SecureRandom; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2024-09-11 15:48 |
| | | * @LastEditTime 2024-09-11 15:48 |
| | | * @Description |
| | | */ |
| | | |
| | | public class CaptchaUtil { |
| | | /** |
| | | * 生成数学文本算式,例如1+1=? |
| | | * @param a 数字 |
| | | * @param b 数字 |
| | | * @return 字符 |
| | | */ |
| | | public static Map<String, String> mathTextCreator(int a, int b) { |
| | | Random random = new SecureRandom(); |
| | | // 生成随机操作,操作范围:[0,4),分别表示: + - * / |
| | | int op = random.nextInt(4); |
| | | // 定义计算的结果 |
| | | Integer result = 0; |
| | | // 定义构建的算式字符串 |
| | | StringBuilder resultString = new StringBuilder(); |
| | | // 运算符:- |
| | | if (1 == op) { |
| | | if (a >= b) { |
| | | result = a - b; |
| | | resultString.append(a).append("-").append(b).append("=?@").append(result); |
| | | } else { |
| | | result = b - a; |
| | | resultString.append(b).append("-").append(a).append("=?@").append(result); |
| | | } |
| | | } |
| | | // 运算符:* |
| | | else if (2 == op) { |
| | | result = a * b; |
| | | resultString.append(a).append("*").append(b).append("=?@").append(result); |
| | | } |
| | | // 运算符:/ |
| | | else if (3 == op) { |
| | | if (a != 0 && b % a == 0) { |
| | | result = b / a; |
| | | resultString.append(b).append("/").append(a).append("=?@").append(result); |
| | | } else if (b != 0 && a % b == 0) { |
| | | result = a / b; |
| | | resultString.append(a).append("/").append(b).append("=?@").append(result); |
| | | } else { |
| | | return mathTextCreator(a, b); |
| | | } |
| | | } |
| | | // 运算符:+ |
| | | else { |
| | | result = b + a; |
| | | resultString.append(a).append("+").append(b).append("=?@").append(result); |
| | | } |
| | | Map<String, String> ret = new HashMap<String, String>(); |
| | | ret.put("resultCode", result.toString()); |
| | | ret.put("resultString", resultString.toString()); |
| | | return ret; |
| | | } |
| | | } |
| | |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper; |
| | | import com.dy.pipIrrGlobal.daoSe.*; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeCardOperate; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeClientCard; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeManagerCard; |
| | | import com.dy.pipIrrGlobal.pojoSe.SePaymentMethod; |
| | | import com.dy.pipIrrGlobal.pojoSe.*; |
| | | import com.dy.pipIrrGlobal.voSe.*; |
| | | import com.dy.pipIrrSell.cardOperate.dto.DtoRecharge; |
| | | import com.dy.pipIrrSell.cardOperate.enums.OperateTypeENUM; |
| | |
| | | |
| | | @Autowired |
| | | private SePaymentMethodMapper sePaymentMethodMapper; |
| | | |
| | | @Autowired |
| | | private SeRechargeHistoryMapper seRechargeHistoryMapper; |
| | | |
| | | @Value("${project.projectNo}") |
| | | private Integer projectNo; |
| | |
| | | |
| | | /** |
| | | * 添加充值记录 |
| | | * 修改农户信息、添加充值记录 |
| | | * 修改农户信息、添加水卡操作记录、添加充值记录 |
| | | * @param po |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 添加充值记录 |
| | | * 添加水卡操作记录 |
| | | */ |
| | | SeCardOperate seCardOperate = new SeCardOperate(); |
| | | seCardOperate.setCardId(cardId); |
| | |
| | | seCardOperateMapper.insert(seCardOperate); |
| | | Long rec = Optional.ofNullable(seCardOperate.getId()).orElse(0L); |
| | | if(rec == 0) { |
| | | return BaseResponseUtils.buildErrorMsg(SellResultCode.REPLACE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); |
| | | return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_ERROR.getMessage()); |
| | | } |
| | | |
| | | /** |
| | | * 添加充值历史记录 |
| | | */ |
| | | SeRechargeHistory seRechargeHistory = new SeRechargeHistory(); |
| | | seRechargeHistory.setCardid(cardId); |
| | | seRechargeHistory.setClientid(clientId); |
| | | seRechargeHistory.setMoney(money); |
| | | seRechargeHistory.setAmount(amount); |
| | | seRechargeHistory.setGift(gift); |
| | | seRechargeHistory.setAfterrecharge(afterRecharge); |
| | | seRechargeHistory.setPaymentid(paymentId); |
| | | seRechargeHistory.setPrice(price); |
| | | seRechargeHistory.setRemarks(remarks); |
| | | seRechargeHistory.setOperator(operator); |
| | | seRechargeHistory.setOperatedt(rechargeTime); |
| | | seRechargeHistoryMapper.insert(seRechargeHistory); |
| | | Long rec_seRechargeHistory = Optional.ofNullable(seRechargeHistory.getId()).orElse(0L); |
| | | if(rec_seRechargeHistory == 0) { |
| | | return BaseResponseUtils.buildErrorMsg(SellResultCode.RECHARGE_FAIL_WRITE_RECHARGE_HISTORY_ERROR.getMessage()); |
| | | } |
| | | |
| | | Map map_response = new HashMap(); |
| | |
| | | }) |
| | | @GetMapping(path = "getSummaries") |
| | | @SsoAop() |
| | | public BaseResponse<Map> getSummaries(QoSummary vo){ |
| | | public BaseResponse<Map> getSummaries( @Valid QoSummary vo, BindingResult bindingResult){ |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | try { |
| | | Map res = generalSv.getSummaries(vo); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | |
| | | import com.dy.pipIrrGlobal.daoSe.*; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeAudits; |
| | | import com.dy.pipIrrGlobal.pojoSe.SeGeneral; |
| | | import com.dy.pipIrrGlobal.pojoSe.SePaymentMethod; |
| | | import com.dy.pipIrrGlobal.voSe.VoGeneral; |
| | | import com.dy.pipIrrGlobal.voSe.VoTradeDetails; |
| | | import com.dy.pipIrrGlobal.voSe.VoTransactionStatistics; |
| | |
| | | |
| | | @Autowired |
| | | private SeRefundMapper seRefundMapper; |
| | | |
| | | @Autowired |
| | | private SePaymentMethodMapper sePaymentMethodMapper; |
| | | |
| | | /** |
| | | * 获取未生成总账的交易日期列表(当天的交易记录不生成总账) |
| | |
| | | // 起始索引位置 |
| | | Integer startIndex = (pageCurr - 1) * pageSize; |
| | | |
| | | // 获取各支付方式ID |
| | | Long paymentId_cash = 0L; |
| | | Long paymentId_wechat = 0L; |
| | | Long paymentId_alipay = 0L; |
| | | Long paymentId_transfer = 0L; |
| | | List<SePaymentMethod> list_payment = sePaymentMethodMapper.getPaymentMethods(); |
| | | for (int i = 0; i < list_payment.size(); i++) { |
| | | SePaymentMethod paymentMethod = list_payment.get(i); |
| | | if(paymentMethod.getName().equals("现金")) { |
| | | paymentId_cash = paymentMethod.getId(); |
| | | } |
| | | if(paymentMethod.getName().equals("微信支付")) { |
| | | paymentId_wechat = paymentMethod.getId(); |
| | | } |
| | | if(paymentMethod.getName().equals("支付宝支付")) { |
| | | paymentId_alipay = paymentMethod.getId(); |
| | | } |
| | | if(paymentMethod.getName().equals("银行转账")) { |
| | | paymentId_transfer = paymentMethod.getId(); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 接收传入参数:交易起止日期、收银员ID |
| | | JSONArray array_paymentSums = new JSONArray(); |
| | |
| | | while (calendar.getTime().before(timeStop) || calendar.getTime().equals(timeStop)) { |
| | | String tradeDate = dateFormat.format(calendar.getTime()) ; |
| | | if(cashierId != 1000000L) { |
| | | Float receivedCash = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 1L)).orElse(0f); |
| | | Float receivedQRCode = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,2L)).orElse(0f); |
| | | Float receivedTransfer = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, 3L)).orElse(0f); |
| | | Float receivedCash = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, paymentId_cash)).orElse(0f); |
| | | Float receivedWechat = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,paymentId_wechat)).orElse(0f); |
| | | Float receivedAlipay = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId,paymentId_alipay)).orElse(0f); |
| | | Float receivedTransfer = Optional.ofNullable(seGeneralMapper.getPaymentSums(tradeDate, cashierId, paymentId_transfer)).orElse(0f); |
| | | |
| | | JSONObject job = new JSONObject(); |
| | | job.put("tradeDate", tradeDate); |
| | | job.put("receivedCash", receivedCash); |
| | | job.put("receivedQRCode", receivedQRCode); |
| | | job.put("receivedWechat", receivedWechat); |
| | | job.put("receivedAlipay", receivedAlipay); |
| | | job.put("receivedTransfer", receivedTransfer); |
| | | array_paymentSums.add(job); |
| | | |
| | |
| | | @NotEmpty(message = "组织单位不能为空") //不能为空也不能为null |
| | | @Length(message = "组织单位标签必须大于{min}位", min = 2) |
| | | public String orgTag ; |
| | | |
| | | /** |
| | | * 图形验证码token,即session的key |
| | | */ |
| | | private String token; |
| | | |
| | | /** |
| | | * 图形验证码结果 |
| | | */ |
| | | private String code; |
| | | } |
| | | |
| | |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 注解Tag 在API中显示: Tag 注解, 给整个接口起了个名字与描述" |
| | |
| | | //在属性上注解@Autowired时,会警告 Field injection is not recommended(不再推荐使用字段注入) |
| | | private SsoSv sv ; |
| | | |
| | | //private KaptchaConfig kaptchaConfig; |
| | | //@Autowired |
| | | //private CacheManager cacheManager ; |
| | | |
| | |
| | | this.sv = sv ; |
| | | } |
| | | |
| | | //@Autowired |
| | | //public void setKaptchaConfig(KaptchaConfig kaptchaConfig) { |
| | | // this.kaptchaConfig = kaptchaConfig; |
| | | //} |
| | | |
| | | /** |
| | | * 客户端请求得到所有组织机构 |
| | |
| | | ) |
| | | }) |
| | | @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult) { |
| | | public BaseResponse<UserVo> loginJson(HttpServletRequest request, @RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | |
| | | //把组织单位标签作为数据源名称 |
| | | DataSourceContext.set(vo.orgTag); |
| | | |
| | | String token = Optional.ofNullable(vo.getToken()).orElse(""); |
| | | String code = Optional.ofNullable(vo.getCode()).orElse(""); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | if(token.length() > 0 && code.length() > 0) { |
| | | // 从session中获取验证码 |
| | | //HttpSession session = (HttpSession) request.getSession(); |
| | | //String localCode = session.getAttribute(token).toString(); |
| | | |
| | | Map map = sv.getCodeByToken(token); |
| | | Long expiration = Long.parseLong(map.get("expiration").toString()); |
| | | Long currentTimestamp = System.currentTimeMillis(); |
| | | if(currentTimestamp > expiration) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码已超时"); |
| | | } |
| | | |
| | | // 从数据库获取验证码 |
| | | String localCode = map.get("code").toString(); |
| | | if(!code.equals(localCode)) { |
| | | return BaseResponseUtils.buildErrorMsg("验证码错误"); |
| | | } |
| | | } |
| | | |
| | | //得到所有用户账号 |
| | | List<String> phones = sv.getPhones(); |
| | | if(!phones.contains(vo.phone)){ |
| | |
| | | package com.dy.sso.busi; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.dy.pipIrrGlobal.daoBa.BaCaptchaMapper; |
| | | import com.dy.pipIrrGlobal.daoBa.BaUserMapper; |
| | | import com.dy.pipIrrGlobal.pojoBa.BaUser; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class SsoSv { |
| | | |
| | | private BaUserMapper baUserMapper; |
| | | |
| | | @Autowired |
| | |
| | | this.baUserMapper = baUserMapper ; |
| | | } |
| | | |
| | | @Autowired |
| | | private BaCaptchaMapper baCaptchaMapper; |
| | | |
| | | /** |
| | | * 需要BaUserMapper.xml |
| | |
| | | public List<String> getPhones(){ |
| | | return baUserMapper.getPhones() ; |
| | | } |
| | | |
| | | /** |
| | | * 依据验证码token获取验证字符 |
| | | * @param token |
| | | * @return |
| | | */ |
| | | public Map getCodeByToken(String token) { |
| | | return baCaptchaMapper.getCodeByToken(token); |
| | | } |
| | | } |