提交 d2e559d9 authored 作者: LJJ's avatar LJJ

上传swagger模版

上级 5798bac1
package com.zjty.efs.misc.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* MD5加密工具类
* @author LJJ cnljj1995@gmail.com
* on 2019-10-28
*/
public class MD5Untils {
public static String getMD5Str(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (byte b : byteArray) {
if (Integer.toHexString(0xFF & b).length() == 1) {
md5StrBuff.append("0").append(Integer.toHexString(0xFF & b));
} else {
md5StrBuff.append(Integer.toHexString(0xFF & b));
}
}
return md5StrBuff.toString();
}
public static void main(String[] args) {
//27FB10C9C07BC00CD4B8CE3A7F34B8C7
System.out.println(getMD5Str("meeting" + "1576475225319"));
}
// public static String MD5ToUpp16(String sourceStr) {
// try {
// // 获得MD5摘要算法的 MessageDigest对象
// StringBuffer buf = getMD5S、tringBuffer(sourceStr);
// return buf.toString().substring(8, 24).toUpperCase();// 16位加密
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
}
......@@ -12,6 +12,12 @@
<artifactId>efs-union</artifactId>
<dependencies>
<dependency>
<groupId>com.zjty</groupId>
<artifactId>efs-misc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
......
......@@ -2,6 +2,7 @@ package com.zjty.efs.union;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* 综合启动模块
......@@ -9,7 +10,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author LJJ cnljj1995@gmail.com
* on 2020-03-23
*/
@SpringBootApplication
@SpringBootApplication(scanBasePackages = {
"com.zjty.efs.misc"
})
@EnableSwagger2
public class UnionApplication {
public static void main(String[] args) {
SpringApplication.run(UnionApplication.class, args);
......
......@@ -11,5 +11,56 @@
<artifactId>efs-user</artifactId>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.zjty</groupId>
<artifactId>efs-misc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--springboot aop 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--springboot-cache-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
# dir files
/target/
/log/*
/file
/files
# Compiled class file
*.class
# Log file
*.log
.log
**/.log
# publisher file
schemes.json
# BlueJ files
*.ctxt
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# other files
!.mvn/wrapper/maven-wrapper.jar
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
/build
/code
MANIFEST.MF
_site/
activemq-data
bin
build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
overridedb.*
settings.xml
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
\ No newline at end of file
package com.zjty.efs.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-03-23
*/
@SpringBootApplication
@ComponentScan(basePackages = {
"com.zjty.efs.misc"
})
@EnableSwagger2
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
}
package com.zjty.efs.user.config;
import lombok.Data;
/**
* @author mcj
*/
@Data
public class AuthenticationBean {
String username;
String password;
}
package com.zjty.efs.user.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextListener;
import javax.servlet.annotation.WebListener;
/**
* @Author: mcj
* @Date: 19-5-7 下午4:26
* @Version 1.0
*/
@Configuration
@WebListener
public class Listener extends RequestContextListener {
}
package com.zjty.efs.user.config;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author mcj
*/
@Component
public class MyEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
httpServletResponse.setStatus(403);
httpServletResponse.setContentType("application/json");
httpServletResponse.setCharacterEncoding("utf-8");
httpServletResponse.getWriter().println("{\"code\":403,\"msg\":\"用户未登陆\"}");
}
}
package com.zjty.efs.user.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Map;
/**
* @author mcj
*/
public class MyFilter extends UsernamePasswordAuthenticationFilter {
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
SecurityContextHolder.clearContext();
//attempt Authentication when Content-Type is json
String contentType = request.getContentType();
Map<String, String[]> parameterMap = request.getParameterMap();
String method = request.getMethod();
Enumeration<String> headerNames = request.getHeaderNames();
if (request.getContentType().equals(MediaType.APPLICATION_JSON_UTF8_VALUE)
|| request.getContentType().equals(MediaType.APPLICATION_JSON_VALUE)) {
//use jackson to deserialize json
ObjectMapper mapper = new ObjectMapper();
UsernamePasswordAuthenticationToken authRequest = null;
try (InputStream is = request.getInputStream()) {
AuthenticationBean authenticationBean = mapper.readValue(is, AuthenticationBean.class);
authRequest = new UsernamePasswordAuthenticationToken(
authenticationBean.getUsername(), authenticationBean.getPassword());
} catch (IOException e) {
e.printStackTrace();
authRequest = new UsernamePasswordAuthenticationToken(
"", "");
}
setDetails(request, authRequest);
return this.getAuthenticationManager().authenticate(authRequest);
} else {
return super.attemptAuthentication(request, response);
}
}
}
package com.zjty.efs.user.config;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
/**
* @author mcj
*/
@Component
public class MyProvider implements AuthenticationProvider {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
Object principal = authentication.getPrincipal();
return null;
}
@Override
public boolean supports(Class<?> aClass) {
return true;
}
}
package com.zjty.efs.user.config;
import com.zjty.efs.user.subject.entity.User;
import com.zjty.efs.user.subject.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author mcj
*/
@Service
public class MyUserDetailsServiceImpl implements UserDetailsService {
private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
return null;
}
// @Autowired
// IUserService iUserService;
// @Autowired
// IRoleService iRoleService;
// @Autowired
// IAuthorityService iAuthorityService;
// @Autowired
// private UserService userService;
// @Override
// public UserDetails loadUserByUsername(Integer id) throws UsernameNotFoundException {
// System.out.println("userService验证:" + id);
// User user = userService.findById(id);
//
// if(user!=null && user.getClock()!=1){
// user.setUsername(username);
// user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
// ArrayList<SimpleGrantedAuthority> list = new ArrayList<>();
// String id = user.getRoleId();
// Role role = iRoleService.findRoleById(id);
// List<Authority> authorityByIds = iAuthorityService.findAuthorityByIds(role.getAuthorityIds());
// SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority("ROLE_" + role.getName());
// list.add(simpleGrantedAuthority);
// authorityByIds.forEach(authority -> {
// list.add(new SimpleGrantedAuthority(authority.getName()));
// });
// user.setArrayList(list);
// return user;
// }else{
// return new User();
// }
// }
}
package com.zjty.efs.user.config;
import com.zjty.efs.user.config.handler.MyAccessHandler;
import com.zjty.efs.user.config.handler.MyFailHandler;
import com.zjty.efs.user.config.handler.MyLogoutHandler;
import com.zjty.efs.user.config.handler.MySuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
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;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.access.channel.ChannelProcessingFilter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @author mcj
*/
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public MyProvider myProvider;
@Autowired
private MyAccessHandler accessHandler;
@Autowired
private MyEntryPoint myEntryPoint;
@Autowired
private MyUserDetailsServiceImpl myUserDetailsServiceImpl;
@Autowired
private MyLogoutHandler myLogoutHandler;
@Autowired
private MySuccessHandler successHandler;
@Autowired
private MyFailHandler failHandler;
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.cors().and()
.authorizeRequests()
// .requestMatchers(CorsUtils::isPreFlightRequest).permitAll()
.antMatchers(HttpMethod.DELETE, "/pas/user/delete/**").hasAuthority("deleteUser")
.antMatchers(HttpMethod.POST, "/pas/user").hasAuthority("addUser")
.antMatchers(HttpMethod.PUT, "/pas/user").hasAuthority("updateUser")
.antMatchers(HttpMethod.POST, "/pas/department").hasAuthority("system")
.antMatchers(HttpMethod.POST, "/pas/role").hasAuthority("system")
.antMatchers(HttpMethod.GET, "/pas/authority").hasAuthority("system")
.antMatchers(HttpMethod.POST, "/pas/group").hasAuthority("system")
.antMatchers(HttpMethod.OPTIONS,"/**").permitAll()
.antMatchers("/pas/count").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginProcessingUrl("/userLogin")
.and()
.logout()
.logoutUrl("/userLogout")
//.logoutSuccessUrl("/userLogout")
.logoutSuccessHandler(myLogoutHandler)
.deleteCookies("JESSIONID")
.permitAll()
.and()
.exceptionHandling()
.accessDeniedHandler(accessHandler)
.authenticationEntryPoint(myEntryPoint)
.and()
.addFilterAt(myFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(corsFilter(), ChannelProcessingFilter.class)
.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).disable().sessionManagement().maximumSessions(1).expiredUrl("/userLogout").sessionRegistry(sessionRegistry())
;
}
@Override
public void configure(WebSecurity web) throws Exception {
//swagger静态资源访问
web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**","/swagger-resources/configuration/ui","/swagge‌​r-ui.html");
}
@Bean
public MyFilter myFilter() throws Exception {
MyFilter filter = new MyFilter();
filter.setAuthenticationSuccessHandler(successHandler);
filter.setAuthenticationFailureHandler(failHandler);
filter.setFilterProcessesUrl("/userLogin");
filter.setAuthenticationManager(this.authenticationManager());
return filter;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(myUserDetailsServiceImpl);
// auth.authenticationProvider(myProvider);
// auth.inMemoryAuthentication().withUser("root").password(bCryptPasswordEncoder().encode("root")).roles("admin").authorities("addUser","deleteUser","updateUser","system");
}
@Bean
public SessionRegistry sessionRegistry(){
return new SessionRegistryImpl();
}
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder(){
return new BCryptPasswordEncoder();
}
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}
package com.zjty.efs.user.config.handler;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author mcj
*/
@Component
public class MyAccessHandler implements AccessDeniedHandler {
@Override
public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
httpServletResponse.setStatus(403);
httpServletResponse.setCharacterEncoding("utf-8");
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().println("{\"code\":403,\"msg\":\"没有权限访问接口\"}");
}
}
package com.zjty.efs.user.config.handler;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author mcj
*/
@Component
public class MyFailHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
httpServletResponse.setStatus(200);
httpServletResponse.setCharacterEncoding("utf-8");
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().println("{\"code\":401,\"msg\":\"用户登陆失败\"}");
}
}
package com.zjty.efs.user.config.handler;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
/**
* @Author: mcj
* @Date: 19-5-31 下午2:10
* @Version 1.0
*/
@Component
public class MyLogoutHandler implements LogoutSuccessHandler {
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
httpServletResponse.setStatus(200);
httpServletResponse.setCharacterEncoding("utf-8");
Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
httpServletResponse.setContentType("application/json");
try {
httpServletResponse.getWriter().println("{\"code\":200,\"msg\":\"用户登出成功\"}");
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.zjty.efs.user.config.handler;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* @author mcj
*/
@Component
@Slf4j
public class MySuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
}
// @Autowired
// private SessionRegistry sessionRegistry;
//
// @Autowired
// private IAuthorityService iAuthorityService;
//
// @Autowired
// IRoleService iRoleService;
//
// @Autowired
// IMenuSerivce iMenuSerivce;
//
// private BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
//
// @Autowired
// IUserService iUserService;
//
// @Autowired
// RedisTemplate redisTemplate;
//
// @Override
// public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
// Cookie[] cookies = httpServletRequest.getCookies();
// if(cookies==null){
// return;
// }
// String value = cookies[0].getValue();
// List<Object> o = sessionRegistry.getAllPrincipals();
// User user = (User) authentication.getPrincipal();
// for (Object principal : o) {
// User cacheUser = (User) principal;
// if (cacheUser.getUsername().equals(user.getUsername())) {
// log.info("当前用户已经在线上.现顶替:{}",user.getUsername());
// List<SessionInformation> sessions = sessionRegistry.getAllSessions(cacheUser, false);
// for (SessionInformation sessionInformation : sessions) {
// String sessionId = sessionInformation.getSessionId();
//
// sessionInformation.expireNow();
// }
// }
// }
//
// redisTemplate.opsForValue().set(user.getUsername(),0);
//
// UserVo userVo = new UserVo().user2userVo(user);
// User username = iUserService.findUserByUsername(userVo.getUsername());
// Role role = iRoleService.findRoleById(user.getRoleId());
// RoleVo roleVo = new RoleVo();
// User user1 = iUserService.findUserByUsername(userVo.getUsername());
// userVo.setPassword(user1.getPassword());
// roleVo.setRoleId(user.getRoleId());
// List<Menu> allByMenuId = iMenuSerivce.findAllByMenuId(role.getMenuIds());
// roleVo.setMenus(allByMenuId);
// roleVo.setRoleName(role.getName());
// userVo.setRole(roleVo);
// List<Authority> authorityByIds = iAuthorityService.findAuthorityByIds(role.getAuthorityIds());
// roleVo.setAuthorities(authorityByIds);
//
// sessionRegistry.registerNewSession(value, authentication.getPrincipal());
// httpServletResponse.setStatus(200);
// httpServletResponse.setContentType("application/json; charset=utf-8");
// httpServletResponse.getWriter().println(new ObjectMapper().writeValueAsString(userVo));
//
//
// }
}
# dir files
/target/
/log/*
/file
/files
# Compiled class file
*.class
# Log file
*.log
.log
**/.log
# publisher file
schemes.json
# BlueJ files
*.ctxt
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# other files
!.mvn/wrapper/maven-wrapper.jar
*#
*.iml
*.ipr
*.iws
*.jar
*.sw?
*~
.#*
.*.md.html
.DS_Store
.classpath
.factorypath
.gradle
.idea
.metadata
.project
.recommenders
.settings
.springBeans
/build
/code
MANIFEST.MF
_site/
activemq-data
bin
build
build.log
dependency-reduced-pom.xml
dump.rdb
interpolated*.xml
lib/
manifest.yml
overridedb.*
settings.xml
target
transaction-logs
.flattened-pom.xml
secrets.yml
.gradletasknamecache
.sts4-cache
\ No newline at end of file
package com.zjty.efs.user.subject.controller;
import com.zjty.efs.user.subject.entity.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-03-24
*/
@RestController
@RequestMapping("/api")
public class UserController {
@GetMapping
@ApiOperation(value = "查询用户的接口")
@ApiImplicitParams({
@ApiImplicitParam(name="id",value="人员id",dataType="Integer", paramType = "int",required = true)
})
public ResponseEntity<User> getUserById(@RequestParam Integer id) {
return ResponseEntity.ok(new User());
}
}
package com.zjty.efs.user.subject.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zjty.efs.misc.config.AutoDocument;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-03-23
*/
@Data
@Entity
@AutoDocument
@ApiModel(value = "用户", description = "用户实体类")
public class User {
@ApiModelProperty(value = "id",example = "jksdhfjks5")
@Id
private String id;
@NotEmpty(message = "用户姓名不可为空")
@ApiModelProperty(value = "用户姓名",example = "mcj")
private String name;
@NotNull(message = "岗位不可为空")
@ApiModelProperty(value = "岗位",example = "1")
private String job;
@NotEmpty(message = "身份证号码不可为空")
@ApiModelProperty(value = "身份证",example = "48489498131566546")
private String idCard;
@NotEmpty(message = "联系方式不可为空")
@ApiModelProperty(value = "联系方式",example = "113665465465")
private String tel;
@NotEmpty(message = "地址不可为空")
@ApiModelProperty(value = "地址",example = "xx路xx楼xx号")
private String address;
@NotNull(message = "到岗时间不可为空")
@ApiModelProperty(value = "到岗时间",example = "2019-01-45 12:12:12")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date insertTime;
@ApiModelProperty(value = "组id",example = "[1,2,3]")
private List<String> groupId;
@NotNull(message = "部门不可为空")
@ApiModelProperty(value = "部门id",example = "1")
private String departId;
@NotNull(message = "性别不可为空")
@ApiModelProperty(value = "性别,0_男,1_女",example = "1")
private Integer sex;
@ApiModelProperty(value = "备注",example = "dadsd")
private String remark;
@NotEmpty(message = "用户名不可为空")
@ApiModelProperty(value = "用户名",example = "username")
private String username;
@NotEmpty(message = "密码不可为空")
@ApiModelProperty(value = "密码",example = "password")
private String password;
@NotNull(message = "用户锁定状态不可为空")
@ApiModelProperty(value = "用户锁定状态,0_未锁定,1_已锁定",example = "1")
private Integer status;
}
package com.zjty.efs.user.subject.service;
import com.sun.tools.corba.se.idl.InterfaceGen;
import com.zjty.efs.user.subject.entity.User;
import java.util.List;
/**
* 提供给前端的方法
*
* @author LJJ cnljj1995@gmail.com
* on 2020-03-24
*/
public interface UserService {
/**
* 根据id查找
* @param id user id
* @return user obj
*/
User findById(Integer id);
/**
* 查找所用用户,除了管理员
* @return users obj
*/
List<User> findAllUser();
/**
* 更新人员状态
* 1,正常 2,冻结
* @return true 成功 false 失败
*/
Boolean updateUserStatus();
/**
* 查询可以发布消息的人员
* 需除去admin及自己
* @param id 人员id
* @return users obj
*/
List<User> getAllowAckUser(Integer id);
/**
* 重置密码
* @param id 人员id
* @param pwd 重置的密码
* @return true 成功 false 失败
*/
Boolean resetPassword(Integer id, String pwd);
/**
* 创建用户
* @param user 用户对象
* @return true or false
*/
Boolean addUser(User user);
}
package com.zjty.efs.user.subject.service.impl;
import com.zjty.efs.user.subject.entity.User;
import com.zjty.efs.user.subject.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author LJJ cnljj1995@gmail.com
* on 2020-03-24
*/
@Service
@Slf4j
public class UserServiceImpl implements UserService {
@Override
public User findById(Integer id) {
return null;
}
@Override
public List<User> findAllUser() {
return null;
}
@Override
public Boolean updateUserStatus() {
return null;
}
@Override
public List<User> getAllowAckUser(Integer id) {
return null;
}
@Override
public Boolean resetPassword(Integer id, String pwd) {
return null;
}
@Override
public Boolean addUser(User user) {
return null;
}
}
logging.file=./log/efs.log
spring.main.allow-bean-definition-overriding=true
##连接中心数据库数据库mysql
spring.datasource.url=jdbc:mysql://localhost:3306/efs?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=ljj123456
server.port=8081
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论