zhaowenxuan
6 天以前 696d71cdc4eefa49951b7e14556fe56072714edd
ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java
@@ -1,5 +1,7 @@
package com.ltkj.web.controller.app;
import cn.hutool.core.date.DateTime;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -7,14 +9,18 @@
import com.google.gson.reflect.TypeToken;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.common.utils.WechatUtil;
import com.ltkj.common.utils.sign.Base64;
import com.ltkj.framework.config.JwtUtils;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.GetPhone;
import com.ltkj.hosp.domain.Wxuser;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.IAbucoderWxuserService;
import com.ltkj.hosp.service.ITjCustomerService;
import com.ltkj.hosp.service.ITjOrderRemarkService;
import com.ltkj.hosp.service.ITjOrderService;
import com.ltkj.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -24,7 +30,9 @@
import okhttp3.Response;
import org.aspectj.bridge.MessageWriter;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import sun.misc.BASE64Decoder;
@@ -40,10 +48,7 @@
import java.security.Security;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
 * @Author: 西安路泰科技有限公司/赵佳豪
@@ -58,10 +63,19 @@
@Api(tags = "A小程序端登录接口大全")
@Slf4j
public class WxloginController extends BaseController {
    @Resource
    private ITjCustomerService customerService;
    @Resource
    private IAbucoderWxuserService wxuserService;
    @Autowired
    private ITjOrderService orderService;
    @Resource
    private ITjOrderRemarkService remarkService;
    @Resource
    private ISysDeptService deptService;
    @Value("${xcx.appid}")
    private String appid;
@@ -71,6 +85,7 @@
    /**
     * 小程序登录
     *
     * @param code 小程序wx.login返回的临时凭证
     * @return
     */
@@ -110,7 +125,7 @@
                wxuser.setCreateTime(new Date());
                wxuser.setWxMiniOpenId(openId);
                wxuserService.save(wxuser);
                map.put("wxuser",wxuser);
                map.put("wxuser", wxuser);
            }
            // 生成令牌
            String token = JwtUtils.getToken(map);
@@ -130,11 +145,13 @@
    @ApiOperation(value = "小程序获取用户详情信息接口")
    public AjaxResult getWxInfo() {
        Wxuser wxuser = UserHoder.getWxuser();
        LambdaQueryWrapper<Wxuser>wq=new LambdaQueryWrapper<>();
        wq.eq(Wxuser::getOpenid,wxuser.getOpenid());
        LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>();
        wq.eq(Wxuser::getOpenid, wxuser.getOpenid());
//        System.out.println("获取 ->"+wxuser.getOpenid());
        Wxuser one = wxuserService.getOne(wq);
        return AjaxResult.success(one);
    }
    /**
     * 微信手机号码绑定
     */
@@ -156,7 +173,7 @@
                byte[] raw = decoder.decodeBuffer(sessionKey);
                SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
                IvParameterSpec iv1 = new IvParameterSpec(decoder.decodeBuffer(iv));
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding","BC");
                Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
                cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv1);
                OkHttpClient client = new OkHttpClient();
                Request okrequest = new Request.Builder()
