Commit 9610ce64 by 王厚康

登陆验证

parent 68a77ac3
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId> <groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId> <artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version> <version>6.0.0</version>
...@@ -91,7 +96,16 @@ ...@@ -91,7 +96,16 @@
<version>1.2.3</version> <version>1.2.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.24</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.31</version>
</dependency>
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
......
package com.bbd.bpm.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.*;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* Created by houkang on 2019/3/19.
*/
@Configuration
public class DruidConfig {
private static final String DB_PREFIX = "spring.datasource-";
@Autowired
private Environment environment;
@Bean
@ConfigurationProperties(prefix = DB_PREFIX)
public DataSource druidDataSource() {
Properties dbProperties = new Properties();
Map<String, Object> map = new HashMap<>();
for (PropertySource<?> propertySource : ((AbstractEnvironment) environment).getPropertySources()) {
getPropertiesFromSource(propertySource, map);
}
dbProperties.putAll(map);
DruidDataSource dds;
try {
dds = (DruidDataSource) DruidDataSourceFactory.createDataSource(dbProperties);
dds.init();
} catch (Exception e) {
throw new RuntimeException("load datasource error, dbProperties is :" + dbProperties, e);
}
return dds;
}
private void getPropertiesFromSource(PropertySource<?> propertySource, Map<String, Object> map) {
if (propertySource instanceof MapPropertySource) {
for (String key : ((MapPropertySource) propertySource).getPropertyNames()) {
if (key.startsWith(DB_PREFIX))
map.put(key.replaceFirst(DB_PREFIX, ""), propertySource.getProperty(key));
else if (key.startsWith(DB_PREFIX))
map.put(key.replaceFirst(DB_PREFIX, ""), propertySource.getProperty(key));
}
}
if (propertySource instanceof CompositePropertySource) {
for (PropertySource<?> s : ((CompositePropertySource) propertySource).getPropertySources()) {
getPropertiesFromSource(s, map);
}
}
}
@Bean
public ServletRegistrationBean druidServlet() {
return new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new WebStatFilter());
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
return filterRegistrationBean;
}
}
package com.bbd.bpm.config;
import com.bbd.bpm.domain.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.ArrayList;
import java.util.Collection;
/**
* Created by houkang on 2019/3/19.
*/
public class SecurityUser extends User implements UserDetails {
private static final long serialVersionUID = 1L;
public SecurityUser(User user) {
if (user != null) {
this.setUserUuid(user.getUserUuid());
this.setUsername(user.getUsername());
this.setPassword(user.getPassword());
this.setEmail(user.getEmail());
this.setTelephone(user.getTelephone());
this.setRole(user.getRole());
this.setImage(user.getImage());
this.setLastIp(user.getLastIp());
this.setLastTime(user.getLastTime());
}
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> authorities = new ArrayList<>();
String username = this.getUsername();
if (username != null) {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(username);
authorities.add(authority);
}
return authorities;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
}
\ No newline at end of file
...@@ -8,7 +8,6 @@ import springfox.documentation.builders.PathSelectors; ...@@ -8,7 +8,6 @@ import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*; import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
...@@ -20,29 +19,35 @@ import java.time.LocalDate; ...@@ -20,29 +19,35 @@ import java.time.LocalDate;
public class SwaggerConfig { public class SwaggerConfig {
@Bean @Bean
public Docket petApi() { public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select() .select()
.apis(RequestHandlerSelectors.basePackage("com.bbd.bpm.controller")) .apis(RequestHandlerSelectors.basePackage("com.bbd.bpm.controller"))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build() .build();
.apiInfo(apiInfo())
.pathMapping("/")
.directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false);
} }
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfoBuilder() return new ApiInfoBuilder()
.title("IOS Api Documentation") .title("springboot利用swagger构建api文档")
.description("IOS Api Documentation") .description("简单优雅的restfun风格,http://blog.csdn.net/saytime")
.contact(new Contact("Jason", "http://www.iata.org", "sunjc@iata.org")) .termsOfServiceUrl("http://blog.csdn.net/saytime")
.version("1.0") .version("1.0")
.build(); .build();
} }
/**
* @ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页数1开始", dataType = "int",paramType = "query"),
@ApiImplicitParam(name = "pageSize", value = "每页的大小", dataType = "int",paramType = "query"),
@ApiImplicitParam(name = "userId", value = "当前登录的用户id", dataType = "int",paramType = "query")
})
* */
} }
\ No newline at end of file
package com.bbd.bpm.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Created by houkang on 2019/3/19.
*/
@Configuration
@EnableAsync
public class ThreadPoolConfig {
@Bean
public Executor getExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);//线程池维护线程的最少数量
executor.setMaxPoolSize(30);//线程池维护线程的最大数量
executor.setQueueCapacity(8); //缓存队列
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //对拒绝task的处理策略
executor.setKeepAliveSeconds(60);//允许的空闲时间
executor.initialize();
return executor;
}
}
\ No newline at end of file
package com.bbd.bpm.config;
import com.bbd.bpm.domain.User;
import com.bbd.bpm.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.Authentication;
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.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* Created by houkang on 2019/3/19.
*/
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger logger = LoggerFactory.getLogger(WebSecurityConfig.class);
@Override
protected void configure(HttpSecurity http) throws Exception { //配置策略
http.csrf().disable();
http.authorizeRequests().
antMatchers("/static/**").permitAll().anyRequest().authenticated().
and().formLogin().loginPage("/login").permitAll().successHandler(loginSuccessHandler()).
and().logout().permitAll().invalidateHttpSession(true).
deleteCookies("JSESSIONID").logoutSuccessHandler(logoutSuccessHandler()).
and().sessionManagement().maximumSessions(10).expiredUrl("/login");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
auth.eraseCredentials(false);
}
@Bean
public BCryptPasswordEncoder passwordEncoder() { //密码加密
return new BCryptPasswordEncoder(4);
}
@Bean
public LogoutSuccessHandler logoutSuccessHandler() { //登出处理
return new LogoutSuccessHandler() {
@Override
public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
try {
SecurityUser user = (SecurityUser) authentication.getPrincipal();
logger.info("USER : " + user.getUsername() + " LOGOUT SUCCESS ! ");
} catch (Exception e) {
logger.info("LOGOUT EXCEPTION , e : " + e.getMessage());
}
httpServletResponse.sendRedirect("/login");
}
};
}
@Bean
public SavedRequestAwareAuthenticationSuccessHandler loginSuccessHandler() { //登入处理
return new SavedRequestAwareAuthenticationSuccessHandler() {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
User userDetails = (User) authentication.getPrincipal();
logger.info("USER : " + userDetails.getUsername() + " LOGIN SUCCESS ! ");
super.onAuthenticationSuccess(request, response, authentication);
}
};
}
@Bean
@Override
public UserDetailsService userDetailsService() { //用户登录实现
return new UserDetailsService() {
@Autowired
private UserRepository userRepository;
@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
User user = userRepository.findByUsername(s);
if (user == null){ throw new UsernameNotFoundException("Username " + s + " not found");}
return new SecurityUser(user);
}
};
}
}
\ No newline at end of file
package com.bbd.bpm.controller;
import com.bbd.bpm.domain.User;
import com.bbd.bpm.domain.VacationForm;
import com.bbd.bpm.service.MiaoService;
import com.bbd.bpm.util.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Controller
public class MiaoController {
@Autowired
private MiaoService miaoService;
@GetMapping( "/")
public String login(){
return "login";
}
//申请者的首页
@GetMapping( "/home")
public String index(ModelMap model, HttpServletRequest request){
List<VacationForm> forms = miaoService.formList();
Cookie[] cookies = request.getCookies();
String user = "";
//从cookie中获取当前用户
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("userInfo")) {
user = cookie.getValue();
break;
}
}
}
List<HashMap<String, Object>> formsMap = new ArrayList<HashMap<String, Object>>();
for(VacationForm form : forms) {
//申请者只能看到自己申请的请假单信息
if(user.equals(form.getApplicant())) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", form.getId());
map.put("title", form.getTitle());
map.put("content", form.getContent());
map.put("applicant", form.getApplicant());
map.put("days", form.getDays());
map.put("state", form.getState());
formsMap.add(map);
}
}
//将forms参数返回
model.addAttribute("forms",formsMap);
return "index";
}
//审核者的首页
@GetMapping( "/homeApprover")
public String indexApprover(ModelMap model){
List<VacationForm> forms = miaoService.formList();
List<HashMap<String, Object>> formsMap = new ArrayList<HashMap<String, Object>>();
for(VacationForm form : forms) {
//审核者只能看到待审核状态的请假单
if("领导审核".equals(form.getState())) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", form.getId());
map.put("title", form.getTitle());
map.put("content", form.getContent());
map.put("applicant", form.getApplicant());
map.put("state", form.getState());
formsMap.add(map);
}
}
model.addAttribute("forms",formsMap);
return "indexApprover";
}
//管理层的首页
@GetMapping( "/homeApproverzjl")
public String homeApproverzjl(ModelMap model){
List<VacationForm> forms = miaoService.formList();
List<HashMap<String, Object>> formsMap = new ArrayList<HashMap<String, Object>>();
for(VacationForm form : forms) {
//审核者只能看到待审核状态的请假单
if("管理层审核".equals(form.getState())) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", form.getId());
map.put("title", form.getTitle());
map.put("content", form.getContent());
map.put("applicant", form.getApplicant());
map.put("state", form.getState());
formsMap.add(map);
}
}
model.addAttribute("forms",formsMap);
return "indexApproverzjl";
}
//人事的首页
@GetMapping( "/homeApproverHr")
public String homeApproverHr(ModelMap model){
List<VacationForm> forms = miaoService.formList();
List<HashMap<String, Object>> formsMap = new ArrayList<HashMap<String, Object>>();
for(VacationForm form : forms) {
//审核者只能看到待审核状态的请假单
if("通知人事".equals(form.getState())||"已结束".equals(form.getState())) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("id", form.getId());
map.put("title", form.getTitle());
map.put("content", form.getContent());
map.put("applicant", form.getApplicant());
map.put("state", form.getState());
map.put("approver",form.getApprover());
formsMap.add(map);
}
}
model.addAttribute("forms",formsMap);
return "indexApproverHr";
}
//请假单页面
@GetMapping( "/form")
public String form(){
return "form";
}
@PostMapping( "/login")
@ResponseBody
public ResultInfo login(HttpServletRequest request, HttpServletResponse response){
ResultInfo result = new ResultInfo();
String username = request.getParameter("username");
User user = miaoService.loginSuccess(username);
if(user != null) {
result.setCode(200);
result.setMsg("登录成功");
result.setInfo(user);
//用户信息存放在Cookie中,实际情况下保存在Redis更佳
Cookie cookie = new Cookie("userInfo", username);
cookie.setPath("/");
response.addCookie(cookie);
}else {
result.setCode(300);
result.setMsg("登录名不存在,登录失败");
}
return result;
}
@GetMapping("/logout")
@ResponseBody
public ResultInfo logout(HttpServletRequest request, HttpServletResponse response) {
ResultInfo result = new ResultInfo();
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("userInfo")) {
cookie.setValue(null);
// 立即销毁cookie
cookie.setMaxAge(0);
cookie.setPath("/");
response.addCookie(cookie);
break;
}
}
}
result.setCode(200);
return result;
}
//添加请假单
@GetMapping( "/writeForm")
@ResponseBody
public ResultInfo writeForm(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String title = request.getParameter("title");
String days = request.getParameter("days");
String content = request.getParameter("content");
String operator = request.getParameter("operator");
VacationForm form = miaoService.writeForm(title,content,operator,days);
result.setCode(200);
result.setMsg("填写请假条成功");
result.setInfo(form);
return result;
}
//申请者放弃请假
@GetMapping( "/giveup")
@ResponseBody
public ResultInfo giveup(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String formId = request.getParameter("formId");
String days = request.getParameter("days");
String operator = request.getParameter("operator");
miaoService.completeProcess(days,formId, operator, "giveup");
result.setCode(200);
result.setMsg("放弃请假成功");
return result;
}
//申请未通过
@GetMapping( "/giveups")
@ResponseBody
public ResultInfo giveups(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String formId = request.getParameter("formId");
String days = request.getParameter("days");
String operator = request.getParameter("operator");
miaoService.completeProcesss(days,formId, operator, "giveup");
result.setCode(200);
result.setMsg("放弃请假成功");
return result;
}
//申请者申请请假
@GetMapping( "/apply")
@ResponseBody
public ResultInfo apply(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String formId = request.getParameter("formId");
String operator = request.getParameter("operator");
String days = request.getParameter("days");
miaoService.completeProcess(days,formId, operator, "apply");
result.setCode(200);
result.setMsg("申请请假成功");
return result;
}
//审批者审核请假信息
@GetMapping( "/approve")
@ResponseBody
public ResultInfo approve(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String formId = request.getParameter("formId");
String operator = request.getParameter("operator");
miaoService.approverVacation(formId, operator);
result.setCode(200);
result.setMsg("请假审核成功");
return result;
}
//获取某条请假信息当前状态
@GetMapping( "/currentState")
public HashMap<String,String> currentState(HttpServletRequest request){
String formId = request.getParameter("formId");
HashMap<String,String> map = new HashMap<String,String>();
map = miaoService.getCurrentState(formId);
return map;
}
@GetMapping( "/historyState")
@ResponseBody
public ResultInfo queryHistoricTask(HttpServletRequest request){
ResultInfo result = new ResultInfo();
String formId = request.getParameter("formId");
List process = miaoService.historyState(formId);
result.setCode(200);
result.setInfo(process);
return result;
}
}
package com.bbd.bpm.controller.user;
import com.bbd.bpm.domain.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
/**
* Created by houkang on 2019/3/19.
*/
@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login() {
return "login";
}
@RequestMapping(value="/" ,method = RequestMethod.GET)
public String root(Principal principal, ModelMap m) {
m.addAttribute("userName",principal.getName());
return "bpm/index";
}
public User getUser() { //为了session从获取用户信息,可以配置如下
User user = new User();
SecurityContext ctx = SecurityContextHolder.getContext();
Authentication auth = ctx.getAuthentication();
if (auth.getPrincipal() instanceof UserDetails){ user = (User) auth.getPrincipal();}
return user;
}
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
}
\ No newline at end of file
...@@ -18,7 +18,7 @@ import javax.servlet.http.HttpSession; ...@@ -18,7 +18,7 @@ import javax.servlet.http.HttpSession;
@Controller @Controller
@RequestMapping(value = "bpm/user") @RequestMapping(value = "bpm/user")
public class userController { public class UserController {
......
package com.bbd.bpm.domain; package com.bbd.bpm.domain;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.GeneratedValue;
import javax.persistence.Id; /**
import javax.persistence.Table; * Created by houkang on 2019/1/3.
*/
//用户信息表 //用户信息表
@Entity @Entity
@Table(name = "user") @Table(name = "user")
public class User { public class User {
@Id @Id
@GeneratedValue @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private Integer id; private Integer id;
private String name; @Column(name="user_uuid")
private String userUuid; //用户UUID
@Column(name="username")
private String username; //用户名
@Column(name="password")
private String password; //用户密码
@Column(name="email")
private String email; //用户邮箱
@Column(name="telephone")
private String telephone; //电话号码
//用户身份标识(1-申请者,2-审核者) @Column(name="role")
private Integer type; private String role; //用户角色
@Column(name="image")
private String image; //用户头像
@Column(name="last_ip")
private String lastIp; //上次登录IP
@Column(name="last_time")
private String lastTime; //上次登录时间
private Integer delete_flag;
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -28,28 +51,93 @@ public class User { ...@@ -28,28 +51,93 @@ public class User {
this.id = id; this.id = id;
} }
public String getName() { public String getUserUuid() {
return name; return userUuid;
}
public void setUserUuid(String userUuid) {
this.userUuid = userUuid;
}
public String getLastIp() {
return lastIp;
}
public void setLastIp(String lastIp) {
this.lastIp = lastIp;
}
public String getLastTime() {
return lastTime;
}
public void setLastTime(String lastTime) {
this.lastTime = lastTime;
} }
public void setName(String name) { public String getUsername() {
this.name = name; return username;
} }
public Integer getType() { public void setUsername(String username) {
return type; this.username = username;
} }
public void setType(Integer type) { public String getPassword() {
this.type = type; return password;
} }
public Integer getDelete_flag() { public void setPassword(String password) {
return delete_flag; this.password = password;
} }
public void setDelete_flag(Integer delete_flag) { public String getEmail() {
this.delete_flag = delete_flag; return email;
} }
public void setEmail(String email) {
this.email = email;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", user_uuid='" + userUuid + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
", email='" + email + '\'' +
", telephone='" + telephone + '\'' +
", role='" + role + '\'' +
", image='" + image + '\'' +
", last_ip='" + lastIp + '\'' +
", last_time='" + lastTime + '\'' +
'}';
}
} }
\ No newline at end of file
package com.bbd.bpm.repository;
import com.bbd.bpm.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* Created by houkang on 2019/3/19.
*/
public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(String username);
}
package com.bbd.bpm.service;
import com.bbd.bpm.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface UserService extends JpaRepository<User, Long> {
public List<User> findByName(String name);
}
\ No newline at end of file
package com.bbd.bpm.serviceImpl;
import com.bbd.bpm.domain.User;
import com.bbd.bpm.domain.VacationForm;
import com.bbd.bpm.service.MiaoService;
import com.bbd.bpm.service.UserService;
import com.bbd.bpm.service.VacationFormService;
import io.swagger.models.auth.In;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Service("miaoService")
public class MiaoServiceImpl implements MiaoService {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
HistoryService historyService;
@Autowired
private VacationFormService vacationFormService;
@Autowired
private UserService userService;
//填写请假信息
@Override
public VacationForm writeForm(String title, String content, String applicant,String days) {
VacationForm form = new VacationForm();
String approver = "未知审批者";
form.setTitle(title);
form.setDays(Integer.valueOf(days));
form.setContent(content);
form.setApplicant(applicant);
form.setApprover(approver);
vacationFormService.save(form);
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employee", form.getApplicant());
//开始请假流程,使用formId作为流程的businessKey
runtimeService.startProcessInstanceByKey("myProcee", form.getId().toString(), variables);
return form;
}
//根据选择,申请或放弃请假
@Override
public void completeProcess(String days,String formId, String operator, String input) {
//根据businessKey找到当前任务节点
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
//设置输入参数,使流程自动流转到对应节点
taskService.setVariable(task.getId(), "input", input);
taskService.complete(task.getId());
if ("apply".equals(input)) {
applyVacation(formId, operator,days);
} else {
giveupVacation(formId, operator);
}
}
//放弃请假
@Override
public boolean giveupVacation(String formId, String operator) {
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employee", operator);
//认领任务
taskService.claim(task.getId(), operator);
//完成任务
taskService.complete(task.getId(), variables);
return true;
}
public boolean applyVacation(String formId, String operator,String days) {
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
List<User> users = userService.findAll();
String managers = "";
//获取所有具有审核权限的用户
for (User user : users) {
if (user.getType().equals(2)) {
managers += user.getName() + ",";
}
}
managers = managers.substring(0, managers.length() - 1);
variables.put("employee", operator);
variables.put("managers", managers);
Integer day= Integer.valueOf(days);
variables.put("days",day);
taskService.claim(task.getId(), operator);
taskService.complete(task.getId(), variables);
return true;
}
@Override
public boolean approverVacation(String formId, String operator) {
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
List<User> users = userService.findAll();
String managers = "";
//获取所有具有审核权限的用户
for (User user : users) {
if (user.getType().equals(3)) {
managers += user.getName() + ",";
}
}
managers = managers.substring(0, managers.length() - 1);
variables.put("employee", operator);
variables.put("managers", managers);
taskService.claim(task.getId(), operator);
taskService.complete(task.getId(),variables);
//更新请假信息的审核人
try{
VacationForm form = vacationFormService.findById(Integer.parseInt(formId)).get();
if (form != null) {
form.setApprover(operator);
vacationFormService.save(form);
}
}catch (Exception e){
e.printStackTrace();
}
return true;
}
//获取请假信息的当前流程状态
@Override
public HashMap<String, String> getCurrentState(String formId) {
HashMap<String, String> map = new HashMap<String, String>();
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
if (task != null) {
map.put("status", "processing");
map.put("taskId", task.getId());
map.put("taskName", task.getName());
map.put("user", task.getAssignee());
} else {
map.put("status", "finish");
}
return map;
}
//请假列表
@Override
public List<VacationForm> formList() {
List<VacationForm> formList = vacationFormService.findAll();
for (VacationForm form : formList) {
Task task = taskService.createTaskQuery().processInstanceBusinessKey(form.getId().toString())
.singleResult();
if (task != null) {
String state = task.getName();
form.setState(state);
} else {
form.setState("已结束");
}
}
return formList;
}
//登录验证用户名是否存在
@Override
public User loginSuccess(String username) {
List<User> users = userService.findByName(username);
if (users != null && users.size() > 0) {
User user = users.get(0);
return user;
}
return null;
}
//获取当前登录用户
public String getCurrentUser(HttpServletRequest request) {
String user = "";
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("userInfo")) {
user = cookie.getValue();
}
}
}
return user;
}
//获取已执行的流程信息
@Override
public List historyState(String formId) {
List<HashMap<String, String>> processList = new ArrayList<HashMap<String, String>>();
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery()
.processInstanceBusinessKey(formId).list();
if (list != null && list.size() > 0) {
for (HistoricTaskInstance hti : list) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", hti.getName());
map.put("operator", hti.getAssignee());
processList.add(map);
}
}
return processList;
}
@Override
public void completeProcesss(String days, String formId, String operator, String input) {
//根据businessKey找到当前任务节点
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
//设置输入参数,使流程自动流转到对应节点
taskService.setVariable(task.getId(), "input", input);
taskService.complete(task.getId());
giveupVacations(formId, operator);
}
//放弃请假
public boolean giveupVacations(String formId, String operator) {
Task task = taskService.createTaskQuery().processInstanceBusinessKey(formId).singleResult();
Map<String, Object> variables = new HashMap<String, Object>();
VacationForm vacationForm = vacationFormService.getOne(Integer.valueOf(formId));
variables.put("employee", vacationForm.getApplicant());
variables.put("managers", operator);
//认领任务
taskService.claim(task.getId(), vacationForm.getApplicant());
return true;
}
}
package com.bbd.bpm.util;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* Created by houkang on 2019/3/19.
*/
public class TestUtil {
public static void encoder() {
String password = "admin";
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(4);
String enPassword = encoder.encode(password);
System.out.println(enPassword);
}
public static void main(String[] args){
encoder();
}
}
#端口 #端口
server.port=8081 server.port=8081
spring.datasource.url=jdbc:mysql://106.75.97.50:3306/test?characterEncoding=UTF-8 spring.datasource-url=jdbc:mysql://106.75.97.50:3306/test?characterEncoding=UTF-8
spring.datasource.username=airuser spring.datasource-username=airuser
spring.datasource.password=!@JD@2016 spring.datasource-password=!@JD@2016
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 spring.datasource-type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver spring.datasource-driver-class-name=com.mysql.cj.jdbc.Driver
##Druid##
#spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#连接池启动时创建的连接数量的初始值
spring.datasource.initialSize=5
#最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请
spring.datasource.minIdle=5
#连接池的最大值,同一时间可以从池分配的最多连接数量,0时无限制
spring.datasource.maxActive=100
#最大建立连接等待时间。单位为 ms,如果超过此时间将接到异常。设为-1表示无限制
spring.datasource.maxWait=60000
#1) Destroy线程会检测连接的间隔时间2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明
spring.datasource.timeBetweenEvictionRunsMillis=60000
#配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.minEvictableIdleTimeMillis=300000
#用来检测连接是否有效的sql,要求是一个查询语句
spring.datasource.validationQuery=SELECT 1
#建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效
spring.datasource.testWhileIdle=true
#申请连接时执行validationQuery检测连接是否有效,配置true会降低性能
spring.datasource.testOnBorrow=false
#归还连接时执行validationQuery检测连接是否有效,配置true会降低性能
spring.datasource.testOnReturn=false
#是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。
spring.datasource.poolPreparedStatements=true
#指定每个连接上PSCache的大小
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
#属性类型是字符串,通过别名的方式配置扩展插件,
#常用的插件有:监控统计用的filter:stat日志用的filter:log4j防御sql注入的filter:wall #常用的插件有:监控统计用的filter:stat日志用的filter:log4j防御sql注入的filter:wall
spring.datasource.filters=stat,wall,log4j
spring.datasource.useGlobalDataSourceStat=true
############################### ###############################
# Specify the DBMS # Specify the DBMS
spring.jpa.database=MYSQL spring.jpa.database=MYSQL
...@@ -48,7 +21,11 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect ...@@ -48,7 +21,11 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.resources.add-mappings=true spring.resources.add-mappings=true
springfox.documentation.swagger.v2.path: /api-docs spring.freemarker.template-loader-path= classpath:/templates/
spring.freemarker.suffix= .html
spring.freemarker.content-type:= text/html
spring.freemarker.charset= UTF-8
spring.mvc.static-path-pattern=/**
...@@ -29,14 +29,21 @@ ...@@ -29,14 +29,21 @@
</div> </div>
</shiro:hasRole> </shiro:hasRole>
<div class="userBox right" style="padding-right:100px;"> <div class="userBox right" style="padding-right:100px;">
<!--<span class="glyphicon glyphicon-user"><span th:text="${session.userInfo.userName}"></span></span> <span class="glyphicon glyphicon-user"><span th:text="${userName}"></span> </span>
<span class="glyphicon glyphicon-off" onclick="loginOut()" style="cursor: pointer" title="退出登陆"></span>--> <a href="/logout"> <span class="glyphicon glyphicon-off" style="cursor: pointer" title="退出登陆"></span></a>
</div> </div>
</div> </div>
<!--end 头部--> <!--end 头部-->
<!--左边导航--> <!--左边导航-->
<div class="main_wrap clearfix" > <div class="main_wrap clearfix" >
<ul id="aside_nav" class="navBox" style='width:125px;min-height: 680px;'></ul> <ul id="aside_nav" class="navBox" style='width:125px;min-height: 680px;'>
<li class="s_menu_item"><a target="main_frame" href="">查看流程</a></li>
<li class="s_menu_item"><a target="main_frame" href="/model/createNew">创建流程</a></li>
<li class="s_menu_item"><a target="main_frame" href="/model/createNew">组织结构</a></li>
<li class="s_menu_item"><a target="main_frame" href="/model/createNew">API</a></li>
</ul>
</div> </div>
<!--end 左边导航--> <!--end 左边导航-->
<div class="mainContentBox"> <div class="mainContentBox">
...@@ -46,51 +53,7 @@ ...@@ -46,51 +53,7 @@
<!--end 主体内容--> <!--end 主体内容-->
</div> </div>
<!--end 首页-->
<!--遮罩层-->
<div class="maskBox"></div>
<!--end 遮罩层-->
<!--修改密码弹窗-->
<div class="PopupBox" id="ph_modifyBox">
<!--内容-->
<div class="PopupCon">
<div class="ph_subPoCon ph_screen">
<form class="form-inline" id="updatePswForm">
<table class="ph_tableBox">
<tr>
<th><span class="require">*</span>旧密码:</th>
<td><input id="password"
class="validate[required,minSize[6],maxSize[16]]"
name="password" type="password"></td>
</tr>
<tr>
<th><span class="require">*</span>新密码:</th>
<td><input id="newPassword"
class="validate[required,minSize[6],maxSize[16]]"
name="newPassword" type="password"></td>
</tr>
<tr>
<th><span class="require">*</span>确认新密码:</th>
<td><input id="confirmPassword"
class="validate[required,equals[newPassword],minSize[6],maxSize[16]]"
name="confirmPassword" type="password"></td>
</tr>
</table>
</form>
</div>
</div>
<!--end 内容-->
</div>
<div id="mydiv1" style="position:absolute;right:120px;top:50px;">
<ul>
<li><a>账户信息</a><a href="#" class="accountSettings">账户设置</a></li><br/>
<li> <hr/></li><br/><br/>
<li th:text="'• 本次登录:'+${#dates.format(loginTime, 'yyyy-MM-dd HH:mm:ss')}">• 本次登录:2017-07-03 14:36:21</li><br/>
<li th:text="'• 登录地区:'+${loginAddress}">• 登录地区:广东省深圳市 (IP:183.14.135.1)</li><br/>
<li th:text="'• 上次登录:'+${#dates.format(lastLoginTime, 'yyyy-MM-dd HH:mm:ss')}"> • 上次登录:2017-07-03 14:36:21</li>
</ul>
</div>
<!--end 修改密码弹窗--> <!--end 修改密码弹窗-->
<script type="text/javascript" th:src="@{/js/common/jquery-1.11.1.min.js}"></script> <script type="text/javascript" th:src="@{/js/common/jquery-1.11.1.min.js}"></script>
...@@ -99,170 +62,6 @@ ...@@ -99,170 +62,6 @@
<script type="text/javascript" th:src="@{/js/plugins/validat/jquery.validationEngine-zh_CN.js}"></script> <script type="text/javascript" th:src="@{/js/plugins/validat/jquery.validationEngine-zh_CN.js}"></script>
<script type="text/javascript" th:src="@{/js/plugins/layer/layer.js}"></script> <script type="text/javascript" th:src="@{/js/plugins/layer/layer.js}"></script>
<script type="text/javascript" th:src="@{/bootstrap-dist/js/bootstrap.js}"></script> <script type="text/javascript" th:src="@{/bootstrap-dist/js/bootstrap.js}"></script>
<script type="text/javascript" th:inline="javascript">
/*document.getElementById('main_frame').contentWindow.document.body.style.minWidth="1100px";*/
$(function() {
var Popupe = new PopupBase();
Popupe.show('.ph_modify', '.maskBox,.ph_modifyBox');
Popupe.hide('.close', '.maskBox,.ph_modifyBox');
/*
var userId = $("#userId").val();
var flag = $("#flag").val();*/
$.ajax({
async: false,
url: "/bpm/user/menuList",
type: "GET",
cache:false,
dataType: "json",
success: function (data) {
console.log(data.data);
if (data.data) {
MenuTree(data.data);
} else {
layer.alert("当前用户无菜单权限", {
icon: 2,
title: '失败',
closeBtn: 0,
btnAlign: 'c'
});
}
},
error: function (data) {
console.log(data);
layer.alert("菜单加载异常", {
icon: 2,
title: '失败',
closeBtn: 0,
btnAlign: 'c'
});
}
});
});
//加载树型菜单
function MenuTree(data) {
var menuTree = '';
//父级
for (var i = 0; i < data.length; i++) {
var lis = '';
//子级
if (data[i].child) {
for (var j = 0; j < data[i].child.length; j++) {
if(data[i].child[j].menuUrl){
lis += '<li class="s_menu_item"><a target="main_frame" href="' + data[i].child[j].menuUrl + '">·' + data[i].child[j].menuName + '</a></li>'
}else{
lis += '<li class="s_menu_item"><a target="main_frame" style="color:#999">' + data[i].child[j].menuName + '</a></li>'
}
}
}
menuTree+= '<li>'+
'<a target="main_frame" href="' + data[i].menuUrl + '"><i class="' + data[i].icon + '"></i>'+ data[i].menuName +'</a>'+
'<ul class="second_level_menu">'+
'<li>'+
//'<h4 class="s_menu_title">订单管理</h4>'+
'<ul>'+ lis +'</ul>'+
'</li>'+
'</ul>'+
'</li>'
/*menuTree += '<li>'
+ '<div class="link"><i class="' + data[i].icon + '"></i>' + data[i].menuName + '<i class="navIconRig"></i></div>'
+ '<ul class="submenu">' + lis + '</ul>'
+ '</li>';*/
}
$("#aside_nav").append(menuTree);
}
$(function () {
//验证初始化
$('#updatePswForm').validationEngine({
promptPosition: 'bottomLeft'
, autoPositionUpdate: false
, addPromptClass: 'formError-text'
, autoHidePrompt: true
, autoHideDelay: 3000
, fadeDuration: 0.3
});
$('.userBox').on('click', '.ph_modify', function () {
layer.open({
type: 1,
title: '修改登录密码',
closeBtn: 0,
area: ['442px', '280px'],
btn: ['确认', '取消'],
btnAlign: 'c',
content: $('#ph_modifyBox'),
btn1: function () {
var flag = $("#updatePswForm").validationEngine("validate");
if (!flag) {
return false;
}
$.ajax({
async: false,
url: "/permission/user/updatePsw",
data: $('#updatePswForm').serialize(),
type: "POST",
dataType: "json",
success: function (data) {
if (data.code == '200') {
window.location.href = '/logout';
} else {
$('#password').val('');
$('#newPassword').val('');
$('#confirmPassword').val('');
layer.alert(data.message, {
icon: 2,
title: '失败',
closeBtn: 0,
btnAlign: 'c'
});
}
},
error: function (data) {
layer.alert("修改密码错误", {
icon: 2,
title: '失败',
closeBtn: 0,
btnAlign: 'c'
});
}
});
},
});
});
});
</script>
<script type="text/javascript" th:src="@{/js/common/index.js}"></script>
<script>
$("#aside_nav").on("click","li",function(){
$(this).addClass("active");
$(this).siblings(".active").removeClass("active");
})
$("#aside_nav").on("click",".s_menu_item",function(){
$(".menu_active").removeClass("menu_active");
$(this).addClass("menu_active");
})
function loginOut() {
location.href="/login/logout";
}
function show(obj,id) {
var objDiv = $("#"+id+"");
$(objDiv).css("display","block");
$(objDiv).css("left", event.clientX);
$(objDiv).css("top", event.clientY + 10);
}
function hide(obj,id) {
var objDiv = $("#"+id+"");
$(objDiv).css("display", "none");
}
</script>
</body> </body>
</html> </html>
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8">
<title>工作流</title> <title>首页</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"/> <#assign user=Session.SPRING_SECURITY_CONTEXT.authentication.principal/>
</head> </head>
<body> <body>
<div> 欢迎你,${user.username}<br/>
<button onclick="writeForm()">填写请假单</button> <a href="/logout">注销</a>
<button class="log" onclick="logout()">退出</button>
</div>
<table th:if="${forms.size()}>0">
<thead>
<tr>
<td>请假标题</td>
<td>请假内容</td>
<td>请假人</td>
<td>请假天数</td>
<td>状态</td>
<td>操作</td>
</tr>
</thead>
<tr th:each="form:${forms}">
<td th:text="${form.title}"></td>
<td th:text="${form.content}"></td>
<td th:text="${form.days}"></td>
<td th:text="${form.applicant}"></td>
<td th:text="${form.state}"></td>
<td>
<button th:if="${form.state} == '填写请假单'"
th:onclick="'javascript:apply(\''+${form.id}+'\',\''+${form.days}+'\')'">申请请假</button>
<button th:if="${form.state} == '填写请假单'"
th:onclick="'javascript:giveup(\''+${form.id}+'\')'">放弃请假</button>
<button th:onclick="'javascript:checkState(\''+${form.id}+'\')'" data-toggle="modal" data-target="#myModal">查看流程</button>
</td>
</tr>
</table>
<div th:if="${forms.size()}==0">
<br />暂无请假数据
</div>
<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">流程</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
</div>
</div>
</div>
</div>
</body> </body>
</html> </html>
\ No newline at end of file
<style>
body{
margin:10px 10px 100px 10px;
}
* {
font-family: "微软雅黑";
font-size: 15px;
}
td {
padding: 5px 10px;
border: 1px solid #ccc;
}
button {
padding: 5px;
margin: 5px 0;
border: 1px solid #aaa;
border-radius: 4px;
}
.log {
float: right;
padding: 5px 8px;
background: #ec5757;
color: #fff;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script
src="http://apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script>
function writeForm() {
location.href = "/form";
}
function logout() {
$.ajax({
url : "/logout",
success : function(data) {
if (data.code == 200) {
location.href = "/";
}
}
});
}
function apply(formId,days) {
var operator = getUser();
if (operator == "") {
location.href = "/";
}
$.ajax({
url : "/apply",
data : {
"formId" : formId,
"operator" : operator,
"days":days
},
success : function(data) {
if (data.code == 200) {
location.href = "/home";
}
}
});
}
function giveup(formId) {
var operator = getUser();
if (operator == "") {
location.href = "/";
}
$.ajax({
url : "/giveup",
data : {
"formId" : formId,
"operator" : operator
},
success : function(data) {
if (data.code == 200) {
location.href = "/home";
}
}
});
}
function checkState(formId) {
$.ajax({
url : "/historyState",
data : {
"formId" : formId
},
success : function(data) {
if (data.code == 200) {
var processList = data.info;
var html = "";
$.each(processList, function(i,item){
html += "<span>"+item.name+"(操作人:"+item.operator+")"+"</span><br/><br/>";
});
$(".modal-body").html(html);
}
}
});
}
function getUser() {
var name = "userInfo=";
var user = "";
var ca = document.cookie.split(';');
$.each(ca, function(i, item) {
if (item.indexOf(name) != -1) {
user = item.substring(name.length, item.length);
}
});
return user;
}
</script>
\ No newline at end of file
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
</head> </head>
<body> <body>
<div> <div>
<span>登录</span> <form action="/login" method="post">
<input id="username" placeholder="用户名" /><br /> 用户名 : <input type="text" name="username"/>
<button onclick="login()">提交</button> 密码 : <input type="password" name="password"/>
<input type="submit" value="登录">
</form>
</div> </div>
</body> </body>
</html> </html>
...@@ -42,31 +44,3 @@ button { ...@@ -42,31 +44,3 @@ button {
</style> </style>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script>
function login(){
$.ajax({
url : "/login",
type: "POST",
data : {
"username" : $("#username").val()
},
success : function(data) {
console.log(data)
if(data.code == 200){
if(data.info.type == 1){
location.href="/home";
}else if(data.info.type == 2){
location.href="/homeApprover";
}else if(data.info.type == 3){
location.href="/homeApproverHr";
}else{
location.href="/homeApproverzjl";
}
}else{
alert(data.msg);
}
}
});
return false;
}
</script>
\ 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