|
|
@@ -0,0 +1,435 @@
|
|
|
+package thyyxxk.wxservice_server.api;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.wechat.pay.java.core.Config;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.JsapiService;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.*;
|
|
|
+import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.wxservice_server.constant.AppletOrderType;
|
|
|
+import thyyxxk.wxservice_server.dao.AppletDao;
|
|
|
+import thyyxxk.wxservice_server.dao.PatientCardsDao;
|
|
|
+import thyyxxk.wxservice_server.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.entity.analyzeidcard.IdCardAnalyzeResult;
|
|
|
+import thyyxxk.wxservice_server.entity.appointment.PatientBriefInfo;
|
|
|
+import thyyxxk.wxservice_server.entity.electronichealthcard.ElectronicHealthCard;
|
|
|
+import thyyxxk.wxservice_server.entity.patientcards.ModifyBindParam;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.wxapplet.request.*;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.wxapplet.response.AppletMallCart;
|
|
|
+import thyyxxk.wxservice_server.entity.wxapi.wxapplet.response.WxAppletOrder;
|
|
|
+import thyyxxk.wxservice_server.service.ElectronicHealthCardService;
|
|
|
+import thyyxxk.wxservice_server.service.IdCardAnalyzeService;
|
|
|
+import thyyxxk.wxservice_server.service.WxRefundService;
|
|
|
+import thyyxxk.wxservice_server.utils.*;
|
|
|
+import thyyxxk.wxservice_server.utils.wxpay.WxPayConfigUtil;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/wxApplet")
|
|
|
+public class WxAppletApi {
|
|
|
+ private final IdCardAnalyzeService idCardAnalyzeService;
|
|
|
+ private final WxRefundService wxRefundService;
|
|
|
+ private final ElectronicHealthCardService electronicHealthCardService;
|
|
|
+ private final AppletDao appletDao;
|
|
|
+ private final PatientCardsDao cardsDao;
|
|
|
+ private final static String GET_USER_INFO = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
|
|
|
+
|
|
|
+ @Value("${appletThmzUrl}")
|
|
|
+ String appletThmzUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public WxAppletApi(IdCardAnalyzeService idCardAnalyzeService, WxRefundService wxRefundService, ElectronicHealthCardService electronicHealthCardService, AppletDao dao, PatientCardsDao cardsDao) {
|
|
|
+ this.idCardAnalyzeService = idCardAnalyzeService;
|
|
|
+ this.wxRefundService = wxRefundService;
|
|
|
+ this.electronicHealthCardService = electronicHealthCardService;
|
|
|
+ this.appletDao = dao;
|
|
|
+ this.cardsDao = cardsDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getAppletUserInfo")
|
|
|
+ public ResultVo<JSONObject> getAppletUserInfo(@RequestBody AppletUserInquiry inquiry) {
|
|
|
+ AppletType appletType = inquiry.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ if (appletType != AppletType.APPLET_MALL && appletType != AppletType.HOSPITAL_SERVICE) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别无效。");
|
|
|
+ }
|
|
|
+ String jscode = inquiry.getCode();
|
|
|
+ if (null == jscode) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "登录凭证不能为空。");
|
|
|
+ }
|
|
|
+ String appId = appletType == AppletType.HOSPITAL_SERVICE ?
|
|
|
+ PropertiesUtil.getLocalProperty("appletAppId") :
|
|
|
+ PropertiesUtil.getLocalProperty("appletMallAppId");
|
|
|
+ String appSecret = appletType == AppletType.HOSPITAL_SERVICE ?
|
|
|
+ PropertiesUtil.getLocalProperty("appletAppSecret") :
|
|
|
+ PropertiesUtil.getLocalProperty("appletMallAppSecret");
|
|
|
+ String url = GET_USER_INFO.replace("APPID", appId)
|
|
|
+ .replace("SECRET", appSecret)
|
|
|
+ .replace("JSCODE", jscode);
|
|
|
+ String response = new RestTemplate().getForObject(url, String.class);
|
|
|
+ log.info("小程序登录:{}\n参数:{}\n结果:{}", url, JSONObject.toJSON(inquiry), response);
|
|
|
+ return ResultVoUtil.success(JSONObject.parseObject(response));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/createOrder")
|
|
|
+ public ResultVo<WxAppletOrder> createOrder(@RequestBody WxAppletOrder order) {
|
|
|
+ AppletType appletType = order.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ AppletOrderType orderType = order.getOrderType();
|
|
|
+ if (null == orderType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "订单类别不能为空。");
|
|
|
+ }
|
|
|
+ String appId = appletType == AppletType.HOSPITAL_SERVICE ?
|
|
|
+ PropertiesUtil.getLocalProperty("appletAppId") :
|
|
|
+ PropertiesUtil.getLocalProperty("appletMallAppId");
|
|
|
+ String mchId = PropertiesUtil.getLocalProperty("mchId");
|
|
|
+ String tradeNo = SnowFlakeId.instance().nextWxAppletTradeNo();
|
|
|
+ Config config = WxPayConfigUtil.getInstance().getConfig();
|
|
|
+ JsapiServiceExtension service = new JsapiServiceExtension .Builder().config(config).build();
|
|
|
+ PrepayRequest request = new PrepayRequest();
|
|
|
+ Amount amount = new Amount();
|
|
|
+ amount.setTotal(order.getTotalAmount());
|
|
|
+ request.setAmount(amount);
|
|
|
+ request.setDescription(order.getDescription());
|
|
|
+ request.setAppid(appId);
|
|
|
+ request.setMchid(mchId);
|
|
|
+ request.setNotifyUrl(PropertiesUtil.getLocalProperty("notifyUrl"));
|
|
|
+ request.setOutTradeNo(tradeNo);
|
|
|
+ Payer payer = new Payer();
|
|
|
+ payer.setOpenid(order.getOpenId());
|
|
|
+ request.setPayer(payer);
|
|
|
+ PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
|
|
+ order.setPrepayId(response.getPackageVal());
|
|
|
+ order.setPayment(response);
|
|
|
+ order.setAppId(appId);
|
|
|
+ order.setMchId(mchId);
|
|
|
+ order.setTradeNo(tradeNo);
|
|
|
+ order.setSerialNo(SnowFlakeId.instance().nextId());
|
|
|
+ log.info("小程序支付下单:\n{}", JSONObject.toJSON(order));
|
|
|
+ if (ListUtil.notEmpty(order.getCartIdList())) {
|
|
|
+ StringBuilder sb = new StringBuilder(",");
|
|
|
+ for (int cartId : order.getCartIdList()) {
|
|
|
+ sb.append(cartId).append(",");
|
|
|
+ }
|
|
|
+ order.setCartIds(sb.toString());
|
|
|
+ }
|
|
|
+ appletDao.insertNewOrder(order);
|
|
|
+ return ResultVoUtil.success(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/queryOrderState")
|
|
|
+ public ResultVo<Transaction> queryOrderState(@RequestBody WxAppletOrder order) {
|
|
|
+ Config config = WxPayConfigUtil.getInstance().getConfig();
|
|
|
+ JsapiService service = new JsapiService.Builder().config(config).build();
|
|
|
+ QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
|
|
|
+ request.setMchid(PropertiesUtil.getLocalProperty("mchId"));
|
|
|
+ request.setOutTradeNo(order.getTradeNo());
|
|
|
+ Transaction transaction = service.queryOrderByOutTradeNo(request);
|
|
|
+ log.info("小程序查询订单状态【{}】:{}", order.getTradeNo(), transaction);
|
|
|
+ Transaction.TradeStateEnum state = transaction.getTradeState();
|
|
|
+ if (state != Transaction.TradeStateEnum.NOTPAY) {
|
|
|
+ appletDao.updateOrderTradeState(order.getTradeNo(), state);
|
|
|
+ String cartIds = appletDao.selectCartIds(order.getTradeNo());
|
|
|
+ String[] splitArr = cartIds.split(",");
|
|
|
+ if (splitArr.length > 2) {
|
|
|
+ List<Integer> idList = new ArrayList<>();
|
|
|
+ for (int i = 1; i < splitArr.length - 1; i ++) {
|
|
|
+ idList.add(Integer.parseInt(splitArr[i]));
|
|
|
+ }
|
|
|
+ appletDao.updateCartTradeState(idList, state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(transaction);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getCartInfo")
|
|
|
+ public ResultVo<List<AppletMallCart>> getCartInfo(@RequestBody @Validated BaseInquiry inquiry) {
|
|
|
+ log.info("查询购物车:{}", JSONObject.toJSON(inquiry));
|
|
|
+ if (null == inquiry.getTradeState()) {
|
|
|
+ inquiry.setTradeState(Transaction.TradeStateEnum.NOTPAY);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(appletDao.selectUserCart(inquiry));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/addItemToCart")
|
|
|
+ public ResultVo<Integer> addItemToCart(@RequestBody AppletMallCart cart) {
|
|
|
+ log.info("添加购物车:{}", JSONObject.toJSON(cart));
|
|
|
+ String serialNo = SnowFlakeId.instance().nextId();
|
|
|
+ cart.setSerialNo(serialNo);
|
|
|
+ appletDao.insertItemToCart(cart);
|
|
|
+ return ResultVoUtil.success(appletDao.selectIdBySerialNo(serialNo));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/modifyCart")
|
|
|
+ public ResultVo<String> modifyCart(@RequestBody AppletMallCart cart) {
|
|
|
+ log.info("修改购物车:{}", JSONObject.toJSON(cart));
|
|
|
+ if (cart.getTemplateAmount() == 0) {
|
|
|
+ appletDao.deleteItemById(cart.getId());
|
|
|
+ } else {
|
|
|
+ appletDao.updateTemplateAmount(cart.getTemplateAmount(), cart.getId());
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success("操作成功。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/deleteItemFromCart")
|
|
|
+ public ResultVo<String> deleteItemFromCart(@RequestBody List<Integer> cartIds) {
|
|
|
+ log.info("删除购物车:{}", cartIds);
|
|
|
+ appletDao.deleteItemByIds(cartIds);
|
|
|
+ return ResultVoUtil.success("删除购物车成功。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/revokeCart")
|
|
|
+ public ResultVo<String> revokeCart(@RequestBody AppletMallCart cart) throws Exception {
|
|
|
+ if (StringUtil.isBlank(cart.getOpenId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "openId不能为空。");
|
|
|
+ }
|
|
|
+ AppletMallCart existCart = appletDao.selectCartById(cart.getId());
|
|
|
+ if (null == existCart) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "订单不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ WxAppletOrder order = appletDao.selectPayedOrderByCartId("%," + cart.getId() + ",%");
|
|
|
+ if (null == order) {
|
|
|
+ appletDao.updateCartTradeStateById(cart.getId(), Transaction.TradeStateEnum.REVOKED);
|
|
|
+ return ResultVoUtil.success("订单已取消。");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isBlank(cart.getRefundReason())) {
|
|
|
+ existCart.setRefundReason("无");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal totalFee = DecimalTool.multiply(existCart.getTemplatePrice(),
|
|
|
+ new BigDecimal(existCart.getTemplateAmount()));
|
|
|
+ order.setRefundAmount(DecimalTool.moneyYuanToFen(totalFee));
|
|
|
+
|
|
|
+ ResultVo<WxAppletOrder> refundResult = wxRefundService.wxAppletRefund(order);
|
|
|
+ if (refundResult.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, refundResult.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ WxAppletOrder refundedOrder = refundResult.getData();
|
|
|
+ if (refundedOrder.getTotalAmount() == Integer.parseInt(refundedOrder.getRefundAmount())) {
|
|
|
+ order.setRefundOpDatetime(new Date());
|
|
|
+ order.setRefundReason(existCart.getRefundReason());
|
|
|
+ appletDao.updateOrderRefundState(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ existCart.setRefundId(order.getRefundId());
|
|
|
+ existCart.setRefundOpCode(cart.getOpenId());
|
|
|
+ existCart.setRefundDateTime(refundedOrder.getRefundOpDatetime());
|
|
|
+ existCart.setRefundReason(refundedOrder.getRefundReason());
|
|
|
+ existCart.setTradeState(Transaction.TradeStateEnum.REFUND);
|
|
|
+ appletDao.updateCartRefund(existCart);
|
|
|
+ return ResultVoUtil.success("订单已取消");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/queryTcDepartment")
|
|
|
+ public ResultVo<JSONArray> queryTcDepartment() {
|
|
|
+ String url = appletThmzUrl + "/queryTcDiscuntDept";
|
|
|
+ ResultVo response = new RestTemplate().getForObject(url, ResultVo.class);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getCode() == 0) {
|
|
|
+ response.setCode(200);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/queryAllDepartment")
|
|
|
+ public ResultVo<JSONArray> queryAllDepartment() {
|
|
|
+ String url = appletThmzUrl + "/queryAllDept";
|
|
|
+ ResultVo response = new RestTemplate().getForObject(url, ResultVo.class);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getCode() == 0) {
|
|
|
+ response.setCode(200);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/queryTcByDepartment")
|
|
|
+ public ResultVo queryTcByDepartment(@RequestBody TcInquiry inquiry) {
|
|
|
+ String url = appletThmzUrl + "/queryTcByDeptCode";
|
|
|
+ ResultVo response = new RestTemplate().postForObject(url, inquiry, ResultVo.class);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getCode() == 0) {
|
|
|
+ response.setCode(200);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/queryTcByTemplateId")
|
|
|
+ public ResultVo queryTcByTemplateId(@RequestBody TcInquiry inquiry) {
|
|
|
+ String url = appletThmzUrl + "/queryTcByTemplateId";
|
|
|
+ ResultVo response = new RestTemplate().postForObject(url, inquiry, ResultVo.class);
|
|
|
+ if (null == response) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (response.getCode() == 0) {
|
|
|
+ response.setCode(200);
|
|
|
+ }
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getBoundCards")
|
|
|
+ public ResultVo<List<PatientBriefInfo>> getBoundCards(@RequestBody CardInquiry inquiry) {
|
|
|
+ AppletType appletType = inquiry.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ String openId = makeSpecialOpenId(appletType, inquiry.getOpenId());
|
|
|
+ log.info("查询小程序绑卡:{}", openId);
|
|
|
+ return ResultVoUtil.success(appletDao.getBindPatientCard(openId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/bindPatientId")
|
|
|
+ public ResultVo<HashMap<String, Object>> bindPatientId(@RequestBody IdCardAnalyzeResult param) {
|
|
|
+ AppletType appletType = param.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(param.getOpenId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "openId不能为空。");
|
|
|
+ }
|
|
|
+ param.setOpenId(makeSpecialOpenId(appletType, param.getOpenId()));
|
|
|
+ param.setSocialNo(param.getCardNo());
|
|
|
+ log.info("绑定就诊卡:{}", JSONObject.toJSON(param));
|
|
|
+ String column = param.getCardType() == 0 ? "patient_id" : "social_no";
|
|
|
+ List<IdCardAnalyzeResult> list = cardsDao.selectMzPatientBriefInfo(column, param.getCardNo());
|
|
|
+ if (null == list || list.isEmpty()) {
|
|
|
+ return idCardAnalyzeService.readInput(param);
|
|
|
+ }
|
|
|
+ if (list.size() > 1) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code", 1);
|
|
|
+ map.put("cards", list);
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
+ IdCardAnalyzeResult mzPatientMi = list.get(0);
|
|
|
+ if (param.getName().trim().equals(mzPatientMi.getName())) {
|
|
|
+ param.setPatientId(mzPatientMi.getPatientId());
|
|
|
+ param.setIcCardNo(mzPatientMi.getIcCardNo());
|
|
|
+ param.setSocialNo(mzPatientMi.getSocialNo());
|
|
|
+ int historyBindCount = cardsDao.selectHistoryBindCount(param.getPatientId(), param.getOpenId());
|
|
|
+ if (historyBindCount > 0) {
|
|
|
+ cardsDao.unfrozenPatientCard(param);
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code", 0);
|
|
|
+ map.put("cards", cardsDao.getBindPatientCard(param.getOpenId()));
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
+ int validBindCount = cardsDao.selectValidBindCount(param.getOpenId());
|
|
|
+ param.setIsDefault(validBindCount == 0 ? 1 : 0);
|
|
|
+ cardsDao.bindPatientCard(param);
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code", 0);
|
|
|
+ map.put("cards", cardsDao.getBindPatientCard(param.getOpenId()));
|
|
|
+ return ResultVoUtil.success(map);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "就诊卡姓名信息不匹配!");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/relieveBindCard")
|
|
|
+ public ResultVo<List<IdCardAnalyzeResult>> relieveBindCard(@RequestBody IdCardAnalyzeResult param) {
|
|
|
+ AppletType appletType = param.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(param.getOpenId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "openId不能为空。");
|
|
|
+ }
|
|
|
+ param.setOpenId(makeSpecialOpenId(appletType, param.getOpenId()));
|
|
|
+ log.info("解除就诊卡绑定:{}", JSONObject.toJSON(param));
|
|
|
+ cardsDao.frozenPatientCard(param.getPatientId(), param.getOpenId());
|
|
|
+ return ResultVoUtil.success(cardsDao.getBindPatientCard(param.getOpenId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/modifyBindInfo")
|
|
|
+ public ResultVo<String> modifyBindInfo(@RequestBody ModifyBindParam param) {
|
|
|
+ log.info("修改个人信息:{}", JSONObject.toJSON(param));
|
|
|
+ cardsDao.modifyPatientBindInfo(param);
|
|
|
+ cardsDao.updateWechatBind(param);
|
|
|
+ return ResultVoUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/getOrders")
|
|
|
+ public ResultVo<List<AppletMallCart>> getOrders(BaseInquiry inquiry) {
|
|
|
+ return ResultVoUtil.success(appletDao.selectUserCart(inquiry));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/updateTemplateThumb")
|
|
|
+ public ResultVo<String> updateTemplateThumb(TemplateThumb thumb) {
|
|
|
+ MultipartFile file = thumb.getFile();
|
|
|
+ if (null == file) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择图片!");
|
|
|
+ }
|
|
|
+ String contentType = file.getContentType();
|
|
|
+ if (null == contentType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择图片!");
|
|
|
+ }
|
|
|
+ if (!contentType.equals("image/jpeg") && !contentType.equals("image/png")) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "请选择 jpg/png 格式的图片!");
|
|
|
+ }
|
|
|
+ int id = thumb.getTemplateId();
|
|
|
+ String prefix = contentType.split("/")[1];
|
|
|
+ String fileName = "thumb_" + id + "." + prefix;
|
|
|
+ String path = "/home/images/template-thumbs/" + fileName;
|
|
|
+ try {
|
|
|
+ File newFile = new File(path);
|
|
|
+ if (newFile.exists()) {
|
|
|
+ newFile.delete();
|
|
|
+ appletDao.deleteTemplateThumb(id);
|
|
|
+ }
|
|
|
+ file.transferTo(newFile);
|
|
|
+ String url = "http://staticweb.hnthyy.cn/images/template-thumbs/" + fileName;
|
|
|
+ appletDao.insertTemplateThumb(id, url);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String makeSpecialOpenId(AppletType appletType, String openId) {
|
|
|
+ return appletType + "@" + openId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/linkHealthCard")
|
|
|
+ public ResultVo<ElectronicHealthCard> linkHealthCard(@RequestBody BaseInquiry inquiry) {
|
|
|
+ AppletType appletType = inquiry.getAppletType();
|
|
|
+ if (null == appletType) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "小程序类别不能为空。");
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(inquiry.getOpenId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "openId不能为空。");
|
|
|
+ }
|
|
|
+ inquiry.setOpenId(makeSpecialOpenId(appletType, inquiry.getOpenId()));
|
|
|
+ return electronicHealthCardService.linkHealthCard(inquiry.getHealthCode(), inquiry.getOpenId());
|
|
|
+ }
|
|
|
+}
|