From d5f729cdbe6a461ffbe1b70d97dffcbf7f8608e4 Mon Sep 17 00:00:00 2001 From: liujun Date: Tue, 19 Dec 2023 15:01:44 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xgf/TrainingBatchController.java | 209 +----------------- .../controller/xgf/XgfUserController.java | 16 +- .../mapper/datasource/xgf/XgfUserMapper.java | 2 + .../zcloud/service/xgf/XgfUserService.java | 4 + .../xgf/impl/TrainingBatchServiceImpl.java | 4 +- .../service/xgf/impl/XgfUserServiceImpl.java | 67 ++++-- .../com/zcloud/util/HttpClientService.java | 37 ---- .../datasource/xgf/TrainingBatchMapper.xml | 20 +- .../mybatis/datasource/xgf/XgfUserMapper.xml | 23 +- 9 files changed, 108 insertions(+), 274 deletions(-) diff --git a/src/main/java/com/zcloud/controller/xgf/TrainingBatchController.java b/src/main/java/com/zcloud/controller/xgf/TrainingBatchController.java index 98beb39a..feb476ac 100644 --- a/src/main/java/com/zcloud/controller/xgf/TrainingBatchController.java +++ b/src/main/java/com/zcloud/controller/xgf/TrainingBatchController.java @@ -1,20 +1,16 @@ package com.zcloud.controller.xgf; -import com.alibaba.fastjson.JSONObject; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; -import com.zcloud.service.system.UsersService; import com.zcloud.service.xgf.TrainingBatchService; +import com.zcloud.service.xgf.XgfUserService; import com.zcloud.util.*; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; import java.util.*; @@ -29,13 +25,10 @@ import java.util.*; public class TrainingBatchController extends BaseController { @Autowired - private TrainingBatchService trainingbatchService; + private TrainingBatchService trainingbatchService; @Autowired - private UsersService usersService; - - @Value("${prevention.api.url}") - private String preventionUrl; + private XgfUserService xgfUserService; /** * 新增 @@ -59,8 +52,6 @@ public class TrainingBatchController extends BaseController { /** * 删除 * - * @param out - * @throws Exception */ @RequestMapping(value = "/delete") @RequiresPermissions("trainingbatch:del") @@ -113,46 +104,6 @@ public class TrainingBatchController extends BaseController { if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim()); page.setPd(pd); List varList = trainingbatchService.list(page); //列出TrainingBatch列表 - for (PageData x : varList) { - PageData condition = new PageData(); - condition.put("USER_ID", x.getString("SUPERVISION_USER_ID")); - Map result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("SUPERVISION_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("SUPERVISION")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("SUPERVISION_DEPT_NAME", result.get("NAME")); - } - - condition.clear(); - condition.put("USER_ID", x.getString("MANAGER_USER_ID")); - result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("MANAGER_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("MANAGER")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("MANAGER_DEPT_NAME", result.get("NAME")); - } - - condition.clear(); - condition.put("USER_ID", x.getString("TERRITORIALITY_USER_ID")); - result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("ERRITORIALITY_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("TERRITORIALITY")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("ERRITORIALITY_DEPT_NAME", result.get("NAME")); - } - } map.put("varList", varList); map.put("page", page); map.put("result", errInfo); @@ -177,7 +128,7 @@ public class TrainingBatchController extends BaseController { String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件 if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim()); page.setPd(pd); - List varList = usersService.flowlistPage(page); //列出TrainingBatch列表 + List varList = xgfUserService.flowlistPage(page); //列出TrainingBatch列表 map.put("varList", varList); map.put("page", page); map.put("result", errInfo); @@ -203,47 +154,6 @@ public class TrainingBatchController extends BaseController { if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim()); page.setPd(pd); List varList = trainingbatchService.batchUserlistPage(page); //列出TrainingBatch列表 - - for (PageData x : varList) { - PageData condition = new PageData(); - condition.put("USER_ID", x.getString("SUPERVISION_USER_ID")); - Map result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("SUPERVISION_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("SUPERVISION")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("SUPERVISION_DEPT_NAME", result.get("NAME")); - } - - condition.clear(); - condition.put("USER_ID", x.getString("MANAGER_USER_ID")); - result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("MANAGER_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("MANAGER")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("MANAGER_DEPT_NAME", result.get("NAME")); - } - - condition.clear(); - condition.put("USER_ID", x.getString("TERRITORIALITY_USER_ID")); - result = HttpClientUtil.doPost(preventionUrl + "/user/getUserInfo", condition); - if (result != null) { - x.put("ERRITORIALITY_USER_NAME", result.get("NAME")); - } - condition.clear(); - condition.put("DEPARTMENT_ID", x.getString("TERRITORIALITY")); - result = HttpClientUtil.doPost(preventionUrl + "/department/getDepartmentInfo", condition); - if (result != null) { - x.put("ERRITORIALITY_DEPT_NAME", result.get("NAME")); - } - } map.put("varList", varList); map.put("page", page); map.put("result", errInfo); @@ -281,120 +191,13 @@ public class TrainingBatchController extends BaseController { @ResponseBody public Object deleteAll() throws Exception { Map map = new HashMap(); - String errInfo = "success"; - PageData pd = new PageData(); - pd = this.getPageData(); + PageData pd = this.getPageData(); String DATA_IDS = pd.getString("DATA_IDS"); if (Tools.notEmpty(DATA_IDS)) { String ArrayDATA_IDS[] = DATA_IDS.split(","); trainingbatchService.deleteAll(ArrayDATA_IDS); - errInfo = "success"; - } else { - errInfo = "error"; } - map.put("result", errInfo); //返回结果 + map.put("result", "success"); //返回结果 return map; } - - /** - * 导出到excel - * - * @param - * @throws Exception - */ - @RequestMapping(value = "/excel") - @RequiresPermissions("toExcel") - public ModelAndView exportExcel() throws Exception { - ModelAndView mv = new ModelAndView(); - PageData pd = new PageData(); - pd = this.getPageData(); - Map dataMap = new HashMap(); - List titles = new ArrayList(); - titles.add("创建人"); //1 - titles.add("创建时间"); //2 - titles.add("修改人"); //3 - titles.add("修改时间"); //4 - titles.add("是否删除"); //5 - titles.add("批次名称"); //6 - titles.add("所属企业"); //7 - titles.add("培训人数"); //8 - titles.add("培训企业"); //9 - dataMap.put("titles", titles); - List varOList = trainingbatchService.listAll(pd); - List varList = new ArrayList(); - for (int i = 0; i < varOList.size(); i++) { - PageData vpd = new PageData(); - vpd.put("var1", varOList.get(i).getString("CREATOR")); //1 - vpd.put("var2", varOList.get(i).getString("CREATTIME")); //2 - vpd.put("var3", varOList.get(i).getString("OPERATOR")); //3 - vpd.put("var4", varOList.get(i).getString("OPERATTIME")); //4 - vpd.put("var5", varOList.get(i).get("ISDELETE").toString()); //5 - vpd.put("var6", varOList.get(i).getString("BATCH_NAME")); //6 - vpd.put("var7", varOList.get(i).getString("CORPINFO_ID")); //7 - vpd.put("var8", varOList.get(i).get("USER_COUNT").toString()); //8 - vpd.put("var9", varOList.get(i).getString("TRAIN_CORP_DEPT")); //9 - varList.add(vpd); - } - dataMap.put("varList", varList); - ObjectExcelView erv = new ObjectExcelView(); - mv = new ModelAndView(erv, dataMap); - return mv; - } - - @RequestMapping(value = "/sendMessage") - @ResponseBody - @Transactional - public Object sendMessage() throws Exception { - PageData request = this.getPageData(); - List list = Warden.getList(request.getString("list")); - List userList = new ArrayList<>(); - for (PageData x : list) { - PageData entity = usersService.getById(x); - Map map = new HashMap<>(entity); - for (Object key : map.keySet()) { - map.putIfAbsent(key, ""); - } - entity.put("CORPINFO_ID", request.get("corp_id")); - userList.add(entity); - // 更新用户信息 - PageData info = usersService.findById(entity); - info.put("EMPLOYER", request.get("corp_id")); - info.put("EMPLOYER_NAME", request.get("corp_name")); - info.put("EMPLOY_FLAG", "1"); - usersService.editUser(info); - } - - PageData info = new PageData(); - info.put("infoList", JSONObject.toJSON(userList)); - HttpClientUtil.doPost(preventionUrl + "/xfgUser/synchronizationUserInfo", info); - - Map response = new HashMap<>(); - response.put("result", "success"); - return response; - } - - @RequestMapping(value = "/submitApplication") - @ResponseBody - @Transactional - public Object submitApplication() throws Exception{ - PageData request = this.getPageData(); - - PageData info = new PageData(); - info.put("xgf_user_ids",request.get("xgf_user_ids")); - HttpClientUtil.doPost(preventionUrl + "/xfgUser/approvalApplication", info); - - List list = Arrays.asList(request.getString("xgf_user_ids").split(",")); - PageData condition = new PageData(); - for (String x : list) { - condition.put("USER_ID", x); - PageData entity = usersService.findById(condition); - entity.put("EMPLOY_FLAG", "2"); - usersService.editUser(entity); - } - - Map response = new HashMap<>(); - response.put("result", "success"); - return response; - } - } diff --git a/src/main/java/com/zcloud/controller/xgf/XgfUserController.java b/src/main/java/com/zcloud/controller/xgf/XgfUserController.java index b71515a5..da7a0863 100644 --- a/src/main/java/com/zcloud/controller/xgf/XgfUserController.java +++ b/src/main/java/com/zcloud/controller/xgf/XgfUserController.java @@ -3,9 +3,7 @@ package com.zcloud.controller.xgf; import com.zcloud.controller.base.BaseController; import com.zcloud.entity.Page; import com.zcloud.entity.PageData; -import com.zcloud.service.system.UsersService; import com.zcloud.service.xgf.XgfUserService; -import com.zcloud.util.HttpClientService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -23,7 +21,7 @@ public class XgfUserController extends BaseController { @RequestMapping(value = "/list") @ResponseBody - public Object getLevels(Page page) throws Exception { + public Object list(Page page) throws Exception { PageData request = this.getPageData(); page.setPd(request); xgfUserService.list(page); @@ -33,4 +31,16 @@ public class XgfUserController extends BaseController { response.put("data", request); return response; } + + @RequestMapping(value = "/approve") + @ResponseBody + public Object approve() throws Exception { + PageData request = this.getPageData(); + xgfUserService.approve(request); + + PageData response = new PageData(); + response.put("result", "success"); + response.put("data", request); + return response; + } } diff --git a/src/main/java/com/zcloud/mapper/datasource/xgf/XgfUserMapper.java b/src/main/java/com/zcloud/mapper/datasource/xgf/XgfUserMapper.java index 28c25a77..20b35f30 100644 --- a/src/main/java/com/zcloud/mapper/datasource/xgf/XgfUserMapper.java +++ b/src/main/java/com/zcloud/mapper/datasource/xgf/XgfUserMapper.java @@ -64,4 +64,6 @@ public interface XgfUserMapper { void graduation(PageData condition); void graduationstudent(PageData condition); + + List flowlistPage(Page page); } diff --git a/src/main/java/com/zcloud/service/xgf/XgfUserService.java b/src/main/java/com/zcloud/service/xgf/XgfUserService.java index 95dd7356..fcf3d30a 100644 --- a/src/main/java/com/zcloud/service/xgf/XgfUserService.java +++ b/src/main/java/com/zcloud/service/xgf/XgfUserService.java @@ -16,4 +16,8 @@ public interface XgfUserService { void init(PageData request); void approvalApplication(PageData request) throws Exception; + + List flowlistPage(Page page)throws Exception; + + void approve(PageData request) throws Exception; } diff --git a/src/main/java/com/zcloud/service/xgf/impl/TrainingBatchServiceImpl.java b/src/main/java/com/zcloud/service/xgf/impl/TrainingBatchServiceImpl.java index 5b6132fb..a6d25eb7 100644 --- a/src/main/java/com/zcloud/service/xgf/impl/TrainingBatchServiceImpl.java +++ b/src/main/java/com/zcloud/service/xgf/impl/TrainingBatchServiceImpl.java @@ -42,8 +42,8 @@ public class TrainingBatchServiceImpl implements TrainingBatchService { @Resource private FlowDetailMapper flowDetailMapper; - @Value("${prevention.api.url}") - private String preventionUrl; +// @Value("${prevention.api.url}") +// private String preventionUrl; /**新增 * @param pd diff --git a/src/main/java/com/zcloud/service/xgf/impl/XgfUserServiceImpl.java b/src/main/java/com/zcloud/service/xgf/impl/XgfUserServiceImpl.java index 4a028a93..19719c4b 100644 --- a/src/main/java/com/zcloud/service/xgf/impl/XgfUserServiceImpl.java +++ b/src/main/java/com/zcloud/service/xgf/impl/XgfUserServiceImpl.java @@ -6,14 +6,19 @@ import com.zcloud.mapper.datasource.xgf.XgfUserDetailsMapper; import com.zcloud.mapper.datasource.xgf.XgfUserMapper; import com.zcloud.service.xgf.XgfUserService; import com.zcloud.util.DateUtil; +import com.zcloud.util.HttpClientService; +import com.zcloud.util.HttpClientUtil; import com.zcloud.util.Warden; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Service public class XgfUserServiceImpl implements XgfUserService { @@ -24,6 +29,9 @@ public class XgfUserServiceImpl implements XgfUserService { @Resource private XgfUserDetailsMapper xgfUserDetailsMapper; + @Value("${preventionxgf.api.url}") + private String prevention_xgf_url; + @Override public void save(PageData pd) throws Exception { xgfUserMapper.save(pd); @@ -52,18 +60,18 @@ public class XgfUserServiceImpl implements XgfUserService { if (entity == null || entity.size() <= 0) { x.put("XGF_USER_ID", x.get("USER_ID")); x.put("XGF_USER_DETAILS_ID", x.get("USER_ID")); - x.put("ISDELETE","0"); - x.put("VALID_FLAG","1"); - x.put("STATUS","2"); + x.put("ISDELETE", "0"); + x.put("VALID_FLAG", "1"); + x.put("STATUS", "2"); x.put("CREATED_TIME", DateUtil.getTime()); - x.put("OPERATOR_TIME",DateUtil.getTime()); + x.put("OPERATOR_TIME", DateUtil.getTime()); xgfUserMapper.save(x); xgfUserDetailsMapper.save(x); } else { x.put("XGF_USER_ID", x.get("USER_ID")); x.put("XFG_USER_DETAILS_ID", x.get("USER_ID")); - x.put("ISDELETE","0"); - x.put("OPERATOR_TIME",DateUtil.getTime()); + x.put("ISDELETE", "0"); + x.put("OPERATOR_TIME", DateUtil.getTime()); xgfUserMapper.edit(x); xgfUserDetailsMapper.edit(x); } @@ -78,20 +86,51 @@ public class XgfUserServiceImpl implements XgfUserService { @Override public void approvalApplication(PageData request) throws Exception { - List list = Arrays.asList(request.getString("xgf_user_ids").split(",")) ; + List list = Arrays.asList(request.getString("xgf_user_ids").split(",")); PageData condition = new PageData(); condition.put("XGF_USER_IDS", list); List entities = xgfUserMapper.listByIds(condition); for (PageData x : entities) { - x.put("VALID_FLAG","0"); - x.put("STATUS","1"); + x.put("VALID_FLAG", "0"); + x.put("STATUS", "1"); xgfUserMapper.edit(x); } - PageData pd = new PageData(); - pd.put("XGF_USER_ID", request.getString("XGF_USER_ID")); - pd.put("ISDELETE", "1"); - xgfUserMapper.edit(pd); - xgfUserDetailsMapper.edit(pd); + } + + @Override + public List flowlistPage(Page page) throws Exception { + return xgfUserMapper.flowlistPage(page); + } + + @Override + @Transactional + public void approve(PageData request) throws Exception { + List _list = Warden.getList(request.getString("list")); + if (_list == null || _list.size() == 0) { + throw new RuntimeException("请求数据异常"); + } + List list = _list.stream().map(x -> x.getString("XGF_USER_ID")).collect(Collectors.toList()); + PageData condition = new PageData(); + for (String x : list) { + condition.put("XGF_USER_ID", x); + PageData entity = xgfUserMapper.findById(condition); + if (entity == null || entity.size() == 0) { + throw new RuntimeException("未找到该用户"); + } + if ("1".equals(request.getString("STATUS"))) { + entity.put("STATUS", "0"); + } else { + entity.put("STATUS", "2"); + } + xgfUserMapper.edit(entity); + + entity.put("USER_ID", condition.get("XGF_USER_ID")); + entity.put("STATUS", request.getString("STATUS")); + Map result = HttpClientService.doPost(prevention_xgf_url + "openApi/user/approve", entity); + if (result == null || !"succeed".equals(result.get("result"))) { + throw new RuntimeException("请求失败"); + } + } } } diff --git a/src/main/java/com/zcloud/util/HttpClientService.java b/src/main/java/com/zcloud/util/HttpClientService.java index 2adb7701..64be5883 100644 --- a/src/main/java/com/zcloud/util/HttpClientService.java +++ b/src/main/java/com/zcloud/util/HttpClientService.java @@ -365,46 +365,9 @@ public class HttpClientService { } public static Map doPost(String url, PageData pd) { - /* 正式上面总是显示一次断一次,未找到原因 - MultiValueMap requestBody = new LinkedMultiValueMap(); - pd.forEach((key, value) -> { - requestBody.add(key.toString(), value.toString()); - }); - System.out.println(requestBody); - Map responseBody = new HashMap(); - TcpClient tcpClient = TcpClient.create() - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000) // Connection Timeout - .doOnConnected(connection -> - connection.addHandlerLast(new ReadTimeoutHandler(10)) // Read Timeout - .addHandlerLast(new WriteTimeoutHandler(10))); // Write Timeout - WebClient client = WebClient.builder().clientConnector(new ReactorClientHttpConnector(HttpClient.from(tcpClient))).build(); - client.post() - .uri(url) - .header("Source","zcloud") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) - .body(BodyInserters.fromFormData(requestBody)) - .exchange() - .flatMap(response -> { - System.out.println("Status code: " + response.statusCode().value()); - return response.bodyToMono(JSONObject.class); - }) - .doOnSuccess(body -> { - System.out.println("success"); - responseBody.putAll(body); - }) - .doOnError(throwable -> { - responseBody.put("msg",throwable.getMessage()); - System.out.println("Error occurred: " + throwable.getMessage()); - }) - .block(); - return responseBody; - */ JSONObject jsonObject = null; HttpResponse response = null; List nameValuePairList = new ArrayList(); -// pd.forEach((key, value) -> { // 这个遍历不好使 -// System.out.println("键:" + key.toString() + ",值:" + value.toString()); -// }); Map map = (Map)pd; System.out.print("参数:{"); for(Map.Entry entry : map.entrySet()){ diff --git a/src/main/resources/mybatis/datasource/xgf/TrainingBatchMapper.xml b/src/main/resources/mybatis/datasource/xgf/TrainingBatchMapper.xml index ece65330..f20102f0 100644 --- a/src/main/resources/mybatis/datasource/xgf/TrainingBatchMapper.xml +++ b/src/main/resources/mybatis/datasource/xgf/TrainingBatchMapper.xml @@ -175,14 +175,14 @@ +