From 14ecea8537d5b29ca64c75aad4ff49265018415d Mon Sep 17 00:00:00 2001
From: zjh <1084500556@qq.com>
Date: 星期三, 02 七月 2025 08:51:22 +0800
Subject: [PATCH] zjh20250702

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/app/CustomerController.java |  191 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 139 insertions(+), 52 deletions(-)

diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/CustomerController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/CustomerController.java
index b9085b3..563370b 100644
--- a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/CustomerController.java
+++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/CustomerController.java
@@ -1,27 +1,41 @@
 package com.ltkj.web.controller.app;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ltkj.common.annotation.RepeatSubmit;
 import com.ltkj.common.core.controller.BaseController;
 import com.ltkj.common.core.domain.AjaxResult;
 import com.ltkj.common.core.domain.entity.SysDictData;
 import com.ltkj.common.utils.StringUtils;
 import com.ltkj.framework.config.MatchUtils;
+import com.ltkj.hosp.domain.HisApiConfig;
 import com.ltkj.hosp.domain.TjCustomer;
 import com.ltkj.hosp.domain.TjOrder;
+import com.ltkj.hosp.service.HisApiConfigService;
 import com.ltkj.hosp.service.ITjCustomerService;
 import com.ltkj.hosp.service.ITjOrderService;
+import com.ltkj.system.service.ISysConfigService;
 import com.ltkj.system.service.ISysDictTypeService;
+import com.ltkj.web.controller.his.HisApiGetMethodService;
+import com.ltkj.web.controller.his.HisApiMethodService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.DigestUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -29,8 +43,8 @@
  * @Date: 2023/1/12 11:08
  */
 @RestController
-@RequestMapping("/cus/hospital")
-@Api(tags = "灏忕▼搴�-瀹㈡埛淇℃伅")
+@RequestMapping ("/cus/hospital")
+@Api (tags = "灏忕▼搴�-瀹㈡埛淇℃伅")
 public class CustomerController extends BaseController {
 
     @Resource
@@ -42,11 +56,21 @@
     @Autowired
     private ISysDictTypeService dictTypeService;
 
+    @Resource
+    private ISysConfigService sysConfigService;
+
+    @Autowired
+    private HisApiConfigService hisApiConfigService;
+    @Autowired
+    private HisApiMethodService controller;
+    @Autowired
+    private HisApiGetMethodService hisApiGetMethodService;
+
     /**
      * 灏忕▼搴忓氨璇婁汉鍒楄〃
      */
-    @GetMapping("/getListByOpenId")
-    @ApiOperation(value = "灏忕▼搴�-灏辫瘖浜哄垪琛�")
+    @GetMapping ("/getListByOpenId")
+    @ApiOperation (value = "灏忕▼搴�-灏辫瘖浜哄垪琛�")
     public AjaxResult getListByOpenId(@RequestParam String openId) {
         LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
         wq.eq(TjCustomer::getConnect, openId);
@@ -57,9 +81,9 @@
     /**
      * 瑙g粦灏辫瘖浜�
      */
-    @PostMapping("/delCustomer")
-    @ApiOperation(value = "灏忕▼搴�-瑙g粦灏辫瘖浜�")
-    public AjaxResult delCustomer(@RequestBody @ApiParam(value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
+    @PostMapping ("/delCustomer")
+    @ApiOperation (value = "灏忕▼搴�-瑙g粦灏辫瘖浜�")
+    public AjaxResult delCustomer(@RequestBody @ApiParam (value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
         if (tjCustomer == null) {
             return AjaxResult.error();
         }
@@ -81,9 +105,11 @@
     /**
      * 鏂板骞剁粦瀹氬氨璇婁汉
      */
-    @PostMapping("/addNew")
-    @ApiOperation(value = "灏忕▼搴�-鏂板骞剁粦瀹氬氨璇婁汉")
-    public AjaxResult addNew(@RequestBody @ApiParam(value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
+    @PostMapping ("/addNew")
+    @ApiOperation (value = "灏忕▼搴�-鏂板骞剁粦瀹氬氨璇婁汉")
+    @Transactional
+    @RepeatSubmit
+    public AjaxResult addNew(@RequestBody @ApiParam (value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
         if (tjCustomer == null) {
             return AjaxResult.error("娣诲姞澶辫触");
         }
@@ -95,35 +121,24 @@
         if (!MatchUtils.isMobileNO(tjCustomer.getCusPhone()))
             return AjaxResult.error("鎵嬫満鍙烽敊璇�");
 
-        if(cusIdcard.length()==18){
+        if (tjCustomer.getIdType().equals("1")) {
             if (!MatchUtils.isIdCard(cusIdcard)) {
                 return AjaxResult.error("韬唤璇佸彿鐮侀敊璇�");
             }
         }
-        if(cusIdcard.length()==9){
-            if (!MatchUtils.cardValidates(cusIdcard)) {
-                return AjaxResult.error("韬唤璇佸彿鐮侀敊璇�");
-            }
-        }
+//        if (cusIdcard.length() == 9) {
+//            if (!MatchUtils.cardValidates(cusIdcard)) {
+//                return AjaxResult.error("韬唤璇佸彿鐮侀敊璇�");
+//            }
+//        }
 
         LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
         wq.eq(TjCustomer::getCusIdcard, cusIdcard);
         TjCustomer customer = customerService.getOne(wq);
 
+        String key = sysConfigService.selectConfigByKey("sfkqdyhis");
+
         if (customer != null) {
-//            BeanUtils.copyBeanProp(tjCustomer, customer);
-//            String substring = cusIdcard.substring(cusIdcard.length() - 6);
-//            substring = DigestUtils.md5DigestAsHex(substring.getBytes());
-//            customer.setCusPassword(substring);
-//            customer.setCusBrithday(DateUtil.parse(MatchUtils.getBirthDayByIdCard(cusIdcard), "yyyy-MM-dd"));
-//            tjCustomer.setCusSex(Long.valueOf(MatchUtils.getSexByIdCard(cusIdcard)));
-//            // tjCustomer.setAddr(MatchUtils.getNativePlace(Integer.parseInt(cusIdcard)));
-//            tjCustomer.setAge(String.valueOf(MatchUtils.getAgeByIdCard(cusIdcard)));
-//            tjCustomer.setIdType("1");
-//            tjCustomer.setAgeUnit("0");
-//            if (customerService.updateById(customer)) {
-//                return AjaxResult.success(tjCustomer);
-//            }
             customer.setConnect(tjCustomer.getConnect());
             customerService.updateById(customer);
             return AjaxResult.success(customer);
@@ -131,9 +146,12 @@
         String substring = cusIdcard.substring(cusIdcard.length() - 6);
         substring = DigestUtils.md5DigestAsHex(substring.getBytes());
         tjCustomer.setCusPassword(substring);
-        tjCustomer.setCusBrithday(DateUtil.parse(MatchUtils.getBirthDayByIdCard(cusIdcard), "yyyy-MM-dd"));
+        try {
+            tjCustomer.setCusBrithday(MatchUtils.getBirthDayByIdCard(cusIdcard));
+        } catch (Exception e) {
+            return AjaxResult.error("韬唤璇佸彿涓嶆纭�");
+        }
         tjCustomer.setCusSex(Long.valueOf(MatchUtils.getSexByIdCard(cusIdcard)));
-        //tjCustomer.setAddr(MatchUtils.getNativePlace(Integer.parseInt((cusIdcard))));
         tjCustomer.setAge(String.valueOf(MatchUtils.getAgeByIdCard(cusIdcard)));
         tjCustomer.setIdType("1");
         tjCustomer.setAgeUnit("0");
@@ -141,31 +159,39 @@
         tjCustomer.setCusIntroduce("鏃�");
         tjCustomer.setCusNumber(0L);
         tjCustomer.setCusIsvip("N");
-        if (customerService.save(tjCustomer)) {
+        if (null != key && key.equals("Y")) {
+            AjaxResult xinXi = suijieHisXinXi(tjCustomer);
+            if (!xinXi.get("code").toString().equals("200")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("娉ㄥ唽澶辫触,璇峰埌鍓嶅彴鐧昏!" + xinXi.get("msg").toString());
+            }
+        } else {
+            customerService.save(tjCustomer);
             return AjaxResult.success(tjCustomer);
         }
-        return AjaxResult.error("娣诲姞澶辫触");
+
+        return AjaxResult.success(tjCustomer);
     }
 
     /**
      * 灏忕▼搴忎綋妫�鎶ュ憡鍒楄〃
      */
-    @GetMapping("/getReportList")
-    @ApiOperation(value = "灏忕▼搴�-浣撴鎶ュ憡鍒楄〃")
-    public AjaxResult getReportList(@RequestParam @ApiParam(value = "鎵嬫満鍙�") String cusPhone) {
+    @GetMapping ("/getReportList")
+    @ApiOperation (value = "灏忕▼搴�-浣撴鎶ュ憡鍒楄〃")
+    public AjaxResult getReportList(@RequestParam @ApiParam (value = "鎵嬫満鍙�") String cusPhone) {
         return AjaxResult.success();
     }
 
     /**
      * 鍥炴樉灏辫瘖浜�
      */
-    @PostMapping("/showCustomer")
-    @ApiOperation(value = "灏忕▼搴�-鍥炴樉灏辫瘖浜�")
-    public AjaxResult showCustomer(@RequestBody @ApiParam(value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
+    @PostMapping ("/showCustomer")
+    @ApiOperation (value = "灏忕▼搴�-鍥炴樉灏辫瘖浜�")
+    public AjaxResult showCustomer(@RequestBody @ApiParam (value = "瀹㈡埛瀵硅薄淇℃伅") TjCustomer tjCustomer) {
         if (tjCustomer == null) {
             return AjaxResult.error();
         }
-        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper();
+        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
         wq.eq(TjCustomer::getCusIdcard, tjCustomer.getCusIdcard());
         wq.eq(TjCustomer::getCusPhone, tjCustomer.getCusPhone());
         wq.eq(TjCustomer::getCusName, tjCustomer.getCusName());
@@ -176,8 +202,8 @@
     /**
      * 灏忕▼搴忓垽鏂槸鍚﹁兘缂栬緫
      */
-    @PostMapping("/canUpdate")
-    @ApiOperation(value = "灏忕▼搴忓垽鏂槸鍚﹁兘缂栬緫")
+    @PostMapping ("/canUpdate")
+    @ApiOperation (value = "灏忕▼搴忓垽鏂槸鍚﹁兘缂栬緫")
     public AjaxResult canUpdate(@RequestBody TjCustomer tjCustomer) {
         if (tjCustomer == null) {
             return AjaxResult.error("鍑洪敊浜嗭紝璇疯仈绯诲伐浣滀汉鍛橈紒");
@@ -194,35 +220,48 @@
     /**
      * 灏忕▼搴忕紪杈戝氨璇婁汉淇℃伅
      */
-    @PostMapping("/updateCustomerBy")
-    @ApiOperation(value = "灏忕▼搴�-淇敼灏辫瘖浜轰俊鎭�")
+    @PostMapping ("/updateCustomerBy")
+    @ApiOperation (value = "灏忕▼搴�-淇敼灏辫瘖浜轰俊鎭�")
+    @Transactional
+    @RepeatSubmit
     public AjaxResult updateCustomerBy(@RequestBody TjCustomer tjCustomer) {
         if (tjCustomer == null) {
             return AjaxResult.error("淇敼澶辫触");
         }
+        String key = sysConfigService.selectConfigByKey("sfkqdyhis");
         TjCustomer one = customerService.getById(tjCustomer);
         one.setCusName(tjCustomer.getCusName());
         one.setCusIdcard(tjCustomer.getCusIdcard());
         one.setCusPhone(tjCustomer.getCusPhone());
         one.setCusNational(tjCustomer.getCusNational());
         one.setCusMarryStatus(tjCustomer.getCusMarryStatus());
-        if (customerService.updateById(one)) {
-            return AjaxResult.success(one);
+
+        if (null != key && key.equals("Y")) {
+            AjaxResult xinXi = suijieHisXinXi(one);
+            if (!xinXi.get("code").toString().equals("200")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error("淇敼灏辫瘖浜轰俊鎭け璐�!" + xinXi.get("msg").toString());
+            }
+        } else {
+            if (!customerService.updateById(one)) {
+                return AjaxResult.error("淇敼澶辫触");
+            }
         }
-        return AjaxResult.error("淇敼澶辫触");
+        return AjaxResult.success(one);
+
     }
 
     /**
      * 灏忕▼搴忔牴鎹墜鏈哄彿鐮佽幏鍙栫敤鎴疯韩浠借瘉鍙风爜
      */
-    @GetMapping(value = "/getIdCardByPhone")
-    @ApiOperation(value = "灏忕▼搴忔牴鎹墜鏈哄彿鐮佽幏鍙栫敤鎴疯韩浠借瘉鍙风爜")
-    public AjaxResult getIdCardByPhone(@RequestParam @ApiParam(value = "鎵嬫満鍙�") String phone) {
+    @GetMapping (value = "/getIdCardByPhone")
+    @ApiOperation (value = "灏忕▼搴忔牴鎹墜鏈哄彿鐮佽幏鍙栫敤鎴疯韩浠借瘉鍙风爜")
+    public AjaxResult getIdCardByPhone(@RequestParam @ApiParam (value = "鎵嬫満鍙�") String phone) {
         if (!"".equals(phone) && phone != null && MatchUtils.isMobileNO(phone)) {
             LambdaQueryWrapper<TjCustomer> qw = new LambdaQueryWrapper<>();
             qw.eq(TjCustomer::getCusPhone, phone);
             List<TjCustomer> tjCustomer1 = customerService.list(qw);
-            if (tjCustomer1 != null && tjCustomer1.size()>0) {
+            if (tjCustomer1 != null && tjCustomer1.size() > 0) {
                 List<String> num = new ArrayList<>();
                 for (TjCustomer tjCustomer : tjCustomer1) {
                     num.add(tjCustomer.getCusIdcard());
@@ -237,7 +276,7 @@
     /**
      * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁淇℃伅
      */
-    @GetMapping(value = "/type/{dictType}")
+    @GetMapping (value = "/type/{dictType}")
     public AjaxResult dictType(@PathVariable String dictType) {
         List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
         if (StringUtils.isNull(data)) {
@@ -246,4 +285,52 @@
         return success(data);
     }
 
+
+    //灏嗘柟娉曡繑鍥炲�艰В鏋愭垚json鏍煎紡
+    public JSONObject getJSONObject(String builder) {
+        String Response = JSONUtil.parseObj(builder).getStr("Response");
+        return JSONUtil.parseObj(Response);
+    }
+
+    //鑾峰彇鏂规硶杩斿洖鍊间俊鎭�
+    public String getAjaxResult(AjaxResult result) {
+        return result.get("data").toString();
+    }
+
+
+    private AjaxResult suijieHisXinXi(TjCustomer tjCustomer) {
+        AjaxResult result = controller.Outpincreateapply(tjCustomer);
+        String result1 = getAjaxResult(result);
+        JSONObject object = getJSONObject(result1);
+        String code = object.getStr("ResultCode");
+        if (code.equals("0")) {
+            JSONArray resultDatass = object.getJSONArray("ResultData");
+            Map<String, Object> resultData = (Map<String, Object>) resultDatass.get(0);
+            if (null != resultData && resultData.size() > 0) {
+                String pationid = resultData.get("PationId").toString();
+                if (null != pationid) {
+                    try {
+                        if (tjCustomer.getCusId() == null) {
+                            tjCustomer.setPationId(pationid);
+                        }
+                        customerService.saveOrUpdate(tjCustomer);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        return AjaxResult.error("鎿嶄綔澶辫触!");
+                    }
+                    //淇濆瓨娉ㄥ唽鍏ュ弬鍑哄弬
+                    resultData.put("cardId", pationid);
+                    JSONObject object4 = JSONUtil.parseObj(resultData);
+                    LambdaQueryWrapper<HisApiConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    lambdaQueryWrapper.eq(HisApiConfig::getApiMethod, "Outpincreateapply");
+                    HisApiConfig hisApiConfig = hisApiConfigService.getOne(lambdaQueryWrapper);
+                    hisApiGetMethodService.save(object4, "Outpincreateapply", hisApiConfig, JSONUtil.toJsonStr(BeanUtil.beanToMap(tjCustomer)));
+                }
+
+            }
+            return AjaxResult.success(tjCustomer);
+        }
+        return AjaxResult.error(object.getStr("ResultContent"));
+    }
+
 }

--
Gitblit v1.8.0