From d5ed2998a3d11b6380dc6198e55d79969f3cb30b Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期二, 23 七月 2024 17:30:09 +0800
Subject: [PATCH] login
---
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java | 180 ++++++++++++++++++++++++++++-------------------------------
1 files changed, 86 insertions(+), 94 deletions(-)
diff --git a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
index 88000f3..cdd944b 100644
--- a/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
+++ b/pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
@@ -7,6 +7,7 @@
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.aop.Log;
+import com.dy.pmsGlobal.pojoBa.BaRole;
import com.dy.pmsGlobal.pojoBa.BaUser;
import com.dy.pmsGlobal.util.Constant;
import com.mysql.cj.util.StringUtils;
@@ -15,7 +16,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
-import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -60,16 +60,11 @@
*/
@PostMapping(path = "some", consumes = MediaType.APPLICATION_JSON_VALUE)
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
- @SsoPowerAop(power = "10100010") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @SsoPowerAop(power = "10100000") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
@Log("鏌ヨ鐢ㄦ埛")
public BaseResponse<QueryResultVo<List<BaUser>>> some(@RequestBody QueryVo vo) {
- try {
- QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo);
- return BaseResponseUtils.buildSuccess(res);
- } catch (Exception e) {
- log.error("鏌ヨ鐢ㄦ埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage());
- }
+ QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo);
+ return BaseResponseUtils.buildSuccess(res);
}
/**
@@ -79,51 +74,37 @@
//@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)//鎸囧墠绔悜鍚庝紶鐨勫弬鏁扮被鍨�
@GetMapping(path = "one")
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
- @SsoPowerAop(power = "10100010") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @SsoPowerAop(power = "10100000") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
@Log("鏌ヨ鍗曚釜鐢ㄦ埛")
public BaseResponse<BaUser> one(String id) {
- try {
- return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id)));
- } catch (Exception e) {
- log.error("鏌ヨ涓�涓敤鎴锋暟鎹紓甯�", e);
- return BaseResponseUtils.buildException(e.getMessage());
- }
+ return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id)));
}
/**
* 淇濆瓨鐢ㄦ埛淇℃伅
* @param po
- * @param bindingResult
* @return
*/
@PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE)
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
- @SsoPowerAop(power = "10100011") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @SsoPowerAop(power = "10100001") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
@Log("淇濆瓨鐢ㄦ埛淇℃伅")
- public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po, BindingResult bindingResult) {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
+ public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po) throws Exception{
po.id = null;
Long id;
- try {
- po.supperAdmin = Constant.no.byteValue() ;
- po.disabled = false ;//榛樿涓嶇鐢�
- po.deleted = false;//榛樿涓嶅垹闄�
- if (!StringUtils.isNullOrEmpty(po.password)) {
+ po.supperAdmin = Constant.no.byteValue() ;
+// po.disabled = false ;//榛樿涓嶇鐢�
+ po.deleted = false;//榛樿涓嶅垹闄�
+ if (!StringUtils.isNullOrEmpty(po.password)) {
/*
濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
po.password = new String(Base64.getDecoder().decode(po.password)) ;
*/
- po.password = MD5.encrypt(po.password);//杩涜鍔犲瘑鐮�
- } else {
- po.password = MD5.encrypt(defaultPassword);
- }
- id = this.sv.save(po);
- } catch (Exception e) {
- log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage());
+ po.password = MD5.encrypt(po.password);//杩涜鍔犲瘑鐮�
+ } else {
+ po.password = MD5.encrypt(defaultPassword);
}
+ id = this.sv.save(po);
if (id <= 0) {
return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
} else {
@@ -134,30 +115,54 @@
/**
* 鏇存柊鐢ㄦ埛淇℃伅
* @param po
- * @param bindingResult
* @return
*/
@PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
- @SsoPowerAop(power = "10100011") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @SsoPowerAop(power = "10100001") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
@Log("鏇存柊鐢ㄦ埛淇℃伅")
- public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po, BindingResult bindingResult) {
- int count;
- try {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
- if (po.id == null) {
- return BaseResponseUtils.buildFail("鏃犳暟鎹疄浣揑D");
- }
- po.password = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
- po.supperAdmin = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
- po.deleted = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
- count = this.sv.update(po);
- } catch (Exception e) {
- log.error("淇敼鐢ㄦ埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage());
+ public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po) {
+ po.password = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+ po.supperAdmin = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+ po.deleted = null;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+ int count = this.sv.update(po);
+ if (count <= 0) {
+ return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+ } else {
+ return BaseResponseUtils.buildSuccess(true);
}
+ }
+
+ /**
+ * 绂佺敤鎴栧惎鐢ㄧ敤鎴蜂俊鎭�
+ * @param po
+ * @return
+ */
+ @PostMapping(path="disabled")
+ @SsoPowerAop(power = "10100001")
+ @Log("绂佺敤鎴栧惎鐢ㄧ敤鎴蜂俊鎭�")
+ public BaseResponse<BaRole> disabled(@RequestBody BaUser po){
+ int count = sv.disabled(po.id,po.disabled);
+ if (count <= 0) {
+ return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
+ } else {
+ return BaseResponseUtils.buildSuccess(true);
+ }
+ }
+
+ /**
+ * 鍒犻櫎鐢ㄦ埛淇℃伅
+ * @param id
+ * @return
+ */
+ @GetMapping(path = "delete")
+ @SsoPowerAop(power = "10100001") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @Log("鍒犻櫎鐢ㄦ埛")
+ public BaseResponse<Boolean> delete(Long id) {
+ BaUser po = new BaUser();
+ po.id = id;
+ po.deleted = true;
+ int count = this.sv.update(po);
if (count <= 0) {
return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
} else {
@@ -174,41 +179,36 @@
@GetMapping(path = "changePassword")
@SsoAop()
@Log("淇敼瀵嗙爜")
- public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) {
+ public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception{
int count;
- try {
- if (id == null) {
+ if (id == null) {
return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖");
- }
- if (StringUtils.isNullOrEmpty(oldPassword)) {
- return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉鑳戒负绌�");
- }
- if (StringUtils.isNullOrEmpty(newPassword)) {
- return BaseResponseUtils.buildFail("鏂板瘑鐮佷笉鑳戒负绌�");
- }
+ }
+ if (StringUtils.isNullOrEmpty(oldPassword)) {
+ return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉鑳戒负绌�");
+ }
+ if (StringUtils.isNullOrEmpty(newPassword)) {
+ return BaseResponseUtils.buildFail("鏂板瘑鐮佷笉鑳戒负绌�");
+ }
/*
濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ;
newPassword = new String(Base64.getDecoder().decode(newPassword)) ;
*/
- oldPassword = MD5.encrypt(oldPassword);//杩涜鍔犲瘑鐮�
- newPassword = MD5.encrypt(newPassword);//杩涜鍔犲瘑鐮�
+ oldPassword = MD5.encrypt(oldPassword);//杩涜鍔犲瘑鐮�
+ newPassword = MD5.encrypt(newPassword);//杩涜鍔犲瘑鐮�
- Long idLg = Long.parseLong(id) ;
+ Long idLg = Long.parseLong(id) ;
- BaUser po = this.sv.selectById(idLg);
- if (Objects.isNull(po)) {
- return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
+ BaUser po = this.sv.selectById(idLg);
+ if (Objects.isNull(po)) {
+ return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
+ } else {
+ if (!po.password.equalsIgnoreCase(oldPassword)) {
+ return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉姝g‘锛岃姹傚け璐�");
} else {
- if (!po.password.equalsIgnoreCase(oldPassword)) {
- return BaseResponseUtils.buildFail("鏃у瘑鐮佷笉姝g‘锛岃姹傚け璐�");
- } else {
- count = this.sv.changePassword(idLg, newPassword);
- }
+ count = this.sv.changePassword(idLg, newPassword);
}
- } catch (Exception e) {
- log.error("淇敼瀵嗙爜寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage());
}
if (count <= 0) {
return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
@@ -225,25 +225,17 @@
*/
@PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE)
//@SsoAop() //鍙湁鐧诲綍楠岃瘉锛屾病鏈夋潈闄愰獙璇�
- @SsoPowerAop(power = "10100011") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
+ @SsoPowerAop(power = "10100001") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇�
@Log("閲嶇疆瀵嗙爜")
- public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) {
+ public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo) throws Exception {
int count;
- try {
- if (bindingResult != null && bindingResult.hasErrors()) {
- return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
- }
- String password = MD5.encrypt(vo.password);//杩涜鍔犲瘑鐮�
- Long idLg = Long.parseLong(vo.id);
- BaUser po = this.sv.selectById(idLg);
- if (Objects.isNull(po)) {
- return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
- } else {
- count = this.sv.changePassword(idLg, password);
- }
- } catch (Exception e) {
- log.error("淇濆瓨鐢ㄦ埛寮傚父", e);
- return BaseResponseUtils.buildException(e.getMessage());
+ String password = MD5.encrypt(vo.password);//杩涜鍔犲瘑鐮�
+ Long idLg = Long.parseLong(vo.id);
+ BaUser po = this.sv.selectById(idLg);
+ if (Objects.isNull(po)) {
+ return BaseResponseUtils.buildFail("鏈緱鍒扮敤鎴凤紝璇锋眰澶辫触");
+ } else {
+ count = this.sv.changePassword(idLg, password);
}
if (count <= 0) {
return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�");
--
Gitblit v1.8.0