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

代码优化

上级 48fc1feb
...@@ -178,6 +178,11 @@ public class InsureVo implements Serializable { ...@@ -178,6 +178,11 @@ public class InsureVo implements Serializable {
*/ */
private String planName; private String planName;
/**
* 创建部门
*/
private Long createDept;
/** /**
* 投保单元集合 * 投保单元集合
*/ */
......
...@@ -166,6 +166,18 @@ public class WeishiController { ...@@ -166,6 +166,18 @@ public class WeishiController {
return R.ok(); 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; package org.dromara.mall.domain.weishi;
import lombok.experimental.Accessors;
import org.dromara.common.tenant.core.TenantEntity; import org.dromara.common.tenant.core.TenantEntity;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import lombok.Data; import lombok.Data;
...@@ -14,6 +15,7 @@ import java.io.Serial; ...@@ -14,6 +15,7 @@ import java.io.Serial;
* @date 2025-05-15 * @date 2025-05-15
*/ */
@Data @Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@TableName("weishi_account") @TableName("weishi_account")
public class Account extends TenantEntity { public class Account extends TenantEntity {
......
...@@ -11,5 +11,4 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; ...@@ -11,5 +11,4 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
* @date 2025-05-15 * @date 2025-05-15
*/ */
public interface AccountMapper extends BaseMapperPlus<Account, AccountVo> { public interface AccountMapper extends BaseMapperPlus<Account, AccountVo> {
} }
package org.dromara.mall.service.weishi; package org.dromara.mall.service.weishi;
import org.dromara.mall.domain.weishi.Account;
/** /**
* @author wenhe * @author wenhe
*/ */
...@@ -20,4 +22,10 @@ public interface IThirdWeishiService { ...@@ -20,4 +22,10 @@ public interface IThirdWeishiService {
*/ */
void updateToken(Long deptId); void updateToken(Long deptId);
/**
* 更新
* @param account 账号
*/
void updateTokens(Account account);
} }
package org.dromara.mall.service.weishi.impl; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -11,8 +12,11 @@ import org.dromara.mall.controller.weishi.admin.vo.AccountVo; ...@@ -11,8 +12,11 @@ import org.dromara.mall.controller.weishi.admin.vo.AccountVo;
import org.dromara.mall.domain.weishi.Account; import org.dromara.mall.domain.weishi.Account;
import org.dromara.mall.mapper.weishi.AccountMapper; import org.dromara.mall.mapper.weishi.AccountMapper;
import org.dromara.mall.service.weishi.IAccountService; import org.dromara.mall.service.weishi.IAccountService;
import org.dromara.mall.service.weishi.IThirdWeishiService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects;
/** /**
* 保险账号Service业务层处理 * 保险账号Service业务层处理
* *
...@@ -24,6 +28,7 @@ import org.springframework.stereotype.Service; ...@@ -24,6 +28,7 @@ import org.springframework.stereotype.Service;
public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo, Account> implements IAccountService { public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo, Account> implements IAccountService {
private final AccountMapper baseMapper; private final AccountMapper baseMapper;
private final IThirdWeishiService thirdWeishiService;
@Override @Override
public BaseMapperPlus<Account, AccountVo> mapper() { public BaseMapperPlus<Account, AccountVo> mapper() {
...@@ -41,6 +46,18 @@ public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo ...@@ -41,6 +46,18 @@ public class AccountServiceImpl extends AbstractBaseService<AccountVo, AccountBo
@Override @Override
public int update(AccountBo bo) { 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 { ...@@ -53,6 +53,13 @@ public class ThirdWeishiServiceImpl implements IThirdWeishiService {
return token; 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 @Override
public void updateToken(Long deptId) { public void updateToken(Long deptId) {
List<Account> accountList; List<Account> accountList;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论