package com.fzzy.group.manager;
|
|
import com.fzzy.igds.constant.Constant;
|
import com.fzzy.igds.data.ChartPie;
|
import com.fzzy.igds.data.GisData;
|
import com.fzzy.igds.domain.Depot;
|
import com.fzzy.igds.domain.Dept;
|
import com.fzzy.igds.domain.DicArea;
|
import com.fzzy.igds.service.CoreDeptService;
|
import com.fzzy.igds.service.DepotService;
|
import com.fzzy.igds.service.DicAreaService;
|
import com.fzzy.igds.utils.ContextUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.text.DecimalFormat;
|
import java.util.*;
|
|
/**
|
* @Description
|
* @Author CZT
|
* @Date 2025/12/11 15:48
|
*/
|
@Slf4j
|
@Component
|
public class GroupManager {
|
|
@Resource
|
private DicAreaService dicAreaService;
|
@Resource
|
private CoreDeptService deptService;
|
@Resource
|
private DepotService depotService;
|
|
/**
|
* 获取省及下属市州集合
|
*
|
* @param areaCode
|
* @return
|
*/
|
public List<DicArea> getArea(String areaCode) {
|
|
DicArea area = dicAreaService.listDicAreaByCode(areaCode);
|
if (null == area) {
|
return null;
|
}
|
|
List<DicArea> list = new ArrayList<>();
|
list.add(area);
|
if (Constant.AREA_TYPE_1.equals(area.getType())) {
|
//市州级别,只查询伊犁
|
List<DicArea> children = dicAreaService.listData(null, null, "654000");
|
if (null != children && !children.isEmpty()) {
|
for (DicArea child : children) {
|
if (Constant.AREA_TYPE_2.equals(child.getType())) {
|
//区县
|
List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
|
if (null != childrenItem && !childrenItem.isEmpty()) {
|
list.addAll(childrenItem);
|
}
|
}
|
}
|
list.addAll(children);
|
}
|
}
|
|
return list;
|
}
|
|
/**
|
* 获取对应省份及下属市州children
|
*
|
* @param areaCode
|
* @return
|
*/
|
public List<DicArea> getAreaAndChild(String areaCode) {
|
|
DicArea area = dicAreaService.listDicAreaByCode(areaCode);
|
if (null == area) {
|
return null;
|
}
|
|
List<DicArea> list = new ArrayList<>();
|
if (Constant.AREA_TYPE_1.equals(area.getType())) {
|
//市州级别,只查询伊犁
|
List<DicArea> children = dicAreaService.listData(null, null, "654000");
|
if (null != children && !children.isEmpty()) {
|
for (DicArea child : children) {
|
if (Constant.AREA_TYPE_2.equals(child.getType())) {
|
//区县
|
List<DicArea> childrenItem = dicAreaService.listData(child.getCode(), null, null);
|
if (null != childrenItem && !childrenItem.isEmpty()) {
|
child.setChildren(childrenItem);
|
}
|
}
|
}
|
area.setChildren(children);
|
}
|
|
}
|
list.add(area);
|
return list;
|
}
|
|
/**
|
* 获取组织下所有库区信息
|
*
|
* @param companyId
|
* @return
|
*/
|
public List<Dept> getAllDept(String companyId) {
|
return deptService.listDept(null, companyId, null);
|
}
|
|
/**
|
* 统计gis数据,只统计登录人下属的数据统计
|
* @return
|
*/
|
public GisData getGisData() {
|
|
GisData gisData = new GisData();
|
|
//查询伊犁下属区县
|
//区县
|
List<DicArea> dicAreaList = dicAreaService.listData("654000", null, null);
|
|
//统计区县下库区数
|
LinkedHashMap<String, Integer> valuePieChart = new LinkedHashMap<>();
|
LinkedHashMap<String, String> namePieChart = new LinkedHashMap<>();
|
if (null != dicAreaList && !dicAreaList.isEmpty()) {
|
for (DicArea dicArea : dicAreaList) {
|
valuePieChart.put(dicArea.getCode(), 0);
|
namePieChart.put(dicArea.getCode(), dicArea.getName());
|
}
|
}
|
List<Dept> deptList = deptService.getDeptData();
|
if (null != deptList && !deptList.isEmpty()) {
|
//库区总数
|
gisData.setDeptNum(deptList.size());
|
for (Dept dept : deptList) {
|
if (StringUtils.isBlank(dept.getXzqhdm()) || null == valuePieChart.get(dept.getXzqhdm())) {
|
if(null == valuePieChart.get("999999")){
|
valuePieChart.put("999999", 0);
|
namePieChart.put("999999", "其他区县");
|
}
|
dept.setXzqhdm("999999");
|
}
|
valuePieChart.put(dept.getXzqhdm(), valuePieChart.get(dept.getXzqhdm()) + 1);
|
}
|
}
|
|
if(gisData.getDeptNum() > 0){
|
for (String mapKey : valuePieChart.keySet()) {
|
gisData.getDeptList().add(new ChartPie(valuePieChart.get(mapKey) + "", namePieChart.get(mapKey), new DecimalFormat("0.0").format((double)valuePieChart.get(mapKey) / gisData.getDeptNum() * 100)));
|
}
|
}
|
|
//统计重量
|
List<Depot> depotLisst = depotService.getData(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), false);
|
if (null != depotLisst && !depotLisst.isEmpty()) {
|
for (Depot depot : depotLisst) {
|
if(null == depot.getStorageReal()){
|
depot.setStorageReal(0.0);
|
}
|
gisData.setSum(gisData.getSum() + depot.getStorageReal());
|
if(StringUtils.isNotBlank(depot.getPledgeBank())){
|
gisData.setBankSum(gisData.getBankSum() + depot.getStorageReal());
|
}else{
|
gisData.setNormalSum(gisData.getNormalSum() + depot.getStorageReal());
|
}
|
}
|
}
|
if(gisData.getSum() > 0){
|
gisData.setSumPer(new DecimalFormat("0.00").format(gisData.getSum() / gisData.getSum() * 100L));
|
gisData.setBankSumPer(new DecimalFormat("0.00").format(gisData.getBankSum() / gisData.getSum() * 100L));
|
gisData.setNormalSumPer(new DecimalFormat("0.00").format(gisData.getNormalSum() / gisData.getSum() * 100L));
|
}
|
|
return gisData;
|
}
|
}
|