From 52d8cf200d7a54890845d4c468c24b6ab97a4762 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 06 May 2021 14:41:34 +0800
Subject: [PATCH] screen-manage                 前台用户增加以及删除功能

---
 screen-manage/src/main/java/com/moral/api/service/impl/UserServiceImpl.java |  205 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 205 insertions(+), 0 deletions(-)

diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/UserServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
index 24a141e..cce9d52 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -1,10 +1,33 @@
 package com.moral.api.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.moral.api.config.mybatis.wrapper.NullFilterWrapper;
+import com.moral.api.entity.Organization;
 import com.moral.api.entity.User;
+import com.moral.api.mapper.OrganizationMapper;
 import com.moral.api.mapper.UserMapper;
+import com.moral.api.pojo.dto.user.UserDTO;
+import com.moral.api.pojo.dto.user.UserQueryDTO;
+import com.moral.api.pojo.form.user.UserDeleteForm;
+import com.moral.api.pojo.form.user.UserInsertForm;
+import com.moral.api.pojo.form.user.UserQueryForm;
+import com.moral.api.pojo.form.user.UserUpdateForm;
 import com.moral.api.service.UserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
+import com.moral.util.ConvertUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 
 /**
  * <p>
@@ -17,4 +40,186 @@
 @Service
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
+    @Autowired
+    UserMapper userMapper;
+    @Autowired
+    OrganizationMapper organizationMapper;
+
+    @Override
+    public UserQueryDTO queryUsers(UserQueryForm form) {
+        //������������������
+        UserQueryDTO dto = new UserQueryDTO();
+        //������
+        Integer page = form.getPage();
+        Integer size = form.getSize();
+        String email = form.getEmail();
+        String mobile = form.getMobile();
+        String wechat = form.getWechat();
+        String order = form.getOrder();
+        String orderType = form.getOrderType();
+        Integer organizationId = form.getOrganizationId();
+        Date exipreStartTime = form.getExpireStartTime();
+        Date exipreEndTime = form.getExpireEndTime();
+        Date createStartTime = form.getCreateStartTime();
+        Date createEndTime = form.getCreateEndTime();
+        Integer isDelete = form.getIsDelete();
+
+        //������������������
+        Page<User> queryPage = new Page<>(page, size);
+        NullFilterWrapper<User> wrapper = new NullFilterWrapper<>();
+        wrapper.like("email", email);
+        wrapper.like("wechat", wechat);
+        wrapper.like("mobile", mobile);
+        wrapper.eq("is_admin", 1);
+        wrapper.eq("organization_id", organizationId);
+        wrapper.between("create_time", createStartTime, createEndTime);
+        wrapper.between("expire_time", exipreStartTime, exipreEndTime);
+        //������������������������
+        if (!ObjectUtils.isEmpty(order) && !ObjectUtils.isEmpty(orderType)) {
+            if (orderType.equals(Constants.ORDER_ASC))
+                wrapper.orderByAsc(ConvertUtils.toLine(order));
+            else
+                wrapper.orderByDesc(ConvertUtils.toLine(order));
+        }
+        //������������������������
+        if (!ObjectUtils.isEmpty(isDelete))
+            wrapper.eq("is_delete", isDelete);
+        else
+            wrapper.eq("is_delete", Constants.NOT_DELETE);
+
+        //������������
+        Page<User> resultPage = userMapper.selectPage(queryPage, wrapper);
+        List<User> users = resultPage.getRecords();
+
+        //������������������������
+        List<UserDTO> userDTOS = new ArrayList<>();
+        for (User user : users) {
+            UserDTO userDTO = new UserDTO();
+            Organization organization = new Organization();
+            organization.setId(user.getOrganizationId());
+            organization.setIsDelete(Constants.NOT_DELETE);
+            QueryWrapper<Organization> organizationWrapper = new QueryWrapper<>();
+            organizationWrapper.setEntity(organization);
+            organization = organizationMapper.selectOne(organizationWrapper);
+            userDTO.setUser(user);
+            userDTO.setOrganization(organization);
+            userDTOS.add(userDTO);
+        }
+
+        //������������������
+        dto.setUserDTOS(userDTOS);
+        dto.setCurrent(resultPage.getCurrent());
+        dto.setPages(resultPage.getPages());
+        dto.setSize(resultPage.getSize());
+        dto.setTotal(resultPage.getTotal());
+        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+
+        return dto;
+    }
+
+    @Override
+    @Transactional
+    public UserDTO updateUser(UserUpdateForm form) {
+        //������������������
+        UserDTO dto = new UserDTO();
+
+        //������
+        User user = form.formConvertEntity();
+
+        //������������������������ ������������������
+        QueryWrapper<User> oldUserWrapper = new QueryWrapper<>();
+        User oldUser = new User();
+        oldUser.setId(user.getId());
+        oldUser.setIsDelete(Constants.NOT_DELETE);
+        oldUserWrapper.setEntity(oldUser);
+        oldUser = userMapper.selectOne(oldUserWrapper);
+        if (ObjectUtils.isEmpty(oldUser)) {
+            dto.setCode(ResponseCodeEnum.USER_NOT_EXIST.getCode());
+            dto.setMsg(ResponseCodeEnum.USER_NOT_EXIST.getMsg());
+            return dto;
+        }
+
+        //������
+        userMapper.updateById(user);
+
+        //������������������
+        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+
+        return dto;
+    }
+
+    @Override
+    @Transactional
+    public UserDTO deleteUser(UserDeleteForm form) {
+        //������������������
+        UserDTO dto = new UserDTO();
+        //������
+        Integer id = form.getId();
+        //������������������������ ������������������
+        User oldUser = new User();
+        oldUser.setIsDelete(Constants.NOT_DELETE);
+        oldUser.setId(id);
+        QueryWrapper<User> oldWrapper = new QueryWrapper<>();
+        oldWrapper.setEntity(oldUser);
+        oldUser = userMapper.selectOne(oldWrapper);
+        if(ObjectUtils.isEmpty(oldUser)){
+            dto.setCode(ResponseCodeEnum.USER_NOT_EXIST.getCode());
+            dto.setMsg(ResponseCodeEnum.USER_NOT_EXIST.getMsg());
+            return dto;
+        }
+        //������������������������������������������������������������
+        UpdateWrapper<User> deleteWrapper = new UpdateWrapper<>();
+        deleteWrapper.eq("organization_id",oldUser.getOrganizationId());
+        deleteWrapper.set("is_delete",Constants.DELETE);
+        userMapper.update(null,deleteWrapper);
+        //������������
+        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        return dto;
+    }
+
+    @Override
+    @Transactional
+    public UserDTO insertUser(UserInsertForm form) {
+        //������������������
+        UserDTO dto = new UserDTO();
+        //������
+        User user = form.formConvertEntity();
+        //������������������������
+        User existUser = new User();
+        existUser.setAccount(user.getAccount());
+        existUser.setIsDelete(Constants.NOT_DELETE);
+        QueryWrapper<User> wrapper = new QueryWrapper<>();
+        wrapper.setEntity(existUser);
+        User existUserResult = userMapper.selectOne(wrapper);
+        if(!ObjectUtils.isEmpty(existUserResult)){
+            dto.setCode(ResponseCodeEnum.USER_EXIST.getCode());
+            dto.setMsg(ResponseCodeEnum.USER_EXIST.getMsg());
+            return dto;
+        }
+        //���������������������������������������������
+        Integer organizationId = user.getOrganizationId();
+        User organizationUser = new User();
+        organizationUser.setIsAdmin(true);
+        organizationUser.setIsDelete(Constants.NOT_DELETE);
+        organizationUser.setOrganizationId(organizationId);
+        QueryWrapper<User> organizationUserWrapper = new QueryWrapper<>();
+        organizationUserWrapper.setEntity(organizationUser);
+        organizationUser = userMapper.selectOne(organizationUserWrapper);
+        if(!ObjectUtils.isEmpty(organizationUser)){
+            dto.setCode(ResponseCodeEnum.ORGANIZATION_USER_EXIST.getCode());
+            dto.setMsg(ResponseCodeEnum.ORGANIZATION_USER_EXIST.getMsg());
+            return dto;
+        }
+        //������
+        userMapper.insert(user);
+        //������������������
+        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        return dto;
+    }
+
+
 }

--
Gitblit v1.8.0