jinpengyong
2022-02-17 ae0a308278e39b89d2e7dda7b09baed72ae44edd
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
@@ -1,15 +1,14 @@
package com.moral.api.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Organization;
import com.moral.api.entity.Supervision;
import com.moral.api.entity.SysArea;
import com.moral.api.mapper.SupervisionMapper;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SupervisionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.SysAreaService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.FileUtils;
@@ -48,7 +47,7 @@
    private SupervisionMapper supervisionMapper;
    @Autowired
    private SysAreaService sysAreaService;
    private OrganizationService organizationService;
    @Override
    @Transactional
@@ -60,8 +59,16 @@
        Map<String, Object> result = new HashMap<>();
        List<String> images = new ArrayList<>();
        //督办单编号唯一
        QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("number", supervision.getNumber()).eq("is_delete", Constants.NOT_DELETE);
        if (supervisionMapper.selectOne(queryWrapper) != null) {
            result.put("code", ResponseCodeEnum.SUPERVISION_NUMBER_EXIT.getCode());
            result.put("msg", ResponseCodeEnum.SUPERVISION_NUMBER_EXIT.getMsg());
            return result;
        }
        List<String> images = new ArrayList<>();
        for (MultipartFile file : files) {
            //判断上传文件格式
            String fileType = file.getContentType();
@@ -89,6 +96,8 @@
                    .collect(Collectors.joining(","));
            supervision.setImages(image);
        }
        supervisionMapper.insert(supervision);
        return result;
    }
@@ -96,51 +105,51 @@
    @Override
    public Map<String, Object> selectSupervisions(Map<String, Object> params) {
        //获取查询参数
        int cityCode = Integer.parseInt(params.get("cityCode").toString());
        int page = Integer.parseInt(params.get("page").toString());
        int size = Integer.parseInt(params.get("size").toString());
        Object start = params.get("start");
        Object end = params.get("end");
        Integer orgId = Integer.parseInt(params.get("organizationId").toString());
        QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("city_code", cityCode)
                .eq("is_delete", Constants.NOT_DELETE);
        //获取组织下所有子组织
        List<Organization> organizations = organizationService.getChildrenOrganizationsById(orgId);
        List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
        orgIds.add(orgId);
        QueryWrapper<Supervision> supervisionQueryWrapper = new QueryWrapper<>();
        supervisionQueryWrapper.eq("is_delete", Constants.NOT_DELETE).in("organization_id", orgIds);
        //如果指定了地区,就获取该组织及其子组织下该地区的。否则获取该组织及其子组织下所有的
        if (params.get("cityCode") != null) {
            String cityCode = params.get("cityCode").toString();
            //如果是市级,就查询该市下所有县市区的,否则只查询该县市区的
            if (cityCode.endsWith("00")) {
                supervisionQueryWrapper.eq("CONCAT(LEFT(city_code,4),'00')", cityCode);
            } else {
                supervisionQueryWrapper.eq("city_code", cityCode);
            }
        }
        if (start != null) {
            queryWrapper.ge("time", start);
            supervisionQueryWrapper.ge("time", start);
        }
        if (start != null) {
            queryWrapper.le("time", end);
            supervisionQueryWrapper.le("time", end);
        }
        //按time倒序
        queryWrapper.orderByDesc("time");
        supervisionQueryWrapper.orderByDesc("time");
        //分页
        Page<Supervision> supervisionPage = new Page<>(page, size);
        supervisionMapper.selectPage(supervisionPage, queryWrapper);
        supervisionMapper.selectPage(supervisionPage, supervisionQueryWrapper);
        List<Supervision> supervisions = supervisionPage.getRecords();
        //获取区域名字
        List<Map<String, Object>> item = new ArrayList<>();
        QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
        sysAreaQueryWrapper.eq("area_code", cityCode);
        SysArea one = sysAreaService.getOne(sysAreaQueryWrapper);
        String cityName = one.getAreaName();
        for (Supervision supervision : supervisions) {
            Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(supervision), Map.class);
            map.remove("isDelete");
            map.remove("createTime");
            map.remove("updateTime");
            map.put("cityName", cityName);
            item.add(map);
        }
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("total", supervisionPage.getTotal());
        result.put("totalPage", supervisionPage.getPages());
        result.put("current", supervisionPage.getCurrent());
        result.put("pageSize", supervisionPage.getSize());
        result.put("item", item);
        result.put("item", supervisions);
        return result;
    }