添加了log4j2日志
添加了第二版接口
This commit is contained in:
刘行 2021-03-05 08:44:42 +08:00
parent 1e5c5a14fa
commit b51c453bba
78 changed files with 2717 additions and 750 deletions

45
pom.xml
View File

@ -22,25 +22,23 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<exclusions><!-- 去掉springboot默认配置 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.6.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@ -58,10 +56,33 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.75</version> <version>1.2.75</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>1.1</version>
</dependency>
<dependency> <!-- 引入log4j2依赖 -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -3,6 +3,7 @@ package com.example.survey.config;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.example.survey.util.TokenUtil; import com.example.survey.util.TokenUtil;
import com.example.survey.vo.ResultVo; import com.example.survey.vo.ResultVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -18,6 +19,7 @@ import java.util.Set;
* @author Pope * @author Pope
* 权限过滤器 * 权限过滤器
*/ */
@Log4j2
@Configuration @Configuration
public class AuthFilterConfig implements Filter { public class AuthFilterConfig implements Filter {
@ -32,10 +34,6 @@ public class AuthFilterConfig implements Filter {
}}; }};
@Autowired
TokenUtil tokenUtil;
@Override @Override
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) throws ServletException {
@ -52,24 +50,32 @@ public class AuthFilterConfig implements Filter {
HttpServletResponse response = (HttpServletResponse) servletResponse; HttpServletResponse response = (HttpServletResponse) servletResponse;
String method = request.getMethod(); String method = request.getMethod();
String uri = request.getRequestURI(); String uri = request.getRequestURI();
log.info(method + uri);
System.out.println(method + " : " + uri);
//判断是否需要token //判断是否需要token
if (URIS.contains(uri)) { if (URIS.contains(uri)) {
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
return; return;
} }
String token = request.getHeader("Authorization"); String token = request.getHeader("Authorization");
if(uri.startsWith("/investigationRecord/record2word")){
token = request.getParameter("token");
}
if (token == null) { if (token == null) {
log.error("请求无token");
returnJson(response, new ResultVo(ResultVo.FAILED, "请先登录!", null)); returnJson(response, new ResultVo(ResultVo.FAILED, "请先登录!", null));
return; return;
} }
if (!tokenUtil.isPass(token,uri,method)) { if (!TokenUtil.isPass(token, uri, method)) {
log.error("token错误");
returnJson(response, new ResultVo(ResultVo.FAILED, "权限不够!", null)); returnJson(response, new ResultVo(ResultVo.FAILED, "权限不够!", null));
return; return;
} }
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
} }

View File

@ -0,0 +1,45 @@
package com.example.survey.config;
import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
/**
* @author Pope
*/
@Log4j2
@Aspect
@Configuration
public class LogConfig {
@Pointcut(value = "execution(* com.example.survey.controller.*.*(..))")
public void controllerLog() {
}
@Pointcut(value = "execution(* com.example.survey.service.impl.*.*(..))")
public void serviceLog() {
}
@Pointcut(value = "execution(* com.example.survey.dao.impl.*.*(..))")
public void daoLog() {
}
@Around(value = "controllerLog()||serviceLog()||daoLog()")
public Object before(ProceedingJoinPoint joinPoint) throws Throwable {
log.info("class:{}, method:{}, params:{}", joinPoint.getTarget().getClass().getName(), joinPoint.getSignature().getName(), Arrays.toString(joinPoint.getArgs()));
return joinPoint.proceed();
}
}

View File

@ -5,9 +5,11 @@ import com.example.survey.service.InvestigationRecordService;
import com.example.survey.vo.InvestigationRecordVo; import com.example.survey.vo.InvestigationRecordVo;
import com.example.survey.vo.ResultVo; import com.example.survey.vo.ResultVo;
import com.example.survey.vo.ReviewVo; import com.example.survey.vo.ReviewVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -15,6 +17,7 @@ import java.util.Map;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@RestController @RestController
@RequestMapping("/investigationRecord") @RequestMapping("/investigationRecord")
public class InvestigationRecordController { public class InvestigationRecordController {
@ -22,38 +25,21 @@ public class InvestigationRecordController {
@Autowired @Autowired
private InvestigationRecordService investigationRecordService; private InvestigationRecordService investigationRecordService;
@PostMapping("/investigationRecord")
public ResultVo addInvestigationRecord(@RequestBody InvestigationRecordVo investigationRecordVo) {
ResultVo resultVo = new ResultVo();
boolean result = investigationRecordService.addInvestigationRecord(investigationRecordVo);
if (result) {
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("提交成功");
} else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("提交失败");
}
resultVo.setData(result);
return resultVo;
}
@GetMapping("/underReviewRecord") @GetMapping("/underReviewRecord")
public ResultVo getUnderReviewRecord(@RequestParam(value = "currentPage") Integer currentPage, public ResultVo getUnderReviewRecord(@RequestParam(value = "currentPage") Integer currentPage,
@RequestParam(value = "pageSize", defaultValue = "30") Integer pageSize, @RequestParam(value = "pageSize", defaultValue = "30") Integer pageSize,
@RequestParam(value = "investigatorPhone", required = false) String investigatorPhone, @RequestParam(value = "userPhone", required = false) String userPhone,
@RequestParam(value = "state", required = false) String state, @RequestParam(value = "state", required = false) String state,
@RequestParam(value = "idNumber", required = false) String idNumber, @RequestParam(value = "idNumber", required = false) String idNumber,
@RequestParam(value = "version", required = false) String version, @RequestParam(value = "version", required = false) String version,
@RequestParam(value = "questionnaireNumber", required = false) String questionnaireNumber, @RequestParam(value = "questionnaireNumber", required = false) String questionnaireNumber,
@RequestParam(value = "diseased", required = false) Boolean diseased) { @RequestParam(value = "diseased", required = false) Boolean diseased) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS); resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功"); resultVo.setMsg("查询成功");
Map<String, Object> resultMap = new HashMap<>(16, 0.75F); Map<String, Object> resultMap = new HashMap<>(16, 0.75F);
List<InvestigationRecord> records = investigationRecordService.listUnderReviewRecordPageByInvestigationPhone(investigatorPhone, currentPage, pageSize, state, idNumber, version, questionnaireNumber, diseased); List<InvestigationRecord> records = investigationRecordService.listUnderReviewRecordLimit(userPhone, currentPage, pageSize, state, idNumber, version, questionnaireNumber, diseased);
resultMap.put("totalCount", records.size()); resultMap.put("totalCount", records.size());
resultMap.put("currentPage", currentPage); resultMap.put("currentPage", currentPage);
resultMap.put("pageSize", pageSize); resultMap.put("pageSize", pageSize);
@ -64,12 +50,12 @@ public class InvestigationRecordController {
} }
@GetMapping("/underReviewRecordCount") @GetMapping("/underReviewRecordCount")
public ResultVo countUnderReviewRecord(@RequestParam(value = "investigatorPhone") String investigatorPhone) { public ResultVo countUnderReviewRecord(@RequestParam(value = "userPhone") String userPhone) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS); resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功"); resultVo.setMsg("查询成功");
resultVo.setData(investigationRecordService.countUnderReviewRecordByInvestigatorPhone(investigatorPhone)); resultVo.setData(investigationRecordService.countUnderReviewRecord(userPhone));
return resultVo; return resultVo;
} }
@ -79,9 +65,7 @@ public class InvestigationRecordController {
public ResultVo reviewRecord(@RequestBody ReviewVo reviewVo) { public ResultVo reviewRecord(@RequestBody ReviewVo reviewVo) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS);
boolean result = investigationRecordService.reviewRecord(reviewVo); boolean result = investigationRecordService.reviewRecord(reviewVo);
if (result) { if (result) {
resultVo.setCode(ResultVo.SUCCESS); resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("审核成功"); resultVo.setMsg("审核成功");
@ -90,6 +74,7 @@ public class InvestigationRecordController {
resultVo.setMsg("审核失败"); resultVo.setMsg("审核失败");
} }
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setData(result); resultVo.setData(result);
return resultVo; return resultVo;
@ -99,12 +84,37 @@ public class InvestigationRecordController {
public ResultVo updateInvestigationRecord(@RequestBody InvestigationRecordVo investigationRecordVo) { public ResultVo updateInvestigationRecord(@RequestBody InvestigationRecordVo investigationRecordVo) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
resultVo.setCode(0);
resultVo.setMsg("修改提交成功,等待审核");
investigationRecordService.changeInvestigationRecord(investigationRecordVo); investigationRecordService.changeInvestigationRecord(investigationRecordVo);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("修改提交成功,等待审核");
resultVo.setData(true); resultVo.setData(true);
return resultVo; return resultVo;
} }
@PostMapping("/investigationRecord")
public ResultVo addInvestigationRecord(@RequestBody InvestigationRecordVo investigationRecordVo) {
ResultVo resultVo = new ResultVo();
boolean result = investigationRecordService.addInvestigationRecord(investigationRecordVo);
if (result) {
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("提交成功");
} else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("提交失败");
}
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setData(result);
return resultVo;
}
@GetMapping("/record2word")
public void record2Word(@RequestParam("token") String token,
@RequestParam("idNumber") String idNumber,
HttpServletResponse response) {
investigationRecordService.export2Word(idNumber, response);
}
} }

View File

@ -1,36 +0,0 @@
package com.example.survey.controller;
import com.example.survey.entity.Investigator;
import com.example.survey.service.InvestigatorService;
import com.example.survey.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author Pope
*/
@RestController
@RequestMapping("/investigator")
public class InvestigatorController {
@Autowired
private InvestigatorService investigatorService;
@PostMapping("/investigator")
public ResultVo addInvestigator(@RequestBody Investigator investigator){
ResultVo resultVo = new ResultVo();
boolean result = investigatorService.addInvestigator(investigator);
if(result){
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("创建成功");
}else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("创建失败");
}
resultVo.setData(result);
return resultVo;
}
}

View File

@ -1,8 +1,9 @@
package com.example.survey.controller; package com.example.survey.controller;
import com.example.survey.entity.Respondent; import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.service.RespondentService; import com.example.survey.service.RespondentService;
import com.example.survey.dto.RespondentDto; import com.example.survey.dto.RespondentDto;
import com.example.survey.vo.CreateRespondentVo;
import com.example.survey.vo.ResultVo; import com.example.survey.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -22,10 +23,10 @@ public class RespondentController {
private RespondentService respondentService; private RespondentService respondentService;
@PostMapping("/respondent") @PostMapping("/respondent")
public ResultVo addRespondent(@RequestBody Respondent respondent) { public ResultVo addRespondent(@RequestBody CreateRespondentVo createRespondentVo) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
boolean result = respondentService.addRespondent(respondent); boolean result = respondentService.addRespondent(createRespondentVo);
if (result) { if (result) {
resultVo.setCode(ResultVo.SUCCESS); resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("创建成功"); resultVo.setMsg("创建成功");
@ -39,19 +40,24 @@ public class RespondentController {
} }
@GetMapping("/respondent") @GetMapping("/respondent")
public ResultVo countRespondent(@RequestParam(value = "investigatorPhone") String investigatorPhone, public ResultVo countRespondent(@RequestParam(value = "userPhone") String userPhone,
@RequestParam(value = "state", required = false) String state,
@RequestParam(value = "province", required = false) String province,
@RequestParam(value = "city", required = false) String city,
@RequestParam(value = "county", required = false) String county,
@RequestParam(value = "currentPage") int currentPage, @RequestParam(value = "currentPage") int currentPage,
@RequestParam(value = "pageSize", defaultValue = "30") int pageSize) { @RequestParam(value = "pageSize", defaultValue = "30") int pageSize) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
Map<String, Object> resultMap = new HashMap<>(16, 0.75F); Map<String, Object> resultMap = new HashMap<>(16, 0.75F);
List<RespondentDto> voList = respondentService.listRespondentPageByInvestigatorPhone(investigatorPhone, currentPage, pageSize); AdministrativeArea administrativeArea = new AdministrativeArea(province, city, county);
resultMap.put("totalCount", voList.size()); List<RespondentDto> voList = respondentService.listRespondentLimit(userPhone, state, administrativeArea, currentPage, pageSize);
resultMap.put("totalCount", respondentService.countRespondent(userPhone, state, administrativeArea));
resultMap.put("currentPage", currentPage); resultMap.put("currentPage", currentPage);
resultMap.put("pageSize", pageSize); resultMap.put("pageSize", pageSize);
resultMap.put("data", voList); resultMap.put("data", voList);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
resultVo.setData(resultMap); resultVo.setData(resultMap);
return resultVo; return resultVo;

View File

@ -1,13 +1,17 @@
package com.example.survey.controller; package com.example.survey.controller;
import com.example.survey.enumeration.AuthEnum;
import com.example.survey.service.RoleService; import com.example.survey.service.RoleService;
import com.example.survey.vo.RoleVo; import com.example.survey.vo.DeleteRoleVo;
import com.example.survey.vo.CreateRoleVo;
import com.example.survey.vo.ModifyRoleVo;
import com.example.survey.vo.ResultVo; import com.example.survey.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.HashMap;
import org.springframework.web.bind.annotation.RestController; import java.util.List;
import java.util.Map;
/** /**
* @author Pope * @author Pope
@ -19,11 +23,32 @@ public class RoleController {
@Autowired @Autowired
private RoleService roleService; private RoleService roleService;
@PostMapping("/role") @GetMapping("/role")
public ResultVo addAuth(@RequestBody RoleVo roleVo){ public ResultVo getRole(@RequestParam(value = "pageSize", defaultValue = "30") int pageSize,
@RequestParam(value = "currentPage") int currentPage,
@RequestParam(value = "roleName", required = false) String roleName) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
boolean result = roleService.addRole(roleVo);
List<CreateRoleVo> roleVoList = roleService.getRole(roleName, currentPage, pageSize);
Map<String, Object> resultMap = new HashMap<>(16, 0.75F);
resultMap.put("totalCount",roleVoList.size());
resultMap.put("pageSize", pageSize);
resultMap.put("currentPage", currentPage);
resultMap.put("data",roleVoList);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
resultVo.setData(resultMap);
return resultVo;
}
@PostMapping("/role")
public ResultVo addRole(@RequestBody CreateRoleVo createRoleVo) {
ResultVo resultVo = new ResultVo();
boolean result = roleService.addRole(createRoleVo);
if (result) { if (result) {
resultVo.setCode(ResultVo.SUCCESS); resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("创建成功"); resultVo.setMsg("创建成功");
@ -36,4 +61,42 @@ public class RoleController {
} }
@DeleteMapping("/role")
public ResultVo deleteRole(@RequestBody DeleteRoleVo deleteRoleVo) {
ResultVo resultVo = new ResultVo();
roleService.deleteRole(deleteRoleVo.getRoleName());
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("删除成功");
return resultVo;
}
@PutMapping("/role")
public ResultVo modifyRole(@RequestBody ModifyRoleVo modifyRoleVo) {
ResultVo resultVo = new ResultVo();
roleService.modifyRole(modifyRoleVo);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("修改成功");
return resultVo;
}
@GetMapping("/authList")
public ResultVo getAuthList() {
ResultVo resultVo = new ResultVo();
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("authList", AuthEnum.getNameList());
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
resultVo.setData(resultMap);
return resultVo;
}
} }

View File

@ -1,14 +1,17 @@
package com.example.survey.controller; package com.example.survey.controller;
import com.example.survey.dto.LoginDto; import com.example.survey.dto.LoginDto;
import com.example.survey.dto.UserDto;
import com.example.survey.service.UserService; import com.example.survey.service.UserService;
import com.example.survey.vo.LoginVo; import com.example.survey.vo.*;
import com.example.survey.vo.ResultVo;
import com.example.survey.vo.SignupVo;
import com.example.survey.vo.UserRoleVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author Pope * @author Pope
*/ */
@ -19,6 +22,42 @@ public class UserController {
@Autowired @Autowired
UserService userService; UserService userService;
@GetMapping("/user")
public ResultVo getUser(@RequestParam(value = "pageSize", defaultValue = "30") int pageSize,
@RequestParam(value = "currentPage") int currentPage,
@RequestParam(value = "username", required = false) String username,
@RequestParam(value = "phoneNumber", required = false) String phoneNumber) {
ResultVo resultVo = new ResultVo();
List<UserDto> userDtoList = userService.listUserLimit(username, phoneNumber, currentPage, pageSize);
Map<String, Object> resultMap = new HashMap<>(16, 0.75F);
resultMap.put("totalCount", userDtoList.size());
resultMap.put("pageSize", pageSize);
resultMap.put("currentPage", currentPage);
resultMap.put("data", userDtoList);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("查询成功");
resultVo.setData(resultMap);
return resultVo;
}
@DeleteMapping("/user")
public ResultVo deleteUser(@RequestBody DeleteUserVo deleteUserVo) {
ResultVo resultVo = new ResultVo();
boolean result = userService.deleteUser(deleteUserVo.getPhoneNumber());
if (result) {
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("删除成功");
} else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("删除失败");
}
return resultVo;
}
@PostMapping("/login") @PostMapping("/login")
public ResultVo login(@RequestBody LoginVo loginVo) { public ResultVo login(@RequestBody LoginVo loginVo) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
@ -36,31 +75,69 @@ public class UserController {
return resultVo; return resultVo;
} }
@PostMapping("/signup")
public ResultVo signup(@RequestBody SignupVo signupVo) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.SUCCESS);
boolean result = userService.addUser(signupVo);
if (result) {
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("注册成功");
} else {
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg("注册失败");
}
return resultVo;
}
@PutMapping("/userRole") @PutMapping("/userRole")
public ResultVo modifyUserRoles(@RequestBody UserRoleVo userRoleVo) { public ResultVo modifyUserRoles(@RequestBody UserRoleVo userRoleVo) {
ResultVo resultVo = new ResultVo(); ResultVo resultVo = new ResultVo();
userService.modifyRoles(userRoleVo); userService.modifyRole(userRoleVo);
resultVo.setCode(0); resultVo.setCode(0);
resultVo.setMsg("修改成功"); resultVo.setMsg("修改成功");
return resultVo; return resultVo;
} }
@PutMapping("/userInfo")
public ResultVo changeUserInfo(@RequestBody UserInfoVo userInfoVo) {
ResultVo resultVo = new ResultVo();
userService.modifyUserInfo(userInfoVo);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("修改成功");
return resultVo;
}
@PutMapping("/pwd")
public ResultVo resetPwd(@RequestBody ResetPwdVo resetPwdVo) {
ResultVo resultVo = new ResultVo();
userService.resetPwd(resetPwdVo.getPhoneNumber());
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("重置成功");
return resultVo;
}
@PostMapping("/user")
public ResultVo createUser(@RequestBody CreateUserVo createUserVo) {
ResultVo resultVo = new ResultVo();
userService.addUser(createUserVo);
resultVo.setCode(ResultVo.SUCCESS);
resultVo.setMsg("创建成功");
return resultVo;
}
// @PostMapping("/signup")
// public ResultVo signup(@RequestBody SignupVo signupVo) {
// ResultVo resultVo = new ResultVo();
//
// resultVo.setCode(ResultVo.SUCCESS);
// boolean result = userService.addUser(signupVo);
// if (result) {
// resultVo.setCode(ResultVo.SUCCESS);
// resultVo.setMsg("注册成功");
// } else {
// resultVo.setCode(ResultVo.FAILED);
// resultVo.setMsg("注册失败");
// }
// return resultVo;
// }
} }

