Sfoglia il codice sorgente

Merge branch 'master' of http://git.dayaedu.com/yonge/edu-saas

zouxuan 5 anni fa
parent
commit
f907745f33

+ 4 - 5
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/message/provider/MOxintongSMSPlugin.java

@@ -9,7 +9,8 @@ import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.keao.edu.thirdparty.exception.ThirdpartyException;
 import com.keao.edu.thirdparty.message.MessageSenderPlugin;
 import com.keao.edu.util.http.HttpUtil;
@@ -20,8 +21,6 @@ import com.keao.edu.util.http.HttpUtil;
 @Service
 public class MOxintongSMSPlugin implements MessageSenderPlugin, InitializingBean {
 
-	private static ObjectMapper MAPPER = new ObjectMapper();
-
 	@Value("${Moxintong.username:1}")
 	private String username;
 	
@@ -49,7 +48,7 @@ public class MOxintongSMSPlugin implements MessageSenderPlugin, InitializingBean
 		} catch (Exception e) {
 			throw new ThirdpartyException("短信发送失败!", e);
 		}
-		HashMap jsonObject = MAPPER.readValue(result, HashMap.class);
+		JSONObject jsonObject = JSON.parseObject(result);
 		if (jsonObject.get("code").toString().equals("0")) {
 			return true;
 		} else {
@@ -77,7 +76,7 @@ public class MOxintongSMSPlugin implements MessageSenderPlugin, InitializingBean
 		} catch (Exception e) {
 			throw new ThirdpartyException("短信发送失败!", e);
 		}
-		HashMap jsonObject = MAPPER.readValue(result, HashMap.class);
+		JSONObject jsonObject = JSON.parseObject(result);
 		if (jsonObject.get("code").toString().equals("0")) {
 			return true;
 		} else {

+ 9 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/ShortUrlDao.java

@@ -0,0 +1,9 @@
+package com.keao.edu.user.dao;
+
+import com.keao.edu.common.dal.BaseDAO;
+import com.keao.edu.user.entity.ShortUrl;
+
+public interface ShortUrlDao extends BaseDAO<Long, ShortUrl> {
+
+	
+}

+ 51 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/entity/ShortUrl.java

@@ -0,0 +1,51 @@
+package com.keao.edu.user.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+/**
+ * 对应数据库表(short_url):
+ */
+public class ShortUrl {
+
+	private Long id;
+	
+	@ApiModelProperty(value = "链接地址")
+	private String url;
+
+	private java.util.Date createTime;
+
+	public ShortUrl(String url) {
+		this.url = url;
+	}
+
+	public void setId(Long id){
+		this.id = id;
+	}
+	
+	public Long getId(){
+		return this.id;
+	}
+			
+	public void setUrl(String url){
+		this.url = url;
+	}
+	
+	public String getUrl(){
+		return this.url;
+	}
+			
+	public void setCreateTime(java.util.Date createTime){
+		this.createTime = createTime;
+	}
+	
+	public java.util.Date getCreateTime(){
+		return this.createTime;
+	}
+			
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this);
+	}
+
+}

+ 18 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/ShortUrlService.java

@@ -0,0 +1,18 @@
+package com.keao.edu.user.service;
+
+
+import com.keao.edu.common.service.BaseService;
+import com.keao.edu.user.entity.ShortUrl;
+
+public interface ShortUrlService extends BaseService<Long, ShortUrl> {
+
+    /**
+     * @describe 创建短链接
+     * @author Joburgess
+     * @date 2020.06.22
+     * @param sourceUrl: 原链接
+     * @return java.lang.String
+     */
+    String createShortUrl(String sourceUrl);
+
+}

+ 41 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ShortUrlServiceImpl.java

@@ -0,0 +1,41 @@
+package com.keao.edu.user.service.impl;
+
+import com.keao.edu.common.dal.BaseDAO;
+import com.keao.edu.common.exception.BizException;
+import com.keao.edu.common.service.impl.BaseServiceImpl;
+import com.keao.edu.user.dao.ShortUrlDao;
+import com.keao.edu.user.entity.ShortUrl;
+import com.keao.edu.user.service.ShortUrlService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class ShortUrlServiceImpl extends BaseServiceImpl<Long, ShortUrl> implements ShortUrlService {
+	
+	@Autowired
+	private ShortUrlDao shortUrlDao;
+
+	@Override
+	public BaseDAO<Long, ShortUrl> getDAO() {
+		return shortUrlDao;
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public String createShortUrl(String sourceUrl) {
+		if(StringUtils.isBlank(sourceUrl)){
+			return null;
+		}
+		ShortUrl shortUrl=new ShortUrl(sourceUrl);
+		shortUrlDao.insert(shortUrl);
+		StringBuffer returnUrl=new StringBuffer("http://");
+		return null;
+	}
+
+	public static void main(String[] args) {
+		String url="http://192.168.3.151/test/test";
+		System.out.println(url.substring(url.indexOf("//")));
+	}
+}

+ 57 - 0
edu-user/edu-user-server/src/main/resources/config/mybatis/ShortUrlMapper.xml

@@ -0,0 +1,57 @@
+<?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.keao.edu.user.dao.ShortUrlDao">
+	
+	<resultMap type="com.keao.edu.user.entity.ShortUrl" id="ShortUrl">
+		<result column="id_" property="id" />
+		<result column="url_" property="url" />
+		<result column="create_time_" property="createTime" />
+	</resultMap>
+	
+	<!-- 根据主键查询一条记录 -->
+	<select id="get" resultMap="ShortUrl" >
+		SELECT * FROM short_url WHERE id_ = #{id} 
+	</select>
+	
+	<!-- 全查询 -->
+	<select id="findAll" resultMap="ShortUrl">
+		SELECT * FROM short_url ORDER BY id_
+	</select>
+	
+	<!-- 向数据库增加一条记录 -->
+	<insert id="insert" parameterType="com.keao.edu.user.entity.ShortUrl" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
+		INSERT INTO short_url (id_,url_,create_time_) VALUES(#{id},#{url},NOW())
+	</insert>
+	
+	<!-- 根据主键查询一条记录 -->
+	<update id="update" parameterType="com.keao.edu.user.entity.ShortUrl">
+		UPDATE short_url <set>
+			<if test="id != null">
+			id_ = #{id},
+			</if>
+			<if test="url != null">
+			url_ = #{url}
+			</if>
+		</set> WHERE id_ = #{id}
+	</update>
+	
+	<!-- 根据主键删除一条记录 -->
+	<delete id="delete" >
+		DELETE FROM short_url WHERE id_ = #{id} 
+	</delete>
+	
+	<!-- 分页查询 -->
+	<select id="queryPage" resultMap="ShortUrl" parameterType="map">
+		SELECT * FROM short_url ORDER BY id_
+		<include refid="global.limit"/>
+	</select>
+	
+	<!-- 查询当前表的总记录数 -->
+	<select id="queryCount" resultType="int">
+		SELECT COUNT(*) FROM short_url
+	</select>
+</mapper>