Просмотр исходного кода

提交企业统计数据接口

liwh 1 год назад
Родитель
Сommit
9a78be7fd3

+ 4 - 0
cql-service/src/main/java/cn/com/taiji/cql/service/IECqlService.java

@@ -2,6 +2,8 @@ package cn.com.taiji.cql.service;
 
 
 import cn.com.taiji.common.domain.PageResult;
+import cn.com.taiji.common.domain.Result;
+import org.geotools.api.feature.FeatureVisitor;
 
 import java.util.List;
 import java.util.Map;
@@ -10,4 +12,6 @@ public interface IECqlService {
 
 
     PageResult cqlQuery4Mysql(Map<String, Object> mapParams, String cql, Map<String,Object> sortMaps, Map<String, Object> pageParams);
+
+    void cqlAggQuery4Mysql(Map<String, Object> mapParams, String cql, FeatureVisitor visitor);
 }

+ 54 - 0
cql-service/src/main/java/cn/com/taiji/cql/service/impl/ECqlServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.com.taiji.cql.service.impl;
 import cn.com.taiji.common.domain.PageResult;
+import cn.com.taiji.common.domain.Result;
 import cn.com.taiji.common.enums.CommonConstant;
 import cn.com.taiji.cql.service.IECqlService;
 import lombok.extern.slf4j.Slf4j;
@@ -7,6 +8,7 @@ import org.geotools.api.data.DataStore;
 import org.geotools.api.data.DataStoreFinder;
 import org.geotools.api.data.Query;
 import org.geotools.api.data.SimpleFeatureSource;
+import org.geotools.api.feature.FeatureVisitor;
 import org.geotools.api.feature.simple.SimpleFeature;
 import org.geotools.api.feature.type.AttributeDescriptor;
 import org.geotools.api.filter.Filter;
@@ -226,4 +228,56 @@ public class ECqlServiceImpl implements IECqlService{
 
 
     }
+
+    @Override
+    public void cqlAggQuery4Mysql(Map<String, Object> mapParams, String cql, FeatureVisitor visitor) {
+
+        String host = mapParams.get(JDBCDataStoreFactory.HOST.key).toString();
+
+        String database = mapParams.get(JDBCDataStoreFactory.DATABASE.key).toString();
+
+        DataStore dataStore = null;
+
+        try{
+
+            dataStore = DataStoreFinder.getDataStore(mapParams);
+
+            if (dataStore != null) {
+
+                log.info("系统连接到位于:" + host + "的空间数据库" + database + "成功!");
+
+                Query query = new Query();
+
+                if(cql !=null && !"".equals(cql)){
+
+                    Filter filter = ECQL.toFilter(cql);
+
+                    query.setFilter(filter);
+
+                }
+
+                //根据表名获取source
+                SimpleFeatureSource fSource = dataStore.getFeatureSource(mapParams.get("tableName").toString());
+
+                SimpleFeatureCollection simpleFeatureCollection =fSource.getFeatures(query);
+
+                simpleFeatureCollection.accepts(visitor,null);
+
+            }
+
+
+        }catch (Exception e) {
+
+            e.printStackTrace();
+            log.error("系统连接到位于:" + mapParams.get(JDBCDataStoreFactory.HOST.key) + "的空间数据库" + mapParams.get(JDBCDataStoreFactory.DATABASE.key) + "失败!请检查相关参数");
+
+        }finally {
+
+            if(dataStore !=null){
+
+                dataStore.dispose();
+
+            }
+        }
+    }
 }

+ 12 - 0
tile-web/src/main/java/cn/com/taiji/web/controller/EnterpriseController.java

@@ -55,6 +55,18 @@ public class EnterpriseController {
         return enterpriseService.deviceQuery(deviceVo);
     }
 
+    /**
+     * 企业数量统计
+     * @return
+     * @throws Exception
+     */
+
+    @PostMapping("/staticsQuery")
+    public Result staticsQuery() throws Exception {
+
+        return enterpriseService.staticsQuery();
+    }
+
 
 
 }

+ 53 - 0
tile-web/src/main/java/cn/com/taiji/web/model/StaticsInfo.java

@@ -0,0 +1,53 @@
+package cn.com.taiji.web.model;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class StaticsInfo implements Serializable {
+
+
+    /**
+     * 预警总数
+     */
+    private int alertCount=0;
+
+    /**
+     * 企业总数
+     */
+    private int count;
+
+    /**
+     * 零关税自用进口生产设备
+     */
+    private int deviceCount;
+
+    /**
+     * 零关税自用进口生产设备占比
+     */
+    private BigDecimal deviceRate;
+
+    /**
+     * 加工增值免关税
+     */
+    private int noTaxCount;
+
+    /**
+     * 加工增值免关税占比
+     */
+    private BigDecimal noTaxRate;
+
+    /**
+     * 零关税进口原辅料
+     */
+    private int materialCount;
+
+    /**
+     * 零关税进口原辅料占比
+     */
+    private BigDecimal materialRate;
+
+
+}

+ 6 - 2
tile-web/src/main/java/cn/com/taiji/web/service/IEnterpriseService.java

@@ -6,8 +6,6 @@ import cn.com.taiji.web.vo.DeviceVo;
 import cn.com.taiji.web.vo.EnterpriseVo;
 import org.springframework.web.bind.annotation.RequestBody;
 
-import java.util.Map;
-
 public interface IEnterpriseService {
 
     /**
@@ -25,4 +23,10 @@ public interface IEnterpriseService {
      */
 
     Result deviceQuery(@RequestBody DeviceVo deviceVo);
+
+    /**
+     * 企业数据统计
+     * @return
+     */
+    Result staticsQuery();
 }