View File

@ -0,0 +1,76 @@
package com.example.survey.controller.advice;
import com.example.survey.exception.*;
import com.example.survey.vo.ResultVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @author Pope
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(UserException.class)
public ResultVo handleUserException(UserException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
@ExceptionHandler(RecordException.class)
public ResultVo handleRecordException(RecordException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
@ExceptionHandler(RespondentException.class)
public ResultVo handleRespondentException(RespondentException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
@ExceptionHandler(RoleException.class)
public ResultVo handleRoleException(RoleException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
@ExceptionHandler(DepartmentException.class)
public ResultVo handleDepartmentException(DepartmentException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
@ExceptionHandler(AuthException.class)
public ResultVo handleAuthException(AuthException e) {
ResultVo resultVo = new ResultVo();
resultVo.setCode(ResultVo.FAILED);
resultVo.setMsg(e.getMessage());
return resultVo;
}
}

View File

@ -1,6 +1,7 @@
package com.example.survey.dao; package com.example.survey.dao;
import com.example.survey.entity.InvestigationRecord; import com.example.survey.entity.InvestigationRecord;
import com.example.survey.entity.User;
import com.example.survey.entity.inner.OperationInformation; import com.example.survey.entity.inner.OperationInformation;
import java.util.List; import java.util.List;
@ -21,7 +22,7 @@ public interface InvestigationRecordDao {
/** /**
* 根据筛选条件分页查询记录 * 根据筛选条件分页查询记录
* *
* @param investigatorPhone 调查人员电话号码 * @param userPhone 用户电话号码
* @param offset 偏移量 * @param offset 偏移量
* @param number 数量 * @param number 数量
* @param state 调查记录状态 * @param state 调查记录状态
@ -31,16 +32,16 @@ public interface InvestigationRecordDao {
* @param diseased 调查对象是否患病 * @param diseased 调查对象是否患病
* @return 筛选结果 * @return 筛选结果
*/ */
List<InvestigationRecord> listLimitInvestigationRecord(String investigatorPhone, int offset, int number, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased); List<InvestigationRecord> listInvestigationRecordLimit(String userPhone, int offset, int number, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased);
/** /**
* 根据流调人员电话号码查询对应状态的记录数量 * 根据流调人员电话号码查询对应状态的记录数量
* *
* @param investigatorPhone 流调人员电话号码 * @param userPhone 流调人员电话号码
* @param state 记录状态 * @param state 记录状态
* @return 记录数量 * @return 记录数量
*/ */
long countInvestigationRecordByInvestigatorPhone(String investigatorPhone, String state); long countInvestigationRecordByUserPhone(String userPhone, String state);
/** /**
* 更新记录状态 * 更新记录状态
@ -71,8 +72,17 @@ public interface InvestigationRecordDao {
* 是否存在当前状态调查记录 * 是否存在当前状态调查记录
* *
* @param idNumber 调查对象身份证号 * @param idNumber 调查对象身份证号
* @param states 调查记录状态 * @param states 调查记录状态
* @return 是否存在 * @return 是否存在
*/ */
boolean existInvestigationRecord(String idNumber, String... states); boolean existInvestigationRecord(String idNumber, String... states);
/**
* 更新所有匹配的调查记录的userPhone字段
*
* @param oldUserPhone 旧的userPhone字段
* @param newUserPhone 新的userPhone字段
*/
void updateManyRecordUserPhone(String oldUserPhone, String newUserPhone);
} }

View File

@ -1,31 +0,0 @@
package com.example.survey.dao;
import com.example.survey.entity.Investigator;
/**
* @author Pope
*/
public interface InvestigatorDao {
/**
* 根据流调人员电话判断是否存在
* @param phoneNumber 流调人员电话
* @return 是否存在该电话
*/
boolean existInvestigator(String phoneNumber);
/**
* 插入调查人员
* @param investigator 调查人员
* @return 是否插入成功
*/
boolean insertInvestigator(Investigator investigator);
/**
* 根据流调人员电话号码查询流调人员
* @param phoneNumber 流调人员电话号码
* @return 对应的流调人员
*/
Investigator selectInvestigator(String phoneNumber);
}

View File

@ -1,7 +1,7 @@
package com.example.survey.dao; package com.example.survey.dao;
import com.example.survey.entity.Investigator;
import com.example.survey.entity.Respondent; import com.example.survey.entity.Respondent;
import com.example.survey.entity.inner.AdministrativeArea;
import java.util.List; import java.util.List;
@ -19,12 +19,14 @@ public interface RespondentDao {
/** /**
* 根据流调人员电话号码分页查询待调查对象列表 * 根据流调人员电话号码分页查询待调查对象列表
* @param investigatorPhone 流调人员电话号码 * @param userPhone 分配的人员电话号码
* @param state 状态
* @param administrativeArea 行政区划
* @param offset 偏移量 * @param offset 偏移量
* @param number 大小 * @param number 大小
* @return 待调查对象列表 * @return 待调查对象列表
*/ */
List<Respondent> listLimitRespondentByInvestigator(String investigatorPhone, int offset, int number); List<Respondent> listRespondentLimit(String userPhone, String state, AdministrativeArea administrativeArea, int offset, int number);
/** /**
* 判断是否存在对应id的调查对象 * 判断是否存在对应id的调查对象
@ -34,9 +36,12 @@ public interface RespondentDao {
boolean existRespondent(String idNumber); boolean existRespondent(String idNumber);
/** /**
* 根据流调人员电话号码查询调查对象数量 * 根绝筛选条件获取调查对象数量
* @param investigatorPhone 流调人员电话号码 *
* @return 对应流调人员id的调查对象数量 * @param userPhone 分配的人员电话号码
* @param state 状态
* @param administrativeArea 行政区划
* @return 数量
*/ */
long countRespondentBuInvestigatorPhone(String investigatorPhone); long countRespondent(String userPhone, String state, AdministrativeArea administrativeArea);
} }

View File

@ -1,8 +1,10 @@
package com.example.survey.dao; package com.example.survey.dao;
import com.example.survey.entity.Role; import com.example.survey.entity.Role;
import com.example.survey.enumeration.AuthEnum;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author Pope * @author Pope
@ -33,10 +35,20 @@ public interface RoleDao {
void deleteRole(String name); void deleteRole(String name);
/** /**
* 更改用户角色 * 根据角色名模糊匹配角色
* *
* @param phoneNumber 电话号码 * @param name 角色名 模糊匹配
* @param roleList 角色列表 * @param offset 偏移量
* @param limit 大小
* @return
*/ */
void updateUserRoles(String phoneNumber, List<Role> roleList); List<Role> listLimitRole(String name, int offset, int limit);
/**
* 更改角色的权限列表
*
* @param roleName 角色名
* @param authEnumSet 权限集合
*/
void updateRole(String roleName, Set<AuthEnum> authEnumSet);
} }

View File

@ -1,6 +1,11 @@
package com.example.survey.dao; package com.example.survey.dao;
import com.example.survey.entity.Role;
import com.example.survey.entity.User; import com.example.survey.entity.User;
import com.example.survey.vo.UserInfoVo;
import org.bson.types.ObjectId;
import java.util.List;
/** /**
* @author Pope * @author Pope
@ -11,11 +16,11 @@ public interface UserDao {
/** /**
* 根据用户名密码查询用户 * 根据用户名密码查询用户
* *
* @param username 用户名 * @param phoneNumber 用户电话号码
* @param password 密码 * @param password 密码
* @return 对应用户 * @return 对应用户
*/ */
User selectUser(String username, String password); User selectUser(String phoneNumber, String password);
/** /**
* 插入用户 * 插入用户
@ -24,4 +29,77 @@ public interface UserDao {
* @return 是否插入成功 * @return 是否插入成功
*/ */
boolean insertUser(User user); boolean insertUser(User user);
/**
* 根据筛选条件分页查询用户
*
* @param username 用户名 模糊匹配
* @param phoneNumber 电话号码 精确匹配
* @param offset 偏移量
* @param limit 数据量
* @return 用户信息dto
*/
List<User> listUserLimit(String username, String phoneNumber, int offset, int limit);
/**
* 根据电话号码判断是否存在用户
*
* @param phoneNumber 电话号码
* @return 是否存在用户
*/
boolean existUser(String phoneNumber);
/**
* 删除用户
*
* @param phoneNumber 电话号码
*/
void deleteUser(String phoneNumber);
/**
* 从含有该角色的用户的角色列表中删除该用户
*
* @param role 角色
*/
void clearRole(Role role);
/**
* 更改用户角色
*
* @param phoneNumber 电话号码
* @param roleList 角色列表
*/
void updateUserRole(String phoneNumber, List<Role> roleList);
/**
* 根据调查人员电话查询用户名
*
* @param investigatorPhone 调查人员电话号码
* @return 用户名
*/
String selectUsername(String investigatorPhone);
/**
* 根据电话号码查询用户
*
* @param phoneNumber 电话
* @return 用户
*/
User selectUser(String phoneNumber);
/**
* 重置密码
*
* @param phoneNumber 电话号码
*/
void resetPwd(String phoneNumber);
/**
* 更新用户信息
*
* @param userInfoVo 用户信息
*/
void modifyUser(UserInfoVo userInfoVo);
} }

View File

@ -2,16 +2,19 @@ package com.example.survey.dao.impl;
import com.example.survey.dao.DepartmentDao; import com.example.survey.dao.DepartmentDao;
import com.example.survey.entity.Department; import com.example.survey.entity.Department;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* @author Pope * @author Pope
*/ */
@Service @Log4j2
@Repository
public class DepartmentDaoImpl implements DepartmentDao { public class DepartmentDaoImpl implements DepartmentDao {
@Autowired @Autowired
@ -22,6 +25,10 @@ public class DepartmentDaoImpl implements DepartmentDao {
try { try {
mongoTemplate.save(department); mongoTemplate.save(department);
}catch (Exception e){ }catch (Exception e){
log.error("部门插入失败");
log.error(e.getMessage());
return false; return false;
} }
return true; return true;

View File

@ -3,6 +3,9 @@ package com.example.survey.dao.impl;
import com.example.survey.dao.InvestigationRecordDao; import com.example.survey.dao.InvestigationRecordDao;
import com.example.survey.entity.InvestigationRecord; import com.example.survey.entity.InvestigationRecord;
import com.example.survey.entity.inner.OperationInformation; import com.example.survey.entity.inner.OperationInformation;
import com.example.survey.exception.RecordException;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators; import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
@ -16,6 +19,7 @@ import java.util.*;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@Repository @Repository
public class InvestigationRecordDaoImpl implements InvestigationRecordDao { public class InvestigationRecordDaoImpl implements InvestigationRecordDao {
@ -27,17 +31,19 @@ public class InvestigationRecordDaoImpl implements InvestigationRecordDao {
try { try {
mongoTemplate.save(record); mongoTemplate.save(record);
} catch (Exception e) { } catch (Exception e) {
//TODO 抛出相应异常 log.error("调查记录插入失败");
return false; log.error(e.getMessage());
throw new RecordException("已存在对应调查对象的调查记录");
} }
return true; return true;
} }
@Override @Override
public List<InvestigationRecord> listLimitInvestigationRecord(String investigatorPhone, int offset, int number, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased) { public List<InvestigationRecord> listInvestigationRecordLimit(String investigatorPhone, int offset, int number, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased) {
Criteria criteria = new Criteria(); ;
//流调人员id Criteria criteria = new Criteria();
//流调人员电话号码
if (investigatorPhone != null) { if (investigatorPhone != null) {
criteria.and("investigatorPhone").is(investigatorPhone); criteria.and("investigatorPhone").is(investigatorPhone);
} }
@ -46,7 +52,7 @@ public class InvestigationRecordDaoImpl implements InvestigationRecordDao {
if (state != null) { if (state != null) {
criteria.and("state").is(state); criteria.and("state").is(state);
} else { } else {
criteria.and("state").in(InvestigationRecord.UNDER_REVIEW,InvestigationRecord.REVIEWED); criteria.and("state").in(InvestigationRecord.UNDER_REVIEW, InvestigationRecord.REVIEWED);
} }
//调查对象身份证号 //调查对象身份证号
@ -75,8 +81,8 @@ public class InvestigationRecordDaoImpl implements InvestigationRecordDao {
} }
@Override @Override
public long countInvestigationRecordByInvestigatorPhone(String investigatorPhone, String state) { public long countInvestigationRecordByUserPhone(String userPhone, String state) {
Query query = new Query(Criteria.where("investigatorPhone").is(investigatorPhone).and("state").is(state)); Query query = new Query(Criteria.where("userPhone").is(userPhone).and("state").is(state));
return mongoTemplate.count(query, InvestigationRecord.class); return mongoTemplate.count(query, InvestigationRecord.class);
} }
@ -108,5 +114,12 @@ public class InvestigationRecordDaoImpl implements InvestigationRecordDao {
return mongoTemplate.exists(query, InvestigationRecord.class); return mongoTemplate.exists(query, InvestigationRecord.class);
} }
@Override
public void updateManyRecordUserPhone(String oldUserPhone, String newUserPhone) {
Query query = new Query(Criteria.where("userPhone").is(oldUserPhone));
Update update = new Update().set("userPhone", newUserPhone);
mongoTemplate.updateMulti(query, update, InvestigationRecord.class);
}
} }

View File

@ -1,42 +0,0 @@
package com.example.survey.dao.impl;
import com.example.survey.dao.InvestigatorDao;
import com.example.survey.entity.Investigator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
/**
* @author Pope
*/
@Repository
public class InvestigatorDaoImpl implements InvestigatorDao {
@Autowired
MongoTemplate mongoTemplate;
@Override
public boolean existInvestigator(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
return mongoTemplate.exists(query, Investigator.class);
}
@Override
public boolean insertInvestigator(Investigator investigator) {
try {
mongoTemplate.save(investigator);
} catch (Exception e) {
//TODO 抛出相应异常
return false;
}
return true;
}
@Override
public Investigator selectInvestigator(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
return mongoTemplate.findOne(query, Investigator.class);
}
}

View File

@ -2,6 +2,9 @@ package com.example.survey.dao.impl;
import com.example.survey.dao.RespondentDao; import com.example.survey.dao.RespondentDao;
import com.example.survey.entity.Respondent; import com.example.survey.entity.Respondent;
import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.exception.RespondentException;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
@ -13,6 +16,7 @@ import java.util.List;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@Repository @Repository
public class RespondentDaoImpl implements RespondentDao { public class RespondentDaoImpl implements RespondentDao {
@ -24,14 +28,37 @@ public class RespondentDaoImpl implements RespondentDao {
try { try {
mongoTemplate.save(respondent); mongoTemplate.save(respondent);
} catch (Exception e) { } catch (Exception e) {
return false; log.error("调查对象插入失败");
log.error(e.getMessage());
throw new RespondentException("调查对象已存在");
} }
return true; return true;
} }
@Override @Override
public List<Respondent> listLimitRespondentByInvestigator(String investigatorPhone, int offset, int number) { public List<Respondent> listRespondentLimit(String userPhone, String state, AdministrativeArea administrativeArea, int offset, int number) {
Query query = new Query(Criteria.where("investigatorPhone").is(investigatorPhone)).skip(offset).limit(number); Criteria criteria = new Criteria();
if (userPhone != null) {
criteria.and("userPhone").is(userPhone);
}
if (state != null) {
criteria.and("state").is(state);
}
if (administrativeArea != null) {
if(administrativeArea.getProvince()!=null){
criteria.and("administrativeArea.province").is(administrativeArea.getProvince());
}
if(administrativeArea.getCity()!=null){
criteria.and("administrativeArea.city").is(administrativeArea.getCity());
}
if(administrativeArea.getCounty()!=null){
criteria.and("administrativeArea.county").is(administrativeArea.getCounty());
}
}
Query query = new Query(criteria).skip(offset).limit(number);
return mongoTemplate.find(query, Respondent.class); return mongoTemplate.find(query, Respondent.class);
} }
@ -42,8 +69,31 @@ public class RespondentDaoImpl implements RespondentDao {
} }
@Override @Override
public long countRespondentBuInvestigatorPhone(String investigatorPhone) { public long countRespondent(String userPhone, String state, AdministrativeArea administrativeArea) {
Query query = new Query(Criteria.where("investigatorPhone").is(investigatorPhone)); Criteria criteria = new Criteria();
if (userPhone != null) {
criteria.and("userPhone").is(userPhone);
}
if (state != null) {
criteria.and("state").is(state);
}
if (administrativeArea != null) {
if(administrativeArea.getProvince()!=null){
criteria.and("administrativeArea.province").is(administrativeArea.getProvince());
}
if(administrativeArea.getCity()!=null){
criteria.and("administrativeArea.city").is(administrativeArea.getCity());
}
if(administrativeArea.getCounty()!=null){
criteria.and("administrativeArea.county").is(administrativeArea.getCounty());
}
}
Query query = new Query(criteria);
return mongoTemplate.count(query, Respondent.class); return mongoTemplate.count(query, Respondent.class);
} }
} }

View File

@ -3,19 +3,25 @@ package com.example.survey.dao.impl;
import com.example.survey.dao.RoleDao; import com.example.survey.dao.RoleDao;
import com.example.survey.entity.Role; import com.example.survey.entity.Role;
import com.example.survey.entity.User; import com.example.survey.entity.User;
import com.example.survey.enumeration.AuthEnum;
import com.example.survey.exception.RoleException;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author Pope * @author Pope
*/ */
@Service @Log4j2
@Repository
public class RoleDaoImpl implements RoleDao { public class RoleDaoImpl implements RoleDao {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
@ -25,7 +31,9 @@ public class RoleDaoImpl implements RoleDao {
try { try {
mongoTemplate.save(role); mongoTemplate.save(role);
} catch (Exception e) { } catch (Exception e) {
return false; log.error("权限插入失败");
log.error(e.getMessage());
throw new RoleException("已存在权限");
} }
return true; return true;
} }
@ -39,14 +47,28 @@ public class RoleDaoImpl implements RoleDao {
@Override @Override
public void deleteRole(String name) { public void deleteRole(String name) {
Query query = new Query(Criteria.where("name").is(name)); Query query = new Query(Criteria.where("name").is(name));
mongoTemplate.remove(query); mongoTemplate.remove(query, Role.class);
}
@Override
public List<Role> listLimitRole(String name, int offset, int limit) {
Criteria criteria = new Criteria();
if (name != null) {
criteria.and("name").regex(name);
}
Query query = new Query(criteria).skip(offset).limit(limit);
return mongoTemplate.find(query, Role.class);
} }
@Override @Override
public void updateUserRoles(String phoneNumber, List<Role> roleList) { public void updateRole(String roleName, Set<AuthEnum> authEnumSet) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber)); Query query = new Query(Criteria.where("name").is(roleName));
Update update = new Update() Role role = mongoTemplate.findOne(query, Role.class);
.set("roleList", roleList); if(role == null){
mongoTemplate.updateFirst(query, update, User.class); throw new RoleException("角色不存在");
}
role.setAuthoritySet(authEnumSet);
mongoTemplate.save(role);
} }
} }

