提交 2bd6b0fe authored 作者: hzh's avatar hzh

代码优化

上级 48fc1feb
......@@ -178,6 +178,11 @@ public class InsureVo implements Serializable {
*/
private String planName;
/**
* 创建部门
*/
private Long createDept;
/**
* 投保单元集合
*/
......
......@@ -166,6 +166,18 @@ public class WeishiController {
return R.ok();
}
/**
* 获取token
*
* @param orderId 订单id
* @return 数据
*/
@GetMapping("/token")
public R<String> token(@RequestParam Integer orderId) {
InsureVo insure = insureService.getOne(new InsureBo().setOrderId(orderId));
return R.ok(thirdWeishiService.getToken(insure.getCreateDept()));
}
/**
* 订单列表
......
package org.dromara.mall.domain.weishi;
import lombok.experimental.Accessors;
import org.dromara.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
......@@ -14,6 +15,7 @@ import java.io.Serial;
* @date 2025-05-15
*/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@TableName("weishi_account")
public class Account extends TenantEntity {
......
......@@ -11,5 +11,4 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
* @date 2025-05-15
*/
public interface AccountMapper extends BaseMapperPlus<Account, AccountVo> {
}
package org.dromara.mall.service.weishi;
import org.dromara.mall.domain.weishi.Account;
/**
* @author wenhe
*/
......@@ -20,4 +22,10 @@ public interface IThirdWeishiService {
*/
void updateToken(Long deptId);
/**
* 更新
* @param account 账号
*/
void updateTokens(Account account);
}
package org.dromara.mall.service.weishi.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
......@@ -11,8 +12,11 @@ import org.dromara.mall.controller.weishi.admin.vo.AccountVo;
import org.dromara.mall.domain.weishi.Account;
import org.dromara.mall.mapper.weishi.AccountMapper;
import org.dromara.mall.service.weishi.IAccountService;
import org.dromara.mall.service.weishi.IThirdWeishiService;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* 保险账号Service业务层处理
*
......@@ -24,6 +28,7 @@ import org.springframework.stereotype.Service;
public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo, Account> implements IAccountService {
private final AccountMapper baseMapper;
private final IThirdWeishiService thirdWeishiService;
@Override
public BaseMapperPlus<Account, AccountVo> mapper() {
......@@ -41,6 +46,18 @@ public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo
@Override
public int update(AccountBo bo) {
return 0;
Account account = baseMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getDeptId, bo.getDeptId()));
int rows;
if (Objects.isNull(account)) {
account = BeanUtil.copyProperties(bo, Account.class);
rows = baseMapper.insert(account);
thirdWeishiService.updateTokens(account);
} else {
account.setUsername(bo.getUsername())
.setPassword(bo.getPassword());
rows = baseMapper.updateById(account);
thirdWeishiService.updateTokens(account);
}
return rows;
}
}
......@@ -53,6 +53,13 @@ public class ThirdWeishiServiceImpl implements IThirdWeishiService {
return token;
}
@Override
public void updateTokens(Account account) {
String key = StringUtils.format(WEISHI_TOKEN, account.getTenantId(), account.getDeptId());
AuthResponse res = weishiService.authorize(new AuthRequest(account.getUsername(), account.getPassword()));
RedisUtils.setCacheObject(key, res.getAccess_token(), Duration.ofSeconds(res.getExpires_in().longValue()));
}
@Override
public void updateToken(Long deptId) {
List<Account> accountList;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论