service_hosp模块
一. 配置和配置文件①. Nacos服务地址/ MySQL数据库连接/ Redis数据库连接/ MongoDB连接/ Rabbitmq连接②. mp分页插件配置③. logback日志配置二. Repository层处理MongoDB数据①. DepartmentRepository—科室接口②. HospitalRepository—医院接口③. ScheduleRepository—排班接口④. Repository层总结三. Controller层接口处理①. DepartmentController—部门处理接口②. HospitalController—医院处理接口③. ScheduleController—排班处理接口④. HospitalSetController—医院设置功能接口处理⑤. HospApiController—医院Api接口⑥. ApiController—Api处理接口四. Service层①. DepartmentService和DepartmentServiceImpl 部门实现类②. HospitalService和HospitalServiceImpl 医院实现类③. ScheduleService和ScheduleServiceImpl 排班实现类④. HospitalSetService和HospitalSetServiceImpl 医院设置五. HospitalReceiver医院消息队列处理预约①. HospitalReceiver②. 消息队列处理订单总结六. 导包七. 多模块服务调用处理1. Springboot启动类 注解配置开启发现Client 开启Feign组件2. 创建一个service_cmn_client模块3. 使用创建的feignclient接口里的方法一. 配置和配置文件
①. Nacos服务地址/ MySQL数据库连接/ Redis数据库连接/ MongoDB连接/ Rabbitmq连接
Nacos服务地址/ MySQL数据库连接/ Redis数据库连接/ MongoDB连接/ Rabbitmq连接
# 服务端口server.port=8201# 服务名spring.application.name=service-hosp# 环境设置:dev、test、prodspring.profiles.active=dev# mysql数据库连接spring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/yygh_hosp?characterEncoding=utf-8&useSSL=falsespring.datasource.username=rootspring.datasource.password=1234#返回json的全局时间格式spring.jackson.date-format=yyyy-MM-dd HH:mm:ssspring.jackson.time-zone=GMT+8#配置mapper xml文件的路径mybatis-plus.mapper-locations=classpath:com/xizi/yygh/mapper/xml/*.xml# nacos服务地址spring.cloud.nacos.discovery.server-addr=112.74.164.23:8848#开启sentinel#feign.sentinel.enabled=true##设置sentinel地址#spring.cloud.sentinel.transport.dashboard=http://127.0.0.1:8858##mongodb地址spring.data.mongodb.host=112.74.164.23spring.data.mongodb.port=27017spring.data.mongodb.database=yygh_hosp##rabbitmq地址spring.rabbitmq.host=112.74.164.23spring.rabbitmq.port=5672spring.rabbitmq.username=guestspring.rabbitmq.password=guest
②. mp分页插件配置
@Configuration@MapperScan("com.xizi.yygh.mapper")public class HospConfig {/*mp分页插件*/@Beanpublic PaginationInterceptor PaginationInnerInterceptor(){return new PaginationInterceptor();}}
③. logback日志配置
<?xml version="1.0" encoding="UTF-8"?><configuration scan="true" scanPeriod="10 seconds"><!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 --><!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true --><!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 --><!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --><contextName>logback</contextName><!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 --><property name="log.path" value="D:/Hospital_log/edu" /><!-- 彩色日志 --><!-- 配置格式变量:CONSOLE_LOG_PATTERN 彩色日志格式 --><!-- magenta:洋红 --><!-- boldMagenta:粗红--><!-- cyan:青色 --><!-- white:白色 --><!-- magenta:洋红 --><property name="CONSOLE_LOG_PATTERN"value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) |%highlight(%-5level) |%blue(%thread) |%blue(%file:%line) |%green(%logger) |%cyan(%msg%n)"/><!--输出到控制台--><appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"><!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--><!-- 例如:如果此处配置了INFO级别,则后面其他位置即使配置了DEBUG级别的日志,也不会被输出 --><filter class="ch.qos.logback.classic.filter.ThresholdFilter"><level>INFO</level></filter><encoder><Pattern>${CONSOLE_LOG_PATTERN}</Pattern><!-- 设置字符集 --><charset>UTF-8</charset></encoder></appender><!--输出到文件--><!-- 时间滚动输出 level为 INFO 日志 --><appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><!-- 正在记录的日志文件的路径及文件名 --><file>${log.path}/log_info.log</file><!--日志文件输出格式--><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern><charset>UTF-8</charset></encoder><!-- 日志记录器的滚动策略,按日期,按大小记录 --><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- 每天日志归档路径以及格式 --><fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy><!--日志文件保留天数--><maxHistory>15</maxHistory></rollingPolicy><!-- 此日志文件只记录info级别的 --><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>INFO</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><!-- 时间滚动输出 level为 WARN 日志 --><appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><!-- 正在记录的日志文件的路径及文件名 --><file>${log.path}/log_warn.log</file><!--日志文件输出格式--><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><!-- 日志记录器的滚动策略,按日期,按大小记录 --><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy><!--日志文件保留天数--><maxHistory>15</maxHistory></rollingPolicy><!-- 此日志文件只记录warn级别的 --><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>warn</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><!-- 时间滚动输出 level为 ERROR 日志 --><appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><!-- 正在记录的日志文件的路径及文件名 --><file>${log.path}/log_error.log</file><!--日志文件输出格式--><encoder><pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern><charset>UTF-8</charset> <!-- 此处设置字符集 --></encoder><!-- 日志记录器的滚动策略,按日期,按大小记录 --><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern><timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><maxFileSize>100MB</maxFileSize></timeBasedFileNamingAndTriggeringPolicy><!--日志文件保留天数--><maxHistory>15</maxHistory></rollingPolicy><!-- 此日志文件只记录ERROR级别的 --><filter class="ch.qos.logback.classic.filter.LevelFilter"><level>ERROR</level><onMatch>ACCEPT</onMatch><onMismatch>DENY</onMismatch></filter></appender><!--<logger>用来设置某一个包或者具体的某一个类的日志打印级别、以及指定<appender>。<logger>仅有一个name属性,一个可选的level和一个可选的addtivity属性。name:用来指定受此logger约束的某一个包或者具体的某一个类。level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,如果未设置此属性,那么当前logger将会继承上级的级别。--><!--使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:第一种把<root level="INFO">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息第二种就是单独给mapper下目录配置DEBUG模式,代码如下,这样配置sql语句会打印,其他还是正常DEBUG级别:--><!--开发环境:打印控制台--><springProfile name="dev"><!--可以输出项目中的debug日志,包括mybatis的sql日志--><logger name="com.guli" level="INFO" /><!--root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,默认是DEBUG可以包含零个或多个appender元素。--><root level="INFO"><appender-ref ref="CONSOLE" /><appender-ref ref="INFO_FILE" /><appender-ref ref="WARN_FILE" /><appender-ref ref="ERROR_FILE" /></root></springProfile><!--生产环境:输出到文件--><springProfile name="pro"><root level="INFO"><appender-ref ref="CONSOLE" /><appender-ref ref="DEBUG_FILE" /><appender-ref ref="INFO_FILE" /><appender-ref ref="ERROR_FILE" /><appender-ref ref="WARN_FILE" /></root></springProfile></configuration>
二. Repository层处理MongoDB数据
①. DepartmentRepository—科室接口
@Repositorypublic interface DepartmentRepository extends MongoRepository<Department,String> {//上传科室接口 MongoRepository定义方法规则Department getDepartmentByHoscodeAndDepcode(String hoscode, String depcode);}
②. HospitalRepository—医院接口
@Repositorypublic interface HospitalRepository extends MongoRepository<Hospital,String> {//判断是否存在数据Hospital getHospitalByHoscode(String hoscode);//根据医院名称查询List<Hospital> findHospitalByHosnameLike(String hosname);}
③. ScheduleRepository—排班接口
@Repositorypublic interface ScheduleRepository extends MongoRepository<Schedule,String> {//根据医院编号 和 排班编号查询Schedule getScheduleByHoscodeAndHosScheduleId(String hoscode, String hosScheduleId);//根据医院编号 、科室编号和工作日期,查询排班详细信息List<Schedule> findScheduleByHoscodeAndDepcodeAndWorkDate(String hoscode, String depcode, Date toDate);}
④. Repository层总结
extends MongoRepository<Department,String> 接口extends MongoRepository<Hospital,String> 接口extends MongoRepository<Schedule,String> 接口根据mongodb规则进行自定义命名方法比如 Hospital getHospitalByHoscode(String hoscode);比如 List findHospitalByHosnameLike(String hosname);三. Controller层接口处理
①. DepartmentController—部门处理接口
@RestController@RequestMapping("/admin/hosp/department")//@CrossOriginpublic class DepartmentController {@Autowiredprivate DepartmentService departmentService;//根据医院编号,查询医院所有科室列表@ApiOperation(value = "查询医院所有科室列表")@GetMapping("getDeptList/{hoscode}")public Result getDeptList(@PathVariable String hoscode) {List<DepartmentVo> list = departmentService.findDeptTree(hoscode);return Result.ok(list);}}
②. HospitalController—医院处理接口
@RestController@RequestMapping("/admin/hosp/hospital")//@CrossOriginpublic class HospitalController {@Autowiredprivate HospitalService hospitalService;//医院列表(条件查询分页)@GetMapping("list/{page}/{limit}")public Result listHosp(@PathVariable Integer page,@PathVariable Integer limit,HospitalQueryVo hospitalQueryVo) {Page<Hospital> pageModel = hospitalService.selectHospPage(page,limit,hospitalQueryVo);List<Hospital> content = pageModel.getContent();long totalElements = pageModel.getTotalElements();return Result.ok(pageModel);}//更新医院上线状态@ApiOperation(value = "更新医院上线状态")@GetMapping("updateHospStatus/{id}/{status}")public Result updateHospStatus(@PathVariable String id,@PathVariable Integer status) {hospitalService.updateStatus(id,status);return Result.ok();}//医院详情信息@ApiOperation(value = "医院详情信息")@GetMapping("showHospDetail/{id}")public Result showHospDetail(@PathVariable String id) {//根据id获取医院的详情信息Map<String, Object> map = hospitalService.getHospById(id);return Result.ok(map);}}
③. ScheduleController—排班处理接口
@RestController@RequestMapping("/admin/hosp/schedule")//@CrossOriginpublic class ScheduleController {@Autowiredprivate ScheduleService scheduleService;//根据医院编号 和 科室编号 ,查询排班规则数据@ApiOperation(value ="查询排班规则数据")@GetMapping("getScheduleRule/{page}/{limit}/{hoscode}/{depcode}")public Result getScheduleRule(@PathVariable long page,@PathVariable long limit,@PathVariable String hoscode,@PathVariable String depcode) {Map<String,Object> map = scheduleService.getRuleSchedule(page,limit,hoscode,depcode);return Result.ok(map);}//根据医院编号 、科室编号和工作日期,查询排班详细信息@ApiOperation(value = "查询排班详细信息")@GetMapping("getScheduleDetail/{hoscode}/{depcode}/{workDate}")public Result getScheduleDetail( @PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate) {List<Schedule> list = scheduleService.getDetailSchedule(hoscode,depcode,workDate);return Result.ok(list);}}
④. HospitalSetController—医院设置功能接口处理
@RestController@RequestMapping("/admin/hosp/hospitalSet")//@CrossOrigin //允许跨域访问public class HospitalSetController {//注入Service@Autowiredprivate HospitalSetService hospitalSetService;@ApiOperation(value = "获取所有医院设置")@GetMapping("findAll")public Result findAll(){List<HospitalSet> list = hospitalSetService.list();return Result.ok(list);}//2 逻辑删除医院设置@ApiOperation(value = "逻辑删除医院设置")@DeleteMapping("{id}")public Result removeHospSet(@PathVariable Long id) {boolean flag = hospitalSetService.removeById(id);if(flag) {return Result.ok();} else {return Result.fail();}}//3 条件查询带分页@PostMapping("findPageHospSet/{current}/{limit}")public Result findPageHospSet(@PathVariable long current,@PathVariable long limit,@RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo) {//创建page对象,传递当前页,每页记录数Page<HospitalSet> page = new Page<>(current,limit);//构建条件QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();String hosname = hospitalSetQueryVo.getHosname();//医院名称String hoscode = hospitalSetQueryVo.getHoscode();//医院编号if(!StringUtils.isEmpty(hosname)) {wrapper.like("hosname",hospitalSetQueryVo.getHosname());}if(!StringUtils.isEmpty(hoscode)) {wrapper.eq("hoscode",hospitalSetQueryVo.getHoscode());}//调用方法实现分页查询Page<HospitalSet> pageHospitalSet = hospitalSetService.page(page, wrapper);//返回结果return Result.ok(pageHospitalSet);}//4 添加医院设置@PostMapping("saveHospitalSet")public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet) {//设置状态 1 使用 0 不能使用hospitalSet.setStatus(1);//签名秘钥Random random = new Random();hospitalSet.setSignKey(MD5.encrypt(System.currentTimeMillis()+""+random.nextInt(1000)));//调用serviceboolean save = hospitalSetService.save(hospitalSet);if(save) {return Result.ok();} else {return Result.fail();}}//5 根据id获取医院设置@GetMapping("getHospSet/{id}")public Result getHospSet(@PathVariable Long id) {HospitalSet hospitalSet = hospitalSetService.getById(id);return Result.ok(hospitalSet);}//6 修改医院设置@PostMapping("updateHospitalSet")public Result updateHospitalSet(@RequestBody HospitalSet hospitalSet) {boolean flag = hospitalSetService.updateById(hospitalSet);if(flag) {return Result.ok();} else {return Result.fail();}}//7 批量删除医院设置@DeleteMapping("batchRemove")public Result batchRemoveHospitalSet(@RequestBody List<Long> idList) {hospitalSetService.removeByIds(idList);return Result.ok();}//8 医院设置锁定和解锁@PutMapping("lockHospitalSet/{id}/{status}")public Result lockHospitalSet(@PathVariable Long id,@PathVariable Integer status) {//根据id查询医院设置信息HospitalSet hospitalSet = hospitalSetService.getById(id);//设置状态hospitalSet.setStatus(status);//调用方法hospitalSetService.updateById(hospitalSet);return Result.ok();}//9 发送签名秘钥@PutMapping("sendKey/{id}")public Result lockHospitalSet(@PathVariable Long id) {HospitalSet hospitalSet = hospitalSetService.getById(id);String signKey = hospitalSet.getSignKey();String hoscode = hospitalSet.getHoscode();//TODO 发送短信return Result.ok();}}
⑤. HospApiController—医院Api接口
@RestController@RequestMapping("/api/hosp/hospital")public class HospApiController {@Autowiredprivate HospitalService hospitalService;@Autowiredprivate DepartmentService departmentService;@Autowiredprivate ScheduleService scheduleService;@Autowiredprivate HospitalSetService hospitalSetService;@ApiOperation(value = "查询医院列表")@GetMapping("findHospList/{page}/{limit}")public Result findHospList(@PathVariable Integer page,@PathVariable Integer limit,HospitalQueryVo hospitalQueryVo) {Page<Hospital> hospitals = hospitalService.selectHospPage(page, limit, hospitalQueryVo);return Result.ok(hospitals);}@ApiOperation(value = "根据医院名称查询")@GetMapping("findByHosName/{hosname}")public Result findByHosName(@PathVariable String hosname) {List<Hospital> list = hospitalService.findByHosname(hosname);return Result.ok(list);}@ApiOperation(value = "根据医院编号获取科室")@GetMapping("department/{hoscode}")public Result index(@PathVariable String hoscode) {List<DepartmentVo> list = departmentService.findDeptTree(hoscode);return Result.ok(list);}@ApiOperation(value = "根据医院编号获取医院预约挂号详情")@GetMapping("findHospDetail/{hoscode}")public Result item(@PathVariable String hoscode) {Map<String, Object> map = hospitalService.item(hoscode);return Result.ok(map);}@ApiOperation(value = "获取可预约排班数据")@GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")public Result getBookingSchedule(@ApiParam(name = "page", value = "当前页码", required = true)@PathVariable Integer page,@ApiParam(name = "limit", value = "每页记录数", required = true)@PathVariable Integer limit,@ApiParam(name = "hoscode", value = "医院code", required = true)@PathVariable String hoscode,@ApiParam(name = "depcode", value = "科室code", required = true)@PathVariable String depcode) {return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));}@ApiOperation(value = "获取排班数据")@GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")public Result findScheduleList(@ApiParam(name = "hoscode", value = "医院code", required = true)@PathVariable String hoscode,@ApiParam(name = "depcode", value = "科室code", required = true)@PathVariable String depcode,@ApiParam(name = "workDate", value = "排班日期", required = true)@PathVariable String workDate) {return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));}@ApiOperation(value = "获取排班id获取排班数据")@GetMapping("getSchedule/{scheduleId}")public Result getSchedule(@PathVariable String scheduleId) {Schedule schedule = scheduleService.getScheduleId(scheduleId);return Result.ok(schedule);}@ApiOperation(value = "根据排班id获取预约下单数据")@GetMapping("inner/getScheduleOrderVo/{scheduleId}")public ScheduleOrderVo getScheduleOrderVo(@ApiParam(name = "scheduleId", value = "排班id", required = true)@PathVariable("scheduleId") String scheduleId) {return scheduleService.getScheduleOrderVo(scheduleId);}@ApiOperation(value = "获取医院签名信息")@GetMapping("inner/getSignInfoVo/{hoscode}")public SignInfoVo getSignInfoVo(@ApiParam(name = "hoscode", value = "医院code", required = true)@PathVariable("hoscode") String hoscode) {return hospitalSetService.getSignInfoVo(hoscode);}}
⑥. ApiController—Api处理接口
@RestController@RequestMapping("/api/hosp")public class ApiController {@Autowiredprivate HospitalService hospitalService;@Autowiredprivate HospitalSetService hospitalSetService;@Autowiredprivate DepartmentService departmentService;@Autowiredprivate ScheduleService scheduleService;//删除排班@PostMapping("schedule/remove")public Result remove(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//获取医院编号和排班编号String hoscode = (String)paramMap.get("hoscode");String hosScheduleId = (String)paramMap.get("hosScheduleId");//TODO 签名校验scheduleService.remove(hoscode,hosScheduleId);return Result.ok();}//查询排班接口@PostMapping("schedule/list")public Result findSchedule(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//医院编号String hoscode = (String)paramMap.get("hoscode");//科室编号String depcode = (String)paramMap.get("depcode");//当前页 和 每页记录数int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page"));int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));//TODO 签名校验ScheduleQueryVo scheduleQueryVo = new ScheduleQueryVo();scheduleQueryVo.setHoscode(hoscode);scheduleQueryVo.setDepcode(depcode);//调用service方法Page<Schedule> pageModel = scheduleService.findPageSchedule(page,limit,scheduleQueryVo);return Result.ok(pageModel);}//上传排班接口@PostMapping("saveSchedule")public Result saveSchedule(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//TODO 签名校验scheduleService.save(paramMap);return Result.ok();}//删除科室接口@PostMapping("department/remove")public Result removeDepartment(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//医院编号 和 科室编号String hoscode = (String)paramMap.get("hoscode");String depcode = (String)paramMap.get("depcode");//TODO 签名校验departmentService.remove(hoscode,depcode);return Result.ok();}//查询科室接口@PostMapping("department/list")public Result findDepartment(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//医院编号String hoscode = (String)paramMap.get("hoscode");//当前页 和 每页记录数int page = StringUtils.isEmpty(paramMap.get("page")) ? 1 : Integer.parseInt((String)paramMap.get("page"));int limit = StringUtils.isEmpty(paramMap.get("limit")) ? 1 : Integer.parseInt((String)paramMap.get("limit"));//TODO 签名校验DepartmentQueryVo departmentQueryVo = new DepartmentQueryVo();departmentQueryVo.setHoscode(hoscode);//调用service方法Page<Department> pageModel = departmentService.findPageDepartment(page,limit,departmentQueryVo);return Result.ok(pageModel);}//上传科室接口@PostMapping("saveDepartment")public Result saveDepartment(HttpServletRequest request) {//获取传递过来科室信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//获取医院编号String hoscode = (String)paramMap.get("hoscode");//1 获取医院系统传递过来的签名,签名进行MD5加密String hospSign = (String)paramMap.get("sign");//2 根据传递过来医院编码,查询数据库,查询签名String signKey = hospitalSetService.getSignKey(hoscode);//3 把数据库查询签名进行MD5加密String signKeyMd5 = MD5.encrypt(signKey);//4 判断签名是否一致if(!hospSign.equals(signKeyMd5)) {throw new HospitalException(ResultCodeEnum.SIGN_ERROR);}//调用service的方法departmentService.save(paramMap);return Result.ok();}//查询医院@PostMapping("hospital/show")public Result getHospital(HttpServletRequest request) {//获取传递过来医院信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//获取医院编号String hoscode = (String)paramMap.get("hoscode");//1 获取医院系统传递过来的签名,签名进行MD5加密String hospSign = (String)paramMap.get("sign");//2 根据传递过来医院编码,查询数据库,查询签名String signKey = hospitalSetService.getSignKey(hoscode);//3 把数据库查询签名进行MD5加密String signKeyMd5 = MD5.encrypt(signKey);//4 判断签名是否一致if(!hospSign.equals(signKeyMd5)) {throw new HospitalException(ResultCodeEnum.SIGN_ERROR);}//调用service方法实现根据医院编号查询Hospital hospital = hospitalService.getByHoscode(hoscode);return Result.ok(hospital);}//上传医院接口@PostMapping("saveHospital")public Result saveHosp(HttpServletRequest request) {//获取传递过来医院信息Map<String, String[]> requestMap = request.getParameterMap();Map<String, Object> paramMap = HttpRequestHelper.switchMap(requestMap);//1 获取医院系统传递过来的签名,签名进行MD5加密String hospSign = (String)paramMap.get("sign");//2 根据传递过来医院编码,查询数据库,查询签名String hoscode = (String)paramMap.get("hoscode");String signKey = hospitalSetService.getSignKey(hoscode);//3 把数据库查询签名进行MD5加密String signKeyMd5 = MD5.encrypt(signKey);//4 判断签名是否一致if(!hospSign.equals(signKeyMd5)) {throw new HospitalException(ResultCodeEnum.SIGN_ERROR);}//传输过程中“+”转换为了“ ”,因此我们要转换回来String logoData = (String)paramMap.get("logoData");logoData = logoData.replaceAll(" ","+");paramMap.put("logoData",logoData);//调用service的方法hospitalService.save(paramMap);return Result.ok();}
四. Service层
①. DepartmentService和DepartmentServiceImpl 部门实现类
public interface DepartmentService {//上传科室接口void save(Map<String, Object> paramMap);//查询科室接口Page<Department> findPageDepartment(int page, int limit, DepartmentQueryVo departmentQueryVo);//删除科室接口void remove(String hoscode, String depcode);//根据医院编号,查询医院所有科室列表List<DepartmentVo> findDeptTree(String hoscode);//根据科室编号,和医院编号,查询科室名称String getDepName(String hoscode, String depcode);//根据科室编号,和医院编号,查询科室Department getDepartment(String hoscode, String depcode);}
②. HospitalService和HospitalServiceImpl 医院实现类
public interface HospitalService {//上传医院接口void save(Map<String, Object> paramMap);//实现根据医院编号查询Hospital getByHoscode(String hoscode);//医院列表(条件查询分页)Page<Hospital> selectHospPage(Integer page, Integer limit, HospitalQueryVo hospitalQueryVo);//更新医院上线状态void updateStatus(String id, Integer status);//医院详情信息Map<String, Object> getHospById(String id);//获取医院名称String getHospName(String hoscode);//根据医院名称查询List<Hospital> findByHosname(String hosname);//根据医院编号获取医院预约挂号详情Map<String, Object> item(String hoscode);}
③. ScheduleService和ScheduleServiceImpl 排班实现类
public interface ScheduleService {//上传排班接口void save(Map<String, Object> paramMap);//查询排班接口Page<Schedule> findPageSchedule(int page, int limit, ScheduleQueryVo scheduleQueryVo);//删除排班void remove(String hoscode, String hosScheduleId);//根据医院编号 和 科室编号 ,查询排班规则数据Map<String, Object> getRuleSchedule(long page, long limit, String hoscode, String depcode);//根据医院编号 、科室编号和工作日期,查询排班详细信息List<Schedule> getDetailSchedule(String hoscode, String depcode, String workDate);//获取可预约的排班数据Map<String,Object> getBookingScheduleRule(int page,int limit,String hoscode,String depcode);//获取排班id获取排班数据Schedule getScheduleId(String scheduleId);//根据排班id获取预约下单数据ScheduleOrderVo getScheduleOrderVo(String scheduleId);//更新排班数据 用于mpvoid update(Schedule schedule);}
④. HospitalSetService和HospitalSetServiceImpl 医院设置
public interface HospitalSetService extends IService<HospitalSet> {//2 根据传递过来医院编码,查询数据库,查询签名String getSignKey(String hoscode);//获取医院签名信息SignInfoVo getSignInfoVo(String hoscode);}
五. HospitalReceiver医院消息队列处理预约
①. HospitalReceiver
@Componentpublic class HospitalReceiver {@Autowiredprivate ScheduleService scheduleService;@Autowiredprivate RabbitService rabbitService;@RabbitListener(bindings = @QueueBinding(value = @Queue(value = MqConst.QUEUE_ORDER, durable = "true"),exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_ORDER),key = {MqConst.ROUTING_ORDER}))public void receiver(OrderMqVo orderMqVo, Message message, Channel channel) throws IOException {//如果剩余的预约数不为nullif(null != orderMqVo.getAvailableNumber()) {//更加排班id获取排班数据Schedule schedule = scheduleService.getScheduleId(orderMqVo.getScheduleId());//设置可预约数量schedule.setReservedNumber(orderMqVo.getReservedNumber());//设置剩余数量schedule.setAvailableNumber(orderMqVo.getAvailableNumber());//更新排班信息scheduleService.update(schedule);} else {//取消预约更新预约数Schedule schedule = scheduleService.getScheduleId(orderMqVo.getScheduleId());//剩余数量+1int availableNumber = schedule.getAvailableNumber().intValue() + 1;//设置剩余数量schedule.setAvailableNumber(availableNumber);//更新剩余数量scheduleService.update(schedule);}//发送短信MsmVo msmVo = orderMqVo.getMsmVo();//如果短信实体不为空的话 if(null != msmVo) {//调用封装好的服务模块rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_MSM, MqConst.ROUTING_MSM_ITEM, msmVo);}}}
②. 消息队列处理订单总结
@RabbitListener(bindings,value,exchange,key) 注解监听器处理订单bindings = @QueueBinding() 绑定队列@Queue(value = MqConst.QUEUE_ORDER, durable = “true”) 队列exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_ORDER) 交换机key = {MqConst.ROUTING_ORDER} key为路由调用RabbitService服务封装的sendMessage() 发送信息方法注入排班服务 及时进行更新排班信息六. 导包
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-mongodb</artifactId></dependency><dependency><groupId>com.xizi</groupId><artifactId>service_cmn_client</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.xizi</groupId><artifactId>rabbit_util</artifactId><version>0.0.1-SNAPSHOT</version></dependency>
七. 多模块服务调用处理
当service_hospital模块想要调用service_cmn里的接口时
1. Springboot启动类 注解配置开启发现Client 开启Feign组件
@EnableDiscoveryClient @EnableFeignClients(basePackages = “com.xizi”) 两个注解
@SpringBootApplication@EnableDiscoveryClient@EnableFeignClients(basePackages = "com.xizi")public class ServiceUserApplication {public static void main(String[] args) {SpringApplication.run(ServiceUserApplication.class, args);}}
2. 创建一个service_cmn_client模块
创建一个DictFeignClient接口
@FeignClient(value = "service-cmn")@Repositorypublic interface DictFeignClient {//根据dictcode和value查询@GetMapping("/admin/cmn/dict/getName/{dictCode}/{value}")public String getName(@PathVariable("dictCode") String dictCode, @PathVariable("value") String value);//根据value查询@GetMapping("/admin/cmn/dict/getName/{value}")public String getName(@PathVariable("value") String value);}
3. 使用创建的feignclient接口里的方法
@Servicepublic class HospitalServiceImpl implements HospitalService {@Autowiredprivate HospitalRepository hospitalRepository;@Autowiredprivate DictFeignClient dictFeignClient;
如果觉得《预约挂号医院管理项目----service_hosp模块—医院管理》对你有帮助,请点赞、收藏,并留下你的观点哦!