View File

@ -1,35 +1,148 @@
package com.example.survey.dao.impl; package com.example.survey.dao.impl;
import com.example.survey.dao.UserDao; import com.example.survey.dao.UserDao;
import com.example.survey.entity.Role;
import com.example.survey.entity.User; import com.example.survey.entity.User;
import com.example.survey.exception.UserException;
import com.example.survey.vo.UserInfoVo;
import com.mongodb.client.result.DeleteResult;
import lombok.extern.log4j.Log4j2;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Iterator;
import java.util.List;
/** /**
* @author Pope * @author Pope
*/ */
@Service @Log4j2
@Repository
public class UserDaoImpl implements UserDao { public class UserDaoImpl implements UserDao {
@Autowired @Autowired
private MongoTemplate mongoTemplate; private MongoTemplate mongoTemplate;
@Override @Override
public User selectUser(String username, String password) { public User selectUser(String phoneNumber, String password) {
Query query = new Query(Criteria.where("phoneNumber").is(username).and("password").is(password)); Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber).and("password").is(password));
return mongoTemplate.findOne(query,User.class); return mongoTemplate.findOne(query, User.class);
} }
@Override @Override
public boolean insertUser(User user) { public boolean insertUser(User user) {
try { try {
mongoTemplate.save(user); mongoTemplate.save(user);
}catch (Exception e){ } catch (Exception e) {
return false; log.error("用户插入失败");
log.error(e.getMessage());
throw new UserException("已存在用户");
} }
return true; return true;
} }
@Override
public List<User> listUserLimit(String username, String phoneNumber, int offset, int limit) {
Criteria criteria = new Criteria();
//用户名模糊查询
if (username != null) {
criteria.and("username").regex(username);
}
//电话号码精确查询
if (phoneNumber != null) {
criteria.and("phoneNumber").is(phoneNumber);
}
Query query = new Query(criteria).skip(offset).limit(limit);
return mongoTemplate.find(query, User.class);
}
@Override
public boolean existUser(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
return mongoTemplate.exists(query, User.class);
}
@Override
public void deleteUser(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
mongoTemplate.remove(query, User.class);
}
@Override
public void clearRole(Role role) {
Query query = new Query(Criteria.where("roleList").elemMatch(Criteria.where("$id").is(role.getId())));
List<User> users = mongoTemplate.find(query, User.class);
for (User user : users) {
List<Role> roleList = user.getRoleList();
Iterator<Role> it = roleList.iterator();
while (it.hasNext()) {
if (role.getName().equals(it.next().getName())) {
it.remove();
break;
}
}
Query userQuery = new Query(Criteria.where("phoneNumber").is(user.getPhoneNumber()));
Update update = new Update().set("roleList", roleList);
mongoTemplate.updateFirst(userQuery, update, User.class);
}
}
@Override
public void updateUserRole(String phoneNumber, List<Role> roleList) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
User user = mongoTemplate.findOne(query, User.class);
if (user == null) {
throw new UserException("用户不存在");
}
user.setRoleList(roleList);
mongoTemplate.save(user);
}
@Override
public String selectUsername(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
User user = mongoTemplate.findOne(query, User.class);
if(user == null){
log.error("用户不存在");
throw new UserException("用户不存在");
}
return user.getUsername();
}
@Override
public User selectUser(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
return mongoTemplate.findOne(query, User.class);
}
@Override
public void resetPwd(String phoneNumber) {
Query query = new Query(Criteria.where("phoneNumber").is(phoneNumber));
Update update = new Update().set("password", "123456");
mongoTemplate.updateFirst(query, update, User.class);
}
@Override
public void modifyUser(UserInfoVo userInfoVo) {
Query query = new Query(Criteria.where("phoneNumber").is(userInfoVo.getPhoneNumber()));
Update update = new Update()
.set("username", userInfoVo.getUsername())
.set("idNumber", userInfoVo.getIdNumber())
.set("administrativeArea", userInfoVo.getAdministrativeArea());
mongoTemplate.updateFirst(query, update, User.class);
}
} }

View File

@ -2,6 +2,8 @@ package com.example.survey.dto;
import com.example.survey.entity.Department; import com.example.survey.entity.Department;
import com.example.survey.entity.Role; import com.example.survey.entity.Role;
import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.vo.RoleVo;
import lombok.*; import lombok.*;
import java.util.List; import java.util.List;
@ -16,6 +18,10 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class LoginDto { public class LoginDto {
private String token; private String token;
private List<Role> roleList; private String username;
private String idNumber;
private String phoneNumber;
private List<RoleVo> roleList;
private List<Department> departmentList; private List<Department> departmentList;
private AdministrativeArea administrativeArea;
} }

View File

