From c1b942ccf2ee1ab5d01ae590d6a16ce14d0cf54b Mon Sep 17 00:00:00 2001 From: luliqiang <kidgrow> Date: Fri, 12 Mar 2021 19:21:45 +0800 Subject: [PATCH] 1、增加私有云客户创建时的标识位和服务器Guuid 2、增加私有云服务器License下载 3、增加私有云数据库下载 --- kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDepartmentServiceImpl.java | 412 ++++++++++++++++++++++++++++++++++++++-- kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java | 1 kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/ISysDepartmentService.java | 8 kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/java/com/kidgrow/usercenter/controller/SysDepartmentController.java | 168 ++++++++++++++-- 4 files changed, 541 insertions(+), 48 deletions(-) diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/ISysDepartmentService.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/ISysDepartmentService.java index 8b6023f..ad2fe2e 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/ISysDepartmentService.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/ISysDepartmentService.java @@ -50,5 +50,13 @@ *运动处方调用 是否开通服务 */ ResultBody getHealth(SysDepartment sysDepartment); + + /** + * 初始化私有云本地数据库 + * @param hospitalId + * @param departmentId + * @return java.lang.String + */ + String initPrivateData(Long hospitalId,Long departmentId); } diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDepartmentServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDepartmentServiceImpl.java index e804af7..df7ac17 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDepartmentServiceImpl.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDepartmentServiceImpl.java @@ -1,12 +1,20 @@ package com.kidgrow.usercenter.service.impl; +import cn.hutool.core.date.DateTime; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.kidgrow.common.constant.CommonConstant; import com.kidgrow.common.model.PageResult; import com.kidgrow.common.model.ResultBody; import com.kidgrow.common.model.SysOrganization; +import com.kidgrow.common.model.UserType; import com.kidgrow.common.service.impl.SuperServiceImpl; import com.kidgrow.common.utils.DateUtils; +import com.kidgrow.oprationcenter.feign.ProductOrderService; +import com.kidgrow.oprationcenter.model.ProductOrder; +import com.kidgrow.oprationcenter.model.ProductOrderDetail; import com.kidgrow.usercenter.mapper.SysDepartmentMapper; import com.kidgrow.usercenter.model.SysDepartment; import com.kidgrow.usercenter.model.SysHospital; @@ -16,18 +24,22 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> + * + * @version 1.0 * @Description: 科室表<br> * @Project: 用户中心<br> * @CreateDate: Created in 2020-04-02 14:02:50 <br> * @Author: <a href="4345453@kidgrow.com">liuke</a> - * @version 1.0 */ @Slf4j @Service @@ -37,53 +49,65 @@ private ISysOrganizationService iSysOrganizationService; @Autowired private ISysHospitalService iSysHospitalService; + + @Autowired + private ProductOrderService productOrderService; + + @Autowired + private PasswordEncoder passwordEncoder; + + @Value("${spring.profiles.active}") + private String envName; + /** * 列表 + * * @param params * @return */ @Override - public PageResult<SysDepartment> findList(Map<String, Object> params){ + public PageResult<SysDepartment> findList(Map<String, Object> params) { Page<SysDepartment> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit")); - List<SysDepartment> list = baseMapper.findList(page, params); + List<SysDepartment> list = baseMapper.findList(page, params); return PageResult.<SysDepartment>builder().data(list).code(0).count(page.getTotal()).build(); } /** - * 根据SysDepartment对象当做查询条件进行查询 - * @param sysDepartment - * @return SysDepartment - */ + * 根据SysDepartment对象当做查询条件进行查询 + * + * @param sysDepartment + * @return SysDepartment + */ @Override - public SysDepartment findByObject(SysDepartment sysDepartment){ + public SysDepartment findByObject(SysDepartment sysDepartment) { return baseMapper.findByObject(sysDepartment); } @Override public boolean updatePay(Long departmentId, boolean isPay) { - return baseMapper.updatePay(departmentId,isPay); + return baseMapper.updatePay(departmentId, isPay); } @Override public ResultBody findAll(Map<String, Object> params) { - return ResultBody.ok().data(baseMapper.selectByMap(params)); + return ResultBody.ok().data(baseMapper.selectByMap(params)); } @Override public ResultBody findListByHospitalId(Map<String, Object> params) { //查询组织 Long id = MapUtils.getLong(params, "id"); - List<SysDepartment> sysDepartments=new ArrayList<>(); + List<SysDepartment> sysDepartments = new ArrayList<>(); SysHospital byId = iSysHospitalService.getById(id); - if(byId!=null){ - params=new HashMap<>(); - params.put("org_parent_id",byId.getOrgId()); + if (byId != null) { + params = new HashMap<>(); + params.put("org_parent_id", byId.getOrgId()); List<SysOrganization> sysOrganizations = iSysOrganizationService.listByMap(params); - if (sysOrganizations.size()>0) { + if (sysOrganizations.size() > 0) { List<Long> collect = sysOrganizations.stream().map(e -> e.getId()).collect(Collectors.toList()); - QueryWrapper<SysDepartment> queryWrapper=new QueryWrapper(); - queryWrapper.in("org_id",collect ); - sysDepartments= baseMapper.selectList(queryWrapper); + QueryWrapper<SysDepartment> queryWrapper = new QueryWrapper(); + queryWrapper.in("org_id", collect); + sysDepartments = baseMapper.selectList(queryWrapper); } } return ResultBody.ok().data(sysDepartments); @@ -91,32 +115,366 @@ @Override public String checkDepartmentName(Long hosId, String departmentName) { - String departName=baseMapper.checkDepartmentName(hosId,departmentName); + String departName = baseMapper.checkDepartmentName(hosId, departmentName); return departName; } @Override public ResultBody getHealth(SysDepartment sysDepartment) { SysDepartment department = baseMapper.selectById(sysDepartment.getId()); - if(department==null){ + if (department == null) { return ResultBody.failed("该数据为空"); - }else { - if(department.getIsHealth()){ - Date now= new Date(); + } else { + if (department.getIsHealth()) { + Date now = new Date(); Date endDate = DateUtils.addDays(department.getHealthEndTime(), 1); - if(now.getTime()<department.getHealthBeginTime().getTime()){ + if (now.getTime() < department.getHealthBeginTime().getTime()) { department.setIsHealth(false); return ResultBody.ok().data(department); - }else if(department.getHealthBeginTime().getTime()<=now.getTime()&&now.getTime()<=endDate.getTime()){ + } else if (department.getHealthBeginTime().getTime() <= now.getTime() && now.getTime() <= endDate.getTime()) { return ResultBody.ok().data(department); - }else if(endDate.getTime()<now.getTime()) { + } else if (endDate.getTime() < now.getTime()) { department.setIsHealth(false); return ResultBody.ok().data(department); } return ResultBody.ok(); - }else { + } else { return ResultBody.ok().data(false); } } } + + /** + * 初始化私有云本地数据库 + * + * @param hospitalId + * @param departmentId + * @return java.lang.String + */ + public String initPrivateData(Long hospitalId, Long departmentId) { + String initSQL = ""; // 初始化数据SQL + String organizationSQL = ""; // 组织数据SQL + String hospitalSQL = ""; // 医院数据SQL + String departmentSQL = ""; // 科室数据SQL + String doctorSQL = ""; // 医生数据SQL + String userSQL = ""; // 用户数据SQL + String userOrgSQL = ""; // 组织用户关系数据SQL + String roleUserSQL = ""; // 角色用户关系数据SQL + String productOrderSQL = ""; // 合同信息数据SQL + String productOrderDetailSQL = ""; // 合同明细(套餐)信息数据SQL + + // 时间转换格式 + SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + String createTime = ""; + String updateTime = ""; + + // 1、根据hospitalId从sys_hospital中查询医院信息 + SysHospital hospitalInfo = iSysHospitalService.getById(hospitalId); + if (hospitalInfo != null) { + createTime = "'" + dateTimeFormat.format(hospitalInfo.getCreateTime()) + "'"; + updateTime = (hospitalInfo.getUpdateTime() == null) ? "NULL" : "'" + dateTimeFormat.format(hospitalInfo.getUpdateTime()) + "'"; + hospitalSQL = " INSERT INTO user_center_pri.sys_hospital VALUES (" + + hospitalInfo.getId() + ", " + + "'" + hospitalInfo.getHospitalName() + "', " + + hospitalInfo.getOrgId() + ", " + + "'" + hospitalInfo.getHospitalShortName() + "', " + + "'" + hospitalInfo.getHospitalCode() + "', " + + "'" + hospitalInfo.getHospitalTypeId() + "', " + + "'" + hospitalInfo.getHospitalTypeName() + "', " + + "'" + hospitalInfo.getHospitalTel() + "', " + + "'" + hospitalInfo.getHospitalProvince() + "', " + + "'" + hospitalInfo.getHospitalCity() + "', " + + "'" + hospitalInfo.getHospitalArea() + "', " + + "'" + hospitalInfo.getAreaCode() + "', " + + "'" + hospitalInfo.getHospitalLink() + "', " + + "'" + hospitalInfo.getHospitalAdress() + "', " + + "'" + hospitalInfo.getLatitude() + "', " + + "'" + hospitalInfo.getLongitude() + "', " + + "'" + hospitalInfo.getHospitalQualifiedId() + "', " + + "'" + hospitalInfo.getHospitalQualifiedName() + "', " + + "NULL," + + "NULL," + + "NULL," + + "'" + hospitalInfo.getHospitalAbout() + "', " + + "0, 0, " + + hospitalInfo.getHospitalState() + ", " + + hospitalInfo.getEnabled() + ", " + + "'" + hospitalInfo.getTenantId() + "', " + + hospitalInfo.getIsDel() + ", " + + hospitalInfo.getCreateUserId() + ", " + + "'" + hospitalInfo.getCreateUserName() + "', " + + hospitalInfo.getUpdateUserId() + ", " + + "'" + hospitalInfo.getUpdateUserName() + "', " + + createTime + ", " + + updateTime + ", " + + "'" + hospitalInfo.getCreateUserOrgCode() + "' " + + ");\n\r"; + } else { + log.error("[%s]医院信息读取失败",hospitalId); + return "医院信息读取失败,请重新生成SQL!"; + } + // 2、根据departmentId从sys_department中查询科室信息 + SysDepartment department = baseMapper.selectById(departmentId); + if (department != null) { + createTime = "'" + dateTimeFormat.format(department.getCreateTime()) + "'"; + updateTime = (department.getUpdateTime() == null) ? "NULL" : "'" + dateTimeFormat.format(department.getUpdateTime()) + "'"; + departmentSQL = " INSERT INTO user_center_pri.sys_department VALUES (" + + department.getId() + ", " + + "'" + department.getDepartmentName() + "', " + + department.getOrgId() + ", " + + department.getServerUserId() + ", " + + "'" + department.getServerUserName() + "', " + + "'" + department.getServerUserTel() + "', " + + department.getIsDel() + ", " + + department.getEnabled() + ", " + + department.getCreateUserId() + ", " + + "'" + department.getCreateUserName() + "', " + + department.getUpdateUserId() + ", " + + "'" + department.getUpdateUserName() + "', " + + createTime + ", " + + updateTime + ", " + + department.getSaleUserId() + ", " + + "'" + department.getSaleUserName() + "', " + + "'" + department.getSaleUserTel() + "', " + + department.getAccountsCount() + ", " + + "0,0,NULL,NULL, " + + "'" + department.getDepartmentLink() + "', " + + "'" + department.getDepartmentTel() + "', " + + "0,0,1," + + "'" + department.getPrivateServerGuuid() + "' " + + ");\n\r"; + } else { + log.error("[%s]科室信息读取失败",departmentId); + return "科室信息读取失败,请重新生成SQL!"; + } + // 3、根据医院和科室表中的org_id查询sys_organization中查询组织信息 + List<SysOrganization> organizationList = iSysOrganizationService.list( + new QueryWrapper<SysOrganization>() + .in("id", hospitalInfo.getOrgId(), department.getOrgId()) + .eq("is_del", 0) + .eq("enabled", 1) + ); + if ((organizationList != null) && (organizationList.size() > 0)) { + for (int i = 0; i < organizationList.size(); i++) { + SysOrganization organization = organizationList.get(i); + createTime = "'" + dateTimeFormat.format(organization.getCreateTime()) + "'"; + updateTime = (organization.getUpdateTime() == null) ? "NULL" : "'" + dateTimeFormat.format(organization.getUpdateTime()) + "'"; + organizationSQL += " INSERT INTO user_center_pri.sys_organization VALUES (" + + organization.getId() + ", " + + organization.getOrgLevel() + ", " + + organization.getOrgAttr() + ", " + + organization.getOrgParentId() + ", " + + "'" + organization.getOrgName() + "', " + + organization.getOrgOrder() + ", " + + organization.getIsDel() + ", " + + organization.getEnabled() + ", " + + organization.getCreateUserId() + ", " + + "'" + organization.getCreateUserName() + "', " + + organization.getUpdateUserId() + ", " + + "'" + organization.getUpdateUserName() + "', " + + createTime + ", " + + updateTime + ", " + + "'" + organization.getCreateUserOrgCode() + "', " + + "'" + organization.getOrgCode() + "' " + + ");\n\r"; + } + } + // 4、给科室创建管理员账号 + // 4.1 sys_user创建账号【userName:admin, password:123456,Mobile:admin,Type:DOCTOR,tenantId:】 + Long userId = IdWorker.getId(); + + userSQL = " INSERT INTO user_center_pri.sys_user VALUES (" + + userId.toString() + ", " + + "'admin', " + + "'" + passwordEncoder.encode("123456") + "', " + + "'admin', " + + "NULL, " + + "'admin', " + + "0, 1, " + + "'"+ UserType.DOCTOR.name()+"', " + + dateTimeFormat.format(DateTime.now()) + ", " + + "NULL, NULL, NULL, 0, " + + "'" +CommonConstant.H_TENANT + "', " + + CommonConstant.ADMIN_USER_ID.toString() +", " + + CommonConstant.ADMIN_USER_NAME + ", " + + "NULL, 0, " + + "NULL, "+ // create_user_org_code + "1" + + ");\n\r"; + // 4.2、 sys_user_org创建记录 + // 用户与医院的关系数据 + userOrgSQL = " INSERT INTO user_center_pri.sys_user_org VALUES (" + + IdWorker.getId() + ", " + + userId.toString() + ", " + + hospitalInfo.getOrgId().toString() + ", " + + hospitalId.toString() + ", " + + CommonConstant.SYSTEM_ORG_HOS_LEVEL.toString() + ", " + + "1, 0, " + + CommonConstant.ADMIN_USER_ID.toString() +", " + + CommonConstant.ADMIN_USER_NAME + ", " + + "NULL, NULL, " + + dateTimeFormat.format(DateTime.now()) + ", " + + "NULL, "+ + "NULL " + // create_user_org_code + ");\n\r"; + // 用户与科室的关系数据 + userOrgSQL += " INSERT INTO user_center_pri.sys_user_org VALUES (" + + IdWorker.getId() + ", " + + userId.toString() + ", " + + department.getOrgId().toString() + ", " + + departmentId.toString() + ", " + + CommonConstant.SYSTEM_ORG_DEP_LEVEL.toString() + ", " + + "1, 0, " + + CommonConstant.ADMIN_USER_ID.toString() +", " + + CommonConstant.ADMIN_USER_NAME + ", " + + "NULL, NULL, " + + dateTimeFormat.format(DateTime.now()) + ", " + + "NULL, "+ + "NULL " + // create_user_org_code + ");\n\r"; + // 4.3、 sys_role_user创建记录 + roleUserSQL = " INSERT INTO user_center_pri.sys_role_user VALUES ( " + + userId.toString() + ", "+ + CommonConstant.HOSPITAL_DOCTOR_ID +" );\n\r" + // 普通医生 + " INSERT INTO user_center_pri.sys_role_user VALUES ( " + + userId.toString() + ", "+ + CommonConstant.HOSPITAL_ADMIN_ID +");\n\r" ; // 医院管理员 + // 4.4、 sys_doctor创建记录 + doctorSQL = " INSERT INTO user_center_pri.sys_doctor VALUES (" + + IdWorker.getId() + ", " + + userId.toString() + ", " + + hospitalInfo.getId().toString() + ", " + + "'" + hospitalInfo.getHospitalName() + "', " + + department.getId().toString() + ", " + + "'" + department.getDepartmentName() + "', " + + "'管理员', NULL, NULL, 'admin', " + + "NULL, NULL, NULL, NULL, NULL, NULL, " + + "0, 0, 0, 0, 1, 1, 1, " + + CommonConstant.ADMIN_USER_ID.toString() +", " + + "'" + CommonConstant.ADMIN_USER_NAME + "', " + + "NULL, NULL, " + + dateTimeFormat.format(DateTime.now()) + ", " + + "NULL, " + + department.getSaleUserId().toString() + ", " + + "'" + department.getSaleUserName() + "', " + + "'" + CommonConstant.ADMIN_USER_ORG_CODE + "'" + + ");\n\r"; + // 5、根据hospitalId和departmentId从opration_center.product_order中查询合同信息 + Map<String, Object> orderMap = new HashMap<>(); + orderMap.put("hospital_id", hospitalId); + orderMap.put("department_id", departmentId); + orderMap.put("enabled", 1); + orderMap.put("is_del", 0); + ResultBody orderResult = productOrderService.findProductOrderListByMap(orderMap); + if (orderResult.isOk()) { + //List<ProductOrder> productOrderList = (List<ProductOrder>) orderResult.getData(); + List<ProductOrder> productOrderList = JSON.parseArray(JSON.toJSONString(orderResult.getData()), ProductOrder.class); + if ((productOrderList != null) && (productOrderList.size() > 0)) { + for (int i = 0; i < productOrderList.size(); i++) { + ProductOrder productOrder = productOrderList.get(i); + createTime = "'" + dateTimeFormat.format(productOrder.getCreateTime()) + "'"; + updateTime = (productOrder.getUpdateTime() == null) ? "NULL" : "'" + dateTimeFormat.format(productOrder.getUpdateTime()) + "'"; + productOrderSQL += "INSERT INTO opration_center_pri.product_order VALUES(" + + productOrder.getId() + ", " + + productOrder.getHospitalId() + ", " + + "'" + productOrder.getHospitalName() + "', " + + productOrder.getDepartmentId() + ", " + + "'" + productOrder.getDepartmentName() + "', " + + "'" + productOrder.getContractNo() + "', " + + "'" + productOrder.getContractTitle() + "', " + + productOrder.getContractNum() + ", " + + "'" + dateFormat.format(productOrder.getContractBeginTime()) + "', " + + "'" + dateFormat.format(productOrder.getContractEndTime()) + "', " + + "'" + dateTimeFormat.format(productOrder.getContractTime()) + "', " + + productOrder.getIsDel() + ", " + + productOrder.getEnabled() + ", " + + updateTime + ", " + + productOrder.getCreateUserId() + ", " + + "'" + productOrder.getCreateUserName() + "', " + + productOrder.getUpdateUserId() + ", " + + "'" + productOrder.getUpdateUserName() + "', " + + createTime + ", " + + "NULL, "+ // tenant_id + "'" + productOrder.getCreateUserOrgCode() + "' " + + ");\n\r"; + + // 6、根据order_id从opration_center.product_order_detail中查询合同中的套餐信息 + orderMap.clear(); + orderMap.put("order_id", productOrder.getId()); + orderMap.put("enabled", 1); + orderMap.put("is_del", 0); + ResultBody detailResult = productOrderService.findProductOrderDetailListByMap(orderMap); + + if (detailResult.isOk()) { + //List<ProductOrderDetail> productOrderDetailList = (List<ProductOrderDetail>) detailResult.getData(); + List<ProductOrderDetail> productOrderDetailList = JSON.parseArray(JSON.toJSONString(detailResult.getData()), ProductOrderDetail.class); + + if ((productOrderDetailList != null) && (productOrderDetailList.size() > 0)) { + + for (int j = 0; j < productOrderDetailList.size(); j++) { + ProductOrderDetail productOrderDetail = productOrderDetailList.get(j); + createTime = "'" + dateTimeFormat.format(productOrderDetail.getCreateTime()) + "'"; + updateTime = (productOrderDetail.getUpdateTime() == null) ? "NULL" : "'" + dateTimeFormat.format(productOrderDetail.getUpdateTime()) + "'"; + productOrderDetailSQL += "INSERT INTO opration_center_pri.product_order_detail VALUES( " + + productOrderDetail.getId() + ", " + + productOrderDetail.getOrderId() + ", " + + productOrderDetail.getProId() + ", " + + productOrderDetail.getProType() + ", " + + productOrderDetail.getTermType() + ", " + + "'" + productOrderDetail.getProName() + "', " + + productOrderDetail.getIsShare() + ", " + + productOrderDetail.getIsDel() + ", " + + productOrderDetail.getOrderAilightCount() + ", " + + productOrderDetail.getOrderRecordCount() + ", " + + productOrderDetail.getAilightCount() + ", " + + "'" + productOrderDetail.getAilightCountEncryption() + "', " + + productOrderDetail.getRecordCount() + ", " + + "'" + dateFormat.format(productOrderDetail.getProBegintime()) + "', " + + "'" + productOrderDetail.getProBegintimeEncryption() + "', " + + "'" + dateFormat.format(productOrderDetail.getProEndtime()) + "', " + + "'" + productOrderDetail.getProEndtimeEncryption() + "', " + + productOrderDetail.getEnabled() + ", " + + productOrderDetail.getCreateUserId() + ", " + + "'" + productOrderDetail.getCreateUserName() + "', " + + productOrderDetail.getUpdateUserId() + ", " + + updateTime + ", " + + "'" + productOrderDetail.getUpdateUserName() + "', " + + createTime + ", " + + "Null, " + // tenant_id + "'" + productOrderDetail.getCreateUserOrgCode() + "' " + + ");\n\r"; + } + } else { + log.error("此合同【】没有合同明细(套餐)",productOrder.getId()); + // return "没有已开通的合同明细(套餐),请先充值,再生成SQL文"; + } + } else { + log.error(detailResult.getMsg()); + return "没有已开通的合同明细(套餐),请先充值,再生成SQL文"; + } + } + } else { + + log.error("此科室【hospital_id:%s,department_id:%s】没有已开通的合同记录",hospitalId,departmentId); + return "没有已开通的合同记录,请先充值,再生成SQL文"; + } + } else { + log.error(orderResult.getMsg()); + return "没有已开通的合同记录,请先充值,再生成SQL文"; + + } + + if ((productOrderSQL.isEmpty()) || (productOrderDetailSQL.isEmpty())){ + log.error("此科室【hospital_id:%s,department_id:%s】没有已开通的合同记录",hospitalId,departmentId); + return "没有已开通的合同记录,请先充值,再生成SQL文"; + } + + initSQL = organizationSQL + hospitalSQL + departmentSQL + + userSQL + userOrgSQL + roleUserSQL + doctorSQL + + productOrderSQL + productOrderDetailSQL; + + return initSQL; + } } diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java index 3513273..d9697f0 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysUserServiceImpl.java @@ -156,7 +156,6 @@ //医院信息 DoctorUserAll doctorUserAllVo = baseMapper.findDoctorUserAllData(sysUser.getId()); if (doctorUserAllVo != null) { - //是否医院管理员 loginAppUser.setHAdminUser(doctorUserAllVo.getIsAdminUser()); //1表示调用老系统接口,2表示调用新系统接口,3表示不执行接口调用 diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/java/com/kidgrow/usercenter/controller/SysDepartmentController.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/java/com/kidgrow/usercenter/controller/SysDepartmentController.java index 4b79c36..5eb5a1c 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/java/com/kidgrow/usercenter/controller/SysDepartmentController.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/java/com/kidgrow/usercenter/controller/SysDepartmentController.java @@ -6,8 +6,9 @@ import com.kidgrow.common.model.PageResult; import com.kidgrow.common.model.ResultBody; import com.kidgrow.common.model.SysOrganization; -import com.kidgrow.common.utils.StringUtils; import com.kidgrow.common.model.SysUser; +import com.kidgrow.common.utils.AesUtils; +import com.kidgrow.common.utils.StringUtils; import com.kidgrow.usercenter.model.SysDepartment; import com.kidgrow.usercenter.service.ISysDepartmentService; import com.kidgrow.usercenter.service.ISysOrganizationService; @@ -22,7 +23,12 @@ import org.springframework.validation.ObjectError; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -73,15 +79,17 @@ SysDepartment model = sysDepartmentService.getById(id); return ResultBody.ok().data(model).msg("查询成功"); } + /** * 查询 */ @ApiOperation(value = "更新支付功能的开通状态") @GetMapping("/updatePay") - public ResultBody updatePay(Long departmentId,Boolean isPay) { - boolean isPays = sysDepartmentService.updatePay(departmentId,isPay); + public ResultBody updatePay(Long departmentId, Boolean isPay) { + boolean isPays = sysDepartmentService.updatePay(departmentId, isPay); return ResultBody.ok().data(isPays).msg("操作成功"); } + /** * 查询 */ @@ -91,6 +99,7 @@ SysDepartment model = sysDepartmentService.getById(departmentId); return ResultBody.ok().data(model.getIsPay()).msg("操作成功"); } + /** * 根据SysDepartment当做查询条件进行查询 */ @@ -106,8 +115,8 @@ */ @ApiOperation(value = "检查科室名是否存在") @GetMapping("/checkName") - public ResultBody checkDepName(Long hospitalId,String departmentName) { - if (departMentNameIsUsed(hospitalId,departmentName)) { + public ResultBody checkDepName(Long hospitalId, String departmentName) { + if (departMentNameIsUsed(hospitalId, departmentName)) { return ResultBody.failed().msg(String.format("该医院下已经存在科室 %s", departmentName)); } return ResultBody.ok().msg(""); @@ -115,22 +124,23 @@ /** * 检查科室名是否存在 + * * @param hosId * @param departmentName * @return */ - private Boolean departMentNameIsUsed(Long hosId,String departmentName) - { - String departName=sysDepartmentService.checkDepartmentName(hosId,departmentName); + private Boolean departMentNameIsUsed(Long hosId, String departmentName) { + String departName = sysDepartmentService.checkDepartmentName(hosId, departmentName); return StringUtils.isNotBlank(departName); } + /** * 新增or更新 */ @ApiOperation(value = "保存") @PostMapping("/{hosId}") @Transactional(rollbackFor = {Exception.class}) - public ResultBody save(@Valid @RequestBody SysDepartment sysDepartment,@PathVariable Long hosId, BindingResult bindingResult,@LoginUser SysUser sysUser) { + public ResultBody save(@Valid @RequestBody SysDepartment sysDepartment, @PathVariable Long hosId, BindingResult bindingResult, @LoginUser SysUser sysUser) { List<String> errMsg = new ArrayList<>(); if (bindingResult.hasErrors()) { for (ObjectError error : bindingResult.getAllErrors()) { @@ -141,7 +151,7 @@ //先检查该医院该科室是否已经存在 if (sysDepartment.getId() == null) { - if (departMentNameIsUsed(hosId,sysDepartment.getDepartmentName())) { + if (departMentNameIsUsed(hosId, sysDepartment.getDepartmentName())) { return ResultBody.failed().msg(String.format("该医院下已经存在科室 %s", sysDepartment.getDepartmentName())); } } @@ -163,7 +173,7 @@ sysOrganization.setOrgLevel(2); //临时暂用其它字段承载数据 sysOrganization.setOrgParentId(sysDepartment.getUpdateUserId()); - if(!sysUser.getOrganizations().isEmpty()){ + if (!sysUser.getOrganizations().isEmpty()) { sysOrganization.setCreateUserOrgCode(sysUser.getOrganizations().get(1).getOrgCode()); } } else { @@ -204,30 +214,148 @@ public ResultBody findListByHospitalId(@RequestParam Map<String, Object> params) { return sysDepartmentService.findListByHospitalId(params); } + @PostMapping - public ResultBody update(@RequestBody SysDepartment sysDepartment){ - if(sysDepartment.getId()==null){ + public ResultBody update(@RequestBody SysDepartment sysDepartment) { + if (sysDepartment.getId() == null) { return ResultBody.failed("请输入id"); } - QueryWrapper queryWrapper =new QueryWrapper(); - queryWrapper.eq("id",sysDepartment.getId()); + QueryWrapper queryWrapper = new QueryWrapper(); + queryWrapper.eq("id", sysDepartment.getId()); boolean update = sysDepartmentService.update(sysDepartment, queryWrapper); - if(update){ + if (update) { return ResultBody.ok(); - }else { + } else { return ResultBody.failed("更新数据失败"); } } + /** - *运动处方调用 是否开通服务 + * 运动处方调用 是否开通服务 */ @PostMapping("getHealth") - public ResultBody getHealth(@RequestBody SysDepartment sysDepartment){ - if(sysDepartment.getId()==null){ + public ResultBody getHealth(@RequestBody SysDepartment sysDepartment) { + if (sysDepartment.getId() == null) { return ResultBody.failed("请输入id"); } return sysDepartmentService.getHealth(sysDepartment); } + /** + * 下载私有云服务器License文件 + * + * @param departmentId 科室ID + * @param response HttpServletResponse + * @return void + */ + @PostMapping("/downloadLicense") + public void downloadLicense(@RequestParam Long departmentId, HttpServletResponse response) { + + SysDepartment department = sysDepartmentService.getById(departmentId); + String serverLicense = ""; + + OutputStream out = null; + InputStream fileInputStream = null; + try { + if (department != null) { + if (department.getIsPrivate() == 1) { + if ((department.getPrivateServerGuuid() != null) && (!department.getPrivateServerGuuid().isEmpty())) { + serverLicense = AesUtils.encrypt(department.getPrivateServerGuuid()); + + } else { + serverLicense = String.format("此科室【%s】未设置服务器GUUID,不能下载私有云服务器License", departmentId); + log.error(serverLicense); + } + } else { + serverLicense = String.format("此科室【%s】非私有云客户,不能下载私有云服务器License", departmentId); + log.error(serverLicense); + } + } else { + serverLicense = String.format("此科室【%s】不存在,不能下载私有云服务器License", departmentId); + log.error(serverLicense); + } + + + + + byte[] arr = serverLicense.getBytes(); + + // 设置输出的格式 + response.reset(); + response.setContentType("application/x-msdownload"); + response.addHeader("Content-Length", "" + arr.length); + response.addHeader("Content-Disposition", "attachment; filename=\"" + department.getDepartmentName() + "License.txt\""); + + + out = response.getOutputStream(); + fileInputStream = new ByteArrayInputStream(arr); + byte[] buffer = new byte[1024 * 10]; + int len = 0; + while ((len = fileInputStream.read(buffer)) > 0) { + out.write(buffer, 0, len); + } + } catch (Exception e) { + e.printStackTrace(); + //log.error("私有云服务器Guuid加密出错"); + } finally { + + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * 下载私有云本地数据库初始化数据 + * @param hospitalId + * @param departmentId + * @param response + * @return void + */ + @PostMapping("/downloadData") + public void downloadPrivateData(@RequestParam("hospitalId") Long hospitalId,@RequestParam("departmentId") Long departmentId, HttpServletResponse response){ + String dataSql = ""; + + dataSql = sysDepartmentService.initPrivateData(hospitalId,departmentId); + + OutputStream out = null; + InputStream fileInputStream = null; + try { + byte[] arr = dataSql.getBytes(); + + // 设置输出的格式 + response.reset(); + response.setContentType("application/x-msdownload"); + response.addHeader("Content-Length", "" + arr.length); + response.addHeader("Content-Disposition", "attachment; filename=\"" + departmentId.toString() + ".sql\""); + + + out = response.getOutputStream(); + fileInputStream = new ByteArrayInputStream(arr); + byte[] buffer = new byte[1024 * 10]; + int len = 0; + while ((len = fileInputStream.read(buffer)) > 0) { + out.write(buffer, 0, len); + } + } catch (Exception e) { + e.printStackTrace(); + + } finally { + + if (fileInputStream != null) { + try { + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + } -- Gitblit v1.8.0