Browse Source

Merge branch 'master' of https://gitee.com/zouxuan/mec

yonge 5 years ago
parent
commit
41094abf54

+ 10 - 1
mec-web/src/main/java/com/ym/mec/web/WebApplication.java

@@ -5,9 +5,12 @@ import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
 
 /**
  * Hello world!
@@ -17,11 +20,17 @@ import org.springframework.context.annotation.Configuration;
 @EnableDiscoveryClient
 @EnableFeignClients
 @MapperScan("com.ym.mec.web.dal.dao")
-@ComponentScan(basePackages="com.ym.mec")
+//@ComponentScan(basePackages="com.ym.mec.web")
 @Configuration
 @EnableSwagger2Doc
 public class WebApplication {
     public static void main( String[] args ){
         SpringApplication.run(WebApplication.class, args);
     }
+
+    @Bean
+    @LoadBalanced
+    public RestTemplate restTemplate() {
+        return new RestTemplate();
+    }
 }

+ 76 - 0
mec-web/src/main/java/com/ym/mec/web/config/AuthorizationServerConfig.java

@@ -0,0 +1,76 @@
+package com.ym.mec.web.config;
+
+import com.ym.mec.common.constant.CommonConstants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
+import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
+import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
+import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
+import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
+import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
+
+import javax.sql.DataSource;
+
+/**
+ * 授权服务器配置
+ */
+@Configuration
+@EnableAuthorizationServer
+public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
+
+	@Autowired
+	private RedisConnectionFactory connectionFactory;
+
+	@Autowired
+	private DataSource dataSource;
+
+	@Override
+	public void configure(AuthorizationServerEndpointsConfigurer endpoints){
+		endpoints
+				.tokenServices(defaultTokenServices())
+				.tokenStore(redisTokenStore());
+	}
+
+	@Override
+	public void configure(AuthorizationServerSecurityConfigurer security){
+		security.tokenKeyAccess("isAuthenticated()")
+				.checkTokenAccess("permitAll()")
+				.allowFormAuthenticationForClients();
+	}
+
+	@Override
+	public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
+
+		JdbcClientDetailsService clientDetailsService = new JdbcClientDetailsService(dataSource);
+
+		clientDetailsService
+				.setSelectClientDetailsSql("select id_, CONCAT('{noop}',client_secret_) as client_secret, resource_ids_, scope_, authorized_grant_types_, web_server_redirect_uri_, authorities_, access_token_validity_, refresh_token_validity_, additional_information_, autoapprove_ from sys_oauth_client_details where id_ = ?");
+		clientDetailsService
+				.setFindClientDetailsSql("select id_, CONCAT('{noop}',client_secret_) as client_secret, resource_ids_, scope_, authorized_grant_types_, web_server_redirect_uri_, authorities_, access_token_validity_, refresh_token_validity_, additional_information_, autoapprove_ from sys_oauth_client_details order by id_");
+
+		clients.withClientDetails(clientDetailsService);
+	}
+
+	@Bean
+	public RedisTokenStore redisTokenStore() {
+		RedisTokenStore tokenStore = new RedisTokenStore(connectionFactory);
+		tokenStore.setPrefix(CommonConstants.OAUTH_PREFIX);
+		return tokenStore;
+	}
+
+	@Bean
+	public DefaultTokenServices defaultTokenServices() {
+		DefaultTokenServices tokenServices = new DefaultTokenServices();
+		tokenServices.setTokenStore(redisTokenStore());
+		tokenServices.setSupportRefreshToken(true);
+		tokenServices.setAccessTokenValiditySeconds(60 * 60 * 24); // token有效期自定义设置,默认12小时
+		tokenServices.setRefreshTokenValiditySeconds(60 * 60 * 24 * 30);// 默认30天,这里修改
+		return tokenServices;
+	}
+
+}

+ 27 - 0
mec-web/src/main/java/com/ym/mec/web/config/ResourceServerConfig.java

@@ -0,0 +1,27 @@
+package com.ym.mec.web.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+
+/**
+ * 资源服务器配置
+ */
+@Configuration
+@EnableResourceServer
+public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
+
+	//Http安全配置,对每个到达系统的http请求链接进行校验
+	@Override
+	public void configure(HttpSecurity http) throws Exception {
+		//所有请求必须认证通过
+		http.authorizeRequests()
+				//下边的路径放行
+				.antMatchers("/v2/api-docs", "/swagger-resources/configuration/ui",
+						"/swagger-resources","/swagger-resources/configuration/security",
+						"/swagger-ui.html","/course/coursebase/**").permitAll()
+				.anyRequest().authenticated();
+	}
+
+}

