jinpengyong
2022-02-17 ae0a308278e39b89d2e7dda7b09baed72ae44edd
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
@@ -2,8 +2,10 @@
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.mapper.SupervisionMapper;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SupervisionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -44,6 +46,9 @@
    @Autowired
    private SupervisionMapper supervisionMapper;
    @Autowired
    private OrganizationService organizationService;
    @Override
    @Transactional
    public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
@@ -54,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();
@@ -83,6 +96,8 @@
                    .collect(Collectors.joining(","));
            supervision.setImages(image);
        }
        supervisionMapper.insert(supervision);
        return result;
    }
@@ -90,30 +105,44 @@
    @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();
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("total", supervisionPage.getTotal());