+ 83 - 6
tile-web/src/main/java/cn/com/taiji/web/service/impl/EnterpriseServiceImpl.java

@@ -6,19 +6,20 @@ import cn.com.taiji.cql.model.GeoDataSource;
 import cn.com.taiji.cql.service.IECqlService;
 import cn.com.taiji.web.config.EnterpriseConfig;
 import cn.com.taiji.web.model.DeviceInfo;
+import cn.com.taiji.web.model.StaticsInfo;
 import cn.com.taiji.web.service.IEnterpriseService;
 import cn.com.taiji.web.vo.DeviceVo;
 import cn.com.taiji.web.vo.EnterpriseVo;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
+import org.geotools.feature.visitor.CountVisitor;
 import org.geotools.jdbc.JDBCDataStoreFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
 
 @Slf4j
 @Service
@@ -62,12 +63,14 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
 
         if(enterpriseVo.getEntType() !=null && !"".equals(enterpriseVo.getEntType())){
 
+            String result = transEntTypeListToSqlString(Arrays.asList(enterpriseVo.getEntType().split(",")));
+
             if(filterCql.length() >0){
 
-                filterCql.append(" and (qykx = '"+enterpriseVo.getEntType()+"')");
+                filterCql.append(" and (qykx in ("+result+"))");
             }else{
 
-                filterCql.append(" (qykx = '"+enterpriseVo.getEntType()+"')");
+                filterCql.append(" (qykx in ("+result+"))");
             }
 
         }
@@ -77,6 +80,21 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
         return ecqlService.cqlQuery4Mysql(entDsParams,filterCql.toString(),sortParams,pageParams);
     }
 
+    public String transEntTypeListToSqlString(List<String> entTypeList) {
+
+        StringBuilder sqlString = new StringBuilder();
+
+        for(String item:entTypeList){
+
+            sqlString.append("'"+item+"',");
+
+        }
+
+        String result = sqlString.toString();
+
+        return result.substring(0,result.lastIndexOf(","));
+    }
+
     @Override
     public Result deviceQuery(DeviceVo deviceVo) {
 
@@ -129,4 +147,63 @@ public class EnterpriseServiceImpl implements IEnterpriseService {
 
 
     }
+
+    @Override
+    public Result staticsQuery() {
+
+        //数据源
+        Map<String, Object> entDsParams = new HashMap<String, Object>();
+        entDsParams.put(JDBCDataStoreFactory.DATABASE.key, enterpriseConfig.getDsBaseName());
+        entDsParams.put(JDBCDataStoreFactory.DBTYPE.key, enterpriseConfig.getDbType());
+
+        entDsParams.put(JDBCDataStoreFactory.HOST.key, enterpriseConfig.getDsIp());
+        entDsParams.put(JDBCDataStoreFactory.PORT.key, enterpriseConfig.getDsPort());
+        entDsParams.put(JDBCDataStoreFactory.USER.key, enterpriseConfig.getDsUserName());
+        entDsParams.put(JDBCDataStoreFactory.PASSWD.key, enterpriseConfig.getDsPassword());
+        entDsParams.put("tableName", enterpriseConfig.getEnterprise());
+
+        //计算企业总数
+
+        CountVisitor countVisitor = new CountVisitor();
+        ecqlService.cqlAggQuery4Mysql(entDsParams,null,countVisitor);
+
+        //计算零关税自用进口生产设备数量
+        CountVisitor deviceCountVisitor = new CountVisitor();
+        String cqlDevice = "(qykx ='零关税自用进口生产设备')";
+        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlDevice,deviceCountVisitor);
+
+        //计算零关税进口原辅料数量
+        CountVisitor materialCountVisitor = new CountVisitor();
+        String cqlMaterial = "(qykx ='零关税进口原辅料')";
+        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlMaterial,materialCountVisitor);
+
+        //计算加工增值免关税数量
+        CountVisitor noTaxCountVisitor = new CountVisitor();
+        String cqlNoTax = "(qykx ='加工增值免关税')";
+        ecqlService.cqlAggQuery4Mysql(entDsParams,cqlNoTax,noTaxCountVisitor);
+
+        StaticsInfo staticsInfo = new StaticsInfo();
+        staticsInfo.setCount(countVisitor.getCount());
+        staticsInfo.setDeviceCount(deviceCountVisitor.getCount());
+        staticsInfo.setMaterialCount(materialCountVisitor.getCount());
+        staticsInfo.setNoTaxCount(noTaxCountVisitor.getCount());
+
+        if(countVisitor.getCount()>0){
+
+            BigDecimal deviceRate = new BigDecimal(deviceCountVisitor.getCount()).divide(new BigDecimal(countVisitor.getCount())).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
+
+            staticsInfo.setDeviceRate(deviceRate.stripTrailingZeros());
+
+            BigDecimal materialRate = new BigDecimal(materialCountVisitor.getCount()).divide(new BigDecimal(countVisitor.getCount())).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
+            staticsInfo.setMaterialRate(materialRate.stripTrailingZeros());
+
+            BigDecimal noTaxRate = new BigDecimal(noTaxCountVisitor.getCount()).divide(new BigDecimal(countVisitor.getCount())).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
+
+            staticsInfo.setNoTaxRate(noTaxRate.stripTrailingZeros());
+
+        }
+
+
+        return Result.of(staticsInfo,0,"操作成功!");
+    }
 }