zjh
2024-07-25 d6e3adf2633accb75590764927939130eaee193c
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;
/**
@@ -41,6 +55,16 @@
    @Autowired
    private ISysDictTypeService dictTypeService;
    @Resource
    private ISysConfigService sysConfigService;
    @Autowired
    private HisApiConfigService hisApiConfigService;
    @Autowired
    private HisApiMethodService controller;
    @Autowired
    private HisApiGetMethodService hisApiGetMethodService;
    /**
     * 小程序就诊人列表
@@ -83,6 +107,8 @@
     */
    @PostMapping("/addNew")
    @ApiOperation(value = "小程序-新增并绑定就诊人")
    @Transactional
    @RepeatSubmit
    public AjaxResult addNew(@RequestBody @ApiParam(value = "客户对象信息") TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error("添加失败");
@@ -110,22 +136,19 @@
        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);
            if (customerService.updateById(customer)) {
                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());
                    }
                }
            }
            return AjaxResult.success(customer);
        }
        String substring = cusIdcard.substring(cusIdcard.length() - 6);
@@ -142,6 +165,13 @@
        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());
                }
            }
            return AjaxResult.success(tjCustomer);
        }
        return AjaxResult.error("添加失败");
@@ -165,7 +195,7 @@
        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());
@@ -196,10 +226,13 @@
     */
    @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());
@@ -207,6 +240,13 @@
        one.setCusNational(tjCustomer.getCusNational());
        one.setCusMarryStatus(tjCustomer.getCusMarryStatus());
        if (customerService.updateById(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());
                }
            }
            return AjaxResult.success(one);
        }
        return AjaxResult.error("修改失败");
@@ -246,4 +286,46 @@
        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) {
                    tjCustomer.setPationId(pationid);
                    customerService.updateById(tjCustomer);
                    //保存注册入参出参
                    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();
        }
        return AjaxResult.error(object.getStr("ResultContent"));
    }
}