Commit e744cda9 by guojuxing

Merge remote-tracking branch 'origin/developer' into developer

parents 8953e98f 8245ffec
package com.gic.auth.dto;
import java.io.Serializable;
import java.util.Date;
/**
* tab_sys_auth_code
*/
public class AuthCodeDTO implements Serializable {
/**
*
*/
private Integer authCodeId;
/**
* 验证码
*/
private String authCode;
/**
*
*/
private Integer enterpriseId;
/**
* 关联业务id
*/
private Integer relationId;
/**
* 1有效 0失效
*/
private Integer status;
/**
*
*/
private Date expirationTime;
public Integer getAuthCodeId() {
return authCodeId;
}
public void setAuthCodeId(Integer authCodeId) {
this.authCodeId = authCodeId;
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Integer getRelationId() {
return relationId;
}
public void setRelationId(Integer relationId) {
this.relationId = relationId;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getExpirationTime() {
return expirationTime;
}
public void setExpirationTime(Date expirationTime) {
this.expirationTime = expirationTime;
}
}
\ No newline at end of file
package com.gic.auth.service;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.AuthCodeDTO;
public interface AuthCodeApiService {
/** @Description: 保存验证码
* @author taogs
* @Date 11:09 2019/9/2
* @Param
* @return
*/
ServiceResponse<Integer> saveAuth(AuthCodeDTO authCodeDTO);
/** @Description: 设置验证码无效
* @author taogs
* @Date 11:09 2019/9/2
* @Param
* @return
*/
ServiceResponse<Integer> expireAuthCode(Integer authCodeId);
/** @Description: 获取验证码
* @author taogs
* @Date 11:10 2019/9/2
* @Param
* @return
*/
ServiceResponse<AuthCodeDTO> getAuthCode(Integer enterpriseId, Integer relationId);
}
package com.gic.auth.dao.mapper;
import com.gic.auth.entity.TabSysAuthCode;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TabSysAuthCodeMapper {
/**
* 根据主键删除
*
* @param authCodeId 主键
* @return 更新条目数
*/
int deleteByPrimaryKey(Integer authCodeId);
/**
* 插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insert(TabSysAuthCode record);
/**
* 动态插入一条记录
*
* @param record 实体对象
* @return 更新条目数
*/
int insertSelective(TabSysAuthCode record);
/**
* 根据主键查询
*
* @param authCodeId 主键
* @return 实体对象
*/
TabSysAuthCode selectByPrimaryKey(Integer authCodeId);
/**
* 根据主键动态更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKeySelective(TabSysAuthCode record);
/**
* 根据主键更新记录
*
* @param record 实体对象
* @return 更新条目数
*/
int updateByPrimaryKey(TabSysAuthCode record);
List<TabSysAuthCode> getAuthCode(@Param("enterpriseId") Integer enterpriseId, @Param("relationId") Integer relationId);
}
\ No newline at end of file
package com.gic.auth.entity;
import java.util.Date;
/**
* tab_sys_auth_code
*/
public class TabSysAuthCode {
/**
*
*/
private Integer authCodeId;
/**
* 验证码
*/
private String authCode;
/**
*
*/
private Integer enterpriseId;
/**
* 关联业务id
*/
private Integer relationId;
/**
* 1有效 0失效
*/
private Integer status;
/**
*
*/
private Date createTime;
/**
*
*/
private Date expirationTime;
/**
*
*/
private Date updateTime;
public Integer getAuthCodeId() {
return authCodeId;
}
public void setAuthCodeId(Integer authCodeId) {
this.authCodeId = authCodeId;
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Integer getRelationId() {
return relationId;
}
public void setRelationId(Integer relationId) {
this.relationId = relationId;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getExpirationTime() {
return expirationTime;
}
public void setExpirationTime(Date expirationTime) {
this.expirationTime = expirationTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
package com.gic.auth.service;
import com.gic.auth.entity.TabSysAuthCode;
public interface AuthCodeService {
int saveAuthCode(TabSysAuthCode tabSysAuthCode);
int expireAuthCode(Integer authCodeId);
TabSysAuthCode getAuthCode(Integer enterpriseId, Integer relationId);
}
package com.gic.auth.service.impl;
import com.gic.auth.dao.mapper.TabSysAuthCodeMapper;
import com.gic.auth.entity.TabSysAuthCode;
import com.gic.auth.service.AuthCodeService;
import com.gic.enterprise.constants.Constants;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("authCodeService")
public class AuthCodeServiceImpl implements AuthCodeService {
@Autowired
private TabSysAuthCodeMapper tabSysAuthCodeMapper;
@Override
public int saveAuthCode(TabSysAuthCode tabSysAuthCode) {
return this.tabSysAuthCodeMapper.insert(tabSysAuthCode);
}
@Override
public int expireAuthCode(Integer authCodeId) {
TabSysAuthCode tabSysAuthCode = new TabSysAuthCode();
tabSysAuthCode.setAuthCodeId(authCodeId);
tabSysAuthCode.setStatus(Constants.DEL_STATUS);
return this.tabSysAuthCodeMapper.updateByPrimaryKeySelective(tabSysAuthCode);
}
@Override
public TabSysAuthCode getAuthCode(Integer enterpriseId, Integer relationId) {
List<TabSysAuthCode> list = this.tabSysAuthCodeMapper.getAuthCode(enterpriseId, relationId);
if(CollectionUtils.isNotEmpty(list)){
return list.get(0);
}
return null;
}
}
package com.gic.auth.service.outer.impl;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.AuthCodeDTO;
import com.gic.auth.entity.TabSysAuthCode;
import com.gic.auth.service.AuthCodeApiService;
import com.gic.auth.service.AuthCodeService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.constants.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service("authCodeApiService")
public class AuthCodeApiServiceImpl implements AuthCodeApiService {
@Autowired
private AuthCodeService authCodeService;
@Override
public ServiceResponse<Integer> saveAuth(AuthCodeDTO authCodeDTO) {
TabSysAuthCode sysAuthCode = EntityUtil.changeEntityByJSON(TabSysAuthCode.class, authCodeDTO);
sysAuthCode.setCreateTime(new Date());
sysAuthCode.setUpdateTime(new Date());
sysAuthCode.setStatus(Constants.NORMAL_STATUS);
int result = this.authCodeService.saveAuthCode(sysAuthCode);
return ServiceResponse.success(result);
}
@Override
public ServiceResponse<Integer> expireAuthCode(Integer authCodeId) {
int result = this.authCodeService.expireAuthCode(authCodeId);
return ServiceResponse.success(result);
}
@Override
public ServiceResponse<AuthCodeDTO> getAuthCode(Integer enterpriseId, Integer relationId) {
TabSysAuthCode sysAuthCode = this.authCodeService.getAuthCode(enterpriseId, relationId);
return ServiceResponse.success(EntityUtil.changeEntityByJSON(AuthCodeDTO.class, sysAuthCode));
}
}
......@@ -20,4 +20,5 @@
<dubbo:reference interface="com.gic.log.api.service.LogApiService" id="logApiService" timeout="6000" />
<!--资源组-->
<dubbo:service interface="com.gic.auth.service.ResourceApiService" ref="resourceApiService" timeout="6000" />
<dubbo:service interface="com.gic.auth.service.AuthCodeApiService" ref="authCodeApiService" timeout="6000" />
</beans>
<?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.gic.auth.dao.mapper.TabSysAuthCodeMapper">
<resultMap id="BaseResultMap" type="com.gic.auth.entity.TabSysAuthCode">
<id column="auth_code_id" jdbcType="INTEGER" property="authCodeId" />
<result column="auth_code" jdbcType="VARCHAR" property="authCode" />
<result column="enterprise_id" jdbcType="INTEGER" property="enterpriseId" />
<result column="relation_id" jdbcType="INTEGER" property="relationId" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="expiration_time" jdbcType="TIMESTAMP" property="expirationTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
auth_code_id, auth_code, enterprise_id, relation_id, status, create_time, expiration_time,
update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_auth_code
where auth_code_id = #{authCodeId,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from tab_sys_auth_code
where auth_code_id = #{authCodeId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.auth.entity.TabSysAuthCode">
insert into tab_sys_auth_code (auth_code_id, auth_code, enterprise_id,
relation_id, status, create_time,
expiration_time, update_time)
values (#{authCodeId,jdbcType=INTEGER}, #{authCode,jdbcType=VARCHAR}, #{enterpriseId,jdbcType=INTEGER},
#{relationId,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{expirationTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.auth.entity.TabSysAuthCode">
insert into tab_sys_auth_code
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="authCodeId != null">
auth_code_id,
</if>
<if test="authCode != null">
auth_code,
</if>
<if test="enterpriseId != null">
enterprise_id,
</if>
<if test="relationId != null">
relation_id,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="expirationTime != null">
expiration_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="authCodeId != null">
#{authCodeId,jdbcType=INTEGER},
</if>
<if test="authCode != null">
#{authCode,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null">
#{enterpriseId,jdbcType=INTEGER},
</if>
<if test="relationId != null">
#{relationId,jdbcType=INTEGER},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="expirationTime != null">
#{expirationTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.auth.entity.TabSysAuthCode">
update tab_sys_auth_code
<set>
<if test="authCode != null">
auth_code = #{authCode,jdbcType=VARCHAR},
</if>
<if test="enterpriseId != null">
enterprise_id = #{enterpriseId,jdbcType=INTEGER},
</if>
<if test="relationId != null">
relation_id = #{relationId,jdbcType=INTEGER},
</if>
<if test="status != null">
status = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="expirationTime != null">
expiration_time = #{expirationTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where auth_code_id = #{authCodeId,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.gic.auth.entity.TabSysAuthCode">
update tab_sys_auth_code
set auth_code = #{authCode,jdbcType=VARCHAR},
enterprise_id = #{enterpriseId,jdbcType=INTEGER},
relation_id = #{relationId,jdbcType=INTEGER},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
expiration_time = #{expirationTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where auth_code_id = #{authCodeId,jdbcType=INTEGER}
</update>
<select id="getAuthCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_auth_code
where enterprise_id = #{enterpriseId,jdbcType=INTEGER}
<if test="relationId != null">
and relation_id = #{relationId}
</if>
and status=1
and expiration_time &gt;= now()
order by create_time desc
</select>
</mapper>
\ No newline at end of file
package com.gic.auth.web.controller;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.dto.AuthCodeDTO;
import com.gic.auth.service.AuthCodeApiService;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.utils.UserDetailUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar;
import java.util.Date;
@RestController
public class AuthCodeController {
private static final Logger log = LogManager.getLogger(AuthCodeController.class);
@Autowired
private AuthCodeApiService authCodeApiService;
@RequestMapping("send-auth-code")
public RestResponse sendAuthCode(Integer eid){
Integer enterpriseId = UserDetailUtils.getUserDetail().getEnterpriseId();
//todo 调用发送验证码模块获取验证码
String code = "12345";
AuthCodeDTO authCodeDTO = new AuthCodeDTO();
authCodeDTO.setAuthCode(code);
authCodeDTO.setEnterpriseId(enterpriseId);
authCodeDTO.setRelationId(eid);
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MINUTE, 5);
authCodeDTO.setExpirationTime(calendar.getTime());
ServiceResponse<Integer> serviceResponse = this.authCodeApiService.saveAuth(authCodeDTO);
return RestResponse.success(serviceResponse.getResult());
}
@RequestMapping("expire-auth-code")
public RestResponse expireAuthCode(Integer authCodeId){
ServiceResponse<Integer> serviceResponse = this.authCodeApiService.expireAuthCode(authCodeId);
return RestResponse.success(serviceResponse.getResult());
}
@RequestMapping("get-auth-code")
public RestResponse getAuthCode(Integer eid){
Integer enterpriseId = UserDetailUtils.getUserDetail().getEnterpriseId();
ServiceResponse<AuthCodeDTO> authCode = this.authCodeApiService.getAuthCode(enterpriseId, eid);
return RestResponse.success(authCode.getResult());
}
}
......@@ -41,5 +41,6 @@
<!--资源组-->
<dubbo:reference interface="com.gic.auth.service.ResourceApiService" id="resourceApiService" timeout="6000" />
<dubbo:reference interface="com.gic.auth.service.AuthCodeApiService" id="authCodeApiService" timeout="6000" />
</beans>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment