From c06ba7626088b15fe8b69364da953ff3d4d9f577 Mon Sep 17 00:00:00 2001
From: chenjiahe <763432473@qq.com>
Date: 星期五, 24 十二月 2021 10:40:54 +0800
Subject: [PATCH] 新增用户划扣项目列表

---
 phi_platform_user/src/main/java/com/hx/phip/controller/user/ProjectController.java |   72 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/phi_platform_user/src/main/java/com/hx/phip/controller/user/ProjectController.java b/phi_platform_user/src/main/java/com/hx/phip/controller/user/ProjectController.java
index 004e7b7..cfa62da 100644
--- a/phi_platform_user/src/main/java/com/hx/phip/controller/user/ProjectController.java
+++ b/phi_platform_user/src/main/java/com/hx/phip/controller/user/ProjectController.java
@@ -6,19 +6,30 @@
 import com.hx.common.BaseController;
 import com.hx.mybatisTool.SqlSentence;
 import com.hx.phiappt.model.BaseEntity;
+import com.hx.phiappt.model.User;
+import com.hx.phip.config.HisParameter;
 import com.hx.phip.dao.mapper.EmployeeMapper;
+import com.hx.phip.dao.mapper.UserMapper;
 import com.hx.phip.entity.employee.EmployeeList;
 import com.hx.phip.entity.user.UserProjectList;
+import com.hx.phip.his.entity.ResponsesData;
+import com.hx.phip.his.tools.UserProjectUtil;
+import com.hx.phip.his.util.ApiUtil;
 import com.hx.util.HttpServletRequestUtil;
 import com.hx.util.StringUtils;
 import com.platform.exception.PlatTipsException;
 import com.platform.resultTool.PlatformCode;
 import com.platform.resultTool.PlatformResult;
+import net.sf.json.JSONArray;
 import org.apache.catalina.servlet4preview.http.HttpServletRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +43,13 @@
 @RestController
 @RequestMapping("/user/project")
 public class ProjectController extends BaseController {
+
+    //log4j鏃ュ織
+    private static Logger logger = LoggerFactory.getLogger(ProjectController.class.getName());
+
+
+    @Resource
+    private HisParameter hisParameter;
 
     /**
      * 鐢ㄦ埛璐拱椤圭洰鍒楄〃
@@ -56,6 +74,14 @@
             throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"鏁版嵁鏍煎紡閿欒");
         }
 
+        if(StringUtils.isEmpty(userProjectList.getUserId())){
+            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鐢ㄦ埛鏍囪瘑涓嶈兘涓虹┖锛�");
+        }
+        User user = commonService.selectOneByKey(UserMapper.class,userProjectList.getUserId());
+        if(user == null){
+            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"鐢ㄦ埛鏍囪瘑閿欒锛�");
+        }
+
         if (userProjectList.getPageNum() == null || userProjectList.getPageNum() <= 0) {
             userProjectList.setPageNum(1);
         }
@@ -63,16 +89,48 @@
             userProjectList.setPageSize(20);
         }
 
+        String token = ApiUtil.getPoiApiAccessToken(hisParameter.getPoiAppId(),hisParameter.getPoiCode(),hisParameter.getPoiSecret(),hisParameter.getUrlGetToken(),commonService);
+        ResponsesData responsesData = UserProjectUtil.projectItems(hisParameter.getProjectItem(), user.getApiId(), null, userProjectList.getPageNum(), userProjectList.getPageSize(), "executing", null, token);
 
+        net.sf.json.JSONObject data = new net.sf.json.JSONObject();
+        data.put("total", 0);
+        data.put("isLastPage", true);
 
-        Map<String,Object> data = new HashMap<>();
-        /*data.put("employeeList",pageInfo.getList());
-        data.put("total",pageInfo.getTotal());
-        data.put("pages",pageInfo.getPages());
-        data.put("pageNum",pageInfo.getPageNum());
-        data.put("pageSize",pageInfo.getPageSize());
-        data.put("isLastPage",pageInfo.isIsLastPage());*/
+        List<Map<String, Object>> projectList = new ArrayList<>();
+        if ("1000".equals(responsesData.getCode())) {
+
+            net.sf.json.JSONObject returnData = net.sf.json.JSONObject.fromObject(responsesData.getData());
+            JSONArray content = returnData.optJSONArray("content");
+            if (content == null) {
+                content = new JSONArray();
+            }
+
+            for (int i = 0; i < content.size(); i++) {
+                net.sf.json.JSONObject contentObj = content.getJSONObject(i);
+
+                Map<String, Object> projectObj = new HashMap<>();
+                projectObj.put("buyNum", contentObj.optInt("totalTimes"));
+                projectObj.put("execute", contentObj.optInt("leftTimes"));
+                projectObj.put("projectId", contentObj.optString("id"));
+                net.sf.json.JSONObject itemObj = contentObj.optJSONObject("item");
+                projectObj.put("name", itemObj.optString("name"));
+                projectObj.put("hisId", itemObj.optString("id"));
+
+                projectList.add(projectObj);
+            }
+
+            data.put("total", returnData.optInt("totalElements"));
+            data.put("isLastPage", returnData.optBoolean("last"));
+
+        } else {
+            logger.error("璇锋眰HIS鍑洪敊锛堣幏鍙栬鍗曚腑鐨勯」鐩潯鐩級:" + responsesData.toString());
+        }
+
+        data.put("list", projectList);
+        data.put("pageNum", userProjectList.getPageNum());
+        data.put("pageSize", userProjectList.getPageSize());
         return PlatformResult.success(data);
+
     }
 
 }

--
Gitblit v1.8.0