lizijie
2022-02-10 0c29adcf7692ad992c70ff1207d7d098a635535c
服务范围列表条件查询接口
1 files added
2 files modified
174 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/ServicesScopeController.java 59 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/ServicesScopeService.java 12 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/ServicesScopeServiceImpl.java 103 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/ServicesScopeController.java
New file
@@ -0,0 +1,59 @@
package com.moral.api.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.entity.Organization;
import com.moral.api.entity.ServicesScope;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.service.*;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.DateUtils;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * @program: screen
 * @description: 图表数据
 * @author: lizijie
 * @create: 2021-11-10 16:05
 **/
@Slf4j
@Api(tags = {"服务范围"})
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/serviceScope")
public class ServicesScopeController {
    @Resource
    private OrganizationService organizationService;
    @Resource
    private ServicesScopeService servicesScopeService;
    @RequestMapping(value = "getDataByOrgIdAndCondition", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getDataByOrgIdAndCondition(HttpServletRequest request) throws ParseException {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request,null);
        Object orgId = parameters.get("organization_id");
        if (ObjectUtils.isEmpty(orgId)){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Organization organization = organizationService.getOrganizationById(Integer.parseInt(orgId.toString()));
        if (ObjectUtils.isEmpty(organization)){
            return ResultMessage.fail(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode(), ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
        }
        List<Map<String, Object>> resultList = servicesScopeService.getDateByOrgIdAndCondition(parameters);
        return ResultMessage.ok(resultList);
    }
}
screen-api/src/main/java/com/moral/api/service/ServicesScopeService.java
@@ -3,6 +3,9 @@
import com.moral.api.entity.ServicesScope;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务类
@@ -13,4 +16,13 @@
 */
public interface ServicesScopeService extends IService<ServicesScope> {
    /**
      *@Description: 通过组织id和条件获取数据
      *@Param: [map]
      *@return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
      *@Author: lizijie
      *@Date: 2022/2/9 14:04
     **/
    List<Map<String, Object>> getDateByOrgIdAndCondition(Map map);
}
screen-api/src/main/java/com/moral/api/service/impl/ServicesScopeServiceImpl.java
@@ -1,10 +1,25 @@
package com.moral.api.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Organization;
import com.moral.api.entity.ServicesScope;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.mapper.ServicesScopeMapper;
import com.moral.api.pojo.vo.organization.OrganizationServicesScopeVO;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.ServicesScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * <p>
@@ -17,4 +32,92 @@
@Service
public class ServicesScopeServiceImpl extends ServiceImpl<ServicesScopeMapper, ServicesScope> implements ServicesScopeService {
    @Autowired
    private OrganizationMapper organizationMapper;
    @Autowired
    private ServicesScopeMapper servicesScopeMapper;
    @Autowired
    private OrganizationService organizationService;
    @Override
    public List<Map<String, Object>> getDateByOrgIdAndCondition(Map map) {
        int orgId = Integer.parseInt(map.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        List<Map<String,Object>> resultList = new ArrayList<>();
        for (int organizationId:allOrgIdWithoutDuplicates) {
            Map<String,Object> resultMap = new HashMap<>();
            QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
            organizationQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
            organizationQueryWrapper.eq("id",organizationId);
            if (!ObjectUtils.isEmpty(map.get("province_code"))){
                organizationQueryWrapper.eq("province_code",Integer.parseInt(map.get("province_code").toString()));
            }
            if (!ObjectUtils.isEmpty(map.get("city_code"))){
                organizationQueryWrapper.eq("city_code",Integer.parseInt(map.get("city_code").toString()));
            }
            if (!ObjectUtils.isEmpty(map.get("area_code"))){
                organizationQueryWrapper.eq("area_code",Integer.parseInt(map.get("area_code").toString()));
            }
            Organization organization = new Organization();
            organization = organizationMapper.selectById(organizationId);
            if (ObjectUtils.isEmpty(organization)){
                continue;
            }
            resultMap.put("organization",organization);
            QueryWrapper<ServicesScope> servicesScopeQueryWrapper = new QueryWrapper<>();
            servicesScopeQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
            servicesScopeQueryWrapper.eq("organization_id",organizationId);
            if (!ObjectUtils.isEmpty(map.get("name"))){
                servicesScopeQueryWrapper.like("name",map.get("name").toString());
            }
            List<ServicesScope> servicesScopes = new ArrayList<>();
            servicesScopes = servicesScopeMapper.selectList(servicesScopeQueryWrapper);
            if (servicesScopes.size()<1){
                continue;
            }
            resultMap.put("servicesScopes",servicesScopes);
            resultList.add(resultMap);
        }
        if (resultList.size()<1){
            return null;
        }
        return resultList;
    }
    private OrganizationServicesScopeVO treeStructure(int orgId){
        OrganizationServicesScopeVO organizationServicesScopeVO = new OrganizationServicesScopeVO();
        Organization organization = organizationMapper.selectById(orgId);
        organizationServicesScopeVO.setOrganization(organization);
        QueryWrapper<Organization> chileOrganizationQueryWrapper = new QueryWrapper<>();
        chileOrganizationQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
        chileOrganizationQueryWrapper.eq("parent_id",orgId);
        List<Organization> childOrganizations = new ArrayList<>();
        childOrganizations = organizationMapper.selectList(chileOrganizationQueryWrapper);
        if (childOrganizations.size()>0){
            List<OrganizationServicesScopeVO> organizationServicesScopeVOS = new ArrayList<>();
            for (Organization childOrganization:childOrganizations) {
                OrganizationServicesScopeVO organizationServicesScopeVO1 = treeStructure(childOrganization.getId());
                if (ObjectUtils.isEmpty(organizationServicesScopeVO1)){
                    organizationServicesScopeVOS.add(organizationServicesScopeVO1);
                }
            }
            organizationServicesScopeVO.setOrganizationServicesScopeVOS(organizationServicesScopeVOS);
        }
        //servicesScopeMapper.selectList()
        return null;
    }
}