+ 21 - 0
mec-web/src/main/java/com/ym/mec/web/config/WebSecurityConfig.java

@@ -0,0 +1,21 @@
+package com.ym.mec.web.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+
+@Configuration
+@EnableWebSecurity
+@EnableGlobalMethodSecurity(prePostEnabled = true)//会拦截注解了@PreAuthrize注解的配置.
+public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+
+	@Override
+	public void configure(WebSecurity web){
+		web.ignoring().antMatchers("/v2/api-docs", "/swagger-resources/configuration/ui",
+				"/swagger-resources","/swagger-resources/configuration/security",
+				"/swagger-ui.html","/course/coursebase/**");
+	}
+
+}

+ 1 - 1
mec-web/src/main/java/com/ym/mec/web/controller/MusicGroupController.java

@@ -45,7 +45,7 @@ public class MusicGroupController extends BaseController {
     }
 
     @ApiOperation(value = "根据乐团编号查询乐团")
-    @DeleteMapping("/get/{id}")
+    @GetMapping("/get/{id}")
     public Object update(@ApiParam(value = "乐团编号", required = true) @PathVariable("id") String id){
         return succeed(musicGroupService.get(id));
     }

+ 22 - 0
mec-web/src/main/java/com/ym/mec/web/controller/OrganizationController.java

@@ -0,0 +1,22 @@
+package com.ym.mec.web.controller;
+
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.page.QueryInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("organization")
+@Api(tags = "组织机构服务")
+@RestController
+public class OrganizationController extends BaseController {
+
+
+    @ApiOperation(value = "分页查询组织机构树状列表")
+    @PostMapping("/queryPage")
+    public Object queryPage(QueryInfo queryInfo){
+        return null;
+    }
+}

+ 0 - 4
mec-web/src/main/java/com/ym/mec/web/controller/SchoolController.java

@@ -1,18 +1,14 @@
 package com.ym.mec.web.controller;
 
 import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.web.dal.entity.MusicGroup;
 import com.ym.mec.web.dal.entity.School;
-import com.ym.mec.web.dal.page.MusicGroupQueryInfo;
 import com.ym.mec.web.dal.page.SchoolQueryInfo;
-import com.ym.mec.web.service.MusicGroupService;
 import com.ym.mec.web.service.SchoolService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-
 import java.util.Date;
 
 @RequestMapping("school")

+ 9 - 0
mec-web/src/main/java/com/ym/mec/web/dal/dao/OrganizationDao.java

@@ -0,0 +1,9 @@
+package com.ym.mec.web.dal.dao;
+
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.web.dal.entity.Organization;
+
+public interface OrganizationDao extends BaseDAO<Integer, Organization> {
+
+	
+}

+ 92 - 0
mec-web/src/main/java/com/ym/mec/web/dal/entity/Organization.java

@@ -0,0 +1,92 @@
+package com.ym.mec.web.dal.entity;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+/**
+ * 对应数据库表(organization):
+ */
+public class Organization {
+
+	/**  */
+	private Integer id;
+	
+	/** 机构名称 */
+	private String name;
+	
+	/** 机构编码 */
+	private Integer code;
+	
+	/** 创建时间 */
+	private java.util.Date createTime;
+	
+	/** 修改时间 */
+	private java.util.Date updateTime;
+	
+	/** 是否删除  -1:已删除  0:正常 */
+	private String delFlag;
+	
+	/** 父节点编号 */
+	private Integer parentOrganId;
+	
+	public void setId(Integer id){
+		this.id = id;
+	}
+	
+	public Integer getId(){
+		return this.id;
+	}
+			
+	public void setName(String name){
+		this.name = name;
+	}
+	
+	public String getName(){
+		return this.name;
+	}
+			
+	public void setCode(Integer code){
+		this.code = code;
+	}
+	
+	public Integer getCode(){
+		return this.code;
+	}
+			
+	public void setCreateTime(java.util.Date createTime){
+		this.createTime = createTime;
+	}
+	
+	public java.util.Date getCreateTime(){
+		return this.createTime;
+	}
+			
+	public void setUpdateTime(java.util.Date updateTime){
+		this.updateTime = updateTime;
+	}
+	
+	public java.util.Date getUpdateTime(){
+		return this.updateTime;
+	}
+			
+	public void setDelFlag(String delFlag){
+		this.delFlag = delFlag;
+	}
+	
+	public String getDelFlag(){
+		return this.delFlag;
+	}
+			
+	public void setParentOrganId(Integer parentOrganId){
+		this.parentOrganId = parentOrganId;
+	}
+	
+	public Integer getParentOrganId(){
+		return this.parentOrganId;
+	}
+			
+	@Override
+	public String toString() {
+		return ToStringBuilder.reflectionToString(this);
+	}
+
+}

