From 381d0465a589a1862e9d79394619ae4bcc04350b Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Wed, 07 Apr 2021 08:39:51 +0800
Subject: [PATCH] 角色功能修改
---
screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 267 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 267 insertions(+), 0 deletions(-)
diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
index 827683d..ce8b1d6 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -1,10 +1,31 @@
package com.moral.api.service.impl;
+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.mapper.OrganizationMapper;
+import com.moral.api.pojo.dto.organization.OrganizationDTO;
+import com.moral.api.pojo.dto.organization.OrganizationQueryDTO;
+import com.moral.api.pojo.form.organization.OrganizationDeleteForm;
+import com.moral.api.pojo.form.organization.OrganizationInsertForm;
+import com.moral.api.pojo.form.organization.OrganizationQueryForm;
+import com.moral.api.pojo.form.organization.OrganizationUpdateForm;
import com.moral.api.service.OrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
+import com.moral.util.ConvertUtils;
+import com.moral.util.DateUtils;
+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 +38,250 @@
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
+ @Autowired
+ OrganizationMapper organizationMapper;
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationInsertForm]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/3/22
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO insertOrganization(OrganizationInsertForm organizationInsertForm) {
+ OrganizationDTO organizationDTO = new OrganizationDTO();
+ QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
+ //form������entity
+ Organization organization = organizationInsertForm.formConvertEntity();
+ //������������������������������������
+ Organization existOrganization = new Organization();
+ existOrganization.setName(organization.getName());
+ existOrganization.setIsDelete(Constants.NOT_DELETE);
+ queryWrapper.setEntity(existOrganization);
+ Organization existOrganizationResult = organizationMapper.selectOne(queryWrapper);
+ if (!ObjectUtils.isEmpty(existOrganizationResult)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg());
+ return organizationDTO;
+ }
+ //���������������������������
+ Integer parentId = organization.getParentId();
+ Organization parentOrganization = new Organization();
+ if (!ObjectUtils.isEmpty(parentId)) {
+ parentOrganization.setId(parentId);
+ parentOrganization.setIsDelete(Constants.NOT_DELETE);
+ queryWrapper.setEntity(parentOrganization);
+ parentOrganization = organizationMapper.selectOne(queryWrapper);
+ if (ObjectUtils.isEmpty(parentOrganization)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg());
+ return organizationDTO;
+ }
+ }
+ //������������
+ organizationMapper.insert(organization);
+ //������DTO������
+ organizationDTO.setParentOrganization(parentOrganization);
+ organizationDTO.setOrganization(organization);
+ organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ return organizationDTO;
+ }
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationUpdateForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
+ * @Author: ���������
+ * @Date: 2021/3/24
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO updateOrganization(OrganizationUpdateForm organizationUpdateForm) {
+ OrganizationDTO organizationDTO = new OrganizationDTO();
+ //form���entity
+ Organization organization = organizationUpdateForm.formConvertEntity();
+
+ //������������������������
+ QueryWrapper<Organization> existWrapper = new QueryWrapper<>();
+ Organization existOrganization = new Organization();
+ existOrganization.setId(organization.getId());
+ existOrganization.setIsDelete(Constants.NOT_DELETE);
+ existWrapper.setEntity(existOrganization);
+ existOrganization = organizationMapper.selectOne(existWrapper);
+ if (ObjectUtils.isEmpty(existOrganization)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
+ return organizationDTO;
+ }
+
+ //������������������������������������������������������
+ Integer parentId = organization.getParentId();
+ Organization parentOrganization = new Organization();
+ if (!ObjectUtils.isEmpty(parentId) && parentId != 0) {
+ QueryWrapper<Organization> existParentWrapper = new QueryWrapper<>();
+ parentOrganization.setId(parentId);
+ parentOrganization.setIsDelete(Constants.NOT_DELETE);
+ existParentWrapper.setEntity(parentOrganization);
+ parentOrganization = organizationMapper.selectOne(existParentWrapper);
+ if (ObjectUtils.isEmpty(parentOrganization)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg());
+ return organizationDTO;
+ }
+ }
+
+ //������������
+ organizationMapper.updateById(organization);
+
+ //������������������������
+ organization = organizationMapper.selectById(organization.getId());
+
+ //������DTO������
+ organizationDTO.setParentOrganization(parentOrganization);
+ organizationDTO.setOrganization(organization);
+ organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ return organizationDTO;
+ }
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationDeleteForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
+ * @Author: ���������
+ * @Date: 2021/3/25
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO deleteOrganization(OrganizationDeleteForm form) {
+ OrganizationDTO dto = new OrganizationDTO();
+ //������
+ Integer id = form.getOrganizationId();
+ //������������������������
+ Organization existOrganization = new Organization();
+ existOrganization.setIsDelete(Constants.NOT_DELETE);
+ existOrganization.setId(id);
+ QueryWrapper queryExistWrapper = new QueryWrapper();
+ queryExistWrapper.setEntity(existOrganization);
+ existOrganization = organizationMapper.selectOne(queryExistWrapper);
+ if (ObjectUtils.isEmpty(existOrganization)) {
+ dto.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
+ dto.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
+ return dto;
+ }
+ //������������������
+ UpdateWrapper deleteWrapper = new UpdateWrapper();
+ deleteWrapper.eq("id", id);
+ deleteWrapper.set("is_delete", Constants.DELETE);
+ organizationMapper.update(null, deleteWrapper);
+ //������������������������������������������������������������������parentId���0
+ if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {
+ UpdateWrapper deleteChildrenWrapper = new UpdateWrapper();
+ deleteChildrenWrapper.eq("parent_id", id);
+ deleteChildrenWrapper.set("is_delete", Constants.DELETE);
+ organizationMapper.update(null, deleteChildrenWrapper);
+ } else {
+ UpdateWrapper updateChildrenWrapper = new UpdateWrapper();
+ updateChildrenWrapper.eq("parent_id", id);
+ updateChildrenWrapper.set("parent_id", 0);
+ organizationMapper.update(null, updateChildrenWrapper);
+ }
+
+ dto.setOrganization(existOrganization);
+ dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ return dto;
+ }
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationQueryForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationQueryDTO
+ * @Author: ���������
+ * @Date: 2021/3/25
+ */
+ @Override
+ public OrganizationQueryDTO queryOrganization(OrganizationQueryForm organizationQueryForm) {
+ OrganizationQueryDTO dto = new OrganizationQueryDTO();
+ //������
+ Integer pageCount = organizationQueryForm.getPage();
+ Integer size = organizationQueryForm.getSize();
+ Integer parentId = organizationQueryForm.getParentId();
+ String name = organizationQueryForm.getName();
+ Integer provinceCode = organizationQueryForm.getProvinceCode();
+ Integer cityCode = organizationQueryForm.getCityCode();
+ Integer areaCode = organizationQueryForm.getAreaCode();
+ Long townCode = organizationQueryForm.getTownCode();
+ Long villageCode = organizationQueryForm.getVillageCode();
+ String phone = organizationQueryForm.getPhone();
+ String email = organizationQueryForm.getEmail();
+ String wechat = organizationQueryForm.getWechat();
+ String isDelete = organizationQueryForm.getIsDelete();
+ String order = organizationQueryForm.getOrder();
+ String orderType = organizationQueryForm.getOrderType();
+ Date createStartTime = organizationQueryForm.getCreateStartTime();
+ Date createEndTime = DateUtils.getDateOfDay(organizationQueryForm.getCreateEndTime(), 1);
+ Date expireStartTime = organizationQueryForm.getExpireStartTime();
+ Date expireEndTime = DateUtils.getDateOfDay(organizationQueryForm.getExpireEndTime(), 1);
+
+ //������������
+ Page<Organization> page = new Page<>(pageCount, size);
+ NullFilterWrapper<Organization> queryWrapper = new NullFilterWrapper<>();
+
+ queryWrapper.eq("parent_id", parentId);
+ queryWrapper.like("name", name);
+ queryWrapper.eq("province_code", provinceCode);
+ queryWrapper.eq("city_code", cityCode);
+ queryWrapper.eq("area_code", areaCode);
+ queryWrapper.eq("town_code", townCode);
+ queryWrapper.eq("village_code", villageCode);
+ queryWrapper.like("phone", phone);
+ queryWrapper.like("email", email);
+ queryWrapper.like("wechat", wechat);
+ queryWrapper.between("create_time", createStartTime, createEndTime);
+ queryWrapper.between("expire_time", expireStartTime, expireEndTime);
+
+ if (!ObjectUtils.isEmpty(isDelete)) {
+ queryWrapper.eq("is_delete", isDelete);
+ } else {
+ queryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ }
+
+ //������������
+ if (!ObjectUtils.isEmpty(order)) {
+ if (!ObjectUtils.isEmpty(orderType)) {
+ if (orderType.equals(Constants.ORDER_ASC))
+ queryWrapper.orderByAsc(ConvertUtils.toLine(order));
+ else
+ queryWrapper.orderByDesc(ConvertUtils.toLine(order));
+ }
+ }
+
+ //������������
+ Page<Organization> resultPage = organizationMapper.selectPage(page, queryWrapper);
+ List<Organization> organizations = resultPage.getRecords();
+ List<OrganizationDTO> organizationDTOS = new ArrayList<>();
+ //������������������������������
+ for (Organization child : organizations) {
+ OrganizationDTO resultDto = new OrganizationDTO();
+ Organization parent = organizationMapper.selectById(child.getParentId());
+ resultDto.setOrganization(child);
+ resultDto.setParentOrganization(parent);
+ organizationDTOS.add(resultDto);
+ }
+
+ dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ dto.setOrganizationDTOS(organizationDTOS);
+ dto.setCurrent(page.getCurrent());
+ dto.setPage(page.getPages());
+ dto.setSize(page.getSize());
+ dto.setTotal(page.getTotal());
+ return dto;
+ }
+
+
}
--
Gitblit v1.8.0