@@ -189,8 +206,182 @@
        return AjaxResult.success();
    }
    @PostMapping("/wx/bindPhoneV2")
    public AjaxResult bindPhoneV2(@RequestBody String json) {
        cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
        String phone = entries.getStr("phone");
        Wxuser wxuser = UserHoder.getWxuser();
        LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>();
        wq.eq(Wxuser::getOpenid, wxuser.getOpenid());
        Wxuser one = wxuserService.getOne(wq);
//        System.out.println("绑定 ->"+wxuser.getOpenid()+",json = "+json);
        if (one != null) {
            one.setPhone(phone);
            wxuserService.updateById(one);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
    @PostMapping("/wx/wenzhenxinxi")
    @ApiOperation("小程序问诊信息")
    public AjaxResult wenzhenxinxi(@RequestBody String json) {
        cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
        String idCard = entries.getStr("idCard");
        TjCustomer tjCustomer = customerService.getTjCustomerByCusIdCard(idCard);
        if (null != tjCustomer) {
            List<Map<String, Object>> mapList = new ArrayList<>();
            LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
            wq.eq(TjOrder::getUserId, tjCustomer.getCusId());
            List<TjOrder> list = orderService.list(wq);
            if (null != list && !list.isEmpty()) {
                for (TjOrder order : list) {
                    Map<String, Object> map = new HashMap<>();
                    if (order.getPacId().equals("0")) {
                        map.put("title", "普通体检");
                    } else {
                        map.put("title", orderService.getpacName(order.getPacId()));
                    }
                    map.put("price", orderService.gettjzj(order.getOrderId()));
                    map.put("time", order.getCreateTime());
                    map.put("items", remarkService.getTjxm(order.getTjNumber()));
                    int czwj = remarkService.panduaniscunzaiweijian(order.getTjNumber());
                    int sfwc = remarkService.panduaniswancheng(order.getTjNumber());
                    Date checkTime = order.getCheckTime();
                    Date reportTime = order.getReportTime();
                    Integer heshouStatus = order.getHeshouStatus();
                    Date lastTime = order.getPrintLastTime();
                    if (czwj == 0) {
                        map.put("status", "未检");
                    }
                    if (czwj > 0) {
                        map.put("status", "在检");
                    }
                    if (sfwc == 0) {
                        map.put("status", "已完成");
                    }
                    if (null != checkTime) {
                        map.put("status", "已审核");
                    }
                    if (null != reportTime) {
                        map.put("status", "生成报告");
                    }
                    if (1 == heshouStatus) {
                        map.put("status", "报告核收");
                    }
                    if (null != lastTime) {
                        map.put("status", "已打印");
                    }
                    mapList.add(map);
                }
                return AjaxResult.success(mapList);
            }
        }
        return AjaxResult.error("暂无问诊记录");
    }
    @PostMapping("/wx/tijianjilu")
    @ApiOperation("小程序体检记录")
    public AjaxResult tijianjilu(@RequestBody String json) {
        cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
        String idCard = entries.getStr("idCard");
        TjCustomer tjCustomer = customerService.getTjCustomerByCusIdCard(idCard);
        if (null != tjCustomer) {
            List<Map<String, Object>> mapList = new ArrayList<>();
            LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
            wq.eq(TjOrder::getUserId, tjCustomer.getCusId());
            List<TjOrder> list = orderService.list(wq);
            if (null != list && !list.isEmpty()) {
                for (TjOrder order : list) {
                    Map<String, Object> map = new HashMap<>();
                    map.put("tjNumber", order.getTjNumber());
                    int czwj = remarkService.panduaniscunzaiweijian(order.getTjNumber());
                    int sfwc = remarkService.panduaniswancheng(order.getTjNumber());
                    Date checkTime = order.getCheckTime();
                    Date reportTime = order.getReportTime();
                    Integer heshouStatus = order.getHeshouStatus();
                    Date lastTime = order.getPrintLastTime();
                    if (czwj == 0) {
                        map.put("status", "未检");
                    }
                    if (czwj > 0) {
                        map.put("status", "在检");
                    }
                    if (sfwc == 0) {
                        map.put("status", "已完成");
                    }
                    if (null != checkTime) {
                        map.put("status", "已审核");
                    }
                    if (null != reportTime) {
                        map.put("status", "生成报告");
                    }
                    if (1 == heshouStatus) {
                        map.put("status", "报告核收");
                    }
                    if (null != lastTime) {
                        map.put("status", "已打印");
                    }
                    mapList.add(map);
                }
                return AjaxResult.success(mapList);
            }
        }
        return AjaxResult.error("暂无体检记录");
    }
    @PostMapping("/wx/tijianjiluxiangqing")
    @ApiOperation("小程序体检记录详情")
    public AjaxResult tijianjiluxiangqing(@RequestBody String json) {
        cn.hutool.json.JSONObject entries = JSONUtil.parseObj(json);
        String tjNumber = entries.getStr("tjNumber");
        TjOrder order = orderService.getOrderByTjNum(tjNumber);
        if (null != order) {
            TjCustomer tjCustomer = customerService.selectTjCustomerByCusId(order.getUserId());
            if (null != tjCustomer) {
                Map<String, Object> map = new HashMap<>();
                map.put("cusName", tjCustomer.getCusName());
                map.put("cusSex", tjCustomer.getCusSex());
                if (order.getPacId().equals("0")) {
                    map.put("pacName", "普通体检");
                } else {
                    map.put("pacName", orderService.getpacName(order.getPacId()));
                }
                map.put("price", orderService.gettjzj(order.getOrderId()));
                map.put("createTime", order.getCreateTime());
                List<TjOrderRemark> remarkList = remarkService.getTjOrderRemarkListByTjNum(order.getTjNumber());
                List<Map<String, Object>> mapList = new ArrayList<>();
                if (null != remarkList && !remarkList.isEmpty()) {
                    for (TjOrderRemark remark : remarkList) {
                        Map<String, Object> map1 = new HashMap<>();
                        SysDept dept = deptService.getById(remark.getDeptId());
                        if(null != dept){
                            map1.put("deptName", dept.getDeptName());
                            map1.put("officialWeb",dept.getOfficialWeb());
                        }
                        map1.put("checkStatus", remark.getType());
                        mapList.add(map1);
                    }
                    map.put("reportlist", mapList);
                } else {
                    map.put("reportlist", mapList);
                }
                return AjaxResult.success(map);
            }
        }
        return AjaxResult.error("暂无记录");
    }
    /**
     * 发送请求用code换取sessionKey和相关信息
     *
     * @param code
     * @return
     */
@@ -208,7 +399,15 @@
     * @param sessionKey
     * @param iv
     * @return
     *
     */
    /**
     * 解决java不支持AES/CBC/PKCS7Padding模式解密
     */
    static {
        Security.addProvider(new BouncyCastleProvider());
    }
    public static JSONObject decryptionUserInfo(String encryptedData, String sessionKey, String iv) {
        // 被加密的数据
        byte[] dataByte = Base64.decode(encryptedData);
@@ -218,7 +417,7 @@
        byte[] ivByte = Base64.decode(iv);
        try {
        // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要
            // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要
            int base = 16;
            if (keyByte.length % base != 0) {
                int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0);
@@ -227,8 +426,12 @@
                System.arraycopy(keyByte, 0, temp, 0, keyByte.length);
                keyByte = temp;
            }
        // 初始化
            // 初始化
            Security.addProvider(new BouncyCastleProvider());
            /**
             * 解决java不支持AES/CBC/PKCS7Padding模式解密
             */
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
            SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
            AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
@@ -245,6 +448,7 @@
        }
        return null;
    }
    /**
     * 发送https请求
@@ -332,5 +536,36 @@
        return response;
    }
    @PostMapping("/wx/wxbindphone")
    @ApiOperation("手动绑定手机号接口")
    @Transactional
    public AjaxResult wxbindphone(@RequestParam @ApiParam(value = "openId") String openId,
                                  @RequestParam @ApiParam(value = "phone") String phone) {
        LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>();
        wq.eq(Wxuser::getOpenid, openId);
        Wxuser one = wxuserService.getOne(wq);
        if (one != null) {
            one.setPhone(phone);
            one.setUpdateTime(new DateTime());
            final boolean b = wxuserService.updateById(one);
            if (b) {
                LambdaQueryWrapper<TjCustomer> qw = new LambdaQueryWrapper<>();
                qw.eq(TjCustomer::getCusPhone, phone);
                List<TjCustomer> tjCustomer1 = customerService.list(qw);
                if (tjCustomer1 != null && !tjCustomer1.isEmpty()) {
                    for (TjCustomer tjCustomer : tjCustomer1) {
                        tjCustomer.setConnect(openId);
                        customerService.updateById(tjCustomer);
                    }
                }
                return AjaxResult.success("绑定成功!");
            }
        }
        return AjaxResult.error("绑定失败!");
    }
}