IntelligentRecognition/ah-jjsp-service/.svn/pristine/1c/1c6474dfd4714f179517a1d34ce...

335 lines
15 KiB
Plaintext

package com.sercurityControl.proteam.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.securityControl.common.core.exception.ServiceException;
import com.securityControl.common.core.utils.DateUtils;
import com.securityControl.common.core.utils.StringUtils;
import com.sercurityControl.proteam.domain.TRiskPressDropRate;
import com.sercurityControl.proteam.domain.dto.RiskDelParamDto;
import com.sercurityControl.proteam.domain.vo.BaseVo;
import com.sercurityControl.proteam.mapper.TRiskPressDropRateMapper;
import com.sercurityControl.proteam.service.TRiskPressDropRateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.NumberFormat;
import java.util.*;
/**
* 风险压降率表(TRiskPressDropRate)表服务实现类
*
* @author makejava
* @since 2022-12-06 11:05:42
*/
@Slf4j
@Service
public class TRiskPressDropRateServiceImpl implements TRiskPressDropRateService {
@Autowired
private TRiskPressDropRateMapper tRiskPressDropRateMapper;
/**
* 通过ID查询单条数据
*
* @param proName 主键
* @return 实例对象
*/
@Override
public TRiskPressDropRate queryById(String proName) {
return this.tRiskPressDropRateMapper.queryById(proName);
}
/**
* 通过主键删除数据
*
* @param proName 主键
* @return 是否成功
*/
@Override
public void deleteById(String proName) {
tRiskPressDropRateMapper.deleteById(proName);
}
@Override
public String importData(List<JSONObject> objectList, String cityName, String downloadPath) {
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
int successNum = 0;
int failureNum = 0;
for (JSONObject obj : objectList) {
if (StringUtils.isBlank(obj.getString("proName"))) {
failureNum++;
failureMsg.append("第").append(obj.getString("rowNo")).append("行无工程名称;").append("<br/>");
continue;
}
if (StringUtils.isBlank(obj.getString("tower"))) {
failureNum++;
failureMsg.append("第").append(obj.getString("rowNo")).append("行无塔号;").append("<br/>");
continue;
}
try {
TRiskPressDropRate pressDropRate = buildObj(obj, cityName);
pressDropRate.setCreateTime(DateUtils.getNowDate());
pressDropRate.setUpdateTime(DateUtils.getNowDate());
tRiskPressDropRateMapper.addOrUpdateRisk(pressDropRate);
successNum++;
} catch (Exception e) {
failureNum++;
String msg = "第" + obj.getString("rowNo") + "行导入失败!" + "工程名称为: " + obj.getString("proName") + "<br/>";
failureMsg.append(msg).append(e.getMessage());
//log.error(msg, e);
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new ServiceException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据导入成功!共 " + objectList.size() + " 条,导入成功" + successNum + "条");
}
return successMsg.toString();
}
@Override
public List<BaseVo> getProNameList(String cityName) {
List<String> cityNameList = null;
if (StringUtils.isNotEmpty(cityName)) {
String[] cityNameArr = cityName.split(",");
cityNameList = Arrays.asList(cityNameArr);
}
return tRiskPressDropRateMapper.getProNameList(cityNameList);
}
@Override
public void delProList(RiskDelParamDto paramDto) {
tRiskPressDropRateMapper.delProList(paramDto.getType(), paramDto.getName());
}
@Override
public List<TRiskPressDropRate> getRiskBloodList(TRiskPressDropRate pressDropRate) {
List<String> cityNameList = null, proNameList = null;
String cityName = pressDropRate.getCityName();
if (StringUtils.isNotEmpty(cityName)) {
String[] cityNameArr = cityName.split(",");
cityNameList = Arrays.asList(cityNameArr);
}
String proName = pressDropRate.getProName();
if (StringUtils.isNotEmpty(proName)) {
String[] proNameArr = proName.split(",");
proNameList = Arrays.asList(proNameArr);
}
return tRiskPressDropRateMapper.getRiskBloodList(pressDropRate, cityNameList, proNameList);
}
@Override
public List<Map<String, Object>> getRiskDropRate(TRiskPressDropRate o) {
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> provinceMap = new HashMap<>(16);
Map<String, Object> currentQueryMap = new HashMap<>(16);
Map<String, Object> currentQueryComplexMap = new HashMap<>(16);
// 全省压降率
int totalNum = 0, num = 0;
List<Map<String, Object>> provinceList = tRiskPressDropRateMapper.getProvinceRiskDropRate();
for (Map<String, Object> map : provinceList) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (Objects.equals("TOTALNUM", entry.getKey())) {
totalNum += Integer.parseInt(String.valueOf(entry.getValue()));
}
if (Objects.equals("NUM", entry.getKey())) {
num += Integer.parseInt(String.valueOf(entry.getValue()));
}
}
}
String calculate = calculate(num, totalNum);
provinceMap.put("totalNum", totalNum);
provinceMap.put("num", num);
provinceMap.put("calculate", calculate);
list.add(provinceMap);
// 当前查询压降率计算结果
int currentTotalNum = 0, basicNum = 0, towNum = 0, wireNum = 0;
List<String> cityNameList = null, proNameList = null;
String cityName = o.getCityName();
if (StringUtils.isNotEmpty(cityName)) {
String[] cityNameArr = cityName.split(",");
cityNameList = Arrays.asList(cityNameArr);
}
String proName = o.getProName();
if (StringUtils.isNotEmpty(proName)) {
String[] proNameArr = proName.split(",");
proNameList = Arrays.asList(proNameArr);
}
List<Map<String, Object>> currentQueryList = tRiskPressDropRateMapper.getCurrentQueryData(o, cityNameList, proNameList);
for (Map<String, Object> map : currentQueryList) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (Objects.equals("TOTALNUM", entry.getKey())) {
currentTotalNum += Integer.parseInt(String.valueOf(entry.getValue()));
}
if (Objects.equals("BASICNUM", entry.getKey())) {
basicNum += Integer.parseInt(String.valueOf(entry.getValue()));
}
if (Objects.equals("TOWNUM", entry.getKey())) {
towNum += Integer.parseInt(String.valueOf(entry.getValue()));
}
if (Objects.equals("WIRENUM", entry.getKey())) {
wireNum += Integer.parseInt(String.valueOf(entry.getValue()));
}
}
}
currentQueryMap.put("currentTotalNum", currentTotalNum);
currentQueryMap.put("currentTotalRate", calculate((basicNum + towNum + wireNum), currentTotalNum * 3));
currentQueryMap.put("currentBasicRate", calculate(basicNum, currentTotalNum));
currentQueryMap.put("currentTowerRate", calculate(towNum, currentTotalNum));
currentQueryMap.put("currentWireRate", calculate(wireNum, currentTotalNum));
list.add(currentQueryMap);
// 当前查询压降率综合计算结果
String workType = o.getWorkType();
if (StringUtils.isNotEmpty(workType)) {
List<String> workTypeList = Arrays.asList(workType.split(","));
if (workTypeList.contains("基础")) {
currentQueryComplexMap.put("currentBasic", basicNum);
currentQueryComplexMap.put("currentTower", 0);
currentQueryComplexMap.put("currentWire", 0);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate(basicNum, currentTotalNum));
currentQueryComplexMap.put("workType", "基础");
}
if (workTypeList.contains("组塔")) {
currentQueryComplexMap.put("currentBasic", 0);
currentQueryComplexMap.put("currentTower", towNum);
currentQueryComplexMap.put("currentWire", 0);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate(towNum, currentTotalNum));
currentQueryComplexMap.put("workType", "组塔");
}
if (workTypeList.contains("架线")) {
currentQueryComplexMap.put("currentBasic", 0);
currentQueryComplexMap.put("currentTower", 0);
currentQueryComplexMap.put("currentWire", wireNum);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate(wireNum, currentTotalNum));
currentQueryComplexMap.put("workType", "架线");
}
if (workTypeList.contains("基础") && workTypeList.contains("组塔")) {
currentQueryComplexMap.put("currentBasic", basicNum);
currentQueryComplexMap.put("currentTower", towNum);
currentQueryComplexMap.put("currentWire", 0);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate((basicNum + towNum), currentTotalNum * 2));
currentQueryComplexMap.put("workType", "基础,组塔");
}
if (workTypeList.contains("基础") && workTypeList.contains("架线")) {
currentQueryComplexMap.put("currentBasic", basicNum);
currentQueryComplexMap.put("currentTower", 0);
currentQueryComplexMap.put("currentWire", wireNum);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate((basicNum + wireNum), currentTotalNum * 2));
currentQueryComplexMap.put("workType", "基础,架线");
}
if (workTypeList.contains("组塔") && workTypeList.contains("架线")) {
currentQueryComplexMap.put("currentBasic", 0);
currentQueryComplexMap.put("currentTower", towNum);
currentQueryComplexMap.put("currentWire", wireNum);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate((towNum + wireNum), currentTotalNum * 2));
currentQueryComplexMap.put("workType", "组塔,架线");
}
if (workTypeList.contains("基础") && workTypeList.contains("组塔") && workTypeList.contains("架线")) {
currentQueryComplexMap.put("currentBasic", basicNum);
currentQueryComplexMap.put("currentTower", towNum);
currentQueryComplexMap.put("currentWire", wireNum);
currentQueryComplexMap.put("currentTotal", currentTotalNum);
currentQueryComplexMap.put("currentTotalRate", calculate((towNum + wireNum + basicNum), currentTotalNum * 3));
currentQueryComplexMap.put("workType", "基础,组塔,架线");
}
} else {
currentQueryComplexMap.put("currentBasic", 0);
currentQueryComplexMap.put("currentTower", 0);
currentQueryComplexMap.put("currentWire", 0);
currentQueryComplexMap.put("currentTotal", 0);
currentQueryComplexMap.put("currentTotalRate", "0%");
currentQueryComplexMap.put("workType", "");
}
list.add(currentQueryComplexMap);
return list;
}
/**
* @return java.lang.String
* @Author roof
* @Description 计算百分比
* @Date 14:47 2022/4/28
* @Param [num, count]
*/
public static String calculate(Integer num, Integer count) {
NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(2); //保留几位小数填写几
//注意需要将Integer转换为float进行计算
String percent = "";
if (count != 0) {
percent = numberFormat.format((float) num / (float) count * 100);
} else {
percent = "0";
}
return percent + "%";
}
private TRiskPressDropRate buildObj(JSONObject obj, String cityName) {
TRiskPressDropRate o = new TRiskPressDropRate();
o.setCityName(cityName);
o.setProName(obj.getString("proName"));
o.setTower(obj.getString("tower"));
o.setLon(obj.getString("lon"));
o.setLat(obj.getString("lat"));
o.setBasicBaseType(obj.getString("basicBaseType"));
o.setBasicWorkStyle(obj.getString("basicWorkStyle"));
o.setBasicRiskLevel(obj.getString("basicRiskLevel"));
o.setBasicOperProcedure(obj.getString("basicOperProcedure"));
o.setBasicAppMethod(obj.getString("basicAppMethod"));
o.setGroupTowerFullHeight(replaceStr(obj.getString("groupTowerFullHeight")));
o.setGroupTowerStyle(obj.getString("groupTowerStyle"));
o.setGroupTowerRiskLevel(obj.getString("groupTowerRiskLevel"));
o.setGroupTowerOperProcedure(obj.getString("groupTowerOperProcedure"));
o.setGroupTowerAppMethod(obj.getString("groupTowerAppMethod"));
o.setWireSpan(obj.getString("wireSpan"));
o.setWireStyle(obj.getString("wireStyle"));
o.setWireRiskLevel(obj.getString("wireRiskLevel"));
o.setWireOperProcedure(obj.getString("wireOperProcedure"));
o.setWireAppMethod(obj.getString("wireAppMethod"));
o.setRiskType(obj.getString("riskType"));
o.setRiskDetails(obj.getString("riskDetails"));
o.setRiskType2(obj.getString("riskType2"));
o.setRiskDetails2(obj.getString("riskDetails2"));
o.setRiskType3(obj.getString("riskType3"));
o.setRiskDetails3(obj.getString("riskDetails3"));
o.setRiskType4(obj.getString("riskType4"));
o.setRiskDetails4(obj.getString("riskDetails4"));
o.setRiskType5(obj.getString("riskType5"));
o.setRiskDetails5(obj.getString("riskDetails5"));
o.setLandFormPath(obj.getString("landFormPath"));
o.setSurroundingsPath(obj.getString("surroundingsPath"));
return o;
}
/**
* @return java.lang.String
* @Author roof
* @Description 替换字符串
* @Date 8:54 2022/5/21
* @Param []
*/
public static String replaceStr(String value) {
if(StringUtils.isBlank(value)){
return "";
}
if (value.contains("m")) {
return value.replaceAll("m", "");
} else if (value.contains("米")) {
return value.replaceAll("米", "");
} else {
return value;
}
}
}