|
@@ -1,22 +1,32 @@
|
|
|
package com.dk.mdm.service.mst;
|
|
package com.dk.mdm.service.mst;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
|
|
+import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
|
import com.dk.common.infrastructure.constant.OauthConstants;
|
|
import com.dk.common.infrastructure.constant.OauthConstants;
|
|
|
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
|
|
+import com.dk.common.model.pojo.PageList;
|
|
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
|
|
+import com.dk.common.util.Md5Utils;
|
|
|
|
|
+import com.dk.mdm.infrastructure.convert.mst.UserConvert;
|
|
|
import com.dk.mdm.infrastructure.util.AESSecurityUtil;
|
|
import com.dk.mdm.infrastructure.util.AESSecurityUtil;
|
|
|
import com.dk.mdm.infrastructure.util.UUID;
|
|
import com.dk.mdm.infrastructure.util.UUID;
|
|
|
import com.dk.mdm.mapper.common.CommonMapper;
|
|
import com.dk.mdm.mapper.common.CommonMapper;
|
|
|
import com.dk.mdm.model.entity.AuthAccessToken;
|
|
import com.dk.mdm.model.entity.AuthAccessToken;
|
|
|
import com.dk.mdm.model.entity.UserLoginSuccess;
|
|
import com.dk.mdm.model.entity.UserLoginSuccess;
|
|
|
|
|
+import com.dk.mdm.model.pojo.mst.Unit;
|
|
|
import com.dk.mdm.model.pojo.mst.User;
|
|
import com.dk.mdm.model.pojo.mst.User;
|
|
|
import com.dk.mdm.mapper.mst.UserMapper;
|
|
import com.dk.mdm.mapper.mst.UserMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
import com.dk.mdm.model.query.mst.UserQuery;
|
|
import com.dk.mdm.model.query.mst.UserQuery;
|
|
|
import com.dk.mdm.model.response.mst.UserResponse;
|
|
import com.dk.mdm.model.response.mst.UserResponse;
|
|
|
|
|
+import com.dk.mdm.model.vo.mst.UnitVO;
|
|
|
|
|
+import com.dk.mdm.model.vo.mst.UserVO;
|
|
|
|
|
+import com.dk.mdm.service.common.CommonService;
|
|
|
import com.dk.mdm.shiro.jwt.JWTGenerator;
|
|
import com.dk.mdm.shiro.jwt.JWTGenerator;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
|
|
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
|
|
@@ -37,6 +47,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -48,16 +59,27 @@ public class UserService extends BaseService<User> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private UserMapper userMapper;
|
|
|
|
|
-
|
|
|
|
|
- @Autowired
|
|
|
|
|
private CommonMapper commonMapper;
|
|
private CommonMapper commonMapper;
|
|
|
-
|
|
|
|
|
@Value("${aes-key}")
|
|
@Value("${aes-key}")
|
|
|
private String AESKey;
|
|
private String AESKey;
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private UserConvert userConvert;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonService commonService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 重写主键
|
|
|
|
|
+ * @author : 宋扬
|
|
|
|
|
+ * @date : 2024/4/29 17:13
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getPrimaryKey() {
|
|
|
|
|
+ return "user_id";
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @desc : 获取token
|
|
* @desc : 获取token
|
|
@@ -146,4 +168,93 @@ public class UserService extends BaseService<User> {
|
|
|
|
|
|
|
|
return ResponseResultUtil.success(userLoginSuccess);
|
|
return ResponseResultUtil.success(userLoginSuccess);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 查询
|
|
|
|
|
+ * @author : 宋扬
|
|
|
|
|
+ * @date : 2024/4/29 17:12
|
|
|
|
|
+ */
|
|
|
|
|
+ @Pagination
|
|
|
|
|
+ public ResponseResultVO<PageList<UserResponse>> selectByCond(UserQuery userQuery) {
|
|
|
|
|
+ return super.mergeListWithCount(userQuery, userMapper.selectByCond(userQuery),
|
|
|
|
|
+ userMapper.countByCond(userQuery));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 新建
|
|
|
|
|
+ * @author : 宋扬
|
|
|
|
|
+ * @date : 2024/4/29 17:22
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public ResponseResultVO<?> insert(UserVO userVO) {
|
|
|
|
|
+ // 判断用户编码是否重复
|
|
|
|
|
+ Long userCount = userMapper.countByCond(new User().setUserCode(userVO.getUserCode()));
|
|
|
|
|
+ if(userCount > 0){
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CODE_EXISTS.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ // 实体转换
|
|
|
|
|
+ User user = userConvert.convertToPo(userVO);
|
|
|
|
|
+ // 默认值
|
|
|
|
|
+ user.setFlgInitPwd(true).setPwdDate(LocalDateTime.now()).setUserPwd(Md5Utils.hash(Constant.StringConstant.LOGIN_INIT_PWD.getName()));
|
|
|
|
|
+ //新建
|
|
|
|
|
+ super.insert(user);
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 编辑
|
|
|
|
|
+ * @date : 2024/4/29 17:25
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public ResponseResultVO<?> update(UserVO userVO) {
|
|
|
|
|
+ // 查询用户数据
|
|
|
|
|
+ User userForUpdate = userMapper.selectByIdForUpdate(userVO.getUserId());
|
|
|
|
|
+ User user = userConvert.convertToPo(userVO);
|
|
|
|
|
+ // 如果Code和name、密码 都没有修改
|
|
|
|
|
+ if(user.getUserCode().equals(userForUpdate.getUserCode())
|
|
|
|
|
+ && user.getUserName().equals(userForUpdate.getUserName())
|
|
|
|
|
+ &&user.getUserPwd()==null){
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 判断用户Code是否有修改,
|
|
|
|
|
+ if(!user.getUserCode().equals(userForUpdate.getUserCode())){
|
|
|
|
|
+ // 判断用户编码是否重复
|
|
|
|
|
+ Long userCount = userMapper.countByCond(new User().setUserCode(userVO.getUserCode()));
|
|
|
|
|
+ if(userCount > 0){
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.STAFF_CODE_EXISTS.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果修改了密码
|
|
|
|
|
+ if (user.getUserPwd()!=null) {
|
|
|
|
|
+ user.setFlgInitPwd(false).setPwdDate(LocalDateTime.now()).setUserPwd(Md5Utils.hash(user.getUserPwd()));
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更新数据
|
|
|
|
|
+ super.updateByUuid(user);
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : desc
|
|
|
|
|
+ * @author : 宋扬
|
|
|
|
|
+ * @date : 2024/4/30 15:20
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(
|
|
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
|
|
+ )
|
|
|
|
|
+ public ResponseResultVO<Boolean> resetPassword(UserVO userVO) {
|
|
|
|
|
+ // 实体转换
|
|
|
|
|
+ List<String> userIdList = userVO.getUserIds();
|
|
|
|
|
+ for (String str : userIdList) {
|
|
|
|
|
+ User user = new User();
|
|
|
|
|
+ user.setUserId(str).setFlgInitPwd(true).setPwdDate(LocalDateTime.now())
|
|
|
|
|
+ .setUserPwd(Md5Utils.hash(Constant.StringConstant.LOGIN_INIT_PWD.getName()));
|
|
|
|
|
+ super.updateByUuid(user);
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|