|
|
@@ -1,5 +1,8 @@
|
|
|
package com.sckw.system.service;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.sckw.core.exception.SystemException;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.PasswordUtils;
|
|
|
@@ -7,49 +10,74 @@ import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.system.dao.KwsUserDao;
|
|
|
+import com.sckw.system.dao.KwsUserDeptDao;
|
|
|
import com.sckw.system.model.KwsUser;
|
|
|
+import com.sckw.system.model.vo.req.UpdatePasswordReqVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 用户service接口
|
|
|
* @author zk
|
|
|
* @date 2023-05-31
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
-public class KwsUserService {
|
|
|
+public class KwsUserService extends ServiceImpl<KwsUserDao, KwsUser> {
|
|
|
|
|
|
@Autowired
|
|
|
KwsUserDao kwsUserDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ KwsUserDeptDao kwsUserDeptDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsDeptService kwsDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsUserDeptService kwsUserDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ KwsEnterpriseService kwsEnterpriseService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加新纪录
|
|
|
- * @param params
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
*/
|
|
|
- public HttpResult add(KwsUser params) throws Exception {
|
|
|
- /**1、数据校验**/
|
|
|
- HttpResult result = paramsCheck(params);
|
|
|
- if (result != null) {
|
|
|
- return result;
|
|
|
+ public void add(KwsUser kwsUser) {
|
|
|
+ /*1、数据校验*/
|
|
|
+ paramsCheck(kwsUser);
|
|
|
+
|
|
|
+ /*2、填充密码*/
|
|
|
+ fillPassword(kwsUser);
|
|
|
+
|
|
|
+ /*3、存库*/
|
|
|
+ kwsUser.setCreateBy(0L);
|
|
|
+ kwsUser.setUpdateBy(0L);
|
|
|
+ int count = kwsUserDao.insert(kwsUser);
|
|
|
+ if (count <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CODE_60601, HttpStatus.INSERT_FAIL);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- params.setCreateBy(0L);
|
|
|
- params.setUpdateBy(0L);
|
|
|
- int count = kwsUserDao.insert(params);
|
|
|
- return count > 0 ? HttpResult.ok("添加成功!") : HttpResult.error();
|
|
|
+ private void fillPassword(KwsUser kwsUser) {
|
|
|
+ //密码为空时,以登录名作为密码
|
|
|
+ if (StringUtils.isBlank(kwsUser.getPassword())) {
|
|
|
+ String password = PasswordUtils.entryptPassword( PasswordUtils.md5(kwsUser.getAccount()));
|
|
|
+ kwsUser.setPassword(password);
|
|
|
+ } else {
|
|
|
+ String password = PasswordUtils.entryptPassword(kwsUser.getPassword());
|
|
|
+ kwsUser.setPassword(password);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除记录-根据主键
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
*/
|
|
|
public HttpResult deleteByKey(String ids) throws Exception {
|
|
|
/**1.数据校验**/
|
|
|
@@ -84,9 +112,9 @@ public class KwsUserService {
|
|
|
if (!user.getAccount().equals(params.getAccount())) {
|
|
|
//用户账号唯一性校验
|
|
|
Map userParams = new HashMap(){{put("systemType", params.getSystemType()); put("account", params.getAccount());}};
|
|
|
- List<Map<String, Object>> users = kwsUserDao.findList(userParams);
|
|
|
+ List users = kwsUserDao.findList(userParams);
|
|
|
if (CollectionUtils.isNotEmpty(users)) {
|
|
|
- return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "用户账号已存在!");
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_EXISTS);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -102,16 +130,18 @@ public class KwsUserService {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public HttpResult resetPassword(Long id) throws Exception {
|
|
|
- //用户信息
|
|
|
+ public void resetPassword(Long id) throws Exception {
|
|
|
+ //查用户信息
|
|
|
KwsUser user = kwsUserDao.selectByKey(id);
|
|
|
- if (user == null) {
|
|
|
- return HttpResult.error("重置密码失败,用户信息不存在!");
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
+ throw new SystemException(HttpStatus.CODE_60602, HttpStatus.ACCOUNT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //重置密码
|
|
|
+ user.setPassword(PasswordUtils.entryptPassword(PasswordUtils.md5(user.getAccount())));
|
|
|
+ if (kwsUserDao.update(user) <= 0) {
|
|
|
+ throw new SystemException(HttpStatus.CODE_60601, HttpStatus.UPDATE_FAIL);
|
|
|
}
|
|
|
- String password = PasswordUtils.entryptPassword( PasswordUtils.md5(user.getAccount()));
|
|
|
- user.setPassword(password);
|
|
|
- int count = kwsUserDao.update(user);
|
|
|
- return count > 0 ? HttpResult.ok("密码重置成功!") : HttpResult.error();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -146,32 +176,42 @@ public class KwsUserService {
|
|
|
|
|
|
/**
|
|
|
* 参数校验
|
|
|
- * @param params
|
|
|
+ * @param kwsUser
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public HttpResult paramsCheck(KwsUser params) {
|
|
|
+ public void paramsCheck(KwsUser kwsUser) {
|
|
|
//用户账号必填校验
|
|
|
- if (StringUtils.isBlank(params.getAccount())) {
|
|
|
- return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "用户账号必填!");
|
|
|
+ if (StringUtils.isBlank(kwsUser.getAccount())) {
|
|
|
+ throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_MISSING);
|
|
|
}
|
|
|
|
|
|
//用户账号唯一性校验
|
|
|
- Map userParams = new HashMap(){{put("systemType", params.getSystemType()); put("account", params.getAccount());}};
|
|
|
- List<Map<String, Object>> users = kwsUserDao.findList(userParams);
|
|
|
+ LambdaQueryWrapper<KwsUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(KwsUser::getSystemType, kwsUser.getSystemType());
|
|
|
+ wrapper.eq(KwsUser::getAccount, kwsUser.getAccount());
|
|
|
+ List<KwsUser> users = this.list(wrapper);
|
|
|
if (CollectionUtils.isNotEmpty(users)) {
|
|
|
- return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, "用户账号已存在!");
|
|
|
+ throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_EXISTS);
|
|
|
}
|
|
|
|
|
|
- //密码校验
|
|
|
- if (StringUtils.isBlank(params.getPassword())) {
|
|
|
- String password = PasswordUtils.entryptPassword( PasswordUtils.md5(params.getAccount()));
|
|
|
- params.setPassword(password);
|
|
|
- } else {
|
|
|
- String password = PasswordUtils.entryptPassword(params.getPassword());
|
|
|
- params.setPassword(password);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户名查用户信息
|
|
|
+ */
|
|
|
+ public KwsUser getUserByAccount(String username) {
|
|
|
+ LambdaQueryWrapper<KwsUser> kwsUserWrapper = new LambdaQueryWrapper<>();
|
|
|
+ kwsUserWrapper.eq(KwsUser::getAccount, username);
|
|
|
+ kwsUserWrapper.eq(KwsUser::getDelFlag, Global.NO);
|
|
|
+ return kwsUserDao.selectOne(kwsUserWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ */
|
|
|
+ public void updatePassword(UpdatePasswordReqVo reqVo) {
|
|
|
|
|
|
- return null;
|
|
|
}
|
|
|
}
|