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; /** * @Author: 西安路泰科技有限公司/lige * @Date: 2023/1/12 11:08 */ @RestController @RequestMapping ("/cus/hospital") @Api (tags = "小程序-客户信息") public class CustomerController extends BaseController { @Resource private ITjCustomerService customerService; @Resource private ITjOrderService tjOrderService; @Autowired private ISysDictTypeService dictTypeService; @Resource private ISysConfigService sysConfigService; @Autowired private HisApiConfigService hisApiConfigService; @Autowired private HisApiMethodService controller; @Autowired private HisApiGetMethodService hisApiGetMethodService; /** * 小程序就诊人列表 */ @GetMapping ("/getListByOpenId") @ApiOperation (value = "小程序-就诊人列表") public AjaxResult getListByOpenId(@RequestParam String openId) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjCustomer::getConnect, openId); final List list = customerService.list(wq); return AjaxResult.success(list); } /** * 解绑就诊人 */ @PostMapping ("/delCustomer") @ApiOperation (value = "小程序-解绑就诊人") public AjaxResult delCustomer(@RequestBody @ApiParam (value = "客户对象信息") TjCustomer tjCustomer) { if (tjCustomer == null) { return AjaxResult.error(); } LambdaQueryWrapper wq = new LambdaQueryWrapper(); wq.eq(TjCustomer::getCusIdcard, tjCustomer.getCusIdcard()); wq.eq(TjCustomer::getCusPhone, tjCustomer.getCusPhone()); wq.eq(TjCustomer::getCusName, tjCustomer.getCusName()); final TjCustomer one = customerService.getOne(wq); one.setConnect(""); final boolean b = customerService.updateById(one); if (b) { return AjaxResult.success(); } else { return AjaxResult.error("解绑失败"); } } /** * 新增并绑定就诊人 */ @PostMapping ("/addNew") @ApiOperation (value = "小程序-新增并绑定就诊人") @Transactional @RepeatSubmit public AjaxResult addNew(@RequestBody @ApiParam (value = "客户对象信息") TjCustomer tjCustomer) { if (tjCustomer == null) { return AjaxResult.error("添加失败"); } String cusIdcard = tjCustomer.getCusIdcard(); if (cusIdcard == null) { return AjaxResult.error("添加失败"); } //判断身份证号格式是否正确 if (!MatchUtils.isMobileNO(tjCustomer.getCusPhone())) return AjaxResult.error("手机号错误"); if (cusIdcard.length() == 18) { if (!MatchUtils.isIdCard(cusIdcard)) { return AjaxResult.error("身份证号码错误"); } } if (cusIdcard.length() == 9) { if (!MatchUtils.cardValidates(cusIdcard)) { return AjaxResult.error("身份证号码错误"); } } LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjCustomer::getCusIdcard, cusIdcard); TjCustomer customer = customerService.getOne(wq); String key = sysConfigService.selectConfigByKey("sfkqdyhis"); if (customer != null) { customer.setConnect(tjCustomer.getConnect()); customerService.updateById(customer); return AjaxResult.success(customer); } 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")); tjCustomer.setCusSex(Long.valueOf(MatchUtils.getSexByIdCard(cusIdcard))); tjCustomer.setAge(String.valueOf(MatchUtils.getAgeByIdCard(cusIdcard))); tjCustomer.setIdType("1"); tjCustomer.setAgeUnit("0"); tjCustomer.setRole(2L); tjCustomer.setCusIntroduce("无"); tjCustomer.setCusNumber(0L); tjCustomer.setCusIsvip("N"); 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.success(tjCustomer); } /** * 小程序体检报告列表 */ @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) { if (tjCustomer == null) { return AjaxResult.error(); } LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjCustomer::getCusIdcard, tjCustomer.getCusIdcard()); wq.eq(TjCustomer::getCusPhone, tjCustomer.getCusPhone()); wq.eq(TjCustomer::getCusName, tjCustomer.getCusName()); final TjCustomer one = customerService.getOne(wq); return AjaxResult.success(one); } /** * 小程序判断是否能编辑 */ @PostMapping ("/canUpdate") @ApiOperation (value = "小程序判断是否能编辑") public AjaxResult canUpdate(@RequestBody TjCustomer tjCustomer) { if (tjCustomer == null) { return AjaxResult.error("出错了,请联系工作人员!"); } LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjOrder::getUserId, tjCustomer.getCusId()); final List list = tjOrderService.list(wq); if (list.size() != 0) { return AjaxResult.success(0); } return AjaxResult.success(1); } /** * 小程序编辑就诊人信息 */ @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 (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.success(one); } /** * 小程序根据手机号码获取用户身份证号码 */ @GetMapping (value = "/getIdCardByPhone") @ApiOperation (value = "小程序根据手机号码获取用户身份证号码") public AjaxResult getIdCardByPhone(@RequestParam @ApiParam (value = "手机号") String phone) { if (!"".equals(phone) && phone != null && MatchUtils.isMobileNO(phone)) { LambdaQueryWrapper qw = new LambdaQueryWrapper<>(); qw.eq(TjCustomer::getCusPhone, phone); List tjCustomer1 = customerService.list(qw); if (tjCustomer1 != null && tjCustomer1.size() > 0) { List num = new ArrayList<>(); for (TjCustomer tjCustomer : tjCustomer1) { num.add(tjCustomer.getCusIdcard()); } return AjaxResult.success(num); } return AjaxResult.success("暂无记录,请先绑定身份证号!"); } return AjaxResult.error("手机号无效"); } /** * 根据字典类型查询字典数据信息 */ @GetMapping (value = "/type/{dictType}") public AjaxResult dictType(@PathVariable String dictType) { List data = dictTypeService.selectDictDataByType(dictType); if (StringUtils.isNull(data)) { data = new ArrayList(); } 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 resultData = (Map) 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 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")); } }