Browse Source

增加关注状态及事务控制

koul 5 years ago
parent
commit
2cb88c3032

+ 15 - 6
src/main/java/com/uas/entity/Business.java

@@ -3,6 +3,7 @@ package com.uas.entity;
 import com.alibaba.fastjson.annotation.JSONField;
 
 import javax.persistence.*;
+import java.util.Date;
 
 /**
  * @author koul
@@ -115,16 +116,24 @@ public class Business {
     private String fb_qrdgsj;
     @JSONField(name = "首席代表")
     private String fb_chiefrepresentative;
+    private String fb_gzstatus;
+    private Date fb_gxdate;
 
-   /* private FBBusinessDetail 注册地;
+    public Date getFb_gxdate() {
+        return fb_gxdate;
+    }
+
+    public void setFb_gxdate(Date fb_gxdate) {
+        this.fb_gxdate = fb_gxdate;
+    }
 
-    public FBBusinessDetail get注册地() {
-        return 注册地;
+    public String getFb_gzstatus() {
+        return fb_gzstatus;
     }
 
-    public void set注册地(FBBusinessDetail 注册地) {
-        this.注册地 = 注册地;
-    }*/
+    public void setFb_gzstatus(String fb_gzstatus) {
+        this.fb_gzstatus = fb_gzstatus;
+    }
 
     public Long getFb_id() {
         return fb_id;

+ 3 - 36
src/main/java/com/uas/service/CustomerService.java

@@ -11,44 +11,11 @@ import java.util.List;
  * @date 2020-10-27 9:00
  */
 public interface CustomerService {
-    /**
-     * 获取所有群组资料
-     * @return
-     */
-   /* List<Group> getGroupAll();*/
 
-    List<String> getFollowingByGroup();
+    List<String> getFollowingByGroup()  throws Exception;
 
-    void saveBusiness(String company_id);
+    void saveBusiness(String company_id) throws Exception;
 
-    /*void saveBusinessChange(String company_id);
-
-    void saveInvestor(String company_id);
-
-    void saveMember(String company_id);
-
-    void saveKtgg(String company_id);
-
-    void saveCpws(String company_id);
-
-    void saveExecutedPerson(String company_id);
-
-    void saveSxbzxr(String company_id);
-
-    void saveJyyc(String company_id);
-
-    void saveSswf(String company_id);
-
-    void saveQsjl(String company_id);
-
-    void saveDcdy(String company_id);
-
-    void saveGqcz(String company_id);
-
-    void saveSfxz(String company_id);
-
-    void saveSsgg(String company_id);*/
-
-    /* void deleteAll();*/
+    void updateGZStatus(List<String> list);
 
 }

+ 108 - 88
src/main/java/com/uas/service/Impl/CustomerServiceImpl.java

@@ -13,11 +13,9 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @author koul
@@ -93,7 +91,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 获取所有分组
      * @return
      */
-    private List<Group> getGroupAll(){
+    private List<Group> getGroupAll() throws Exception{
         Map<String, String> param = new HashMap<>();
         param.put("apikey",apikey);
         String group = httpResponse(url + httpConfig.get("group"), hender, param);
@@ -108,7 +106,7 @@ public class CustomerServiceImpl implements CustomerService {
      * @return
      */
     @Override
-    public List<String> getFollowingByGroup() {
+    public List<String> getFollowingByGroup()  throws Exception {
         Map<String, String> param = new HashMap<>();
         param.put("apikey",apikey);
         param.put("from",Integer.toString(0));
@@ -135,21 +133,24 @@ public class CustomerServiceImpl implements CustomerService {
      * @param company_id
      */
     @Async("taskExecutor")
+    @Transactional(rollbackFor=Exception.class)
     @Override
-    public void saveBusiness(String company_id) {
+    public void saveBusiness(String company_id) throws Exception{
         deleteByCompanyId(company_id);
         Map<String, String> param = new HashMap<>();
-        param.put("apikey",apikey);
+        param.put("apikey", apikey);
         String s = httpResponse(url + company + "/" + company_id, hender, param);
-        if (s!=null){
+        if (s != null) {
             Business business = JSON.parseObject(s, Business.class);
+            business.setFb_gzstatus("正在关注");
+            business.setFb_gxdate(new Date());
             business.setFb_evaluation(stringArraytoString(business.getFb_evaluation()));
             business.setFb_oldname(stringArraytoString(business.getFb_oldname()));
             Business save = businessDao.save(business);
             Long fb_id = save.getFb_id();
             JSONObject jsonObject = JSONObject.parseObject(s);
             Object objzcd = jsonObject.get("注册地");
-            if (objzcd!=null) {
+            if (objzcd != null) {
                 BusinessDetail zcd = JSON.parseObject(objzcd.toString(), BusinessDetail.class);
                 zcd.setFbd_fbid(fb_id);
                 zcd.setFbd_type("注册地");
@@ -157,7 +158,7 @@ public class CustomerServiceImpl implements CustomerService {
                 businessDetailDao.save(zcd);
             }
             Object objjyd = jsonObject.get("经营地");
-            if (objjyd!=null) {
+            if (objjyd != null) {
                 BusinessDetail zcd = JSON.parseObject(objjyd.toString(), BusinessDetail.class);
                 zcd.setFbd_fbid(fb_id);
                 zcd.setFbd_type("经营地");
@@ -165,33 +166,34 @@ public class CustomerServiceImpl implements CustomerService {
                 businessDetailDao.save(zcd);
             }
             Object objgp = jsonObject.get("股票");
-            if (objgp!=null&&!"[]".equals(objgp.toString())) {
+            if (objgp != null && !"[]".equals(objgp.toString())) {
                 List<BusinessDetail> gps = JSON.parseArray(objgp.toString(),
                         BusinessDetail.class);
-                int detno=1;
-                for (BusinessDetail gp:gps) {
+                int detno = 1;
+                for (BusinessDetail gp : gps) {
                     gp.setFbd_fbid(fb_id);
                     gp.setFbd_type("股票");
                     gp.setFbd_detno(detno);
-                    detno=detno+1;
+                    detno = detno + 1;
                 }
                 businessDetailDao.save(gps);
             }
-            saveBusinessChange(company_id,fb_id);
-            saveInvestor(company_id,fb_id);
-            saveMember(company_id,fb_id);
-            saveKtgg(company_id,fb_id);
-            saveCpws(company_id,fb_id);
-            saveExecutedPerson(company_id,fb_id);
-            saveSxbzxr(company_id,fb_id);
-            saveJyyc(company_id,fb_id);
-            saveSswf(company_id,fb_id);
-            saveQsjl(company_id,fb_id);
-            saveDcdy(company_id,fb_id);
-            saveGqcz(company_id,fb_id);
-            saveSfxz(company_id,fb_id);
-            saveSsgg(company_id,fb_id);
-            saveDanbao(company_id,fb_id);
+        saveBusinessChange(company_id,fb_id);
+        saveInvestor(company_id,fb_id);
+        saveMember(company_id,fb_id);
+        saveKtgg(company_id,fb_id);
+        saveCpws(company_id,fb_id);
+        saveExecutedPerson(company_id,fb_id);
+        saveSxbzxr(company_id,fb_id);
+        saveJyyc(company_id,fb_id);
+        saveSswf(company_id,fb_id);
+        saveQsjl(company_id,fb_id);
+        saveDcdy(company_id,fb_id);
+        saveGqcz(company_id,fb_id);
+        saveSfxz(company_id,fb_id);
+        saveSsgg(company_id,fb_id);
+        saveDanbao(company_id,fb_id);
+        baseDao.execute("update customer set cu_gzstatus='正在关注' where cu_name in (select fb_name from fbbusiness where fb_tyshxycode='"+company_id+"')");
         }
     }
 
@@ -200,7 +202,7 @@ public class CustomerServiceImpl implements CustomerService {
      * @param company_id
      */
    /*@Async("taskExecutor")*/
-    private void saveBusinessChange(String company_id,Long id) {
+    private void saveBusinessChange(String company_id,Long id) throws Exception{
         JSONArray gsbg = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gsbg"),
                 apikey, size, hender, params);
         if(gsbg!=null) {
@@ -222,7 +224,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存工商登记股东信息
      * @param company_id
      */
-    private void saveInvestor(String company_id,Long id) {
+    private void saveInvestor(String company_id,Long id) throws Exception{
         JSONArray objects = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("investor")
                 , apikey, size, hender, params);
         if (objects!=null) {
@@ -269,7 +271,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存主要成员
      * @param company_id
      */
-    private void saveMember(String company_id,Long id) {
+    private void saveMember(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("member")
                 , apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -286,7 +288,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存开庭公告
      * @param company_id
      */
-    private void saveKtgg(String company_id,Long id) {
+    private void saveKtgg(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ktgg")
                 , apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -334,7 +336,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存裁判文书
      * @param company_id
      */
-   private void saveCpws(String company_id,Long id) {
+   private void saveCpws(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("cpws"), apikey, size, hender, params);
         if (jsonArray!=null) {
             int detno=1;
@@ -404,7 +406,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存被执行人
      * @param company_id
      */
-    private void saveExecutedPerson(String company_id,Long id) {
+    private void saveExecutedPerson(String company_id,Long id) throws Exception{
         JSONArray zhixing = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("zhixing"), apikey, size, hender, params);
         if (zhixing!=null) {
             List<ExecutedPerson> executedPersonList = JSON.parseArray(zhixing.toString(), ExecutedPerson.class);
@@ -421,7 +423,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存失信被执行人
      * @param company_id
      */
-    private void saveSxbzxr(String company_id,Long id) {
+    private void saveSxbzxr(String company_id,Long id) throws Exception{
         JSONArray shixin = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("shixin"), apikey, size, hender, params);
         if (shixin!=null) {
             List<Sxbzxr> sxbzxrs = JSON.parseArray(shixin.toString(), Sxbzxr.class);
@@ -437,7 +439,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存经营异常
      * @param company_id
      */
-    private void saveJyyc(String company_id,Long id) {
+    private void saveJyyc(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("jyyc"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -454,7 +456,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存重大税收违法
      * @param company_id
      */
-    private void saveSswf(String company_id,Long id) {
+    private void saveSswf(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sswf"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -471,7 +473,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存催缴/欠税
      * @param company_id
      */
-    private void saveQsjl(String company_id,Long id) {
+    private void saveQsjl(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("qsjl"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -488,7 +490,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存动产抵押
      * @param company_id
      */
-    private void saveDcdy(String company_id,Long id) {
+    private void saveDcdy(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("dcdy"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -525,7 +527,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存股权出质
      * @param company_id
      */
-    private void saveGqcz(String company_id,Long id) {
+    private void saveGqcz(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("gqcz"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -542,7 +544,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存司法协助
      * @param company_id
      */
-    private void saveSfxz(String company_id,Long id) {
+    private void saveSfxz(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("sfxz"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -559,7 +561,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存涉诉公告
      * @param company_id
      */
-    private void saveSsgg(String company_id,Long id) {
+    private void saveSsgg(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("ssgg"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -578,7 +580,7 @@ public class CustomerServiceImpl implements CustomerService {
      * 保存担保
      * @param company_id
      */
-    private void saveDanbao(String company_id,Long id) {
+    private void saveDanbao(String company_id,Long id) throws Exception{
         JSONArray jsonArray = httpResponseBySize(url + company + "/" + company_id + "/" + httpConfig.get("danbao"),
                 apikey, size, hender, params);
         if (jsonArray!=null) {
@@ -599,6 +601,17 @@ public class CustomerServiceImpl implements CustomerService {
         }
     }
 
+    /**
+     * 更新客户关注状态为已取消关注
+     */
+    @Override
+    public void updateGZStatus(List<String> list){
+        if (list!=null&&list.size()>0) {
+            baseDao.execute("update fbbusiness set fb_gzstatus='已取消关注' where fb_tyshxycode not in (" + list2String(list) + ")");
+            baseDao.execute("update customer set cu_gzstatus='已取消关注' where cu_name in (select fb_name from fbbusiness where fb_tyshxycode not in (" + list2String(list) + "))");
+        }
+    }
+
 
     /**
      * 清除所有相关表中数据
@@ -658,19 +671,16 @@ public class CustomerServiceImpl implements CustomerService {
      * @param param
      * @return
      */
-    private String httpResponse(String url,HashMap<String,String> hend,Map<String,String> param){
+    private String httpResponse(String url,HashMap<String,String> hend,Map<String,String> param) throws Exception{
         logger.info(url +"?apikey="+apikey+"  参数:"+param.toString());
-        try {
-            HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
-            int statusCode = response.getStatusCode();
-            logger.info(Integer.toString(statusCode));
-            if (statusCode==200) {
-                return response.getResponseText();
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
+        HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
+        int statusCode = response.getStatusCode();
+        logger.info(Integer.toString(statusCode));
+        if (statusCode==200) {
+            return response.getResponseText();
+        }else{
+            throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText());
         }
-        return null;
     }
 
     /**
@@ -680,47 +690,47 @@ public class CustomerServiceImpl implements CustomerService {
      * @param param
      * @return
      */
-    private JSONArray httpResponseBySize(String url,String apikey,int size,HashMap<String,String> hend, Map<String,
-            String> param){
+    private JSONArray httpResponseBySize(String url,String apikey,int size,HashMap<String,String> hend, Map<String, String> param) throws Exception{
         logger.info(url +"?apikey="+apikey+"  参数:"+param.toString());
         JSONArray jsonArray=null;
-        try {
-            HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
-            int statusCode = response.getStatusCode();
-            logger.info(Integer.toString(statusCode));
-            if (statusCode==200) {
-                String responseText = response.getResponseText();
-                if (responseText != null) {
-                    JSONObject jsonObject = JSON.parseObject(responseText);
-                    int total = Integer.parseInt(jsonObject.get("total").toString());
-                    if (total>0) {
-                        Object hits = jsonObject.get("hits");
-                        jsonArray = JSON.parseArray(hits.toString());
-                        if (total > size) {
-                            Map<String, String> map = new HashMap<>();
-                            map.put("apikey", apikey);
-                            for (int i = size; i < total; i += size) {
-                                map.put("from", Integer.toString(i));
-                                map.put("size", Integer.toString(size));
-                                HttpUtil.Response response1 = HttpUtil.sendGetRequest(url, hend, map);
-                                int status = response1.getStatusCode();
-                                if (status == 200) {
-                                    String s = response1.getResponseText();
-                                    if (s != null) {
-                                        Object hits1 = JSON.parseObject(s).get("hits");
-                                        JSONArray array = JSON.parseArray(hits1.toString());
-                                        jsonArray.addAll(array);
-                                    }
+        HttpUtil.Response response = HttpUtil.sendGetRequest(url, hend, param);
+        int statusCode = response.getStatusCode();
+        logger.info(Integer.toString(statusCode));
+        if (statusCode==200) {
+            String responseText = response.getResponseText();
+            if (responseText != null) {
+                JSONObject jsonObject = JSON.parseObject(responseText);
+                int total = Integer.parseInt(jsonObject.get("total").toString());
+                if (total>0) {
+                    Object hits = jsonObject.get("hits");
+                    jsonArray = JSON.parseArray(hits.toString());
+                    if (total > size) {
+                        Map<String, String> map = new HashMap<>();
+                        map.put("apikey", apikey);
+                        for (int i = size; i < total; i += size) {
+                            map.put("from", Integer.toString(i));
+                            map.put("size", Integer.toString(size));
+                            HttpUtil.Response response1 = HttpUtil.sendGetRequest(url, hend, map);
+                            int status = response1.getStatusCode();
+                            if (status == 200) {
+                                String s = response1.getResponseText();
+                                if (s != null) {
+                                    Object hits1 = JSON.parseObject(s).get("hits");
+                                    JSONArray array = JSON.parseArray(hits1.toString());
+                                    jsonArray.addAll(array);
                                 }
+                            }else {
+                                throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText());
                             }
                         }
                     }
                 }
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+            return jsonArray;
+        } else{
+            logger.error("接口状态:"+statusCode+",返回内容:"+response.getResponseText());
+            throw new Exception("接口状态:"+statusCode+",返回内容:"+response.getResponseText());
         }
-        return jsonArray;
     }
 
     /**
@@ -740,6 +750,16 @@ public class CustomerServiceImpl implements CustomerService {
     return str.substring(0,str.length()-1);
 }
 
+private String list2String(List<String> list){
+    StringBuffer str = new StringBuffer();
+    for (int i = 0; i < list.size(); i++) {
+        if (i > 0) {
+            str.append(",");
+        }
 
+        str.append("'").append(list.get(i)).append("'");
+    }
+    return str.toString();
+}
 
 }

+ 14 - 8
src/main/java/com/uas/task/ScheduleTask.java

@@ -25,15 +25,21 @@ public class ScheduleTask {
      * 保存客户资料
      */
     public void saveFbCustomer() {
-
-        logger.info("保存客户资料开始");
-        Date date = new Date();
-        List<String> following = customerService.getFollowingByGroup();
-        if (following != null) {
-            for (String s : following) {
-                customerService.saveBusiness(s);
+        try {
+            logger.info("保存客户资料开始");
+            Date date = new Date();
+            List<String> following = customerService.getFollowingByGroup();
+            customerService.updateGZStatus(following);
+            if (following != null) {
+                for (String s : following) {
+                    customerService.saveBusiness(s);
+                }
             }
+            logger.info("保存客户资料结束:用时" + ((System.currentTimeMillis() - date.getTime()) / 1000));
+        } catch (Exception e) {
+            logger.error(e.getMessage());
+            e.printStackTrace();
         }
-        logger.info("保存客户资料结束:用时" + ((System.currentTimeMillis() - date.getTime()) / 1000));
+
     }
 }