Commit 8f1741c5 by 杨琪琪

死亡登记标注死亡

parent f72bb9ca
package com.zq.api.utils;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileTypeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.HashUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
......@@ -19,11 +25,17 @@ import com.zq.common.encrypt.EncryptUtils;
import com.zq.common.encrypt.RsaUtils;
import com.zq.common.vo.ResultVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.ognl.enhance.ContextClassLoader;
import org.springframework.stereotype.Component;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
@Component
......@@ -235,9 +247,9 @@ public class ApiUtils {
}
public static void main(String[] args) {
String appId = "d469c70c4e8b11ecaa2900163e1475c7";
String appId = "c817c558589611ecaa2900163e1475c7";
String apiNo = IdUtil.simpleUUID();
String method = "getSingleUserInfo";
String method = "getSsoUserInfo";
String timestamp = System.currentTimeMillis() + "";
String version = "1.0.0";
String bizContent = "{}";//JSON字符串
......@@ -264,14 +276,14 @@ public class ApiUtils {
for (Map.Entry<String, String> entry : signTreeMap.entrySet()) {
src.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
src.append("key=").append("ce8fcdd1ae6e42efaabe8819e3fbd8da");
src.append("key=").append("82bb8e368055403f91bd67992db17800");
params.put("sign", MD5.create().digestHex(src.toString()).toUpperCase());
HttpRequest request = HttpRequest.post("http://127.0.0.1:9888/api/action")
HttpRequest request = HttpRequest.post("http://106.52.179.107:9888/api/action")
.header("appId", appId)
.header("appSecret", "e209eb5e4e8b11ecaa2900163e1475c7")
.header("Authorization", "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJhZG1pbiIsImp0aSI6IjY4OTJlY2E2OTAwNzRjZDRhOGI0NjJlNDM5NDNhZmI1In0.AB77eTqqiBsSunVChqfAx9jB8FN58I7fph1Dw-RfYEVWvN-U2AQYYvuMlCczsiBbduL0vCNALjBzo_1jjKlAPg")
.header("appSecret", "1f6baf5b589711ecaa2900163e1475c7")
.header("Authorization", "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ0ZXN0MTIwODE1MzQiLCJhdXRoIjoiIiwianRpIjoiZjc4NmM4Nzk0OGQ1NDA3YWIzMjYyNTNmNDk3YzUzZjUifQ.-_ty93y4sIQu4Lx1lQM_819Ay8cMtYHMlKPKA6n12E9RwJIqmI1OMzU9G5ANSPYgo22jdL1r23heHElBJEEuBg")
.contentType("application/x-www-form-urlencoded")
.formStr(params);
......
......@@ -24,18 +24,13 @@ public class PageReqVo {
@ApiModelProperty("每页记录条数")
private int size = DEFAULT_SIZE;
@ApiModelProperty(value = "排序字段名", allowEmptyValue = true)
private String sort;
@ApiModelProperty(value = "排序方向", allowableValues = "asc,desc", allowEmptyValue = true)
private String dir;
public static PageReqVo of(int page, int size) {
PageReqVo pageReqVo = new PageReqVo();
pageReqVo.setPage(page);
pageReqVo.setSize(size);
return pageReqVo;
}
private int start;
private int end;
public PageReqVo() {
}
......@@ -77,4 +72,20 @@ public class PageReqVo {
public void setDir(String dir) {
this.dir = dir;
}
}
\ No newline at end of file
public int getEnd() {
return getPage() * getSize();
}
public void setEnd(int end) {
this.end = end;
}
public int getStart() {
return (getPage() - 1) * getSize();
}
public void setStart(int start) {
this.start = start;
}
}
......@@ -192,6 +192,12 @@
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
......
......@@ -3,13 +3,28 @@ package com.zq.system.modules.system.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zq.common.constant.DBName;
import com.zq.system.modules.system.domain.vo.ReportDeathVo;
import com.zq.system.modules.system.entity.ReportDeath;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@DS(DBName.OZT)
public interface ReportDeathDao extends BaseMapper<ReportDeath> {
ReportDeath selectByIdCard(String idCard);
List<ReportDeathVo> selectAllDeaths(ReportDeathVo vo);
int selectAllCount(ReportDeathVo vo);
ReportDeath selectByNameOrIdcard(ReportDeathVo vo);
int insertInTo(ReportDeath death);
List<ReportDeathVo> getDeathByName(ReportDeathVo vo);
int updateDeath(ReportDeath death);
}
......@@ -20,6 +20,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
......@@ -59,6 +60,7 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
* @param lastPasswordResetTime /
*/
@Modifying
@Transactional(rollbackFor = Exception.class)
@Query(value = "update sys_user set password = ?2 , pwd_reset_time = ?3 where username = ?1",nativeQuery = true)
void updatePass(String username, String pass, Date lastPasswordResetTime);
......@@ -128,4 +130,20 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
@Query(value = "SELECT count(1) FROM sys_user u, sys_users_roles r WHERE " +
"u.user_id = r.user_id AND r.role_id in ?1", nativeQuery = true)
int countByRoles(Set<Long> ids);
/**
* 根据电话查询
* @param phone/
* @return /
*/
@Query(value = "SELECT * FROM sys_user u WHERE u.phone= ?1", nativeQuery = true)
User findBySysname(String phone);
/**
* 根据电话查询
* @param currentUsername/
* @return /
*/
@Query(value = "SELECT * FROM sys_user u WHERE u.username= ?1", nativeQuery = true)
User findByname(String currentUsername);
}
......@@ -13,10 +13,7 @@ import com.zq.system.modules.system.service.ReportDeathService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -45,10 +42,16 @@ public class DeathRegisterController {
@ApiOperation("获取死亡列表")
@PostMapping(value = "/getDeathList")
public ResultVo<PageVo<ReportDeath>> getDeathList(@RequestBody ReportDeathVo vo) {
public ResultVo<PageVo<ReportDeathVo>> getDeathList(@RequestBody ReportDeathVo vo) {
return ResultVo.success(reportDeathService.getDeathList(vo));
}
@ApiOperation("查询死亡记录")
@PostMapping(value = "/getDeathByName")
public ResultVo getDeathByName(@RequestBody ReportDeathVo vo) {
return ResultVo.success(reportDeathService.getDeathByName(vo));
}
@ApiOperation("获取死亡人详情")
@AnonymousPostMapping(value = "/getDeathDetail")
public ResultVo getDeathDetail(@RequestBody ReportDeathVo vo) {
......@@ -61,5 +64,11 @@ public class DeathRegisterController {
return ResultVo.success(reportDeathService.updateDeath(vo));
}
@ApiOperation("是否能进入死亡登记系统")
@GetMapping(value = "/inSysDeath")
public ResultVo inSysDeath() {
return ResultVo.success(reportDeathService.inSysDeath());
}
}
package com.zq.system.modules.system.rest;
import cn.hutool.core.lang.tree.TreeUtil;
import com.zq.common.annotation.rest.AnonymousGetMapping;
import com.zq.common.annotation.rest.AnonymousPostMapping;
import com.zq.common.config.redis.RedisUtils;
......
......@@ -180,6 +180,17 @@ public class UserController {
return ResultVo.success();
}
@ApiOperation("重置sys登录密码")
@PostMapping(value = "/resetPassw")
@AnonymousAccess
public ResultVo resetPassw(@RequestBody LoginVo vo) {
AssertUtils.hasText(vo.getPhone(), "手机号不能为空");
AssertUtils.isTrue(ValidateUtil.isMobilePhoneNo(vo.getPhone()), "手机号格式不正确");
AssertUtils.hasText(vo.getVerifyCode(), "请输入验证码");
userService.resetPassword2(vo);
return ResultVo.success();
}
@ApiOperation("修改头像")
@PostMapping(value = "/updateAvatar")
public ResponseEntity<Object> updateAvatar(@RequestParam MultipartFile avatar) {
......
......@@ -12,9 +12,13 @@ public interface ReportDeathService {
Object importDeath(MultipartFile file);
PageVo<ReportDeath> getDeathList(ReportDeathVo vo);
PageVo<ReportDeathVo> getDeathList(ReportDeathVo vo);
Object getDeathDetail(ReportDeathVo vo);
ResultVo updateDeath(ReportDeathVo vo);
ResultVo inSysDeath();
ResultVo getDeathByName(ReportDeathVo vo);
}
......@@ -24,6 +24,7 @@ import com.zq.system.modules.system.dao.SysInfoDao;
import com.zq.system.modules.system.domain.Job;
import com.zq.system.modules.system.domain.Role;
import com.zq.system.modules.system.domain.User;
import com.zq.system.modules.system.domain.vo.ReportDeathVo;
import com.zq.system.modules.system.domain.vo.SsoLoginVo;
import com.zq.system.modules.system.domain.vo.SsoRegisterVo;
import com.zq.system.modules.system.entity.AreaCode;
......@@ -246,12 +247,14 @@ public class SsoService {
SysInfo sysInfo = sysInfoDao.selectOne(Wrappers.lambdaQuery(SysInfo.builder().appId(appId).build()));
BindUserInfo bindUserInfo = blindUserInfoDao.selectOne(Wrappers.lambdaQuery(BindUserInfo.builder().sysId(sysInfo.getId()).userId(adminContext.getUserId()).build()));
AssertUtils.notNull(bindUserInfo, 501, "用户未绑定该系统");
Map<String, Object> data = new HashMap<>();
List<BindUserInfo> bindUserInfos = blindUserInfoDao.selectList(Wrappers.lambdaQuery(BindUserInfo.builder().sysId(sysInfo.getId()).userId(adminContext.getUserId()).build()));
AssertUtils.notNull(bindUserInfos.size()==0, 501, "用户未绑定该系统");
for (BindUserInfo bindUserInfo:bindUserInfos) {
data.put("userId", bindUserInfo.getSystemUserId());
data.put("username", bindUserInfo.getSystemUserName());
}
return data;
}
......
......@@ -165,4 +165,6 @@ public interface UserService {
* @return
*/
ApiTokenVo passwdLogin(LoginVo vo);
void resetPassword2(LoginVo vo);
}
......@@ -5,12 +5,8 @@ import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.exception.BusinessException;
import com.zq.common.utils.AssertUtils;
import com.zq.common.utils.PagingUtils;
import com.zq.common.vo.PageVo;
import com.zq.common.vo.ResultVo;
import com.zq.system.modules.system.dao.CremationInfoSumDao;
......@@ -25,7 +21,6 @@ import com.zq.system.modules.system.service.ReportDeathService;
import com.zq.system.modules.system.service.SsoService;
import com.zq.system.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
......@@ -45,13 +40,12 @@ public class ReportDeathImpl implements ReportDeathService {
private final HdptRstSwmdDao hdptRstSwmdDao;
@Override
public ResultVo save(ReportDeathVo vo) {
ReportDeath Death=reportDeathDao.selectByIdCard(vo.getIdCard());
if (Death!=null){
ReportDeath Death = reportDeathDao.selectByIdCard(vo.getIdCard());
if (Death != null) {
return ResultVo.fail("该死者已重复上报");
}else {
} else {
ReportDeath reportDeath = new ReportDeath();
reportDeath.setName(vo.getName());
reportDeath.setIdCard(vo.getIdCard());
......@@ -92,75 +86,107 @@ public class ReportDeathImpl implements ReportDeathService {
reportDeath.setUserArea(user.getUserArea());
reportDeath.setDeathType("1");
ReportDeath reportDeaths = reportDeathDao.selectOne(Wrappers.lambdaQuery(ReportDeath.builder().idCard(Convert.toStr(CollUtil.get(objectList, 2))).build()));
if (reportDeaths!=null){
return "已上报过该死者"+reportDeaths.getName()+"信息";
}else {
reportDeathDao.insert(reportDeath);
}
if (reportDeaths != null) {
return "已上报过该死者" + reportDeaths.getName() + "信息";
} else {
reportDeathDao.insert(reportDeath);
}
}
return null;
}
@Override
public PageVo<ReportDeath> getDeathList(ReportDeathVo vo) {
LambdaQueryWrapper<ReportDeath> lambdaQuery = Wrappers.lambdaQuery(ReportDeath.builder().build());
if (StringUtils.isNotBlank(vo.getIdCard())){
lambdaQuery.like(ReportDeath::getIdCard,vo.getIdCard());
}
if (StringUtils.isNotBlank(vo.getName())){
lambdaQuery.like(ReportDeath::getName,vo.getName());
}
if (StringUtils.isNotBlank(vo.getDeathType())) {
lambdaQuery.like(ReportDeath::getDeathType,vo.getDeathType());
public PageVo<ReportDeathVo> getDeathList(ReportDeathVo vo) {
List<ReportDeathVo> list = reportDeathDao.selectAllDeaths(vo);
int i = reportDeathDao.selectAllCount(vo);
PageVo<ReportDeathVo> p = new PageVo<ReportDeathVo>();
if (vo.getPage() - 1 == 0) {
vo.setStart(0);
vo.setEnd(vo.getPage() * vo.getSize());
} else {
vo.setStart((vo.getPage() - 1) * vo.getSize());
vo.setEnd(vo.getPage() * vo.getSize());
}
PageVo<ReportDeath> paging = PagingUtils.paging(vo, reportDeathDao, lambdaQuery);
return paging;
p.setRows(list);
p.setStart(vo.getPage());
p.setSize(vo.getSize());
p.setTotal(i);
return p;
}
@Override
public Object getDeathDetail(ReportDeathVo vo) {
HashMap<String, Object> map = new HashMap<>();
CremationInfoSum cremationInfoSum = cremationInfoSumDao.selectByNameOrIdcard(vo);
EnbuzMemberStop enbuzMemberStop = enbuzMemberStopDao.selectByNameOrIdcard(vo);
HdptRstSwmd hdptRstSwmd = hdptRstSwmdDao.selectByNameOrIdcard(vo);
if (cremationInfoSum==null && enbuzMemberStop==null && hdptRstSwmd==null){
return "未查到该死者信息";
}else{
map.put("此数据来源殡葬火化库",cremationInfoSum);
map.put("此数据来源死亡上报小程序(低保)",enbuzMemberStop);
map.put("此数据来源共享平台死亡记录数",hdptRstSwmd);
switch (vo.getSource()) {
case "1":
EnbuzMemberStop enbuzMemberStop = enbuzMemberStopDao.selectByNameOrIdcard(vo);
map.put("enbuzMemberStop", enbuzMemberStop);
break;
case "2":
CremationInfoSum cremationInfoSum = cremationInfoSumDao.selectByNameOrIdcard(vo);
map.put("cremationInfoSum", cremationInfoSum);
break;
case "3":
HdptRstSwmd hdptRstSwmd = hdptRstSwmdDao.selectByNameOrIdcard(vo);
map.put("hdptRstSwmd", hdptRstSwmd);
break;
case "4":
ReportDeath death = reportDeathDao.selectByNameOrIdcard(vo);
map.put("death", death);
default:
map.put("list", "无此人具体数据");
}
return map;
}
@Override
public ResultVo updateDeath(ReportDeathVo vo) {
ReportDeath reportDeath1 = reportDeathDao.selectByIdCard(vo.getIdCard());
ReportDeath death = new ReportDeath();
int i = 0;
User user = userRepository.findByname(SecurityUtils.getCurrentUsername());
death.setName(vo.getName().trim());
death.setIdCard(vo.getIdCard());
death.setDeathPlace(vo.getDeathPlace());
death.setDeathReason(vo.getDeathReason());
death.setDeathDate(vo.getDeathDate());
death.setDeathType(vo.getDeathType());
death.setNotes(vo.getNotes());
death.setSource(vo.getSource());
death.setUserArea(user.getUserArea());
death.setUserName(user.getUsername());
death.setUpdateTime(DateUtil.date());
if (reportDeath1 == null) {
i = reportDeathDao.insertInTo(death);
} else {
i = reportDeathDao.updateDeath(death);
}
return ResultVo.success(i > 0 ? "标注成功" : "标注失败");
}
@Override
public ResultVo inSysDeath() {
List<BindUserInfo> bindSysList = ssoService.getBindSysList();
for (BindUserInfo bindUser:bindSysList) {
if (bindUser.getSysId()==3||bindUser.getSysId()==9||bindUser.getSysId()==4) {
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
ReportDeath reportDeath = reportDeathDao.selectById(vo.getId());
AssertUtils.notNull(reportDeath, "无此条记录");
ReportDeath death = new ReportDeath();
death.setId(vo.getId());
death.setName(vo.getName());
death.setIdCard(vo.getIdCard());
death.setDeathPlace(vo.getDeathPlace());
death.setDeathReason(vo.getDeathReason());
death.setDeathDate(vo.getDeathDate());
death.setDeathType(vo.getDeathType());
death.setNotes(vo.getNotes());
death.setSource(vo.getSource());
death.setUserArea(user.getUserArea());
death.setUserName(reportDeath.getUserName());
death.setUpdateTime(DateUtil.date());
reportDeathDao.updateById(death);
return ResultVo.success("标注成功");
}else{
return ResultVo.fail("无权限修改");
String sysId = null;
for (BindUserInfo bindUser : bindSysList) {
sysId = bindUser.getSysId().toString();
if (sysId.equals("3") || sysId.equals("9") || sysId.equals("4")) {
return ResultVo.success();
}
}
return ResultVo.success();
return ResultVo.fail("抱歉您目前无权限进入此系统");
}
@Override
public ResultVo getDeathByName(ReportDeathVo vo) {
List<ReportDeathVo> list = reportDeathDao.getDeathByName(vo);
if (list.size() == 0) {
return ResultVo.fail("抱歉查无此人信息!");
} else {
return ResultVo.success(list);
}
}
}
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zq.system.modules.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.config.redis.RedisUtils;
import com.zq.common.config.security.ApiTokenUtils;
import com.zq.common.constant.SystemName;
import com.zq.common.utils.AssertUtils;
import com.zq.common.utils.StringUtils;
import com.zq.common.utils.UploadUtils;
import com.zq.common.vo.ApiTokenVo;
import com.zq.system.config.CacheKeys;
import com.zq.system.config.FileProperties;
import com.zq.system.exception.EntityExistException;
import com.zq.system.exception.EntityNotFoundException;
import com.zq.system.modules.system.dao.PfuserDao;
import com.zq.system.modules.system.domain.Job;
import com.zq.system.modules.system.domain.Role;
import com.zq.system.modules.system.domain.User;
import com.zq.system.modules.system.domain.vo.LoginVo;
import com.zq.system.modules.system.entity.Pfuser;
import com.zq.system.modules.system.repository.DeptRepository;
import com.zq.system.modules.system.repository.JobRepository;
import com.zq.system.modules.system.repository.RoleRepository;
import com.zq.system.modules.system.repository.UserRepository;
import com.zq.system.modules.system.service.OnlineUserService;
import com.zq.system.modules.system.service.UserCacheClean;
import com.zq.system.modules.system.service.UserService;
import com.zq.system.modules.system.service.dto.JobSmallDto;
import com.zq.system.modules.system.service.dto.RoleSmallDto;
import com.zq.system.modules.system.service.dto.UserDto;
import com.zq.system.modules.system.service.dto.UserQueryCriteria;
import com.zq.system.modules.system.service.mapstruct.UserMapper;
import com.zq.system.utils.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
* @date 2018-11-23
*/
@Slf4j
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "user")
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final UserMapper userMapper;
private final FileProperties properties;
private final RedisUtils redisUtils;
private final UserCacheClean userCacheClean;
private final OnlineUserService onlineUserService;
private final PfuserDao pfuserDao;
private final PasswordEncoder passwordEncoder;
private final DeptRepository deptRepository;
private final RoleRepository roleRepository;
private final JobRepository jobRepository;
@Override
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
Page<User> page = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(userMapper::toDto));
}
@Override
public List<UserDto> queryAll(UserQueryCriteria criteria) {
List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
return userMapper.toDto(users);
}
@Override
@Cacheable(key = "'id:' + #p0")
@Transactional(rollbackFor = Exception.class)
public UserDto findById(long id) {
User user = userRepository.findById(id).orElseGet(User::new);
ValidationUtil.isNull(user.getId(), "User", "id", id);
return userMapper.toDto(user);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(User resources) {
if (userRepository.findByUsername(resources.getUsername()) != null) {
throw new EntityExistException(User.class, "username", resources.getUsername());
}
if (StringUtils.isNotBlank(resources.getEmail()) && userRepository.findByEmail(resources.getEmail()) != null) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
if (userRepository.findByPhone(resources.getPhone()) != null) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
userRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(User resources) throws Exception {
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
User user1 = userRepository.findByUsername(resources.getUsername());
User user2 = userRepository.findByEmail(resources.getEmail());
User user3 = userRepository.findByPhone(resources.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "username", resources.getUsername());
}
if (user2 != null && !user.getId().equals(user2.getId())) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
if (user3 != null && !user.getId().equals(user3.getId())) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
// 如果用户的角色改变
if (!resources.getRoles().equals(user.getRoles())) {
redisUtils.del(CacheKey.DATA_USER + resources.getId());
redisUtils.del(CacheKey.MENU_USER + resources.getId());
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
}
// 如果用户被禁用,则清除用户登录信息
if (!resources.getEnabled()) {
onlineUserService.kickOutForUsername(resources.getUsername());
}
user.setUsername(resources.getUsername());
user.setEmail(resources.getEmail());
user.setEnabled(resources.getEnabled());
user.setRoles(resources.getRoles());
user.setDept(resources.getDept());
user.setJobs(resources.getJobs());
user.setPhone(resources.getPhone());
user.setNickName(resources.getNickName());
user.setGender(resources.getGender());
userRepository.save(user);
// 清除缓存
delCaches(user.getId(), user.getUsername());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCenter(User resources) {
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
User user1 = userRepository.findByPhone(resources.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
user.setNickName(resources.getNickName());
user.setPhone(resources.getPhone());
user.setGender(resources.getGender());
userRepository.save(user);
// 清理缓存
delCaches(user.getId(), user.getUsername());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
for (Long id : ids) {
// 清理缓存
UserDto user = findById(id);
delCaches(user.getId(), user.getUsername());
}
userRepository.deleteAllByIdIn(ids);
}
@Override
public UserDto findByName(String userName) {
User user = userRepository.findByUsername(userName);
if (user == null) {
throw new EntityNotFoundException(User.class, "name", userName);
} else {
return userMapper.toDto(user);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePass(String username, String pass) {
userRepository.updatePass(username, pass, new Date());
flushCache(username);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
String oldPath = user.getAvatarPath();
String imaUrl = UploadUtils.saveImg(multipartFile, SystemName.SYS);
user.setAvatarPath(imaUrl);
user.setAvatarName(imaUrl);
userRepository.save(user);
if (StringUtils.isNotBlank(oldPath)) {
FileUtil.del(oldPath);
}
@NotBlank String username = user.getUsername();
flushCache(username);
return new HashMap<String, String>(1) {{
put("avatar", imaUrl);
}};
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEmail(String username, String email) {
userRepository.updateEmail(username, email);
flushCache(username);
}
@Override
public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (UserDto userDTO : queryAll) {
List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList());
Map<String, Object> map = new LinkedHashMap<>();
map.put("用户名", userDTO.getUsername());
map.put("角色", roles);
map.put("部门", userDTO.getDept().getName());
map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList()));
map.put("邮箱", userDTO.getEmail());
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
map.put("手机号码", userDTO.getPhone());
map.put("修改密码的时间", userDTO.getPwdResetTime());
map.put("创建日期", userDTO.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
/**
* 清理缓存
*
* @param id /
*/
public void delCaches(Long id, String username) {
redisUtils.del(CacheKey.USER_ID + id);
flushCache(username);
}
/**
* 清理 登陆时 用户缓存信息
*
* @param username /
*/
private void flushCache(String username) {
userCacheClean.cleanUserCache(username);
}
@Override
public void sendCode(String phone) {
User user = userRepository.findByUsername(phone);
if (user == null) {
Pfuser pfuser = pfuserDao.selectOne(Wrappers.lambdaQuery(Pfuser.builder().phone(phone).build()));
AssertUtils.notNull(pfuser, "手机号不存在");
}
String code = RandomUtil.randomNumbers(6);
String content = "您的验证码为:" + code + "(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。";
boolean sendMsg = MobileSmsUtils.sendMsg(phone, content);
log.info(">> phone: {}, sendCode: {}, success: {}", phone, code, sendMsg);
redisUtils.setStr(CacheKeys.authCodeKey(phone), code, 5);
}
@Override
public void resetPassword(LoginVo vo) {
verificationCode(vo.getPhone(), vo.getVerifyCode());
User user = userRepository.findByUsername(vo.getPhone());
if (user == null) {
user = addUser(vo.getPhone());
}
AssertUtils.notNull(user, "手机号不存在");
updatePass(user.getUsername(), passwordEncoder.encode(vo.getPasswd()));
}
/**
* 保存用户
*
* @param phone
* @return
*/
private User addUser(String phone) {
Pfuser pfuser = pfuserDao.selectOne(Wrappers.lambdaQuery(Pfuser.builder().phone(phone).build()));
if (pfuser == null) {
return null;
}
User user = userRepository.findByUsername(phone);
if (user == null) {
user = new User();
List<Role> roleList = roleRepository.findAllById(Collections.singletonList(2L));
user.setRoles(new HashSet<>(roleList));
List<Job> jobList = jobRepository.findAllById(Collections.singletonList(13L));
user.setJobs(new HashSet<>(jobList));
deptRepository.findById(8L).ifPresent(user::setDept);
user.setUsername(phone);
user.setNickName(pfuser.getUsername());
user.setGender(pfuser.getSex() == null ? "未知" : pfuser.getSex() == 0 ? "男" : "女");
user.setPhone(phone);
user.setEmail(pfuser.getSourcemail());
user.setPassword(passwordEncoder.encode("gxmz!23"));
user.setIsAdmin(false);
user.setEnabled(true);
user.setCreateBy("admin");
user.setUpdatedBy("admin");
user.setCreateTime(DateUtil.date().toTimestamp());
user.setUpdateTime(DateUtil.date().toTimestamp());
create(user);
}
return user;
}
/**
* 判断验证码
*
* @param phone
* @param code
*/
public void verificationCode(String phone, String code) {
String cacheCode = redisUtils.getStr(CacheKeys.authCodeKey(phone));
AssertUtils.isTrue(org.apache.commons.lang3.StringUtils.isNotBlank(cacheCode) && cacheCode.equalsIgnoreCase(code), "验证码错误");
redisUtils.deleteStr(CacheKeys.authCodeKey(phone));
}
@Override
public void modifyPasswd(LoginVo vo) {
verificationCode(vo.getPhone(), vo.getVerifyCode());
User user = userRepository.findByUsername(vo.getPhone());
AssertUtils.notNull(user, "手机号不存在");
updatePass(user.getUsername(), passwordEncoder.encode(vo.getPasswd()));
}
@Override
public ApiTokenVo phoneLogin(LoginVo vo) {
User user = userRepository.findByUsername(vo.getPhone());
if (user == null) {
user = addUser(vo.getPhone());
}
AssertUtils.notNull(user, "手机号不存在");
verificationCode(vo.getPhone(), vo.getVerifyCode());
AssertUtils.isTrue(user.getEnabled(), "账号已禁用");
return getApiToken(user);
}
/**
* 获取ApiToken
*
* @param user
* @return
*/
private ApiTokenVo getApiToken(User user) {
ApiTokenVo tokenVo = ApiTokenVo.builder()
.userId(user.getId())
.phone(user.getPhone())
.username(user.getUsername())
.name(user.getNickName())
.nickname(user.getNickName())
.sex(user.getGender())
.avatar(user.getAvatarPath())
.build();
String token = ApiTokenUtils.createToken(tokenVo, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
tokenVo.setToken(token);
// 重新登录删除前一个token实现单机登录
String cacheToken = redisUtils.getStr(CacheKeys.liveAppTokenKey(user.getId().toString()));
redisUtils.deleteObj(CacheKeys.appTokenKey(cacheToken));
redisUtils.deleteStr(CacheKeys.liveAppTokenKey(user.getId().toString()));
// 缓存登录用户
redisUtils.setObj(CacheKeys.appTokenKey(token), tokenVo, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
// 用户ID作为key保存token, 再次登录可以找出该用户的token
redisUtils.setStr(CacheKeys.liveAppTokenKey(user.getId().toString()), token, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
return tokenVo;
}
@Override
public ApiTokenVo passwdLogin(LoginVo vo) {
User user = userRepository.findByUsername(vo.getPhone());
AssertUtils.notNull(user, "手机号不存在");
AssertUtils.hasText(user.getPassword(), "未设置密码");
AssertUtils.isTrue(passwordEncoder.matches(vo.getPasswd(), user.getPassword()), "密码错误");
AssertUtils.isTrue(user.getEnabled(), "账号已禁用");
return getApiToken(user);
}
}
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zq.system.modules.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zq.common.config.redis.RedisUtils;
import com.zq.common.config.security.ApiTokenUtils;
import com.zq.common.constant.SystemName;
import com.zq.common.utils.AssertUtils;
import com.zq.common.utils.StringUtils;
import com.zq.common.utils.UploadUtils;
import com.zq.common.vo.ApiTokenVo;
import com.zq.system.config.CacheKeys;
import com.zq.system.config.FileProperties;
import com.zq.system.exception.EntityExistException;
import com.zq.system.exception.EntityNotFoundException;
import com.zq.system.modules.system.dao.PfuserDao;
import com.zq.system.modules.system.domain.Job;
import com.zq.system.modules.system.domain.Role;
import com.zq.system.modules.system.domain.User;
import com.zq.system.modules.system.domain.vo.LoginVo;
import com.zq.system.modules.system.entity.Pfuser;
import com.zq.system.modules.system.repository.DeptRepository;
import com.zq.system.modules.system.repository.JobRepository;
import com.zq.system.modules.system.repository.RoleRepository;
import com.zq.system.modules.system.repository.UserRepository;
import com.zq.system.modules.system.service.OnlineUserService;
import com.zq.system.modules.system.service.UserCacheClean;
import com.zq.system.modules.system.service.UserService;
import com.zq.system.modules.system.service.dto.JobSmallDto;
import com.zq.system.modules.system.service.dto.RoleSmallDto;
import com.zq.system.modules.system.service.dto.UserDto;
import com.zq.system.modules.system.service.dto.UserQueryCriteria;
import com.zq.system.modules.system.service.mapstruct.UserMapper;
import com.zq.system.utils.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Zheng Jie
* @date 2018-11-23
*/
@Slf4j
@Service
@RequiredArgsConstructor
@CacheConfig(cacheNames = "user")
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final UserMapper userMapper;
private final FileProperties properties;
private final RedisUtils redisUtils;
private final UserCacheClean userCacheClean;
private final OnlineUserService onlineUserService;
private final PfuserDao pfuserDao;
private final PasswordEncoder passwordEncoder;
private final DeptRepository deptRepository;
private final RoleRepository roleRepository;
private final JobRepository jobRepository;
@Override
public Object queryAll(UserQueryCriteria criteria, Pageable pageable) {
Page<User> page = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(userMapper::toDto));
}
@Override
public List<UserDto> queryAll(UserQueryCriteria criteria) {
List<User> users = userRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder));
return userMapper.toDto(users);
}
@Override
@Cacheable(key = "'id:' + #p0")
@Transactional(rollbackFor = Exception.class)
public UserDto findById(long id) {
User user = userRepository.findById(id).orElseGet(User::new);
ValidationUtil.isNull(user.getId(), "User", "id", id);
return userMapper.toDto(user);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(User resources) {
if (userRepository.findByUsername(resources.getUsername()) != null) {
throw new EntityExistException(User.class, "username", resources.getUsername());
}
if (StringUtils.isNotBlank(resources.getEmail()) && userRepository.findByEmail(resources.getEmail()) != null) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
if (userRepository.findByPhone(resources.getPhone()) != null) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
userRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(User resources) throws Exception {
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
ValidationUtil.isNull(user.getId(), "User", "id", resources.getId());
User user1 = userRepository.findByUsername(resources.getUsername());
User user2 = userRepository.findByEmail(resources.getEmail());
User user3 = userRepository.findByPhone(resources.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "username", resources.getUsername());
}
if (user2 != null && !user.getId().equals(user2.getId())) {
throw new EntityExistException(User.class, "email", resources.getEmail());
}
if (user3 != null && !user.getId().equals(user3.getId())) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
// 如果用户的角色改变
if (!resources.getRoles().equals(user.getRoles())) {
redisUtils.del(CacheKey.DATA_USER + resources.getId());
redisUtils.del(CacheKey.MENU_USER + resources.getId());
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
}
// 如果用户被禁用,则清除用户登录信息
if (!resources.getEnabled()) {
onlineUserService.kickOutForUsername(resources.getUsername());
}
user.setUsername(resources.getUsername());
user.setEmail(resources.getEmail());
user.setEnabled(resources.getEnabled());
user.setRoles(resources.getRoles());
user.setDept(resources.getDept());
user.setJobs(resources.getJobs());
user.setPhone(resources.getPhone());
user.setNickName(resources.getNickName());
user.setGender(resources.getGender());
userRepository.save(user);
// 清除缓存
delCaches(user.getId(), user.getUsername());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCenter(User resources) {
User user = userRepository.findById(resources.getId()).orElseGet(User::new);
User user1 = userRepository.findByPhone(resources.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "phone", resources.getPhone());
}
user.setNickName(resources.getNickName());
user.setPhone(resources.getPhone());
user.setGender(resources.getGender());
userRepository.save(user);
// 清理缓存
delCaches(user.getId(), user.getUsername());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Set<Long> ids) {
for (Long id : ids) {
// 清理缓存
UserDto user = findById(id);
delCaches(user.getId(), user.getUsername());
}
userRepository.deleteAllByIdIn(ids);
}
@Override
public UserDto findByName(String userName) {
User user = userRepository.findByUsername(userName);
if (user == null) {
throw new EntityNotFoundException(User.class, "name", userName);
} else {
return userMapper.toDto(user);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePass(String username, String pass) {
userRepository.updatePass(username, pass, new Date());
flushCache(username);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> updateAvatar(MultipartFile multipartFile) {
User user = userRepository.findByUsername(SecurityUtils.getCurrentUsername());
String oldPath = user.getAvatarPath();
String imaUrl = UploadUtils.saveImg(multipartFile, SystemName.SYS);
user.setAvatarPath(imaUrl);
user.setAvatarName(imaUrl);
userRepository.save(user);
if (StringUtils.isNotBlank(oldPath)) {
FileUtil.del(oldPath);
}
@NotBlank String username = user.getUsername();
flushCache(username);
return new HashMap<String, String>(1) {{
put("avatar", imaUrl);
}};
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateEmail(String username, String email) {
userRepository.updateEmail(username, email);
flushCache(username);
}
@Override
public void download(List<UserDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (UserDto userDTO : queryAll) {
List<String> roles = userDTO.getRoles().stream().map(RoleSmallDto::getName).collect(Collectors.toList());
Map<String, Object> map = new LinkedHashMap<>();
map.put("用户名", userDTO.getUsername());
map.put("角色", roles);
map.put("部门", userDTO.getDept().getName());
map.put("岗位", userDTO.getJobs().stream().map(JobSmallDto::getName).collect(Collectors.toList()));
map.put("邮箱", userDTO.getEmail());
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
map.put("手机号码", userDTO.getPhone());
map.put("修改密码的时间", userDTO.getPwdResetTime());
map.put("创建日期", userDTO.getCreateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
/**
* 清理缓存
*
* @param id /
*/
public void delCaches(Long id, String username) {
redisUtils.del(CacheKey.USER_ID + id);
flushCache(username);
}
/**
* 清理 登陆时 用户缓存信息
*
* @param username /
*/
private void flushCache(String username) {
userCacheClean.cleanUserCache(username);
}
@Override
public void sendCode(String phone) {
User user = userRepository.findByUsername(phone);
if (user == null) {
Pfuser pfuser = pfuserDao.selectOne(Wrappers.lambdaQuery(Pfuser.builder().phone(phone).build()));
AssertUtils.notNull(pfuser, "手机号不存在");
}
String code = RandomUtil.randomNumbers(6);
String content = "您的验证码为:" + code + "(5分钟内有效)。为了保障信息安全,如非本人操作请忽略本短信。";
boolean sendMsg = MobileSmsUtils.sendMsg(phone, content);
log.info(">> phone: {}, sendCode: {}, success: {}", phone, code, sendMsg);
redisUtils.setStr(CacheKeys.authCodeKey(phone), code, 5);
}
@Override
public void resetPassword(LoginVo vo) {
verificationCode(vo.getPhone(), vo.getVerifyCode());
User user = userRepository.findByUsername(vo.getPhone());
if (user == null) {
user = addUser(vo.getPhone());
}
AssertUtils.notNull(user, "手机号不存在");
updatePass(user.getUsername(), passwordEncoder.encode(vo.getPasswd()));
}
/**
* 保存用户
*
* @param phone
* @return
*/
private User addUser(String phone) {
Pfuser pfuser = pfuserDao.selectOne(Wrappers.lambdaQuery(Pfuser.builder().phone(phone).build()));
if (pfuser == null) {
return null;
}
User user = userRepository.findByUsername(phone);
if (user == null) {
user = new User();
List<Role> roleList = roleRepository.findAllById(Collections.singletonList(2L));
user.setRoles(new HashSet<>(roleList));
List<Job> jobList = jobRepository.findAllById(Collections.singletonList(13L));
user.setJobs(new HashSet<>(jobList));
deptRepository.findById(8L).ifPresent(user::setDept);
user.setUsername(phone);
user.setNickName(pfuser.getUsername());
user.setGender(pfuser.getSex() == null ? "未知" : pfuser.getSex() == 0 ? "男" : "女");
user.setPhone(phone);
user.setEmail(pfuser.getSourcemail());
user.setPassword(passwordEncoder.encode("gxmz!23"));
user.setIsAdmin(false);
user.setEnabled(true);
user.setCreateBy("admin");
user.setUpdatedBy("admin");
user.setCreateTime(DateUtil.date().toTimestamp());
user.setUpdateTime(DateUtil.date().toTimestamp());
create(user);
}
return user;
}
/**
* 判断验证码
*
* @param phone
* @param code
*/
public void verificationCode(String phone, String code) {
String cacheCode = redisUtils.getStr(CacheKeys.authCodeKey(phone));
AssertUtils.isTrue(org.apache.commons.lang3.StringUtils.isNotBlank(cacheCode) && cacheCode.equalsIgnoreCase(code), "验证码错误");
redisUtils.deleteStr(CacheKeys.authCodeKey(phone));
}
@Override
public void modifyPasswd(LoginVo vo) {
verificationCode(vo.getPhone(), vo.getVerifyCode());
User user = userRepository.findByUsername(vo.getPhone());
AssertUtils.notNull(user, "手机号不存在");
updatePass(user.getUsername(), passwordEncoder.encode(vo.getPasswd()));
}
@Override
public ApiTokenVo phoneLogin(LoginVo vo) {
User user = userRepository.findByUsername(vo.getPhone());
if (user == null) {
user = addUser(vo.getPhone());
}
AssertUtils.notNull(user, "手机号不存在");
verificationCode(vo.getPhone(), vo.getVerifyCode());
AssertUtils.isTrue(user.getEnabled(), "账号已禁用");
return getApiToken(user);
}
/**
* 获取ApiToken
*
* @param user
* @return
*/
private ApiTokenVo getApiToken(User user) {
ApiTokenVo tokenVo = ApiTokenVo.builder()
.userId(user.getId())
.phone(user.getPhone())
.username(user.getUsername())
.name(user.getNickName())
.nickname(user.getNickName())
.sex(user.getGender())
.avatar(user.getAvatarPath())
.build();
String token = ApiTokenUtils.createToken(tokenVo, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
tokenVo.setToken(token);
// 重新登录删除前一个token实现单机登录
String cacheToken = redisUtils.getStr(CacheKeys.liveAppTokenKey(user.getId().toString()));
redisUtils.deleteObj(CacheKeys.appTokenKey(cacheToken));
redisUtils.deleteStr(CacheKeys.liveAppTokenKey(user.getId().toString()));
// 缓存登录用户
redisUtils.setObj(CacheKeys.appTokenKey(token), tokenVo, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
// 用户ID作为key保存token, 再次登录可以找出该用户的token
redisUtils.setStr(CacheKeys.liveAppTokenKey(user.getId().toString()), token, CacheKeys.APP_TOKEN_EXPIRE_MINUTES);
return tokenVo;
}
@Override
public ApiTokenVo passwdLogin(LoginVo vo) {
User user = userRepository.findByUsername(vo.getPhone());
AssertUtils.notNull(user, "手机号不存在");
AssertUtils.hasText(user.getPassword(), "未设置密码");
AssertUtils.isTrue(passwordEncoder.matches(vo.getPasswd(), user.getPassword()), "密码错误");
AssertUtils.isTrue(user.getEnabled(), "账号已禁用");
return getApiToken(user);
}
@Override
public void resetPassword2(LoginVo vo) {
verificationCode(vo.getPhone(), vo.getVerifyCode());
User user =userRepository.findBySysname(vo.getPhone());
AssertUtils.notNull(user, "手机号不存在");
updatePass(user.getUsername(), passwordEncoder.encode(vo.getPasswd()));
}
}
......@@ -12,6 +12,6 @@
</resultMap>
<select id="selectByNameOrIdcard" resultMap="BaseResultMap">
select * from GX_BZ.FIS_CREMATION_INFO_SUM t
where t.ID_CARD=#{idCard} and t.NAME=#{name}
where t.ID_CARD=#{idCard} OR t.NAME=#{name}
</select>
</mapper>
\ No newline at end of file
</mapper>
......@@ -14,4 +14,4 @@
select t.MEMBER_NAME as name,t.IDENTIFCARD_ID as idCard,t.* from GX_BZ.ENBUZ_MEMBER_STOP t
where t.IDENTIFCARD_ID=#{idCard} and t.MEMBER_NAME=#{name}
</select>
</mapper>
\ No newline at end of file
</mapper>
......@@ -15,6 +15,6 @@
FROM
GX_BZ.HDPT_RST_SWMD
WHERE
ID = ( SELECT MAX( ID ) FROM GX_BZ.HDPT_RST_SWMD t WHERE t.ID_CARD = #{idCard} AND t.NAME = #{name} )
ID = ( SELECT MAX( ID ) FROM GX_BZ.HDPT_RST_SWMD t WHERE t.ID_CARD = #{idCard} OR t.NAME = #{name} )
</select>
</mapper>
\ No newline at end of file
</mapper>
......@@ -17,28 +17,90 @@
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<insert id="insertInTo">
INSERT INTO GX_BZ.REPORT_DEATHS (NAME, ID_CARD, DEATH_REASON,DEATH_PLACE,DEATH_DATE, SOURCE,USER_AREA, USER_NAME, DEATH_TYPE, update_time)
VALUES (#{name,jdbcType=VARCHAR}, #{idCard,jdbcType=VARCHAR},#{deathReason,jdbcType=VARCHAR}, #{deathPlace,jdbcType=VARCHAR},#{deathDate,jdbcType=VARCHAR},#{source,jdbcType=VARCHAR},#{userArea,jdbcType=VARCHAR},#{userName,jdbcType=VARCHAR},#{deathType,jdbcType=VARCHAR},#{updateTime,jdbcType=TIMESTAMP})
</insert>
<update id="updateDeath">
UPDATE GX_BZ.REPORT_DEATHS SET DEATH_TYPE=#{deathType} WHERE ID_CARD=#{idCard}
</update>
<select id="selectByIdCard" resultMap="BaseResultMap">
select * from GX_BZ.REPORT_DEATHS t where t.ID_CARD=#{idCard}
select *
from GX_BZ.REPORT_DEATHS t
where t.ID_CARD = #{idCard}
</select>
<!-- <update id="updateByappId">-->
<!-- UPDATE report_death-->
<!-- <set>-->
<!-- <if test="appId != null">-->
<!-- app_id = #{appId, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="systemName != null">-->
<!-- system_name = #{systemName, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="systemTag != null">-->
<!-- system_tag = #{systemTag, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="createTime != null">-->
<!-- create_time = #{createTime, jdbcType=TIMESTAMP},-->
<!-- </if>-->
<!-- <if test="updateTime != null">-->
<!-- update_time = #{updateTime, jdbcType=TIMESTAMP},-->
<!-- </if>-->
<!-- </set>-->
<!-- WHERE app_id = #{appId}-->
<!-- </update>-->
</mapper>
\ No newline at end of file
<select id="selectAllDeaths" resultType="com.zq.system.modules.system.domain.vo.ReportDeathVo">
SELECT
*
FROM
( SELECT t.*, ROWNUM r FROM GX_BZ.REPORT_DEATH t WHERE UPDATE_TIME IS NOT NULL) h
WHERE
r BETWEEN ( ( #{page} - 1 ) * #{size} + 1 )
AND ( #{page} * #{size} )
<!-- <if test="idCard != null">-->
<!-- AND h.ID_CARD = #{idCard, jdbcType=VARCHAR}-->
<!-- </if>-->
<!-- <if test="name != null">-->
<!-- AND h.NAME = #{name, jdbcType=VARCHAR}-->
<!-- </if>-->
ORDER BY UPDATE_TIME DESC
</select>
<select id="selectAllCount" resultType="java.lang.Integer">
select count(1) from GX_BZ.REPORT_DEATH t
<where>
<if test="idCard != null">
AND t.ID_CARD = #{idCard, jdbcType=OTHER}
</if>
<if test="name != null">
AND t.NAME = #{name, jdbcType=OTHER}
</if>
<if test="deathType != null">
AND t.DEATH_TYPE = #{deathType, jdbcType=OTHER}
</if>
</where>
</select>
<select id="selectByNameOrIdcard" resultType="com.zq.system.modules.system.entity.ReportDeath">
SELECT *
FROM GX_BZ.REPORT_DEATHS t
WHERE t.ID_CARD = #{idCard}
OR t.NAME LIKE CONCAT('#{name}','%' )
</select>
<select id="getDeathByName" resultType="com.zq.system.modules.system.domain.vo.ReportDeathVo">
select * from GX_BZ.REPORT_DEATH t
<where>
<if test="idCard != null">
AND t.ID_CARD = #{idCard}
</if>
<if test="name != null">
AND t.NAME LIKE CONCAT('${name}','%' )
</if>
<if test="deathType">
AND t.DEATH_TYPE = #{deathType}
</if>
</where>
</select>
<!-- <update id="updateByappId">-->
<!-- UPDATE report_death-->
<!-- <set>-->
<!-- <if test="appId != null">-->
<!-- app_id = #{appId, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="systemName != null">-->
<!-- system_name = #{systemName, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="systemTag != null">-->
<!-- system_tag = #{systemTag, jdbcType=OTHER},-->
<!-- </if>-->
<!-- <if test="createTime != null">-->
<!-- create_time = #{createTime, jdbcType=TIMESTAMP},-->
<!-- </if>-->
<!-- <if test="updateTime != null">-->
<!-- update_time = #{updateTime, jdbcType=TIMESTAMP},-->
<!-- </if>-->
<!-- </set>-->
<!-- WHERE app_id = #{appId}-->
<!-- </update>-->
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment