187 lines
7.8 KiB
Java
187 lines
7.8 KiB
Java
|
|
package com.seeyon.apps.assetsmap.service;
|
|||
|
|
|
|||
|
|
import com.seeyon.apps.assetsmap.config.AssetsMapConfigProvider;
|
|||
|
|
import com.seeyon.apps.assetsmap.constants.AssetsMapConstans;
|
|||
|
|
import com.seeyon.apps.assetsmap.vo.AssetsItem;
|
|||
|
|
import com.seeyon.apps.assetsmap.vo.RegionVo;
|
|||
|
|
import com.seeyon.ctp.common.AppContext;
|
|||
|
|
import com.seeyon.ctp.common.exceptions.BusinessException;
|
|||
|
|
import com.seeyon.ctp.organization.bo.V3xOrgDepartment;
|
|||
|
|
import com.seeyon.ctp.organization.manager.OrgManager;
|
|||
|
|
import com.seeyon.utils.form.*;
|
|||
|
|
import org.apache.commons.lang3.StringUtils;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
public class AssetsQueryService {
|
|||
|
|
|
|||
|
|
private AssetsMapConfigProvider configProvider = (AssetsMapConfigProvider) AppContext.getBean("assetsMapConfigProvider");
|
|||
|
|
private OrgManager orgManager = (OrgManager) AppContext.getBean("orgManager");
|
|||
|
|
|
|||
|
|
private String getFormNo(){
|
|||
|
|
return configProvider.getBizConfigByKey(AssetsMapConstans.ASSETSFORMNO);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<RegionVo> queryAllZoneAssets() throws Exception {
|
|||
|
|
System.out.println("表单编码为:" + getFormNo());
|
|||
|
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
|||
|
|
List<FormColumn> formColumns = FormTableExecutor.query(tableContext,null, null, true);
|
|||
|
|
List<RegionVo> regionVos = new ArrayList<>();
|
|||
|
|
System.out.println("查询出的数据条数:" + formColumns.size());
|
|||
|
|
for (FormColumn formColumn : formColumns) {
|
|||
|
|
Map<String, Object> fieldsMap = formColumn.getFieldsMap();
|
|||
|
|
if(fieldsMap == null) {
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
upsertRegionVos(regionVos,fieldsMap);
|
|||
|
|
}
|
|||
|
|
return regionVos;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void upsertRegionVos(List<RegionVo> regionVos, Map<String, Object> fieldsMap) {
|
|||
|
|
|
|||
|
|
String latStr = (String) fieldsMap.get("纬度");
|
|||
|
|
String lngStr = (String) fieldsMap.get("经度");
|
|||
|
|
|
|||
|
|
// 1️⃣ 经纬度必须有
|
|||
|
|
if (StringUtils.isAnyBlank(latStr, lngStr)) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
double lat = Double.parseDouble(latStr);
|
|||
|
|
double lng = Double.parseDouble(lngStr);
|
|||
|
|
|
|||
|
|
String address = (String) fieldsMap.get("位置详情");
|
|||
|
|
String owner = (String) fieldsMap.get("权属公司");
|
|||
|
|
|
|||
|
|
// 2️⃣ 地址 & 权属公司建议也做非空控制(关键!)
|
|||
|
|
if (StringUtils.isAnyBlank(address)) {
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
String assetId = getStringValue(fieldsMap,"id");
|
|||
|
|
AssetsItem newAsset = buildAssetsItem(fieldsMap);
|
|||
|
|
Long managerId = fieldsMap.get("运营单位") == null ? null : Long.parseLong(fieldsMap.get("运营单位") + "");
|
|||
|
|
String deptName = getDeptName(managerId);
|
|||
|
|
// 3️⃣ 查找区域
|
|||
|
|
for (RegionVo regionVo : regionVos) {
|
|||
|
|
|
|||
|
|
// 3.1 经纬度必须存在
|
|||
|
|
if (regionVo.getLat() == null || regionVo.getLng() == null) {
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
boolean sameLocation =
|
|||
|
|
Double.compare(regionVo.getLat(), lat) == 0 &&
|
|||
|
|
Double.compare(regionVo.getLng(), lng) == 0;
|
|||
|
|
|
|||
|
|
// 3.2 地址 & 权属公司必须非空才参与匹配
|
|||
|
|
if (!sameLocation ||
|
|||
|
|
StringUtils.isAnyBlank(regionVo.getAddress())) {
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
boolean sameAddress = address.equals(regionVo.getAddress());
|
|||
|
|
|
|||
|
|
if (sameAddress) {
|
|||
|
|
|
|||
|
|
// 4️⃣ 判断资产是否存在
|
|||
|
|
boolean exists = regionVo.getAssets().stream()
|
|||
|
|
.anyMatch(a -> a.getId().equals(assetId) );
|
|||
|
|
|
|||
|
|
if (!exists) {
|
|||
|
|
regionVo.getAssets().add(newAsset);
|
|||
|
|
}
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 5️⃣ 新建区域(这里可以放心,因为关键字段都有值)
|
|||
|
|
RegionVo newRegion = new RegionVo();
|
|||
|
|
newRegion.setLat(lat);
|
|||
|
|
newRegion.setLng(lng);
|
|||
|
|
newRegion.setAddress(address);
|
|||
|
|
newRegion.setOwner(owner);
|
|||
|
|
newRegion.setManager(deptName);
|
|||
|
|
|
|||
|
|
List<AssetsItem> assets = new ArrayList<>();
|
|||
|
|
assets.add(newAsset);
|
|||
|
|
newRegion.setAssets(assets);
|
|||
|
|
|
|||
|
|
regionVos.add(newRegion);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private String getDeptName(Long deptId) {
|
|||
|
|
if(deptId != null) {
|
|||
|
|
try {
|
|||
|
|
V3xOrgDepartment department = orgManager.getDepartmentById(deptId);
|
|||
|
|
if(department != null) {
|
|||
|
|
return department.getName();
|
|||
|
|
}
|
|||
|
|
}catch (Exception e) {
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private AssetsItem buildAssetsItem(Map<String, Object> fieldsMap) {
|
|||
|
|
AssetsItem assetsItem = new AssetsItem();
|
|||
|
|
assetsItem.setId(getStringValue(fieldsMap,"id"));
|
|||
|
|
assetsItem.setArea(fieldsMap.get("资产面积") == null ? null : Double.parseDouble(fieldsMap.get("资产面积") + ""));
|
|||
|
|
assetsItem.setTenant(getStringValue(fieldsMap,"租户名称"));
|
|||
|
|
assetsItem.setPurpose(getStringValue(fieldsMap,"资产用途"));
|
|||
|
|
assetsItem.setRemark(getStringValue(fieldsMap,"备注"));
|
|||
|
|
assetsItem.setOwner(getStringValue(fieldsMap,"权属单位"));
|
|||
|
|
assetsItem.setAssetName(getStringValue(fieldsMap,"资产名称"));
|
|||
|
|
assetsItem.setAddress(getStringValue(fieldsMap,"位置详情"));
|
|||
|
|
String certNo = fieldsMap.get("权证号码") == null ? null : (String)fieldsMap.get("权证号码");
|
|||
|
|
// assetsItem.setManager(fieldsMap.get("运营单位") == null ? null : (String)fieldsMap.get("运营单位") + "");
|
|||
|
|
Long managerId = fieldsMap.get("运营单位") == null ? null : Long.parseLong(fieldsMap.get("运营单位") + "");
|
|||
|
|
assetsItem.setLat(getStringValue(fieldsMap,"纬度"));
|
|||
|
|
assetsItem.setLng(getStringValue(fieldsMap,"经度"));
|
|||
|
|
assetsItem.setManager(getDeptName(managerId));
|
|||
|
|
assetsItem.setCertNo(certNo);
|
|||
|
|
assetsItem.setStatus(getStringValue(fieldsMap,"资产状态"));
|
|||
|
|
return assetsItem;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private String getStringValue(Map<String, Object> fieldsMap, String key) {
|
|||
|
|
return fieldsMap.get(key) == null ? null : (String)fieldsMap.get(key);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public Integer countAssets(String type) throws BusinessException {
|
|||
|
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
|||
|
|
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
|
|||
|
|
if(type == null || "0".equals(type)) {
|
|||
|
|
conditions = null;
|
|||
|
|
}
|
|||
|
|
if("1".equals(type)) {
|
|||
|
|
conditions.add(FormWhereCondition.build().display("资产状态").value(EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"资产状态","已租")));
|
|||
|
|
}
|
|||
|
|
if("2".equals(type)) {
|
|||
|
|
conditions.add(FormWhereCondition.build().display("资产状态").value(EnumMapUtils.getEnumItemValueByDisplayValue(tableContext.getTableBean(),"资产状态","待租")));
|
|||
|
|
}
|
|||
|
|
List<FormColumn> formColumns = FormTableExecutor.query(tableContext,null, conditions, true);
|
|||
|
|
return formColumns.size();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public List<AssetsItem> queryAssetsByKeyword(String keyword) throws BusinessException {
|
|||
|
|
List<FormWhereCondition> conditions = new ArrayList<FormWhereCondition>();
|
|||
|
|
if(StringUtils.isNotBlank(keyword)){
|
|||
|
|
conditions.add(FormWhereCondition.build().display("位置详情").value(keyword).concatFactor(ClauseFactor.OR).clauseFactor(ClauseFactor.LIKE));
|
|||
|
|
}
|
|||
|
|
TableContext tableContext = FormTableExecutor.master(getFormNo());
|
|||
|
|
List<FormColumn> formColumns = FormTableExecutor.pageQuery(tableContext,null, conditions, 1,10,true);
|
|||
|
|
List<AssetsItem> assetsItems = new ArrayList<AssetsItem>();
|
|||
|
|
for (FormColumn formColumn : formColumns) {
|
|||
|
|
AssetsItem assetsItem = buildAssetsItem(formColumn.getFieldsMap());
|
|||
|
|
assetsItems.add(assetsItem);
|
|||
|
|
}
|
|||
|
|
return assetsItems;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|