@ -1,7 +1,8 @@
package com.example.survey.dto; package com.example.survey.dto;
import com.example.survey.entity.Investigator; import com.example.survey.dto.inner.RelevantUserInfo;
import com.example.survey.entity.Respondent; import com.example.survey.entity.Respondent;
import com.example.survey.entity.User;
import lombok.*; import lombok.*;
/** /**
@ -35,9 +36,9 @@ public class RespondentDto {
private String msg; private String msg;
/** /**
* 分配的调查人员 * 分配的人员
*/ */
private Investigator investigator; private RelevantUserInfo relevantUserInfo;
/** /**
* 是否发病 * 是否发病
@ -49,11 +50,11 @@ public class RespondentDto {
*/ */
private String gender; private String gender;
public RespondentDto(Respondent respondent, Investigator investigator){ public RespondentDto(Respondent respondent, User user){
this.idNumber = respondent.getIdNumber(); this.idNumber = respondent.getIdNumber();
this.name = respondent.getName(); this.name = respondent.getName();
this.phoneNumber = respondent.getPhoneNumber(); this.phoneNumber = respondent.getPhoneNumber();
this.investigator = investigator; this.relevantUserInfo = new RelevantUserInfo(user);
this.diseased = respondent.isDiseased(); this.diseased = respondent.isDiseased();
this.gender = respondent.getGender(); this.gender = respondent.getGender();
this.msg = respondent.getMsg(); this.msg = respondent.getMsg();

View File

@ -0,0 +1,35 @@
package com.example.survey.dto;
import com.example.survey.dao.UserDao;
import com.example.survey.entity.Department;
import com.example.survey.entity.Role;
import com.example.survey.entity.User;
import lombok.*;
import java.util.LinkedList;
import java.util.List;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class UserDto {
private String username;
private String phoneNumber;
private List<String> roleList;
private List<Department> departmentList;
public UserDto(User user){
username = user.getUsername();
phoneNumber = user.getPhoneNumber();
roleList = new LinkedList<>();
for (Role role : user.getRoleList()) {
roleList.add(role.getName());
}
departmentList = user.getDepartmentList();
}
}

View File

@ -0,0 +1,35 @@
package com.example.survey.dto.inner;
import com.example.survey.entity.User;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class RelevantUserInfo {
/**
* 身份证号
*/
private String idNumber;
/**
* 电话号码
*/
private String phoneNumber;
/**
* 用户名
*/
private String username;
public RelevantUserInfo(User user) {
this.idNumber = user.getIdNumber();
this.phoneNumber = user.getPhoneNumber();
this.username = user.getUsername();
}
}

View File

@ -1,6 +1,7 @@
package com.example.survey.entity; package com.example.survey.entity;
import lombok.*; import lombok.*;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef; import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@ -19,9 +20,9 @@ import java.util.List;
public class Department { public class Department {
/** /**
* 唯一索引 * id
*/ */
private String uniqueIndex; private ObjectId id;
/** /**
* 部门名 * 部门名
@ -31,6 +32,7 @@ public class Department {
/** /**
* 子部门 * 子部门
*/ */
@DBRef
private List<Department> children; private List<Department> children;
/** /**

View File

@ -3,12 +3,12 @@ package com.example.survey.entity;
import com.example.survey.entity.inner.*; import com.example.survey.entity.inner.*;
import com.example.survey.vo.InvestigationRecordVo; import com.example.survey.vo.InvestigationRecordVo;
import lombok.*; import lombok.*;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* @author Pope * @author Pope
@ -58,6 +58,11 @@ public class InvestigationRecord {
public static final String WOMAN = ""; public static final String WOMAN = "";
/**
* id
*/
private ObjectId id;
/** /**
* 问卷编号 * 问卷编号
*/ */
@ -230,7 +235,7 @@ public class InvestigationRecord {
* 外键 * 外键
*/ */
@Indexed @Indexed
private String investigatorPhone; private String userPhone;
/** /**
* 调查日期 * 调查日期
@ -244,9 +249,14 @@ public class InvestigationRecord {
private List<TempHistory> tempHistoryList; private List<TempHistory> tempHistoryList;
/** /**
* *
*/ */
private List<LiveAndTravelHistory> liveAndTravelHistoryList; private List<LiveHistory> liveHistoryList;
/**
* 旅行史
*/
private List<TravelHistory> travelHistoryList;
/** /**
* 状态信息 * 状态信息
@ -269,62 +279,61 @@ public class InvestigationRecord {
* 密切接触者身份证 * 密切接触者身份证
* 外键 * 外键
*/ */
private List<String> closeContactList; @DBRef
private List<InvestigationRecord> closeContactList;
/** /**
* 上级感染者 * 上级感染者
*/ */
private List<SuperiorInfectedIndividual> superiorInfectedIndividualList; private List<SuperiorInfectedIndividual> superiorInfectedIndividualList;
/** /**
* 生成提交待审核的记录 * 存放一些url
* @param vo 调查记录vo
*/ */
public static InvestigationRecord getInvestigationRecord(InvestigationRecordVo vo) { private Map<String, String> urlMap;
InvestigationRecord record = new InvestigationRecord();
record.questionnaireNumber = vo.getQuestionnaireNumber();
record.idNumber = vo.getIdNumber();
record.name = vo.getName();
record.gender = vo.getGender();
record.overseasCase = vo.isOverseasCase();
record.diseased = vo.isDiseased();
record.entryExperience = vo.getEntryExperience();
record.wayOfBeingDiscovered = vo.getWayOfBeingDiscovered();
record.dateOfAdmission = vo.getDateOfAdmission();
record.symptomAndSign = vo.getSymptomAndSign();
record.existComplication = vo.isExistComplication();
record.complication = vo.getComplication();
record.maxTemp = vo.getMaxTemp();
record.existImagingFeatureOfPneumonia = vo.isExistImagingFeatureOfPneumonia();
record.testDate = vo.getTestDate();
record.dateOfDischarge = vo.getDateOfDischarge();
record.specificOccupation = vo.getSpecificOccupation();
record.otherSpecificOccupation = vo.getOtherSpecificOccupation();
record.workInformation = vo.getWorkInformation();
record.otherWorkInformation = vo.getOtherWorkInformation();
record.pregnant = vo.isPregnant();
record.pregnantWeek = vo.getPregnantWeek();
record.medicalHistory = vo.getMedicalHistory();
record.medicalHistoryDetail = vo.getMedicalHistoryDetail();
record.nearSeriousRegion = vo.isNearSeriousRegion();
record.contactWithSeriousRegionPatients = vo.isContactWithSeriousRegionPatients();
record.contactWithConfirmedCase = vo.isContactWithConfirmedCase();
record.aggregationDisease = vo.isAggregationDisease();
record.detectionList = vo.getDetectionList();
record.investigationCompany = vo.getInvestigationCompany();
record.investigatorPhone = vo.getInvestigatorPhone();
record.investigationDate = vo.getInvestigationDate();
record.tempHistoryList = vo.getTempHistoryList();
record.liveAndTravelHistoryList = vo.getLiveAndTravelHistoryList();
record.closeContactList = new ArrayList<>();
record.superiorInfectedIndividualList = new ArrayList<>();
return record; public InvestigationRecord(InvestigationRecordVo vo) {
questionnaireNumber = vo.getQuestionnaireNumber();
idNumber = vo.getIdNumber();
name = vo.getName();
gender = vo.getGender();
overseasCase = vo.isOverseasCase();
diseased = vo.isDiseased();
entryExperience = vo.getEntryExperience();
wayOfBeingDiscovered = vo.getWayOfBeingDiscovered();
dateOfAdmission = vo.getDateOfAdmission();
symptomAndSign = vo.getSymptomAndSign();
existComplication = vo.isExistComplication();
complication = vo.getComplication();
maxTemp = vo.getMaxTemp();
existImagingFeatureOfPneumonia = vo.isExistImagingFeatureOfPneumonia();
testDate = vo.getTestDate();
dateOfDischarge = vo.getDateOfDischarge();
specificOccupation = vo.getSpecificOccupation();
otherSpecificOccupation = vo.getOtherSpecificOccupation();
workInformation = vo.getWorkInformation();
otherWorkInformation = vo.getOtherWorkInformation();
pregnant = vo.isPregnant();
pregnantWeek = vo.getPregnantWeek();
medicalHistory = vo.getMedicalHistory();
medicalHistoryDetail = vo.getMedicalHistoryDetail();
nearSeriousRegion = vo.isNearSeriousRegion();
contactWithSeriousRegionPatients = vo.isContactWithSeriousRegionPatients();
contactWithConfirmedCase = vo.isContactWithConfirmedCase();
aggregationDisease = vo.isAggregationDisease();
detectionList = vo.getDetectionList();
investigationCompany = vo.getInvestigationCompany();
userPhone = vo.getUserPhone();
investigationDate = vo.getInvestigationDate();
tempHistoryList = vo.getTempHistoryList();
liveHistoryList = vo.getLiveHistoryList();
travelHistoryList = vo.getTravelHistoryList();
closeContactList = new ArrayList<>();
superiorInfectedIndividualList = new ArrayList<>();
urlMap = vo.getUrlMap();
} }
} }

View File

@ -1,36 +0,0 @@
package com.example.survey.entity;
import lombok.*;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Pope
* 调查人员表
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "investigator")
public class Investigator {
/**
* 身份证号
*/
private String idNumber;
/**
* 姓名
*/
private String name;
/**
* 电话号码
*/
@Indexed(unique = true)
private String phoneNumber;
}

View File

@ -1,6 +1,11 @@
package com.example.survey.entity; package com.example.survey.entity;
import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.enumeration.RespondentStateEnum;
import com.example.survey.vo.CreateRespondentVo;
import lombok.*; import lombok.*;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@ -17,13 +22,10 @@ import org.springframework.data.mongodb.core.mapping.Document;
public class Respondent { public class Respondent {
/** /**
* 性别为男 * id
*/ */
public static final String MAN = ""; @Id
/** private ObjectId id;
* 性别为女
*/
public static final String WOMAN = "";
/** /**
* 身份证号 * 身份证号
@ -50,7 +52,7 @@ public class Respondent {
* 分配的调查人员 * 分配的调查人员
*/ */
@Indexed @Indexed
private String investigatorPhone; private String userPhone;
/** /**
* 是否发病 * 是否发病
@ -62,7 +64,25 @@ public class Respondent {
*/ */
private String gender; private String gender;
/**
* 行政区划
*/
private AdministrativeArea administrativeArea;
/**
* 状态
*/
private String state;
public Respondent(CreateRespondentVo createRespondentVo) {
this.idNumber = createRespondentVo.getIdNumber();
this.phoneNumber = createRespondentVo.getPhoneNumber();
this.name = createRespondentVo.getName();
this.msg = createRespondentVo.getMsg();
this.userPhone = createRespondentVo.getUserPhone();
this.diseased = createRespondentVo.isDiseased();
this.gender = createRespondentVo.getGender();
this.administrativeArea = createRespondentVo.getAdministrativeArea();
this.state = RespondentStateEnum.NOT_INVESTIGATED.getValue();
}
} }

View File

@ -2,6 +2,8 @@ package com.example.survey.entity;
import com.example.survey.enumeration.AuthEnum; import com.example.survey.enumeration.AuthEnum;
import lombok.*; import lombok.*;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@ -18,6 +20,12 @@ import java.util.Set;
@Document(collection = "role") @Document(collection = "role")
public class Role { public class Role {
/**
* id
*/
@Id
private ObjectId id;
/** /**
* 角色名 * 角色名
*/ */

View File

@ -1,14 +1,15 @@
package com.example.survey.entity; package com.example.survey.entity;
import com.example.survey.vo.SignupVo; import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.vo.CreateUserVo;
import lombok.*; import lombok.*;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* @author Pope * @author Pope
@ -21,6 +22,12 @@ import java.util.Set;
@Document(collection = "user") @Document(collection = "user")
public class User { public class User {
/**
* id
*/
@Id
private ObjectId id;
/** /**
* 用户名 * 用户名
*/ */
@ -36,6 +43,11 @@ public class User {
*/ */
private String idNumber; private String idNumber;
/**
* 行政区划
*/
private AdministrativeArea administrativeArea;
/** /**
* 手机号 * 手机号
*/ */
@ -45,20 +57,23 @@ public class User {
/** /**
* 一个人可以拥有多个角色 * 一个人可以拥有多个角色
*/ */
@DBRef
private List<Role> roleList; private List<Role> roleList;
/** /**
* 一个人所属的部门 * 一个人所属的部门
*/ */
@DBRef
private List<Department> departmentList; private List<Department> departmentList;
public User(SignupVo vo){ public User(CreateUserVo vo) {
this.username = vo.getUsername(); username = vo.getUsername();
this.password = vo.getPassword(); password = vo.getPassword();
this.phoneNumber = vo.getPhoneNumber(); idNumber = vo.getIdNumber();
this.roleList = new ArrayList<>(); phoneNumber = vo.getPhoneNumber();
this.departmentList = new ArrayList<>(); roleList = new LinkedList<>();
departmentList = new LinkedList<>();
} }
} }

View File

@ -0,0 +1,26 @@
package com.example.survey.entity.inner;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class AdministrativeArea {
/**
*
*/
private String province;
/**
*
*/
private String city;
/**
*
*/
private String county;
}

View File

@ -9,19 +9,13 @@ import java.util.List;
/** /**
* @author Pope * @author Pope
* 居旅史 * 居旅史
* TODO 完善类
*/ */
@Getter @Getter
@Setter @Setter
@ToString @ToString
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class LiveAndTravelHistory { public class LiveHistory {
/**
* 居住史或者旅行史
*/
private List<String> type;
/** /**
* 起始时间 * 起始时间
@ -38,7 +32,7 @@ public class LiveAndTravelHistory {
/** /**
* 地点 * 地点
*/ */
private String location; private Location location;
/** /**
* 事件 * 事件

View File

@ -0,0 +1,30 @@
package com.example.survey.entity.inner;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Location {
/**
* 地点信息
*/
private String msg;
/**
* 经度
*/
private double longitude;
/**
* 纬度
*/
private double latitude;
}

View File

@ -20,7 +20,7 @@ public class OperationInformation {
/** /**
* 修改操作 * 修改操作
*/ */
public static final String CHANGE = "修改"; public static final String MODIFY = "修改";
/** /**
* 删除操作 * 删除操作
@ -50,7 +50,7 @@ public class OperationInformation {
/** /**
* 操作者id * 操作者id
*/ */
private String investigatorPhone; private String userPhone;
/** /**
* 版本信息 * 版本信息
@ -66,4 +66,48 @@ public class OperationInformation {
* 操作结果 * 操作结果
*/ */
private String result; private String result;
public static OperationInformation submitOp(String userPhone, String msg) {
OperationInformation submit = new OperationInformation();
submit.setType(SUBMIT);
submit.setTime(new Date());
submit.setUserPhone(userPhone);
submit.setVersion(userPhone + new Date().toString());
submit.setMsg(msg);
submit.setResult("提交成功");
return submit;
}
public static OperationInformation modifyOp(String investigatorPhone, String msg) {
OperationInformation modify = new OperationInformation();
modify.setType(MODIFY);
modify.setTime(new Date());
modify.setUserPhone(investigatorPhone);
modify.setVersion(investigatorPhone + new Date().toString());
modify.setMsg(msg);
modify.setResult("提交修改");
return modify;
}
public static OperationInformation deleteOp(String investigatorPhone, String msg) {
OperationInformation delete = new OperationInformation();
delete.setType(MODIFY);
delete.setTime(new Date());
delete.setUserPhone(investigatorPhone);
delete.setVersion(investigatorPhone + new Date().toString());
delete.setMsg(msg);
delete.setResult("删除成功");
return delete;
}
public static OperationInformation reviewOp(String investigatorPhone, String msg, String result) {
OperationInformation review = new OperationInformation();
review.setType(REVIEW);
review.setTime(new Date());
review.setUserPhone(investigatorPhone);
review.setVersion(investigatorPhone + new Date().toString());
review.setMsg(msg);
review.setResult(result);
return review;
}
} }

View File

@ -0,0 +1,43 @@
package com.example.survey.entity.inner;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import java.util.Date;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class TravelHistory {
/**
* 起始时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date beginTime;
/**
* 结束时间
*/
@JsonFormat(pattern = "yyyy-MM-dd")
private Date endTime;
/**
* 开始地点
*/
private Location startLocation;
/**
* 结束地点
*/
private Location endLocation;
/**
* 事件
*/
private String detail;
}

View File

@ -1,6 +1,8 @@
package com.example.survey.enumeration; package com.example.survey.enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -12,24 +14,33 @@ public enum AuthEnum {
/** /**
* 管理员权限可以访问所有接口 * 管理员权限可以访问所有接口
*/ */
ADMIN(0, "管理员", new HashSet<String>() {{ ADMIN("管理员", new HashSet<String>() {{
add("/investigator/investigator : POST"); add("/investigator/investigator : POST");
add("/investigationRecord/underReviewRecord : GET"); add("/investigationRecord/underReviewRecord : GET");
add("/investigationRecord/underReviewRecordCount : GET"); add("/investigationRecord/underReviewRecordCount : GET");
add("/investigationRecord/investigationRecord : POST"); add("/investigationRecord/investigationRecord : POST");
add("/investigationRecord/investigationRecord : PUT"); add("/investigationRecord/investigationRecord : PUT");
add("/investigationRecord/underReviewRecord : PUT"); add("/investigationRecord/underReviewRecord : PUT");
add("/investigationRecord/record2word : GET");
add("/respondent/respondent : POST"); add("/respondent/respondent : POST");
add("/respondent/respondent : GET"); add("/respondent/respondent : GET");
add("/user/userRole : PUT"); add("/user/userRole : PUT");
add("/user/user : GET");
add("/user/user : DELETE");
add("/user/user : POST");
add("/role/role : POST"); add("/role/role : POST");
add("/role/role : GET");
add("/role/role : DELETE");
add("/role/role : PUT");
add("/role/authList : GET");
add("/user/userInfo : PUT");
add("/user/pwd : PUT");
}}), }}),
/** /**
* 查询调查记录的权限 * 查询调查记录的权限
*/ */
RETRIEVE_RECORD(1, "查询调查记录的权限", new HashSet<String>() {{ RETRIEVE_RECORD("查询调查记录的权限", new HashSet<String>() {{
add("/investigationRecord/underReviewRecord : GET"); add("/investigationRecord/underReviewRecord : GET");
add("/investigationRecord/underReviewRecordCount : GET"); add("/investigationRecord/underReviewRecordCount : GET");
}}), }}),
@ -37,92 +48,132 @@ public enum AuthEnum {
/** /**
* 提交记录的权限 * 提交记录的权限
*/ */
CREATE_RECORD(2, "提交调查记录权限", new HashSet<String>() {{ CREATE_RECORD("提交调查记录权限", new HashSet<String>() {{
add("/investigationRecord/investigationRecord : POST"); add("/investigationRecord/investigationRecord : POST");
}}), }}),
/** /**
* 修改调查记录信息的权限 * 修改调查记录信息的权限
*/ */
UPDATE_RECORD(3, "修改调查记录权限", new HashSet<String>() {{ UPDATE_RECORD("修改调查记录权限", new HashSet<String>() {{
add("/investigationRecord/investigationRecord : PUT"); add("/investigationRecord/investigationRecord : PUT");
}}), }}),
/** /**
* 审核调查记录权限 * 审核调查记录权限
*/ */
REVIEW_RECORD(4, "审核调查记录权限", new HashSet<String>() {{ REVIEW_RECORD("审核调查记录权限", new HashSet<String>() {{
add("/investigationRecord/underReviewRecord : PUT"); add("/investigationRecord/underReviewRecord : PUT");
}}), }}),
/** /**
* 删除调查记录权限 * 删除调查记录权限
*/ */
DELETE_RECORD(5, "删除调查记录权限", new HashSet<String>() {{ DELETE_RECORD("删除调查记录权限", new HashSet<String>() {{
}}), }}),
/** /**
* 分析调查记录的权限 * 分析调查记录的权限
*/ */
ANALYSE_RECORD(6, "分析调查记录权限", new HashSet<String>() {{ ANALYSE_RECORD("分析调查记录权限", new HashSet<String>() {{
}}), }}),
/** /**
* 可以增删改流调人员信息 * 可以增删改流调人员信息
*/ */
CUD_INVESTIGATOR(7, "增删改流调人员信息的权限", new HashSet<String>() {{ CUD_INVESTIGATOR("增删改流调人员信息的权限", new HashSet<String>() {{
}}), }}),
/** /**
* 查询流调人员信息 * 查询流调人员信息
*/ */
RETRIEVE_INVESTIGATOR(8, "查询流调人员信息的权限", new HashSet<String>() {{ RETRIEVE_INVESTIGATOR("查询流调人员信息的权限", new HashSet<String>() {{
}}), }}),
/** /**
* 增删改调查对象信息的权限 * 增删改调查对象信息的权限
*/ */
CUD_RESPONDENT(9, "增删改调查对象信息的权限", new HashSet<String>() {{ CUD_RESPONDENT("增删改调查对象信息的权限", new HashSet<String>() {{
add("/respondent/respondent : POST"); add("/respondent/respondent : POST");
}}), }}),
/** /**
* 查询调查对象信息的权限 * 查询调查对象信息的权限
*/ */
RETRIEVE_RESPONDENT(10, "查询调查对象信息的权限", new HashSet<String>() {{ RETRIEVE_RESPONDENT("查询调查对象信息的权限", new HashSet<String>() {{
add("/respondent/respondent : GET"); add("/respondent/respondent : GET");
}}),
/**
* 查看用户的权限
*/
RETRIEVE_USER("查看用户的权限", new HashSet<String>() {{
add("/user/user : GET");
}}),
/**
* 删除用户的权限
*/
DELETE_USER("删除用户的权限", new HashSet<String>() {{
add("/user/user : DELETE");
}}),
/**
* 查看角色的权限
*/
RETRIEVE_ROLE("查看角色的权限", new HashSet<String>() {{
add("/role/role : GET");
}}),
/**
* 删除角色的权限
*/
DELETE_ROLE("删除角色的权限", new HashSet<String>() {{
add("/role/role : DELETE");
}}),
/**
* 修改角色的权限
*/
UPDATE_ROLE("修改角色的权限", new HashSet<String>() {{
add("/role/role : PUT");
}}),
/**
* 查看权限列表
*/
LIST_AUTHORITY("查看权限列表的权限", new HashSet<String>() {{
add("/role/authList : GET");
}}); }});
private int code;
private String name; private String name;
private Set<String> routes; private Set<String> routes;
AuthEnum(int code, String name, Set<String> routes) { AuthEnum(String name, Set<String> routes) {
this.code = code;
this.name = name; this.name = name;
this.routes = routes; this.routes = routes;
} }
public static AuthEnum getRoleEnum(int code) { public static AuthEnum getRoleEnum(String name) {
for (AuthEnum value : AuthEnum.values()) { for (AuthEnum value : AuthEnum.values()) {
if (value.code == code) { if (value.name.equals(name)) {
return value; return value;
} }
} }
return null; return null;
} }
public int getCode() { public static List<String> getNameList() {
return code; List<String> res = new LinkedList<>();
} for (AuthEnum value : AuthEnum.values()) {
res.add(value.name);
public void setCode(int code) { }
this.code = code; return res;
} }
public String getName() { public String getName() {

View File

@ -0,0 +1,26 @@
package com.example.survey.enumeration;
/**
* @author Pope
*/
public enum GenderEnum {
/**
* 男性
*/
MAN(""),
/**
* 女性
*/
WOMAN("");
private final String value;
GenderEnum(String gender) {
this.value = gender;
}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,26 @@
package com.example.survey.enumeration;
/**
* @author Pope
*/
public enum RespondentStateEnum {
/**
* 已调查状态
*/
INVESTIGATED("已调查"),
/**
* 未调查状态
*/
NOT_INVESTIGATED("未调查");
private final String value;
RespondentStateEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

View File

@ -0,0 +1,10 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class AuthException extends RuntimeException{
public AuthException(String message) {
super(message);
}
}

View File

@ -0,0 +1,10 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class DepartmentException extends RuntimeException{
public DepartmentException(String message) {
super(message);
}
}

View File

@ -0,0 +1,11 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class RecordException extends RuntimeException{
public RecordException(String message) {
super(message);
}
}

View File

@ -0,0 +1,10 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class RespondentException extends RuntimeException{
public RespondentException(String message) {
super(message);
}
}

View File

@ -0,0 +1,10 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class RoleException extends RuntimeException{
public RoleException(String msg){
super(msg);
}
}

View File

@ -0,0 +1,10 @@
package com.example.survey.exception;
/**
* @author Pope
*/
public class UserException extends RuntimeException{
public UserException(String msg){
super(msg);
}
}

View File

@ -4,6 +4,7 @@ import com.example.survey.entity.InvestigationRecord;
import com.example.survey.vo.InvestigationRecordVo; import com.example.survey.vo.InvestigationRecordVo;
import com.example.survey.vo.ReviewVo; import com.example.survey.vo.ReviewVo;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
/** /**
@ -22,7 +23,7 @@ public interface InvestigationRecordService {
/** /**
* 根据筛选条件查询调查记录 * 根据筛选条件查询调查记录
* *
* @param investigatorPhone 流调人员电话号码 * @param userPhone 用户电话号码
* @param currentPage 当前页数 * @param currentPage 当前页数
* @param pageSize 页大小 * @param pageSize 页大小
* @param state 状态 * @param state 状态
@ -32,15 +33,15 @@ public interface InvestigationRecordService {
* @param diseased 是否患病 * @param diseased 是否患病
* @return 调查记录列表 * @return 调查记录列表
*/ */
List<InvestigationRecord> listUnderReviewRecordPageByInvestigationPhone(String investigatorPhone, int currentPage, int pageSize, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased); List<InvestigationRecord> listUnderReviewRecordLimit(String userPhone, int currentPage, int pageSize, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased);
/** /**
* 根据流调人员电话号码查询待审核记录数量 * 根据流调人员电话号码查询待审核记录数量
* *
* @param investigatorPhone 流调人员id * @param userPhone 用户电话号码
* @return 记录数量 * @return 记录数量
*/ */
long countUnderReviewRecordByInvestigatorPhone(String investigatorPhone); long countUnderReviewRecord(String userPhone);
/** /**
* 提交修改后的调查记录等待审核 * 提交修改后的调查记录等待审核
@ -53,8 +54,16 @@ public interface InvestigationRecordService {
/** /**
* 审核待调查记录 * 审核待调查记录
* *
* @param vo 审核信息 * @param reviewVo 审核信息
* @return 是否成功 * @return 是否成功
*/ */
boolean reviewRecord(ReviewVo vo); boolean reviewRecord(ReviewVo reviewVo);
/**
* 导出为word
*
* @param idNumber 调查对象身份证号
* @param response 响应
*/
void export2Word(String idNumber, HttpServletResponse response);
} }

View File

@ -1,17 +0,0 @@
package com.example.survey.service;
import com.example.survey.entity.Investigator;
/**
* @author Pope
*/
public interface InvestigatorService {
/**
* 创建调查人员
* @param investigator 调查人员
* @return 是否创建成功
*/
boolean addInvestigator(Investigator investigator);
}

View File

@ -2,6 +2,8 @@ package com.example.survey.service;
import com.example.survey.entity.Respondent; import com.example.survey.entity.Respondent;
import com.example.survey.dto.RespondentDto; import com.example.survey.dto.RespondentDto;
import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.vo.CreateRespondentVo;
import java.util.List; import java.util.List;
@ -11,24 +13,31 @@ import java.util.List;
public interface RespondentService { public interface RespondentService {
/** /**
* 创建待调查对象 * 创建待调查对象
* @param respondent 待调查对象 *
* @param createRespondentVo 待调查对象信息
* @return 是否创建成功 * @return 是否创建成功
*/ */
boolean addRespondent(Respondent respondent); boolean addRespondent(CreateRespondentVo createRespondentVo);
/** /**
* 根据流调人员电话号码分页查询待调查对象数据 * 根据流调人员电话号码分页查询待调查对象数据
* @param investigatorPhone 流调人员电话号码 *
* @param currentPage 当前页数 * @param userPhone 分配的人员电话号码
* @param pageSize 页大小 * @param state 状态
* @param administrativeArea 行政区划
* @param currentPage 当前页数
* @param pageSize 页大小
* @return 页数据 * @return 页数据
*/ */
List<RespondentDto> listRespondentPageByInvestigatorPhone(String investigatorPhone, int currentPage, int pageSize); List<RespondentDto> listRespondentLimit(String userPhone, String state, AdministrativeArea administrativeArea, int currentPage, int pageSize);
/** /**
* 根据流调人员phone查询调查对象数量 * 根据筛选条件查询调查对象数量
* @param investigatorPhone 流调人员电话号码 *
* @return 对应流调人员id的调查对象数量 * @param userPhone 分配的人员电话号码
* @param state 状态
* @param administrativeArea 行政区划
* @return 数量
*/ */
long countRespondentByInvestigatorPhone(String investigatorPhone); long countRespondent(String userPhone, String state, AdministrativeArea administrativeArea);
} }

View File

@ -1,6 +1,9 @@
package com.example.survey.service; package com.example.survey.service;
import com.example.survey.vo.RoleVo; import com.example.survey.vo.CreateRoleVo;
import com.example.survey.vo.ModifyRoleVo;
import java.util.List;
/** /**
* @author Pope * @author Pope
@ -10,8 +13,33 @@ public interface RoleService {
/** /**
* 创建角色 * 创建角色
* *
* @param roleVo 角色信息 * @param createRoleVo 角色信息
* @return 是否创建成功 * @return 是否创建成功
*/ */
boolean addRole(RoleVo roleVo); boolean addRole(CreateRoleVo createRoleVo);
/**
* 根据权限名分页查询权限
*
* @param roleName 角色名 模糊匹配
* @param currentPage 当前页数
* @param pageSize 页大小
* @return 查询结果
*/
List<CreateRoleVo> getRole(String roleName, int currentPage, int pageSize);
/**
* 删除角色
*
* @param roleName 角色名
* @return 是否删除成功
*/
void deleteRole(String roleName);
/**
* 修改角色权限
*
* @param modifyRoleVo 修改后角色信息
*/
void modifyRole(ModifyRoleVo modifyRoleVo);
} }

View File

@ -1,10 +1,14 @@
package com.example.survey.service; package com.example.survey.service;
import com.example.survey.dto.LoginDto; import com.example.survey.dto.LoginDto;
import com.example.survey.dto.UserDto;
import com.example.survey.vo.LoginVo; import com.example.survey.vo.LoginVo;
import com.example.survey.vo.SignupVo; import com.example.survey.vo.CreateUserVo;
import com.example.survey.vo.UserInfoVo;
import com.example.survey.vo.UserRoleVo; import com.example.survey.vo.UserRoleVo;
import java.util.List;
/** /**
* @author Pope * @author Pope
*/ */
@ -20,14 +24,48 @@ public interface UserService {
/** /**
* 注册用户 * 注册用户
* *
* @param signupVo 注册信息 * @param createUserVo 注册信息
* @return 是否注册成功 * @return 是否注册成功
*/ */
boolean addUser(SignupVo signupVo); boolean addUser(CreateUserVo createUserVo);
/** /**
* 修改用户权限 * 修改用户权限
*
* @param userRoleVo 新权限信息 * @param userRoleVo 新权限信息
*/ */
void modifyRoles(UserRoleVo userRoleVo); void modifyRole(UserRoleVo userRoleVo);
/**
* 根据筛选条件分页查询用户
*
* @param username 用户名 模糊匹配
* @param phoneNumber 电话号码 精确匹配
* @param currentPage 当前页数
* @param pageSize 页大小
* @return 用户信息dto
*/
List<UserDto> listUserLimit(String username, String phoneNumber, int currentPage, int pageSize);
/**
* 删除用户
*
* @param phoneNumber 电话号码
* @return 是否删除成功
*/
boolean deleteUser(String phoneNumber);
/**
* 修改用户信息
*
* @param userInfoVo 用户信息
*/
void modifyUserInfo(UserInfoVo userInfoVo);
/**
* 重置密码
*
* @param phoneNumber 电话号码
*/
void resetPwd(String phoneNumber);
} }

View File

@ -1,17 +1,23 @@
package com.example.survey.service.impl; package com.example.survey.service.impl;
import com.example.survey.dao.InvestigationRecordDao; import com.example.survey.dao.InvestigationRecordDao;
import com.example.survey.dao.InvestigatorDao;
import com.example.survey.dao.RespondentDao; import com.example.survey.dao.RespondentDao;
import com.example.survey.dao.UserDao;
import com.example.survey.entity.InvestigationRecord; import com.example.survey.entity.InvestigationRecord;
import com.example.survey.entity.inner.OperationInformation; import com.example.survey.entity.inner.OperationInformation;
import com.example.survey.exception.RecordException;
import com.example.survey.exception.RespondentException;
import com.example.survey.exception.UserException;
import com.example.survey.service.InvestigationRecordService; import com.example.survey.service.InvestigationRecordService;
import com.example.survey.util.WordUtil;
import com.example.survey.vo.InvestigationRecordVo; import com.example.survey.vo.InvestigationRecordVo;
import com.example.survey.vo.ReviewVo; import com.example.survey.vo.ReviewVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -19,71 +25,67 @@ import java.util.List;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@Service @Service
public class InvestigationRecordServiceImpl implements InvestigationRecordService { public class InvestigationRecordServiceImpl implements InvestigationRecordService {
@Autowired @Autowired
private InvestigationRecordDao investigationRecordDao; private InvestigationRecordDao investigationRecordDao;
@Autowired @Autowired
private InvestigatorDao investigatorDao; private RespondentDao respondentDao;
@Autowired @Autowired
private RespondentDao respondentDao; private UserDao userDao;
@Override @Override
public boolean addInvestigationRecord(InvestigationRecordVo vo) { public boolean addInvestigationRecord(InvestigationRecordVo vo) {
InvestigationRecord record = InvestigationRecord.getInvestigationRecord(vo); //如果不存在对应电话号码的调查对象
if (!respondentDao.existRespondent(vo.getIdNumber())) {
log.error("调查对象不存在");
throw new RespondentException("调查对象不存在");
}
//如果已经存在待审核或已审核记录则失败
if (investigationRecordDao.existInvestigationRecord(vo.getIdNumber(), InvestigationRecord.UNDER_REVIEW, InvestigationRecord.REVIEWED)) {
log.error("数据库已存在对应调查对象的待审核或已审核记录");
throw new RecordException("数据库已存在对应调查对象的待审核或已审核记录");
}
//如果不存在对应电话号码的流调人员
if(!userDao.existUser(vo.getUserPhone())){
log.error("用户不存在");
throw new UserException("用户不存在");
}
InvestigationRecord record = new InvestigationRecord(vo);
//生成版本信息 //生成版本信息
record.setState(InvestigationRecord.UNDER_REVIEW); record.setState(InvestigationRecord.UNDER_REVIEW);
record.setVersion(vo.getInvestigatorPhone() + new Date().toString()); record.setVersion(vo.getUserPhone() + new Date().toString());
List<OperationInformation> opList = new ArrayList<>(); List<OperationInformation> opList = new ArrayList<>();
OperationInformation op = new OperationInformation(); opList.add(OperationInformation.submitOp(vo.getUserPhone(), vo.getMsg()));
op.setType(OperationInformation.SUBMIT);
op.setTime(new Date());
op.setInvestigatorPhone(vo.getInvestigatorPhone());
op.setVersion(vo.getInvestigatorPhone() + new Date().toString());
op.setMsg(vo.getMsg());
op.setResult("提交成功");
opList.add(op);
record.setOperationInformationList(opList); record.setOperationInformationList(opList);
//如果不存在对应id的调查对象
if (!respondentDao.existRespondent(record.getIdNumber())) {
//TODO 改为抛出相应异常
return false;
}
//如果已经存在则失败
if (investigationRecordDao.existInvestigationRecord(record.getIdNumber(), InvestigationRecord.UNDER_REVIEW, InvestigationRecord.REVIEWED)) {
return false;
}
//如果不存在对应id的流调人员
if (!investigatorDao.existInvestigator(record.getInvestigatorPhone())) {
//TODO 改为抛出相应异常
return false;
}
//TODO 插入消息队列 //TODO 插入消息队列
return investigationRecordDao.insertInvestigationRecord(record); return investigationRecordDao.insertInvestigationRecord(record);
} }
@Override @Override
public List<InvestigationRecord> listUnderReviewRecordPageByInvestigationPhone(String investigatorPhone, int currentPage, int pageSize, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased) { public List<InvestigationRecord> listUnderReviewRecordLimit(String userPhone, int currentPage, int pageSize, String state, String idNumber, String version, String questionnaireNumber, Boolean diseased) {
//TODO 从消息队列进行筛选 //TODO 从消息队列进行筛选
return investigationRecordDao.listLimitInvestigationRecord(investigatorPhone, pageSize * currentPage, pageSize, state, idNumber, version, questionnaireNumber, diseased); return investigationRecordDao.listInvestigationRecordLimit(userPhone, pageSize * currentPage, pageSize, state, idNumber, version, questionnaireNumber, diseased);
} }
@Override @Override
public long countUnderReviewRecordByInvestigatorPhone(String investigatorPhone) { public long countUnderReviewRecord(String userPhone) {
//TODO 从消息队列获取调查记录数量 //TODO 从消息队列获取调查记录数量
return investigationRecordDao.countInvestigationRecordByInvestigatorPhone(investigatorPhone, InvestigationRecord.UNDER_REVIEW); return investigationRecordDao.countInvestigationRecordByUserPhone(userPhone, InvestigationRecord.UNDER_REVIEW);
} }
@Override @Override
@ -91,24 +93,22 @@ public class InvestigationRecordServiceImpl implements InvestigationRecordServic
public void changeInvestigationRecord(InvestigationRecordVo vo) { public void changeInvestigationRecord(InvestigationRecordVo vo) {
//创建新记录 //创建新记录
InvestigationRecord oldRecord = investigationRecordDao.selectInvestigationRecord(vo.getIdNumber(), InvestigationRecord.REVIEWED); InvestigationRecord oldRecord = investigationRecordDao.selectInvestigationRecord(vo.getIdNumber(), InvestigationRecord.REVIEWED);
if(oldRecord == null){ if (oldRecord == null) {
oldRecord = investigationRecordDao.selectInvestigationRecord(vo.getIdNumber(), InvestigationRecord.NOT_PASS); oldRecord = investigationRecordDao.selectInvestigationRecord(vo.getIdNumber(), InvestigationRecord.NOT_PASS);
} }
InvestigationRecord newRecord = InvestigationRecord.getInvestigationRecord(vo);
if(oldRecord == null){
log.error("调查记录不存在");
throw new RecordException("调查记录不存在");
}
InvestigationRecord newRecord = new InvestigationRecord(vo);
//生成版本信息 //生成版本信息
newRecord.setState(InvestigationRecord.UNDER_REVIEW); newRecord.setState(InvestigationRecord.UNDER_REVIEW);
newRecord.setVersion(vo.getInvestigatorPhone() + new Date().toString()); newRecord.setVersion(vo.getUserPhone() + new Date().toString());
//生成操作记录 //生成操作记录
List<OperationInformation> opList = oldRecord.getOperationInformationList(); List<OperationInformation> opList = oldRecord.getOperationInformationList();
OperationInformation op = new OperationInformation(); opList.add(OperationInformation.submitOp(vo.getUserPhone(), vo.getMsg()));
op.setType(OperationInformation.CHANGE);
op.setTime(new Date());
op.setInvestigatorPhone(vo.getInvestigatorPhone());
op.setVersion(vo.getInvestigatorPhone() + new Date().toString());
op.setMsg(vo.getMsg());
op.setResult("提交成功");
opList.add(op);
newRecord.setOperationInformationList(opList); newRecord.setOperationInformationList(opList);
//存入新纪录 //存入新纪录
@ -121,35 +121,28 @@ public class InvestigationRecordServiceImpl implements InvestigationRecordServic
} }
@Override @Override
public boolean reviewRecord(ReviewVo vo) { public boolean reviewRecord(ReviewVo reviewVo) {
//如果调查记录表不存在 //如果待审核调查记录表不存在
if (!investigationRecordDao.existInvestigationRecord(vo.getIdNumber(), InvestigationRecord.UNDER_REVIEW)) { if (!investigationRecordDao.existInvestigationRecord(reviewVo.getIdNumber(), InvestigationRecord.UNDER_REVIEW)) {
//TODO 抛出相应异常 log.error("未审核记录不存在");
return false; throw new RecordException("未审核记录不存在");
} }
//如果审核人不存在 //如果审核人不存在
if (!investigatorDao.existInvestigator(vo.getReviewerPhone())) { if(!userDao.existUser(reviewVo.getReviewerPhone())){
//TODO 抛出相应异常 log.error("审核人不存在");
return false; throw new UserException("审核人不存在");
} }
InvestigationRecord record = investigationRecordDao.selectInvestigationRecord(vo.getIdNumber(), InvestigationRecord.UNDER_REVIEW); InvestigationRecord record = investigationRecordDao.selectInvestigationRecord(reviewVo.getIdNumber(), InvestigationRecord.UNDER_REVIEW);
//审核结果与版本信息 //审核结果与版本信息
record.setState(vo.isPass() ? InvestigationRecord.REVIEWED : InvestigationRecord.NOT_PASS); record.setState(reviewVo.isPass() ? InvestigationRecord.REVIEWED : InvestigationRecord.NOT_PASS);
record.setVersion(vo.getReviewerPhone() + new Date().toString()); record.setVersion(reviewVo.getReviewerPhone() + new Date().toString());
//生成操作记录 //生成操作记录
List<OperationInformation> opList = record.getOperationInformationList(); List<OperationInformation> opList = record.getOperationInformationList();
OperationInformation op = new OperationInformation(); opList.add(OperationInformation.reviewOp(reviewVo.getReviewerPhone(), reviewVo.getMsg(), reviewVo.isPass() ? "审核通过" : "审核不通过"));
op.setType(OperationInformation.REVIEW);
op.setTime(new Date());
op.setInvestigatorPhone(vo.getReviewerPhone());
op.setVersion(vo.getReviewerPhone() + new Date().toString());
op.setMsg(vo.getMsg());
op.setResult(vo.isPass() ? "审核通过" : "审核不通过");
opList.add(op);
record.setOperationInformationList(opList); record.setOperationInformationList(opList);
//更新数据库记录 //更新数据库记录
@ -157,4 +150,14 @@ public class InvestigationRecordServiceImpl implements InvestigationRecordServic
return true; return true;
} }
@Override
public void export2Word(String idNumber, HttpServletResponse response) {
InvestigationRecord record = investigationRecordDao.selectInvestigationRecord(idNumber, InvestigationRecord.REVIEWED);
try {
WordUtil.writeDocx(record, response);
} catch (Exception e) {
log.error(e.getMessage());
}
}
} }

View File

@ -1,22 +0,0 @@
package com.example.survey.service.impl;
import com.example.survey.dao.InvestigatorDao;
import com.example.survey.entity.Investigator;
import com.example.survey.service.InvestigatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author Pope
*/
@Service
public class InvestigatorServiceImpl implements InvestigatorService {
@Autowired
private InvestigatorDao investigatorDao;
@Override
public boolean addInvestigator(Investigator investigator) {
return investigatorDao.insertInvestigator(investigator);
}
}

View File

@ -1,11 +1,14 @@
package com.example.survey.service.impl; package com.example.survey.service.impl;
import com.example.survey.dao.InvestigatorDao;
import com.example.survey.dao.RespondentDao; import com.example.survey.dao.RespondentDao;
import com.example.survey.entity.Investigator; import com.example.survey.dao.UserDao;
import com.example.survey.entity.Respondent; import com.example.survey.entity.Respondent;
import com.example.survey.entity.User;
import com.example.survey.entity.inner.AdministrativeArea;
import com.example.survey.service.RespondentService; import com.example.survey.service.RespondentService;
import com.example.survey.dto.RespondentDto; import com.example.survey.dto.RespondentDto;
import com.example.survey.vo.CreateRespondentVo;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,6 +18,7 @@ import java.util.List;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@Service @Service
public class RespondentServiceImpl implements RespondentService { public class RespondentServiceImpl implements RespondentService {
@ -22,32 +26,32 @@ public class RespondentServiceImpl implements RespondentService {
private RespondentDao respondentDao; private RespondentDao respondentDao;
@Autowired @Autowired
private InvestigatorDao investigatorDao; private UserDao userDao;
@Override @Override
public boolean addRespondent(Respondent respondent) { public boolean addRespondent(CreateRespondentVo createRespondentVo) {
//如果不存在对应phone的流调人员 if (!userDao.existUser(createRespondentVo.getUserPhone())) {
if (!investigatorDao.existInvestigator(respondent.getInvestigatorPhone())) { log.error("不存在对应id的用户");
//TODO 改为抛出相应异常
return false;
} }
Respondent respondent = new Respondent(createRespondentVo);
return respondentDao.insertRespondent(respondent); return respondentDao.insertRespondent(respondent);
} }
@Override @Override
public List<RespondentDto> listRespondentPageByInvestigatorPhone(String investigatorPhone, int currentPage, int pageSize) { public List<RespondentDto> listRespondentLimit(String userPhone, String state, AdministrativeArea administrativeArea, int currentPage, int pageSize) {
List<RespondentDto> voList = new ArrayList<>(); List<RespondentDto> dtoList = new ArrayList<>();
List<Respondent> respondentList = respondentDao.listLimitRespondentByInvestigator(investigatorPhone, currentPage * pageSize, pageSize); List<Respondent> respondentList = respondentDao.listRespondentLimit(userPhone, state, administrativeArea, currentPage * pageSize, pageSize);
for (Respondent respondent : respondentList) { for (Respondent respondent : respondentList) {
Investigator investigator = investigatorDao.selectInvestigator(respondent.getInvestigatorPhone()); User user = userDao.selectUser(respondent.getUserPhone());
voList.add(new RespondentDto(respondent, investigator)); dtoList.add(new RespondentDto(respondent, user));
} }
return voList; return dtoList;
} }
@Override @Override
public long countRespondentByInvestigatorPhone(String investigatorPhone) { public long countRespondent(String userPhone, String state, AdministrativeArea administrativeArea) {
return respondentDao.countRespondentBuInvestigatorPhone(investigatorPhone); return respondentDao.countRespondent(userPhone, state, administrativeArea);
} }
} }

View File

@ -1,14 +1,21 @@
package com.example.survey.service.impl; package com.example.survey.service.impl;
import com.example.survey.dao.RoleDao; import com.example.survey.dao.RoleDao;
import com.example.survey.dao.UserDao;
import com.example.survey.entity.Role; import com.example.survey.entity.Role;
import com.example.survey.enumeration.AuthEnum; import com.example.survey.enumeration.AuthEnum;
import com.example.survey.exception.AuthException;
import com.example.survey.service.RoleService; import com.example.survey.service.RoleService;
import com.example.survey.vo.RoleVo; import com.example.survey.util.TokenUtil;
import com.example.survey.vo.CreateRoleVo;
import com.example.survey.vo.ModifyRoleVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -20,16 +27,58 @@ public class RoleServiceImpl implements RoleService {
@Autowired @Autowired
private RoleDao roleDao; private RoleDao roleDao;
@Autowired
private UserDao userDao;
@Override @Override
public boolean addRole(RoleVo roleVo) { public boolean addRole(CreateRoleVo createRoleVo) {
Role role = new Role(); Role role = new Role();
role.setName(roleVo.getRoleName()); role.setName(createRoleVo.getRoleName());
Set<AuthEnum> authoritySet = new HashSet<>(); Set<AuthEnum> authoritySet = new HashSet<>();
for (Integer code : roleVo.getAuthList()) { for (String name : createRoleVo.getAuthList()) {
authoritySet.add(AuthEnum.getRoleEnum(code)); authoritySet.add(AuthEnum.getRoleEnum(name));
} }
role.setAuthoritySet(authoritySet); role.setAuthoritySet(authoritySet);
return roleDao.insertRole(role); return roleDao.insertRole(role);
} }
@Override
public List<CreateRoleVo> getRole(String roleName, int currentPage, int pageSize) {
List<Role> roleList = roleDao.listLimitRole(roleName, currentPage * pageSize, pageSize);
List<CreateRoleVo> roleVoList = new LinkedList<>();
for (Role role : roleList) {
roleVoList.add(new CreateRoleVo(role));
}
return roleVoList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteRole(String roleName) {
//将用户数据库中含有该角色的用户更新
userDao.clearRole(roleDao.selectRole(roleName));
//从角色数据库删除角色
roleDao.deleteRole(roleName);
//删除redis中的角色
TokenUtil.expireKey(roleName);
}
@Override
public void modifyRole(ModifyRoleVo modifyRoleVo) {
Set<AuthEnum> authEnumList = new HashSet<>();
Set<String> routeSet = new HashSet<>();
for (String authName : modifyRoleVo.getAuthList()) {
AuthEnum authEnum = AuthEnum.getRoleEnum(authName);
if(authEnum == null){
throw new AuthException("权限不存在");
}
authEnumList.add(authEnum);
routeSet.addAll(authEnum.getRoutes());
}
roleDao.updateRole(modifyRoleVo.getRoleName(), authEnumList);
TokenUtil.setWithoutExpireTime(modifyRoleVo.getRoleName(), routeSet);
}
} }

View File

@ -1,18 +1,18 @@
package com.example.survey.service.impl; package com.example.survey.service.impl;
import com.example.survey.dao.InvestigatorDao; import com.example.survey.dao.InvestigationRecordDao;
import com.example.survey.dao.RoleDao; import com.example.survey.dao.RoleDao;
import com.example.survey.dao.UserDao; import com.example.survey.dao.UserDao;
import com.example.survey.dto.LoginDto; import com.example.survey.dto.LoginDto;
import com.example.survey.entity.Investigator; import com.example.survey.dto.UserDto;
import com.example.survey.entity.Role; import com.example.survey.entity.Role;
import com.example.survey.entity.User; import com.example.survey.entity.User;
import com.example.survey.enumeration.AuthEnum; import com.example.survey.enumeration.AuthEnum;
import com.example.survey.exception.UserException;
import com.example.survey.service.UserService; import com.example.survey.service.UserService;
import com.example.survey.util.TokenUtil; import com.example.survey.util.TokenUtil;
import com.example.survey.vo.LoginVo; import com.example.survey.vo.*;
import com.example.survey.vo.SignupVo; import lombok.extern.log4j.Log4j2;
import com.example.survey.vo.UserRoleVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -21,38 +21,43 @@ import java.util.*;
/** /**
* @author Pope * @author Pope
*/ */
@Log4j2
@Service @Service
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
@Autowired @Autowired
private UserDao userDao; private UserDao userDao;
@Autowired @Autowired
private TokenUtil tokenUtil;
@Autowired
private RoleDao roleDao; private RoleDao roleDao;
@Autowired @Autowired
private InvestigatorDao investigatorDao; private InvestigationRecordDao investigationRecordDao;
@Override @Override
public LoginDto matchAuth(LoginVo loginVo) { public LoginDto matchAuth(LoginVo loginVo) {
User user = userDao.selectUser(loginVo.getPhoneNumber(), loginVo.getPassword()); User user = userDao.selectUser(loginVo.getPhoneNumber());
if (user == null) { if (user == null) {
return null; log.error("用户不存在");
throw new UserException("用户不存在");
}
if (!loginVo.getPassword().equals(user.getPassword())) {
log.error("密码错误");
throw new UserException("密码错误");
} }
LoginDto loginDto = new LoginDto();
LoginDto loginDto = new LoginDto();
//判断是否已经登录过 //判断是否已经登录过
if (tokenUtil.existToken(user.getPhoneNumber())) { if (TokenUtil.existKey(user.getPhoneNumber())) {
String oldToken = (String) tokenUtil.getValue(user.getPhoneNumber()); String oldToken = (String) TokenUtil.get(user.getPhoneNumber());
if (tokenUtil.existToken(oldToken)) { if (TokenUtil.existKey(oldToken)) {
//已经登录将旧token过期 //已经登录将旧token过期
tokenUtil.expire(oldToken); TokenUtil.expireKey(oldToken);
} }
} }
//生成新的token并存入redis //生成新的token并存入redis
String newToken = UUID.randomUUID().toString(); String newToken = UUID.randomUUID().toString();
tokenUtil.setPhoneNumberAndToken(user.getPhoneNumber(), newToken); TokenUtil.set(user.getPhoneNumber(), newToken);
//生成角色列表 //生成角色列表
Set<String> roleNameSet = new HashSet<>(); Set<String> roleNameSet = new HashSet<>();
@ -61,41 +66,93 @@ public class UserServiceImpl implements UserService {
for (AuthEnum authEnum : role.getAuthoritySet()) { for (AuthEnum authEnum : role.getAuthoritySet()) {
routeSet.addAll(authEnum.getRoutes()); routeSet.addAll(authEnum.getRoutes());
} }
tokenUtil.setAuthAndRoute(role.getName(), routeSet); TokenUtil.setWithoutExpireTime(role.getName(), routeSet);
roleNameSet.add(role.getName()); roleNameSet.add(role.getName());
} }
tokenUtil.setTokenAndAuth(newToken, roleNameSet); TokenUtil.set(newToken, roleNameSet);
loginDto.setToken(newToken); loginDto.setToken(newToken);
loginDto.setRoleList(user.getRoleList()); loginDto.setUsername(user.getUsername());
loginDto.setIdNumber(user.getIdNumber());
loginDto.setPhoneNumber(user.getPhoneNumber());
List<RoleVo> roleVoList = new ArrayList<>();
for (Role role : user.getRoleList()) {
roleVoList.add(new RoleVo(role));
}
loginDto.setRoleList(roleVoList);
loginDto.setDepartmentList(user.getDepartmentList()); loginDto.setDepartmentList(user.getDepartmentList());
loginDto.setAdministrativeArea(user.getAdministrativeArea());
return loginDto; return loginDto;
} }
@Override @Override
public boolean addUser(SignupVo signupVo) { public boolean addUser(CreateUserVo createUserVo) {
User user = new User(signupVo); User user = new User(createUserVo);
//初始化为流调人员权限 //初始化为流调人员权限
Role investigatorRole = roleDao.selectRole("流调人员"); // Role investigatorRole = roleDao.selectRole("流调人员");
List<Role> roleList = user.getRoleList(); // List<Role> roleList = user.getRoleList();
roleList.add(investigatorRole); // roleList.add(investigatorRole);
user.setRoleList(roleList); // user.setRoleList(roleList);
Investigator investigator = new Investigator(); return userDao.insertUser(user);
investigator.setName(user.getUsername());
investigator.setIdNumber(user.getIdNumber());
investigator.setPhoneNumber(user.getPhoneNumber());
return userDao.insertUser(user) && investigatorDao.insertInvestigator(investigator);
} }
@Override @Override
public void modifyRoles(UserRoleVo userRoleVo) { public void modifyRole(UserRoleVo userRoleVo) {
List<Role> roleList = new ArrayList<>(); List<Role> roleList = new ArrayList<>();
for (String roleName : userRoleVo.getRoleNameList()) { for (String roleName : userRoleVo.getRoleNameList()) {
roleList.add(roleDao.selectRole(roleName)); roleList.add(roleDao.selectRole(roleName));
} }
roleDao.updateUserRoles(userRoleVo.getPhoneNumber(), roleList); userDao.updateUserRole(userRoleVo.getPhoneNumber(), roleList);
} }
@Override
public List<UserDto> listUserLimit(String username, String phoneNumber, int currentPage, int pageSize) {
List<User> userList = userDao.listUserLimit(username, phoneNumber, currentPage * pageSize, pageSize);
List<UserDto> userDtoList = new LinkedList<>();
for (User user : userList) {
userDtoList.add(new UserDto(user));
}
return userDtoList;
}
@Override
public boolean deleteUser(String phoneNumber) {
if (!userDao.existUser(phoneNumber)) {
log.error("用户不存在");
throw new UserException("用户不存在");
}
userDao.deleteUser(phoneNumber);
investigationRecordDao.updateManyRecordUserPhone(phoneNumber, null);
if (TokenUtil.existKey(phoneNumber)) {
String token = (String) TokenUtil.get(phoneNumber);
TokenUtil.expireKey(phoneNumber);
TokenUtil.expireKey(token);
}
return true;
}
@Override
public void modifyUserInfo(UserInfoVo userInfoVo) {
if (!userDao.existUser(userInfoVo.getPhoneNumber())) {
log.error("用户不存在");
throw new UserException("用户不存在");
}
userDao.modifyUser(userInfoVo);
}
@Override
public void resetPwd(String phoneNumber) {
if (!userDao.existUser(phoneNumber)) {
log.error("用户不存在");
throw new UserException("用户不存在");
}
userDao.resetPwd(phoneNumber);
}
} }

View File

@ -4,9 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashSet; import javax.annotation.PostConstruct;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -20,46 +19,68 @@ public class TokenUtil {
*/ */
private static final long EXPIRATION_TIME = 6L; private static final long EXPIRATION_TIME = 6L;
private static TokenUtil tokenUtil;
@Autowired @Autowired
RedisTemplate<String, Object> redisTemplate; RedisTemplate<String, Object> redisTemplate;
@PostConstruct
public void init() {
tokenUtil = this;
tokenUtil.redisTemplate = this.redisTemplate;
}
/** /**
* 判断token是否存在 * 判断key是否存在
* *
* @param token key * @param key key
* @return 是否存在 * @return 是否存在
*/ */
public boolean existToken(String token) { public static boolean existKey(String key) {
Boolean result = redisTemplate.hasKey(token); Boolean result = tokenUtil.redisTemplate.hasKey(key);
return result != null && result; return result != null && result;
} }
/** /**
* 设置<手机号, token>类型的键值对 * 存储key-value键值对如果key已存在则更新value
* 过期时间为{@link TokenUtil#EXPIRATION_TIME}小时
* *
* @param phoneNumber 手机号 * @param key key
* @param token token * @param value value
*/ */
public void setPhoneNumberAndToken(String phoneNumber, String token) { public static void set(String key, String value) {
redisTemplate.opsForValue().set(phoneNumber, token, 6L, TimeUnit.HOURS); tokenUtil.redisTemplate.opsForValue().set(key, value, EXPIRATION_TIME, TimeUnit.HOURS);
}
public void refreshExpireTime(String key) {
redisTemplate.expire(key, 6L, TimeUnit.HOURS);
} }
/** /**
* 存储token与对应的可访问路由集合 * 刷新key的过期时间
* *
* @param token token * @param key key
* @param authSet 对应权限集合
*/ */
public void setTokenAndAuth(String token, Set<String> authSet) { public static void refreshExpireTime(String key) {
redisTemplate.opsForValue().set(token, authSet, 6L, TimeUnit.HOURS); tokenUtil.redisTemplate.expire(key, EXPIRATION_TIME, TimeUnit.HOURS);
} }
public void setAuthAndRoute(String authName, Set<String> route) { /**
redisTemplate.opsForValue().set(authName, route); * 存储key-set键值对如果key已存在则更新set
* 过期时间为{@link TokenUtil#EXPIRATION_TIME}小时
*
* @param key key
* @param set 集合
*/
public static void set(String key, Set<String> set) {
tokenUtil.redisTemplate.opsForValue().set(key, set, 6L, TimeUnit.HOURS);
}
/**
* 存储key-set键值对如果key已存在则更新set
* <b>无过期时间</b>
*
* @param key key
* @param set set
*/
public static void setWithoutExpireTime(String key, Set<String> set) {
tokenUtil.redisTemplate.opsForValue().set(key, set);
} }
/** /**
@ -70,15 +91,18 @@ public class TokenUtil {
* @param method 请求方法 * @param method 请求方法
* @return 是否允许访问 * @return 是否允许访问
*/ */
public boolean isPass(String token, String route, String method) { public static boolean isPass(String token, String route, String method) {
if (!existToken(token)) { if (!existKey(token)) {
return false; return false;
} }
String request = route + " : " + method; String request = route + " : " + method;
Set<String> authSet = (Set<String>) redisTemplate.opsForValue().get(token); Set<String> authSet = (Set<String>) tokenUtil.redisTemplate.opsForValue().get(token);
if (authSet == null) {
return false;
}
for (String auth : authSet) { for (String auth : authSet) {
Set<String> routeSet = (Set<String>) redisTemplate.opsForValue().get(auth); Set<String> routeSet = (Set<String>) tokenUtil.redisTemplate.opsForValue().get(auth);
if(routeSet.contains(request)){ if (routeSet != null && routeSet.contains(request)) {
return true; return true;
} }
} }
@ -91,8 +115,8 @@ public class TokenUtil {
* @param key key * @param key key
* @return value * @return value
*/ */
public Object getValue(String key) { public static Object get(String key) {
return redisTemplate.opsForValue().get(key); return tokenUtil.redisTemplate.opsForValue().get(key);
} }
/** /**
@ -100,7 +124,7 @@ public class TokenUtil {
* *
* @param key 要过期的key * @param key 要过期的key
*/ */
public void expire(String key) { public static void expireKey(String key) {
redisTemplate.expire(key, 0, TimeUnit.MICROSECONDS); tokenUtil.redisTemplate.expire(key, 0, TimeUnit.MICROSECONDS);
} }
} }

View File

@ -0,0 +1,430 @@
package com.example.survey.util;
import com.example.survey.dao.UserDao;
import com.example.survey.entity.InvestigationRecord;
import com.example.survey.entity.inner.*;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import java.math.BigInteger;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author Pope
*/
@Component
public class WordUtil {
@Autowired
private UserDao userDao;
private static WordUtil wordUtil;
@PostConstruct
public void init() {
wordUtil = this;
wordUtil.userDao = this.userDao;
}
/**
* 分隔符
*/
private static final String SEPARATOR = " ";
private static final String OTHER = "other";
public static void writeDocx(InvestigationRecord record, HttpServletResponse response) throws Exception {
XWPFDocument document = new XWPFDocument();
int index = 1;
//添加标题
XWPFParagraph title = document.createParagraph();
title.setAlignment(ParagraphAlignment.CENTER);
XWPFRun titleRun = title.createRun();
titleRun.setText("新型冠状病毒肺炎病例个案调查表");
//设置字体
setRunFont(titleRun, "宋体", 18, true);
//换行
document.createParagraph().createRun().setText("\r");
//问卷编号与身份证号
XWPFParagraph firstPara = document.createParagraph();
firstPara.setAlignment(ParagraphAlignment.CENTER);
XWPFRun firstParaRun = firstPara.createRun();
firstParaRun.setText("问卷编号:" + record.getQuestionnaireNumber() + SEPARATOR + "身份证号:" + record.getIdNumber());
//设置字体
setRunFont(firstParaRun, "仿宋", 10, false);
//换行
document.createParagraph().createRun().setText("\r");
//信息表格
XWPFTable infoTable = document.createTable();
//列宽自动分割
CTTblWidth infoTableWidth = infoTable.getCTTbl().addNewTblPr().addNewTblW();
infoTableWidth.setType(STTblWidth.DXA);
infoTableWidth.setW(BigInteger.valueOf(9072));
//表格第一行 基本信息
XWPFTableRow infoTableRow1 = infoTable.getRow(0);
XWPFTableCell basicInfoCell = infoTableRow1.getCell(0);
basicInfoCell.removeParagraph(0);
//基本信息标题
createParaInCell(basicInfoCell, "一、基本信息", true);
createBreakLine(basicInfoCell);
//姓名 性别
createParaInCell(basicInfoCell, index++ + ".姓名:" + record.getName() + SEPARATOR + index++ + ".性别:" + record.getGender(), false);
//是否为境外输入病例
createParaInCell(basicInfoCell, index++ + ".是否为境外输入病例:" + (record.isOverseasCase() ? "" : ""), false);
if (record.isOverseasCase()) {
//如果为境外输入病例填写入境信息
EntryExperience entryExperience = record.getEntryExperience();
createParaInCell(basicInfoCell, SEPARATOR + "入境前居住或旅行的国家或地区:" + entryExperience.getAreaOfResidence(), false);
createParaInCell(basicInfoCell, SEPARATOR + "入境前途经国家和地区:" + entryExperience.getAreaOfAccess(), false);
createParaInCell(basicInfoCell, SEPARATOR + "国籍:" + entryExperience.getNationality() + SEPARATOR + "护照号码:" + entryExperience.getPassportNumber(), false);
createParaInCell(basicInfoCell, SEPARATOR + "入境口岸:" + entryExperience.getEntryPort().getProvince() + "" + entryExperience.getEntryPort().getPort(), false);
createParaInCell(basicInfoCell, SEPARATOR + "入境日期:" + formatDate(entryExperience.getEntryDate()), false);
createParaInCell(basicInfoCell, SEPARATOR + "入境交通方式:" + entryExperience.getTransportation(), false);
}
//病例发现与就诊
XWPFTableRow infoTableRow2 = infoTable.createRow();
XWPFTableCell hospInfoCell = infoTableRow2.getCell(0);
hospInfoCell.removeParagraph(0);
//病例发现与就诊标题
createParaInCell(hospInfoCell, "二、病例发现与就诊", true);
createBreakLine(hospInfoCell);
//病例发现途径
createParaInCell(hospInfoCell, index++ + ".病例发现途径:" + record.getWayOfBeingDiscovered(), false);
//入院日期
createParaInCell(hospInfoCell, index++ + ".入院日期:" + formatDate(record.getDateOfAdmission()), false);
StringBuilder symptomAndSign = new StringBuilder();
//入院时症状和体征
for (String s : record.getSymptomAndSign()) {
symptomAndSign.append(s).append(" ");
}
createParaInCell(hospInfoCell, index++ + ".入院症状和体征:" + symptomAndSign.toString(), false);
//有无并发症
createParaInCell(hospInfoCell, index++ + ".有无并发症:" + (record.isExistComplication() ? "" : ""), false);
if (record.getComplication() != null) {
StringBuilder complication = new StringBuilder("并发症:");
for (String s : record.getComplication()) {
complication.append(s);
}
createParaInCell(hospInfoCell, complication.toString(), false);
if (record.getComplication().contains("发热")) {
//如果并发症包含发热则打印最高温度
createParaInCell(hospInfoCell, SEPARATOR + "发热:最高温度" + record.getMaxTemp() + "°C", false);
}
}
//胸部线或CT检测是否有肺炎影像学特征
createParaInCell(hospInfoCell, index++ + ".胸部线或CT检测是否有肺炎影像学特征" + (record.isExistImagingFeatureOfPneumonia() ? "" : ""), false);
if (record.isExistImagingFeatureOfPneumonia()) {
//如果存在肺炎影像学特征打印检测时间
createParaInCell(hospInfoCell, SEPARATOR + "检测时间:" + formatDate(record.getTestDate()), false);
}
//出院日期
createParaInCell(hospInfoCell, index++ + ".出院日期:" + formatDate(record.getDateOfDischarge()), false);
//是否为以下特定职业人群
createParaInCell(hospInfoCell, index++ + ".是否为以下特定职业人群:" + record.getSpecificOccupation(), false);
if (OTHER.equals(record.getSpecificOccupation())) {
//若职业为其他
createParaInCell(hospInfoCell, SEPARATOR + "职业:" + record.getOtherSpecificOccupation(), false);
}
//如为医务人员请选择具体工作性质
createParaInCell(hospInfoCell, SEPARATOR + "如为医务人员,请选择具体工作性质:" + record.getWorkInformation(), false);
if (OTHER.equals(record.getWorkInformation())) {
//若工作性质为其他
createParaInCell(hospInfoCell, SEPARATOR + "其他工作性质:" + record.getOtherWorkInformation(), false);
}
//是否为孕妇
createParaInCell(hospInfoCell, index++ + ".是否为孕妇:" + (record.isPregnant() ? "" : ""), false);
if (record.isPregnant()) {
//如果是孕妇打印孕周
createParaInCell(hospInfoCell, SEPARATOR + "孕周:" + record.getPregnantWeek(), false);
}
//既往病史和基本情况可多选
StringBuilder medicalHistory = new StringBuilder();
for (String s : record.getMedicalHistory()) {
medicalHistory.append(s).append(" ");
}
createParaInCell(hospInfoCell, index++ + ".既往病史与基本情况:" + medicalHistory, false);
//既往病史描述
createParaInCell(hospInfoCell, SEPARATOR + "既往病史描述:" + record.getMedicalHistoryDetail(), false);
//发病或检测阳性前 14 天内是否有以下暴露史或接触史
XWPFTableRow infoTableRow3 = infoTable.createRow();
XWPFTableCell contactHistoryCell = infoTableRow3.getCell(0);
contactHistoryCell.removeParagraph(0);
//病例发现与就诊标题
createParaInCell(contactHistoryCell, "三、发病或检测阳性前 14 天内是否有以下暴露史或接触史:", true);
createBreakLine(contactHistoryCell);
//是否有境外疫情严重国家或地区的旅行史或居住史
createParaInCell(contactHistoryCell, index++ + ".是否有境外疫情严重国家或地区的旅行史或居住史:" + (record.isNearSeriousRegion() ? "" : ""), false);
//是否接触过来自境外疫情严重的国家或地区的发热或有呼吸道症状的患者
createParaInCell(contactHistoryCell, index++ + ".是否接触过来自境外疫情严重的国家或地区的发热或有呼吸道症状的患者:" + (record.isContactWithSeriousRegionPatients() ? "" : ""), false);
//是否曾有确诊病例或无症状感染者的接触史
createParaInCell(contactHistoryCell, index++ + ".是否曾有确诊病例或无症状感染者的接触史:" + (record.isContactWithConfirmedCase() ? "" : ""), false);
//患者同一家庭办公室学校或托幼机构班级车间等集体单位是否有聚集性发病
createParaInCell(contactHistoryCell, index++ + ".患者同一家庭、办公室、学校或托幼机构班级、车间等集体单位是否有聚集性发病:" + (record.isAggregationDisease() ? "" : ""), false);
//体温记录
XWPFTableRow infoTableRow4 = infoTable.createRow();
XWPFTableCell tempHistory = infoTableRow4.getCell(0);
tempHistory.removeParagraph(0);
createParaInCell(tempHistory, "四、体温记录", true);
createBreakLine(tempHistory);
//体温记录表
XWPFTable tempTable = createTableInCell(tempHistory);
//创建表头
XWPFTableRow tempTableHead = tempTable.createRow();
XWPFTableCell tempDateHead = tempTableHead.createCell();
tempDateHead.removeParagraph(0);
createParaInCell(tempDateHead, "记录时间", false);
setCellCenter(tempDateHead);
XWPFTableCell tempHead = tempTableHead.createCell();
tempHead.removeParagraph(0);
createParaInCell(tempHead, "温度", false);
setCellCenter(tempHead);
//创建数据
for (TempHistory history : record.getTempHistoryList()) {
XWPFTableRow row = tempTable.createRow();
XWPFTableCell temp = row.getCell(0);
temp.removeParagraph(0);
createParaInCell(temp, history.getData(), false);
setCellCenter(temp);
XWPFTableCell date = row.getCell(1);
date.removeParagraph(0);
createParaInCell(date, formatTime(history.getTime()), false);
setCellCenter(date);
}
//居住史
XWPFTableRow infoTableRow5 = infoTable.createRow();
XWPFTableCell liveAndTravelHistory = infoTableRow5.getCell(0);
liveAndTravelHistory.removeParagraph(0);
createParaInCell(liveAndTravelHistory, "五、居旅史", true);
createBreakLine(liveAndTravelHistory);
List<LiveHistory> liveHistoryList = record.getLiveHistoryList();
if (liveHistoryList != null) {
for (int i = 0; i < liveHistoryList.size(); i++) {
createParaInCell(liveAndTravelHistory, "居住史" + (i + 1), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "开始时间:" + formatDate(liveHistoryList.get(i).getBeginTime()), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "地点:" + liveHistoryList.get(i).getLocation().getMsg(), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "结束时间:" + formatDate(liveHistoryList.get(i).getEndTime()), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "详细信息:" + liveHistoryList.get(i).getDetail(), false);
}
}
List<TravelHistory> travelHistoryList = record.getTravelHistoryList();
if (travelHistoryList != null) {
for (int i = 0; i < travelHistoryList.size(); i++) {
createParaInCell(liveAndTravelHistory, "旅行史" + (i + 1), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "开始时间:" + formatDate(travelHistoryList.get(i).getBeginTime()), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "开始地点:" + travelHistoryList.get(i).getStartLocation().getMsg(), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "结束时间:" + formatDate(travelHistoryList.get(i).getEndTime()), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "结束地点:" + travelHistoryList.get(i).getEndLocation().getMsg(), false);
createParaInCell(liveAndTravelHistory, SEPARATOR + "详细信息:" + travelHistoryList.get(i).getDetail(), false);
}
}
//实验室检测单
XWPFTableRow infoTableRow6 = infoTable.createRow();
XWPFTableCell detectionList = infoTableRow6.getCell(0);
detectionList.removeParagraph(0);
createParaInCell(detectionList, "六、实验室检测单", true);
createBreakLine(detectionList);
//实验室检测单表格
XWPFTable detectionTable = createTableInCell(detectionList);
//创建表头
XWPFTableRow detectionTableHead = detectionTable.createRow();
XWPFTableCell nameHead = detectionTableHead.createCell();
nameHead.removeParagraph(0);
createParaInCell(nameHead, "标本类型:", false);
setCellCenter(nameHead);
XWPFTableCell detectionDate = detectionTableHead.createCell();
detectionDate.removeParagraph(0);
createParaInCell(detectionDate, "采样时间:", false);
setCellCenter(detectionDate);
XWPFTableCell detectionResult = detectionTableHead.createCell();
detectionResult.removeParagraph(0);
createParaInCell(detectionResult, "采样结果:", false);
setCellCenter(detectionResult);
for (Detection detection : record.getDetectionList()) {
XWPFTableRow row = detectionTable.createRow();
XWPFTableCell name = row.getCell(0);
name.removeParagraph(0);
createParaInCell(name, detection.getName(), false);
setCellCenter(name);
XWPFTableCell date = row.getCell(1);
date.removeParagraph(0);
createParaInCell(date, formatDate(detection.getDate()), false);
setCellCenter(date);
XWPFTableCell result = row.getCell(2);
result.removeParagraph(0);
createParaInCell(result, detection.getResult(), false);
setCellCenter(result);
}
//调查信息
XWPFParagraph surveyInfo = document.createParagraph();
XWPFRun surveyInfoRun = surveyInfo.createRun();
String surveyInfoStr = "调查单位:" + record.getInvestigationCompany() + " " +
"调查者:" + wordUtil.userDao.selectUsername(record.getUserPhone()) + " " +
"调查时间:" + formatDate(record.getInvestigationDate());
surveyInfoRun.setText(surveyInfoStr);
setRunFont(surveyInfoRun, "仿宋", 11, false);
//八进制输出流
response.setContentType("application/octet-stream");
//这后面可以设置导出Excel的名称此例中名为student.xls
response.setHeader("Content-disposition", "attachment;filename=" + record.getIdNumber() + ".docx");
document.write(response.getOutputStream());
}
public static XWPFTable createTableInCell(XWPFTableCell cell) {
cell.addParagraph();
XWPFTable table = cell.insertNewTbl(cell.getParagraphArray(1).getCTP().newCursor());
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewLeft().setVal(STBorder.SINGLE);
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewRight().setVal(STBorder.SINGLE);
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewTop().setVal(STBorder.SINGLE);
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewBottom().setVal(STBorder.SINGLE);
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewInsideH().setVal(STBorder.SINGLE);
table.getCTTbl().addNewTblPr().addNewTblBorders()
.addNewInsideV().setVal(STBorder.SINGLE);
//设置表格水平居中
table.getCTTbl().getTblPr().addNewJc().setVal(STJc.CENTER);
//设置表格垂直居中
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
table.setWidth(8000);
return table;
}
/**
* 设置单元格内容居中
*/
public static void setCellCenter(XWPFTableCell cell) {
CTTc cttc = cell.getCTTc();
CTTcPr ctPr = cttc.addNewTcPr();
ctPr.addNewVAlign().setVal(STVerticalJc.CENTER);
cttc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
}
/**
* 在单元格中创建段落
*/
public static void createParaInCell(XWPFTableCell cell, String text, boolean title) {
XWPFParagraph paragraph = cell.addParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
XWPFRun run = paragraph.createRun();
run.setText(text);
if (title) {
setRunFont(run, "仿宋", 14, true);
} else {
setRunFont(run, "仿宋", 11, false);
}
}
/**
* 换行
*/
public static void createBreakLine(XWPFTableCell cell) {
cell.addParagraph().createRun().setText("\r");
}
/**
* 设置段落字体
*/
public static void setRunFont(XWPFRun run, String font, int fontSize, boolean bold) {
run.setFontFamily(font);
run.getCTR().addNewRPr().addNewRFonts().setEastAsia(font);
run.setBold(bold);
run.setFontSize(fontSize);
}
/**
* 根据日期提取时间
*
* @param date 日期
* @return 格式化后的时间字符串 --
*/
public static String formatDate(Date date) {
StringBuilder res = new StringBuilder();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
res.append(calendar.get(Calendar.YEAR)).append("");
res.append(calendar.get(Calendar.MONTH) + 1).append("");
res.append(calendar.get(Calendar.DAY_OF_MONTH)).append("");
return res.toString();
}
/**
* 根据日期提取时间
*
* @param date 日期
* @return 格式化后的时间字符串 -----
*/
public static String formatTime(Date date) {
StringBuilder res = new StringBuilder();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
res.append(calendar.get(Calendar.YEAR)).append("");
res.append(calendar.get(Calendar.MONTH) + 1).append("");
res.append(calendar.get(Calendar.DAY_OF_MONTH)).append("");
res.append(calendar.get(Calendar.HOUR_OF_DAY)).append("");
res.append(calendar.get(Calendar.MINUTE)).append("");
res.append(calendar.get(Calendar.SECOND)).append("");
return res.toString();
}
}

View File

@ -0,0 +1,55 @@
package com.example.survey.vo;
import com.example.survey.entity.inner.AdministrativeArea;
import lombok.*;
import org.springframework.data.mongodb.core.index.Indexed;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class CreateRespondentVo {
/**
* 身份证号
*/
private String idNumber;
/**
* 电话
*/
private String phoneNumber;
/**
* 姓名
*/
private String name;
/**
* 备注
*/
private String msg;
/**
* 分配的调查人员
*/
private String userPhone;
/**
* 是否发病
*/
private boolean diseased;
/**
* 性别
*/
private String gender;
/**
* 行政区划
*/
private AdministrativeArea administrativeArea;
}

View File

@ -0,0 +1,29 @@
package com.example.survey.vo;
import com.example.survey.entity.Role;
import com.example.survey.enumeration.AuthEnum;
import lombok.*;
import java.util.LinkedList;
import java.util.List;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class CreateRoleVo {
private String roleName;
private List<String> authList;
public CreateRoleVo(Role role) {
roleName = role.getName();
authList = new LinkedList<>();
for (AuthEnum authEnum : role.getAuthoritySet()) {
authList.add(authEnum.getName());
}
}
}

View File

@ -1,5 +1,6 @@
package com.example.survey.vo; package com.example.survey.vo;
import com.example.survey.entity.inner.AdministrativeArea;
import lombok.*; import lombok.*;
/** /**
@ -10,7 +11,11 @@ import lombok.*;
@ToString @ToString
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class SignupVo { public class CreateUserVo {
/**
* 身份证号
*/
private String idNumber;
/** /**
* 用户名 * 用户名
*/ */
@ -23,4 +28,8 @@ public class SignupVo {
* 密码 * 密码
*/ */
private String password; private String password;
/**
* 行政区划
*/
private AdministrativeArea administrativeArea;
} }

View File

@ -0,0 +1,17 @@
package com.example.survey.vo;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class DeleteRoleVo {
private String roleName;
}

View File

@ -0,0 +1,17 @@
package com.example.survey.vo;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class DeleteUserVo {
private String phoneNumber;
}

View File

@ -1,15 +1,12 @@
package com.example.survey.vo; package com.example.survey.vo;
import com.example.survey.entity.inner.Detection; import com.example.survey.entity.inner.*;
import com.example.survey.entity.inner.EntryExperience;
import com.example.survey.entity.inner.LiveAndTravelHistory;
import com.example.survey.entity.inner.TempHistory;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*; import lombok.*;
import org.springframework.data.mongodb.core.index.Indexed;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author Pope * @author Pope
@ -194,8 +191,7 @@ public class InvestigationRecordVo {
* 调查者身份证 * 调查者身份证
* 外键 * 外键
*/ */
@Indexed private String userPhone;
private String investigatorPhone;
/** /**
* 调查日期 * 调查日期
@ -210,15 +206,23 @@ public class InvestigationRecordVo {
private List<TempHistory> tempHistoryList; private List<TempHistory> tempHistoryList;
/** /**
* *
*/ */
private List<LiveAndTravelHistory> liveAndTravelHistoryList; private List<LiveHistory> liveHistoryList;
/**
* 旅行史
*/
private List<TravelHistory> travelHistoryList;
/** /**
* 备注 * 备注
*/ */
private String msg; private String msg;
/**
* 存放一些url
*/
private Map<String, String> urlMap;
} }

View File

@ -0,0 +1,18 @@
package com.example.survey.vo;
import lombok.*;
import java.util.List;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ModifyRoleVo {
private String roleName;
private List<String> authList;
}

View File

@ -0,0 +1,19 @@
package com.example.survey.vo;
import lombok.*;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResetPwdVo {
/**
* 电话号码
*/
private String phoneNumber;
}

View File

@ -1,9 +1,16 @@
package com.example.survey.vo; package com.example.survey.vo;
import lombok.*;
/** /**
* @author Pope * @author Pope
* 返回结果类 * 返回结果类
*/ */
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResultVo { public class ResultVo {
public static final int SUCCESS = 0; public static final int SUCCESS = 0;
@ -23,37 +30,4 @@ public class ResultVo {
* 数据 * 数据
*/ */
private Object data; private Object data;
public ResultVo() {
}
public ResultVo(int code, String msg, Object data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
} }

View File

@ -1,7 +1,10 @@
package com.example.survey.vo; package com.example.survey.vo;
import com.example.survey.entity.Role;
import com.example.survey.enumeration.AuthEnum;
import lombok.*; import lombok.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -13,6 +16,15 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class RoleVo { public class RoleVo {
private String roleName; private String roleName;
private List<Integer> authList; private List<String> authorityList;
public RoleVo(Role role) {
roleName = role.getName();
authorityList = new ArrayList<>();
for (AuthEnum authEnum : role.getAuthoritySet()) {
authorityList.add(authEnum.getName());
}
}
} }

View File

@ -0,0 +1,39 @@
package com.example.survey.vo;
import com.example.survey.entity.Department;
import com.example.survey.entity.inner.AdministrativeArea;
import lombok.*;
import java.util.List;
/**
* @author Pope
*/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class UserInfoVo {
/**
* 电话号码
*/
private String phoneNumber;
/**
* 用户名
*/
private String username;
/**
* 身份证号
*/
private String idNumber;
/**
* 行政区划
*/
private AdministrativeArea administrativeArea;
}

View File

@ -0,0 +1,13 @@
spring:
data:
mongodb:
# uri: mongodb://cveo:cveo123456@120.78.177.67:27017/survey
#创建索引
auto-index-creation: true
host: 127.0.0.1
port: 27017
database: survey
redis:
host: 127.0.0.1
port: 6379

View File

@ -0,0 +1,38 @@
spring:
data:
mongodb:
# uri: mongodb://cveo:cveo123456@120.78.177.67:27017/survey
#创建索引
auto-index-creation: true
host: mongo
port: 27017
database: survey
username: cveo
password: cveo123456
authentication-database: admin
redis:
host: redis
port: 6379
password: cveo
# kafka:
# bootstrap-servers: localhost:9092 # 指定kafka 代理地址,可以多个
# producer: # 生产者
# retries: 0 # 设置大于0的值则客户端会将发送失败的记录重新发送
# # 每次批量发送消息的数量
# batch-size: 16384
# buffer-memory: 33554432
# # 指定消息key和消息体的编解码方式
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
# value-serializer: org.apache.kafka.common.serialization.StringSerializer
# consumer:
# group-id: consumer-test
# enable-auto-commit: true # 是否自动提交offset
# auto-commit-interval: 100 # 提交offset延时(接收到消息后多久提交offset)
# auto-offset-reset: latest
# # 指定消息key和消息体的编解码方式
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# topic:
# under-review: "under_review"

View File

@ -1,38 +1,3 @@
spring: spring:
data: profiles:
mongodb: active: prod
# uri: mongodb://cveo:cveo123456@120.78.177.67:27017/survey
#创建索引
auto-index-creation: true
host: mongo
port: 27017
database: survey
username: cveo
password: cveo123456
authentication-database: admin
redis:
host: redis
port: 6379
password: cveo
# kafka:
# bootstrap-servers: localhost:9092 # 指定kafka 代理地址,可以多个
# producer: # 生产者
# retries: 0 # 设置大于0的值则客户端会将发送失败的记录重新发送
# # 每次批量发送消息的数量
# batch-size: 16384
# buffer-memory: 33554432
# # 指定消息key和消息体的编解码方式
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
# value-serializer: org.apache.kafka.common.serialization.StringSerializer
# consumer:
# group-id: consumer-test
# enable-auto-commit: true # 是否自动提交offset
# auto-commit-interval: 100 # 提交offset延时(接收到消息后多久提交offset)
# auto-offset-reset: latest
# # 指定消息key和消息体的编解码方式
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
# topic:
# under-review: "under_review"

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Configuration后面的status这个用于设置log4j2自身内部的信息输出可以不设置当设置成trace时你会看到log4j2内部各种详细输出-->
<!--monitorIntervalLog4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
<configuration monitorInterval="5">
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<!--变量配置-->
<Properties>
<!-- 格式化输出:%date表示日期%thread表示线程名%-5level级别从左显示5个字符宽度 %msg日志消息%n是换行符-->
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
<!-- 定义日志存储的路径 -->
<property name="FILE_PATH" value="./log" />
<property name="FILE_NAME" value="survey" />
</Properties>
<appenders>
<console name="Console" target="SYSTEM_OUT">
<!--输出日志的格式-->
<PatternLayout pattern="${LOG_PATTERN}"/>
<!--控制台只输出level及其以上级别的信息onMatch其他的直接拒绝onMismatch-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</console>
<!--文件会打印出所有信息这个log每次运行程序会自动清空由append属性决定适合临时测试用-->
<File name="Filelog" fileName="${FILE_PATH}/test.log" append="false">
<PatternLayout pattern="${LOG_PATTERN}"/>
</File>
<!-- 这个会打印出所有的info及以下级别的信息每次大小超过size则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileInfo" fileName="${FILE_PATH}/info.log" filePattern="${FILE_PATH}/${FILE_NAME}-INFO-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息onMatch其他的直接拒绝onMismatch-->
<ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次默认是1 hour-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="15"/>
</RollingFile>
<!-- 这个会打印出所有的warn及以下级别的信息每次大小超过size则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileWarn" fileName="${FILE_PATH}/warn.log" filePattern="${FILE_PATH}/${FILE_NAME}-WARN-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息onMatch其他的直接拒绝onMismatch-->
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次默认是1 hour-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="15"/>
</RollingFile>
<!-- 这个会打印出所有的error及以下级别的信息每次大小超过size则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileError" fileName="${FILE_PATH}/error.log" filePattern="${FILE_PATH}/${FILE_NAME}-ERROR-%d{yyyy-MM-dd}_%i.log.gz">
<!--控制台只输出level及以上级别的信息onMatch其他的直接拒绝onMismatch-->
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<!--interval属性用来指定多久滚动一次默认是1 hour-->
<TimeBasedTriggeringPolicy interval="1"/>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<!-- DefaultRolloverStrategy属性如不设置则默认为最多同一文件夹下7个文件开始覆盖-->
<DefaultRolloverStrategy max="15"/>
</RollingFile>
</appenders>
<!--Logger节点用来单独指定日志的形式比如要为指定包下的class指定不同的日志级别等。-->
<!--然后定义loggers只有定义了logger并引入的appenderappender才会生效-->
<loggers>
<!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
<logger name="org.mybatis" level="info" additivity="false">
<AppenderRef ref="Console"/>
</logger>
<!--监控系统信息-->
<!--若是additivity设为false则 子Logger 只会在自己的appender里输出而不会在 父Logger 的appender里输出。-->
<Logger name="org.springframework" level="info" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<root level="info">
<appender-ref ref="Console"/>
<appender-ref ref="Filelog"/>
<appender-ref ref="RollingFileInfo"/>
<appender-ref ref="RollingFileWarn"/>
<appender-ref ref="RollingFileError"/>
</root>
</loggers>
</configuration>

View File

@ -1,35 +1,38 @@
POST http://localhost:8080/role/role #创建流调人员权限
POST http://{{host}}:{{port}}{{prefix}}/role/role
Content-Type: application/json Content-Type: application/json
{ {
"roleName": "流调人员", "roleName": "流调人员",
"authList": [ "authList": [
1, "查询调查记录的权限",
2, "提交调查记录权限",
3, "修改调查记录权限",
5, "删除调查记录权限",
6, "分析调查记录权限",
8, "查询流调人员信息的权限",
9, "增删改调查对象信息的权限",
10 "查询调查对象信息的权限"
] ]
} }
### ###
POST http://localhost:8080/role/role #创建管理员权限
POST http://{{host}}:{{port}}{{prefix}}/role/role
Content-Type: application/json Content-Type: application/json
{ {
"roleName": "管理员", "roleName": "管理员",
"authList": [ "authList": [
0 "管理员"
] ]
} }
### ###
POST http://{{host}}:8080/user/signup #注册用户
POST http://{{host}}:{{port}}{{prefix}}/user/signup
Content-Type: application/json Content-Type: application/json
{ {
@ -40,10 +43,16 @@ Content-Type: application/json
### ###
PUT http://localhost:8080/user/userRole #修改用户为管理员权限
PUT http://{{host}}:{{port}}{{prefix}}/user/userRole
Content-Type:application/json Content-Type:application/json
{ {
"phoneNumber": "123456789", "phoneNumber": "123456789",
"roleNameList": ["管理员"] "roleNameList": [
"管理员"
]
} }
###

View File

@ -2,10 +2,11 @@
#提交调查记录 #提交调查记录
POST http://localhost:8080/investigationRecord/investigationRecord POST http://localhost:8080/investigationRecord/investigationRecord
Content-Type: application/json Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"questionnaireNumber": "002", "questionnaireNumber": "001",
"idNumber": "420704200002270011", "idNumber": "420704200002270014",
"name": "Pope0", "name": "Pope0",
"gender": "男", "gender": "男",
"overseasCase": false, "overseasCase": false,
@ -65,7 +66,7 @@ Content-Type: application/json
} }
], ],
"investigationCompany": "武汉大学", "investigationCompany": "武汉大学",
"investigatorPhone": "13995833301", "userPhone": "cveo",
"investigationDate": "2021-1-28", "investigationDate": "2021-1-28",
"tempHistoryList": [ "tempHistoryList": [
{ {
@ -81,42 +82,54 @@ Content-Type: application/json
], ],
"beginTime": "2021-1-28", "beginTime": "2021-1-28",
"endTime": "2021-1-29", "endTime": "2021-1-29",
"location": "鄂州市", "location": {
"msg": "鄂州市",
"longitude": 100,
"latitude": 100
},
"detail": "详细描述" "detail": "详细描述"
} }
], ],
"msg": "备注信息" "msg": "备注信息",
"urlMap":{
"msg1": "url1",
"msg2": "url2"
}
} }
### ###
#查询调查记录 #查询调查记录
GET http://localhost:8080/investigationRecord/underReviewRecord?currentPage=0&state=待审核 GET http://localhost:8080/investigationRecord/underReviewRecord?currentPage=0&state=待审核
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
### ###
#查询未审核记录数量 #查询未审核记录数量
GET http://localhost:8080/investigationRecord/underReviewRecordCount?investigatorPhone=13995833300 GET http://localhost:8080/investigationRecord/underReviewRecordCount?userPhone=cveo
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
### ###
PUT http://localhost:8080/investigationRecord/underReviewRecord PUT http://localhost:8080/investigationRecord/underReviewRecord
Content-Type: application/json Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"idNumber": "420704200002270011", "idNumber": "420704200002270014",
"pass": true, "pass": true,
"passInformation": "经审核通过", "passInformation": "经审核通过",
"reviewerPhone": "13995833300" "reviewerPhone": "cveo"
} }
### ###
#修改记录提交
#查询
PUT http://localhost:8080/investigationRecord/investigationRecord PUT http://localhost:8080/investigationRecord/investigationRecord
Content-Type: application/json Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"questionnaireNumber": "002", "questionnaireNumber": "001",
"idNumber": "420704200002270011", "idNumber": "420704200002270014",
"name": "Pope0", "name": "Pope0",
"gender": "女", "gender": "女",
"overseasCase": false, "overseasCase": false,
@ -176,7 +189,7 @@ Content-Type: application/json
} }
], ],
"investigationCompany": "武汉大学", "investigationCompany": "武汉大学",
"investigatorPhone": "13995833301", "userPhone": "cveo",
"investigationDate": "2021-1-28", "investigationDate": "2021-1-28",
"tempHistoryList": [ "tempHistoryList": [
{ {
@ -192,9 +205,20 @@ Content-Type: application/json
], ],
"beginTime": "2021-1-28", "beginTime": "2021-1-28",
"endTime": "2021-1-29", "endTime": "2021-1-29",
"location": "鄂州市", "location": {
"msg": "鄂州市",
"longitude": 100,
"latitude": 100
},
"detail": "详细描述" "detail": "详细描述"
} }
], ],
"msg": "备注信息" "msg": "备注信息",
"urlMap":{
"msg1": "url1",
"msg2": "url2"
}
} }
###
GET http://{{host}}:{{port}}{{prefix}}/investigationRecord/record2word?idNumber=420704200002270011

