mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.dg.core.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dg.core.db.gen.entity.AreaCode2022;
import com.dg.core.db.gen.entity.OrganizationChartEntity;
import com.dg.core.db.gen.entity.TransactionEvent;
import com.dg.core.db.gen.mapper.AreaCode2022Mapper;
import com.dg.core.db.gen.mapper.OrganizationChartMapper;
import com.dg.core.db.gen.mapper.TransactionEventMapper;
import com.dg.core.service.IAreaCodeService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
 
@Service
public class AreaCodeServiceImpl extends ServiceImpl<AreaCode2022Mapper, AreaCode2022> implements IAreaCodeService {
 
    @Resource
    private OrganizationChartMapper organizationChartMapper;
 
    @Resource
    private TransactionEventMapper transactionEventMapper;
 
    @Override
    public List<AreaCode2022> getAreaCodeByTransactionId(Integer transactionId) {
        List<String> areaCodes = new ArrayList<>();
        TransactionEvent transactionEvent = transactionEventMapper.selectOne(new QueryWrapper<TransactionEvent>().lambda().
                eq(TransactionEvent::getId, transactionId));
        List<String> departmentIds = new ArrayList<>();
        if (transactionEvent.getDepartmentIds() != null) {
            departmentIds = new ArrayList<>(Arrays.asList(transactionEvent.getDepartmentIds().split(",")));
        }
 
        departmentIds.add(transactionEvent.getDepartmentId());
        for (String departmentId : departmentIds) {
            OrganizationChartEntity organizationChartEntity = organizationChartMapper.selectOne(new QueryWrapper<OrganizationChartEntity>().lambda()
                    .eq(OrganizationChartEntity::getId, departmentId));
            if (organizationChartEntity != null) {
                if (organizationChartEntity.getCity() != null)
                    areaCodes.add(organizationChartEntity.getCity());
                if (organizationChartEntity.getDistrict() != null)
                    areaCodes.add(organizationChartEntity.getDistrict());
                if (organizationChartEntity.getVillage() != null)
                    areaCodes.add(organizationChartEntity.getVillage());
            }
 
        }
        return baseMapper.selectByIdSet(areaCodes);
    }
 
 
    public List<String> getAreaCodeIds(List<String> areaCodes, OrganizationChartEntity organizationChartEntity) {
        List<OrganizationChartEntity> organizationChartEntitys = organizationChartMapper.selectList(new QueryWrapper<OrganizationChartEntity>().lambda()
                .eq(OrganizationChartEntity::getParentId, organizationChartEntity.getId()));
        for (OrganizationChartEntity organizationChart : organizationChartEntitys) {
            if (organizationChart.getCity() != null)
                areaCodes.add(organizationChart.getCity());
            if (organizationChart.getDistrict() != null)
                areaCodes.add(organizationChart.getDistrict());
            if (organizationChart.getVillage() != null)
                areaCodes.add(organizationChart.getVillage());
            getAreaCodeIds(areaCodes, organizationChart);
        }
        return areaCodes;
    }
 
    @Override
    public List<AreaCode2022> getListByPCode(String id) {
        List<AreaCode2022> areaCode2022s = baseMapper.selectList(new QueryWrapper<AreaCode2022>().lambda().eq(AreaCode2022::getPcode, id));
        for (AreaCode2022 areaCode2022 : areaCode2022s) {
            if (areaCode2022.getLevel() != 3)
                areaCode2022.setChild(this.getListByPCode(areaCode2022.getCode().toString()));
        }
        return areaCode2022s;
    }
 
 
}