+ 15 - 15
mec-web/src/main/java/com/ym/mec/web/dal/entity/School.java

@@ -21,7 +21,7 @@ public class School {
 	
 	/**  */
 	@ApiModelProperty(value = "地址",required = false)
-	private String adress;
+	private String address;
 	
 	/**  */
 	@ApiModelProperty(value = "联系电话",required = false)
@@ -64,15 +64,15 @@ public class School {
 	public Integer getOrganId(){
 		return this.organId;
 	}
-			
-	public void setAdress(String adress){
-		this.adress = adress;
+
+	public String getAddress() {
+		return address;
 	}
-	
-	public String getAdress(){
-		return this.adress;
+
+	public void setAddress(String address) {
+		this.address = address;
 	}
-			
+
 	public void setContactPhone(String contactPhone){
 		this.contactPhone = contactPhone;
 	}
@@ -96,15 +96,15 @@ public class School {
 	public java.util.Date getUpdateTime(){
 		return this.updateTime;
 	}
-			
-	public void setDelFlag(String delFlag){
-		this.delFlag = delFlag;
+
+	public String getDelFlag() {
+		return delFlag;
 	}
-	
-	public String getDelFlag(){
-		return this.delFlag;
+
+	public void setDelFlag(String delFlag) {
+		this.delFlag = delFlag;
 	}
-			
+
 	public void setContactName(String contactName){
 		this.contactName = contactName;
 	}

+ 0 - 12
mec-web/src/main/java/com/ym/mec/web/dal/enums/DelFlagEnum.java

@@ -1,12 +0,0 @@
-package com.ym.mec.web.dal.enums;
-
-import com.ym.mec.common.enums.BaseEnum;
-
-public enum DelFlagEnum implements BaseEnum<String,DelFlagEnum> {
-    ;
-
-    @Override
-    public String getCode() {
-        return null;
-    }
-}

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/service/OrganizationService.java

@@ -0,0 +1,8 @@
+package com.ym.mec.web.service;
+
+import com.ym.mec.common.service.BaseService;
+import com.ym.mec.web.dal.entity.Organization;
+
+public interface OrganizationService extends BaseService<Integer, Organization> {
+
+}

+ 22 - 0
mec-web/src/main/java/com/ym/mec/web/service/impl/OrganizationServiceImpl.java

@@ -0,0 +1,22 @@
+package com.ym.mec.web.service.impl;
+
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.web.dal.dao.OrganizationDao;
+import com.ym.mec.web.dal.entity.Organization;
+import com.ym.mec.web.service.OrganizationService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organization> implements OrganizationService {
+	
+	@Autowired
+	private OrganizationDao organizationDao;
+
+	@Override
+	public BaseDAO<Integer, Organization> getDAO() {
+		return organizationDao;
+	}
+	
+}

+ 1 - 2
mec-web/src/main/resources/config.mybatis/MusicGroupMapper.xml

@@ -5,7 +5,6 @@
 不要修改此文件。所有改动将在下次重新自动生成时丢失。
 -->
 <mapper namespace="com.ym.mec.web.dal.dao.MusicGroupDao">
-
     <resultMap type="com.ym.mec.web.dal.entity.MusicGroup" id="MusicGroup">
         <result column="id_" property="id"/>
         <result column="name_" property="name"/>
@@ -110,7 +109,7 @@
     </select>
 
     <!-- 查询当前表的总记录数 -->
-    <select id="queryCount" resultType="int">
+    <select id="queryCount" resultType="int" parameterType="map">
 		SELECT COUNT(*) FROM music_group
 	</select>
 </mapper>

+ 85 - 0
mec-web/src/main/resources/config.mybatis/OrganizationMapper.xml

@@ -0,0 +1,85 @@
+<?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.ym.mec.web.dal.dao.OrganizationDao">
+
+    <resultMap type="com.ym.mec.web.dal.entity.Organization" id="Organization">
+        <result column="id_" property="id"/>
+        <result column="name_" property="name"/>
+        <result column="code_" property="code"/>
+        <result column="create_time_" property="createTime"/>
+        <result column="update_time_" property="updateTime"/>
+        <result column="del_flag_" property="delFlag"/>
+        <result column="parent_organ_id_" property="parentOrganId"/>
+    </resultMap>
+
+    <!-- 根据主键查询一条记录 -->
+    <select id="get" resultMap="Organization">
+		SELECT * FROM organization WHERE id_ = #{id} 
+	</select>
+
+    <!-- 全查询 -->
+    <select id="findAll" resultMap="Organization">
+		SELECT * FROM organization ORDER BY id_
+	</select>
+
+    <!-- 向数据库增加一条记录 -->
+    <insert id="insert" parameterType="com.ym.mec.web.dal.entity.Organization" useGeneratedKeys="true" keyColumn="id"
+            keyProperty="id">
+        <!--
+        <selectKey resultClass="int" keyProperty="id" >
+        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
+        </selectKey>
+        -->
+        INSERT INTO organization (id_,name_,code_,create_time_,update_time_,del_flag_,parent_organ_id_)
+        VALUES(#{id},#{name},#{code},#{createTime},#{updateTime},#{delFlag},#{parentOrganId})
+    </insert>
+
+    <!-- 根据主键查询一条记录 -->
+    <update id="update" parameterType="com.ym.mec.web.dal.entity.Organization">
+        UPDATE organization
+        <set>
+            <if test="delFlag != null">
+                del_flag_ = #{delFlag},
+            </if>
+            <if test="parentOrganId != null">
+                parent_organ_id_ = #{parentOrganId},
+            </if>
+            <if test="id != null">
+                id_ = #{id},
+            </if>
+            <if test="code != null">
+                code_ = #{code},
+            </if>
+            <if test="updateTime != null">
+                update_time_ = #{updateTime},
+            </if>
+            <if test="name != null">
+                name_ = #{name},
+            </if>
+            <if test="createTime != null">
+                create_time_ = #{createTime},
+            </if>
+        </set>
+        WHERE id_ = #{id}
+    </update>
+
+    <!-- 根据主键删除一条记录 -->
+    <delete id="delete">
+		DELETE FROM organization WHERE id_ = #{id} 
+	</delete>
+
+    <!-- 分页查询 -->
+    <select id="queryPage" resultMap="Organization" parameterType="map">
+        SELECT * FROM organization ORDER BY id_
+        <include refid="global.limit"/>
+    </select>
+
+    <!-- 查询当前表的总记录数 -->
+    <select id="queryCount" resultType="int">
+		SELECT COUNT(*) FROM organization
+	</select>
+</mapper>

+ 5 - 5
mec-web/src/main/resources/config.mybatis/SchoolMapper.xml

@@ -10,7 +10,7 @@
         <result column="id_" property="id"/>
         <result column="name_" property="name"/>
         <result column="organ_id_" property="organId"/>
-        <result column="adress_" property="adress"/>
+        <result column="address_" property="address"/>
         <result column="contact_phone_" property="contactPhone"/>
         <result column="create_time_" property="createTime"/>
         <result column="update_time_" property="updateTime"/>
@@ -37,8 +37,8 @@
         </selectKey>
         -->
         INSERT INTO school
-        (id_,name_,organ_id_,adress_,contact_phone_,create_time_,update_time_,del_flag_,contact_name_)
-        VALUES(#{id},#{name},#{organId},#{adress},#{contactPhone},#{createTime},#{updateTime},#{delFlag},#{contactName})
+        (id_,name_,organ_id_,address_,contact_phone_,create_time_,update_time_,del_flag_,contact_name_)
+        VALUES(#{id},#{name},#{organId},#{address},#{contactPhone},#{createTime},#{updateTime},#{delFlag},#{contactName})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -57,8 +57,8 @@
             <if test="contactPhone != null">
                 contact_phone_ = #{contactPhone},
             </if>
-            <if test="adress != null">
-                adress_ = #{adress},
+            <if test="address != null">
+                address_ = #{address},
             </if>
             <if test="contactName != null">
                 contact_name_ = #{contactName},