View File

@ -1,13 +0,0 @@
#创建流调人员
POST http://localhost:8080/investigator/investigator
Content-Type: application/json
Authorization: fcf3f723-5a65-45ad-a518-f92e1c32b948
{
"idNumber": null,
"name": "Pope2",
"phoneNumber": "13995833302"
}
###

View File

@ -3,20 +3,26 @@
#创建调查对象 #创建调查对象
POST http://{{host}}:{{port}}{{prefix}}/respondent/respondent POST http://{{host}}:{{port}}{{prefix}}/respondent/respondent
Content-Type: application/json Content-Type: application/json
Authorization: cb94336e-f849-4e04-b956-9d8f71fe7830 Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"idNumber": "420704200002270014", "idNumber": "420704200002270014",
"phoneNumber": "13995833308", "phoneNumber": "13995833300",
"name": "Pope4", "name": "Pope0",
"msg": "无备注", "msg": "无备注",
"investigatorPhone": "123456789", "userPhone": "cveo",
"diseased": false, "diseased": false,
"gender": "男" "gender": "男",
"administrativeArea": {
"province": "湖北省",
"city": "鄂州市",
"county": "鄂城区"
}
} }
### ###
#根据流调人员id分页查询待调查对象列表 #根据流调人员id分页查询待调查对象列表
GET http://localhost:8080/respondent/respondent?investigatorPhone=13995833300&currentPage=0 GET http://localhost:8080/respondent/respondent?userPhone=cveo&province=湖北省&currentPage=0
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd

View File

@ -1,26 +1,79 @@
#添加流调人员角色
POST http://localhost:8080/role/role POST http://localhost:8080/role/role
Content-Type: application/json Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"roleName": "流调人员", "roleName": "测试角色",
"authList": [ "authList": [
1, "查询调查记录的权限",
2, "提交调查记录权限",
3, "修改调查记录权限",
5, "删除调查记录权限",
6, "分析调查记录权限",
8, "查询流调人员信息的权限",
9, "增删改调查对象信息的权限",
10 "查询调查对象信息的权限"
] ]
} }
### ###
#添加管理员角色
POST http://localhost:8080/role/role POST http://localhost:8080/role/role
Content-Type: application/json Content-Type: application/json
{ {
"roleName": "管理员", "roleName": "管理员",
"authList": [ "authList": [
0 "管理员"
] ]
} }
###
#添加测试角色
POST http://{{host}}:{{port}}{{prefix}}/role/role
Content-Type: application/json
Authorization: 958efa46-44c3-4271-b44a-cc1b7e8e8d2e
{
"roleName": "测试角色",
"authList": [
"管理员"
]
}
###
#查询角色
GET http://{{host}}:{{port}}{{prefix}}/role/role?currentPage=0
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
###
#删除角色
DELETE http://{{host}}:{{port}}{{prefix}}/role/role
Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{
"roleName": "测试角色"
}
###
#修改角色权限
PUT http://{{host}}:{{port}}{{prefix}}/role/role
Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{
"roleName": "测试角色",
"authList": [
"查询调查记录的权限"
]
}
###
GET http://{{host}}:{{port}}{{prefix}}/role/authList
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd

View File

@ -1,19 +1,23 @@
POST http://localhost:8080/user/signup #注册用户
POST http://{{host}}:{{port}}{{prefix}}/user/signup
Content-Type: application/json Content-Type: application/json
{ {
"username": "cveo", "username": "Pope0",
"phoneNumber": "123456789", "phoneNumber": "13995833300",
"password": "cveo123456" "password": "13995833308"
} }
### ###
PUT http://localhost:8080/user/userRole
#修改用户权限
PUT http://{{host}}:{{port}}{{prefix}}/user/userRole
Content-Type:application/json Content-Type:application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{ {
"phoneNumber": "123456789", "phoneNumber": "13995833308",
"roleNameList": ["管理员"] "roleNameList": ["测试角色"]
} }
### ###
@ -21,6 +25,65 @@ POST http://{{host}}:{{port}}{{prefix}}/user/login
Content-Type: application/json Content-Type: application/json
{ {
"phoneNumber": "123456789", "phoneNumber": "cveo",
"password": "cveo123456" "password": "cveo123456"
} }
###
GET http://{{host}}:{{port}}{{prefix}}/user/user?currentPage=0
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
###
DELETE http://{{host}}:{{port}}{{prefix}}/user/user
Content-Type: application/json
Authorization: 845a6d23-8d84-4a2d-85db-4f7e99c272bd
{
"phoneNumber": "13995833308"
}
###
#用户信息修改
PUT http://{{host}}:{{port}}{{prefix}}/user/userInfo
Content-Type: application/json
Authorization: 8f54a7d3-b82b-4059-ab46-ac9eae545796
{
"phoneNumber": "13995833308",
"username": "Pope",
"idNumber": "420704200002270011",
"administrativeArea": {
"province": "湖北省",
"city": "鄂州市"
}
}
###
#用户密码重置
PUT http://{{host}}:{{port}}{{prefix}}/user/pwd
Content-Type: application/json
Authorization: 8f54a7d3-b82b-4059-ab46-ac9eae545796
{
"phoneNumber": "13995833308"
}
###
#添加用户
POST http://{{host}}:{{port}}{{prefix}}/user/user
Content-Type: application/json
Authorization: 8f54a7d3-b82b-4059-ab46-ac9eae545796
{
"idNumber": "420704200002270010",
"username": "Pope0",
"phoneNumber": "139958333000",
"password": "139958333008",
"administrativeArea": {
"province": "湖北省",
"city": "鄂州市"
}
}

View File

@ -1,6 +1,6 @@
{ {
"dev": { "dev": {
"host": "120.78.177.67", "host": "127.0.0.1",
"port": "8080", "port": "8080",
"prefix": "" "prefix": ""
}, },
@ -8,5 +8,10 @@
"host": "8.136.133.77", "host": "8.136.133.77",
"port": "8081", "port": "8081",
"prefix": "/backend" "prefix": "/backend"
},
"pope": {
"host": "http://pope.cn1.utools.club",
"port": "",
"prefix": ""
} }
} }