From f465ea3473d23a8f8caf77f3d21e244c113d9353 Mon Sep 17 00:00:00 2001
From: Administrator <zhubaomin>
Date: 星期六, 09 十二月 2023 11:42:46 +0800
Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
---
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java | 167 +++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 136 insertions(+), 31 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
index feb87c0..0c900bd 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
@@ -3,59 +3,164 @@
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
+import com.dy.pipIrrGlobal.daoBa.BaUserRoleMapper;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
+import com.dy.pipIrrGlobal.pojoBa.BaUserRole;
import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Map;
+import java.util.Random;
@Slf4j
@Service
-//public class UserSv extends MPJBaseServiceImpl<BaUserMapper, BaUser> {
public class UserSv {
private BaUserMapper dao;
+ private BaUserRoleMapper urDao;
@Autowired
- private void setDao(BaUserMapper dao){
+ private void setDao(BaUserMapper dao) {
this.dao = dao;
}
- /**
- * 寰楀埌涓�涓墖鍖�
- * @param id 鐗囧尯ID
- * @return 鐗囧尯瀹炰綋
- */
- public BaUser selectById(Long id){
- return this.dao.selectById(id) ;
-
+ @Autowired
+ private void setDao(BaUserRoleMapper dao) {
+ this.urDao = dao;
}
/**
- * 寰楀埌涓�涓墖鍖�
+ * 寰楀埌涓�涓敤鎴�
+ *
+ * @param id 鐢ㄦ埛ID
+ * @return 鐢ㄦ埛瀹炰綋
+ */
+ public BaUser selectById(Long id) {
+ return this.dao.selectById(id);
+ }
+
+ /**
+ * 寰楀埌涓�涓敤鎴�
+ *
* @param vo 鏌ヨ鏉′欢鍊煎璞�
- * @return 鐗囧尯瀹炰綋
+ * @return 鐢ㄦ埛瀹炰綋
*/
- public QueryResultVo<List<BaUser>> selectSome(QueryVo vo){
-// MPJLambdaWrapper<BaUser> wrapper = new MPJLambdaWrapper<BaUser>()
-// .selectAll(BaUser.class)//鏌ヨuser琛ㄥ叏閮ㄥ瓧娈�
-// .select(BaRole::getId, BaRole::getName)
-// .leftJoin(BaUserRole.class, BaUserRole::getUserId, BaUser::getId)
-// .leftJoin(BaRole.class, BaRole::getId, BaUserRole::getRoleId);
-//
-// wrapper.like(StringUtils.isNotEmpty(vo.name), "t.name", vo.name) ;
-// wrapper.eq(StringUtils.isNotEmpty(vo.name), "t.phone", vo.phone) ;
-// wrapper.eq(!Objects.isNull(vo.roleId), "t1.id", vo.roleId) ;
-//
-// Page<BaUser> page = new Page<>(vo.pageCurr, vo.pageSize) ;
-//
-// IPage<BaUser> iPage = this.dao.selectJoinPage(page, BaUser.class, wrapper) ;
-//
-// List<BaUser> list = iPage.getRecords() ;
-//
-// return (QueryResultVo.<List<BaUser>>builder().content(list)).build() ;
- return null ;
+ @SuppressWarnings("unchecked")
+ public QueryResultVo<List<BaUser>> selectSome(QueryVo vo) {
+ Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(vo);
+ Long itemTotal = this.dao.selectTotal(params);
+
+ QueryResultVo<List<BaUser>> rsVo = new QueryResultVo<>();
+ rsVo.pageSize = vo.pageSize;
+ rsVo.pageCurr = vo.pageCurr;
+ rsVo.calculateAndSet(itemTotal, params);
+ rsVo.obj = this.dao.selectSome(params);
+
+ return rsVo;
}
+ /**
+ * 淇濆瓨瀹炰綋
+ * @param po 瀹炰綋
+ * @return 褰卞搷璁板綍鏁伴噺
+ */
+ @Transactional
+ public int save(BaUser po){
+ return this.dao.putin(po) ;
+ }
+
+ /**
+ * 淇濆瓨淇敼瀹炰綋
+ * @param po 瀹炰綋
+ * @return 褰卞搷璁板綍鏁伴噺
+ */
+ @Transactional
+ public int update(BaUser po) {
+ return this.dao.updateByPrimaryKeySelective(po);
+ }
+
+ /**
+ * 淇敼瀵嗙爜
+ *
+ * @param id 鐢ㄦ埛ID
+ * @param password 鏂板瘑鐮�
+ * @return 褰卞搷璁板綍鏁伴噺
+ */
+ public int changePassword(Long id, String password) {
+ return this.dao.changePassword(id, password);
+ }
+
+ /**
+ * 璁剧疆鐢ㄦ埛瑙掕壊
+ *
+ * @param userId 鐢ㄦ埛id
+ * @param roleIds 閫夋嫨鐨勮鑹瞚d闆嗗悎
+ * @return 鎻掑叆鐢ㄦ埛涓庤鑹插叧鑱旇褰曟暟閲�
+ */
+ public int setRoles(Long userId, Long[] roleIds) {
+ this.urDao.deleteByUserId(userId);
+ int count = 0;
+ if (roleIds != null && roleIds.length > 0) {
+ for (Long roleId : roleIds) {
+ count += this.urDao.insertSelective(new BaUserRole(userId, roleId));
+ }
+ }
+ return count ;
+ }
+
+ /**
+ * 璁剧疆鐢ㄦ埛瑙掕壊
+ *
+ * @param userId 鐢ㄦ埛id
+ * @param roleIds 閫夋嫨鐨勮鑹瞚d闆嗗悎
+ * @return 鎻掑叆鐢ㄦ埛涓庤鑹插叧鑱旇褰曟暟閲�
+ */
+ public int setRoles(Long userId, String[] roleIds) {
+ this.urDao.deleteByUserId(userId);
+ int count = 0;
+ if (roleIds != null && roleIds.length > 0) {
+ for (String roleId : roleIds) {
+ count += this.urDao.insertSelective(new BaUserRole(userId, Long.parseLong(roleId)));
+ }
+ }
+ return count;
+ }
+
+ /**
+ * 淇濆瓨淇敼瀹炰綋
+ * @param id 瀹炰綋ID
+ * @return 褰卞搷璁板綍鏁伴噺
+ */
+ @Transactional
+ public int delete(Long id) {
+ return this.dao.deleteLogicById(id);
+ }
+
+
+ /**
+ * 鐢熸垚鎸囧畾浣嶆暟闅忔満鏁板瓧瀵嗙爜
+ *
+ * @param length 澶氶暱闅忔満鏁�
+ * @return 闅忔満鏁�
+ */
+ public String getStringRandom(int length) {
+ String val = "";
+ Random random = new Random();
+ for (int i = 0; i < length; i++) {
+ String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
+ if ("char".equalsIgnoreCase(charOrNum)) {
+ int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
+ val += (char) (random.nextInt(26) + temp);
+ } else if ("num".equalsIgnoreCase(charOrNum)) {
+ val += String.valueOf(random.nextInt(10));
+ }
+ }
+ return val;
+ }
+
+
}
--
Gitblit v1.8.0