|
@@ -1,5 +1,6 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.dto.TokenHospitaDTO;
|
|
@@ -13,7 +14,9 @@ import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.RSATokenIdUtil;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
+import com.diagbot.vo.TokenHospitalCancelVO;
|
|
|
import com.diagbot.vo.TokenHospitalInfoVO;
|
|
|
+import com.diagbot.vo.TokenHospitalUpdataVO;
|
|
|
import com.diagbot.vo.TokenHospitalVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -47,7 +50,10 @@ public class TokenHospitalFacade extends TokenHospitalServiceImpl {
|
|
|
tokenHospitalQueryWrapper
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
.eq("hospital_id", tokenHospitalInfoVO.getHospitalId());
|
|
|
- remove(tokenHospitalQueryWrapper);
|
|
|
+ int count = tokenHospitalService.count(tokenHospitalQueryWrapper);
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该医院Token信息已存在!");
|
|
|
+ }
|
|
|
TokenHospital tokenHospitalData = getOne(tokenHospitalQueryWrapper, false);
|
|
|
Date now = DateUtil.now();
|
|
|
Date startTime = tokenHospitalInfoVO.getStartTime();
|
|
@@ -79,7 +85,67 @@ public class TokenHospitalFacade extends TokenHospitalServiceImpl {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return save(tokenHospital);
|
|
|
+ return tokenHospitalService.save(tokenHospital);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean cancelTokenHospitals(TokenHospitalCancelVO tokenHospitalCancelVO) {
|
|
|
+ UpdateWrapper<TokenHospital> tokenHospitalQueryWrapper = new UpdateWrapper<>();
|
|
|
+ tokenHospitalQueryWrapper
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", tokenHospitalCancelVO.getId());
|
|
|
+ return tokenHospitalService.remove(tokenHospitalQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean updataTokenHospitals(TokenHospitalUpdataVO tokenHospitalInfoVO) {
|
|
|
+ //校验数据
|
|
|
+ checkTokenHospital(tokenHospitalInfoVO.getId());
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ Date startTime = tokenHospitalInfoVO.getStartTime();
|
|
|
+ Date endTime = tokenHospitalInfoVO.getEndTime();
|
|
|
+ if (endTime.getTime() < startTime.getTime()) {
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_ERROR, "截止时间不能小于起始时间");
|
|
|
+ }
|
|
|
+ int validDays = (int) ((endTime.getTime() - startTime.getTime()) / (1000 * 3600 * 24));
|
|
|
+ //生成Token规则, 请勿调换顺序!
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sb.append("Token")
|
|
|
+ .append(DateUtil.formatDateTime(startTime))// 开始时间
|
|
|
+ .append(DateUtil.formatDateTime(endTime)) //结束时间
|
|
|
+ .append(tokenHospitalInfoVO.getHospitalId().toString()); // 医院id
|
|
|
+ //加密Token
|
|
|
+ String appidToken = "";
|
|
|
+ try {
|
|
|
+ appidToken = RSATokenIdUtil.encrypt(sb.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (appidToken.isEmpty()) {
|
|
|
+ throw new CommonException(CommonErrorCode.FAIL, "生成token失败!");
|
|
|
+ }
|
|
|
+ UpdateWrapper<TokenHospital> tokenHospitalQueryWrapper = new UpdateWrapper<>();
|
|
|
+ tokenHospitalQueryWrapper
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", tokenHospitalInfoVO.getId())
|
|
|
+ .eq("hospital_id", tokenHospitalInfoVO.getHospitalId())
|
|
|
+ .set("appid_token", appidToken)
|
|
|
+ .set("start_time", startTime)
|
|
|
+ .set("end_time", endTime)
|
|
|
+ .set("valid_days", validDays);
|
|
|
+ return update(new TokenHospital(), tokenHospitalQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检验数据是否有效
|
|
|
+ */
|
|
|
+ private TokenHospital checkTokenHospital(Long id) {
|
|
|
+ // 1.先判断数据是否存在有效
|
|
|
+ QueryWrapper<TokenHospital> tokenHospitalFand = new QueryWrapper<>();
|
|
|
+ tokenHospitalFand.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("id", id);
|
|
|
+ TokenHospital tokenHospital = getOne(tokenHospitalFand, false);
|
|
|
+ if (null == tokenHospital) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据不存在");
|
|
|
+ }
|
|
|
+ return tokenHospital;
|
|
|
}
|
|
|
|
|
|
}
|