feat:用户商户部门

This commit is contained in:
dzc committed 2025-05-14 19:36:01 +08:00
1 parent 4360790f68
commit 360fcf8c98
15 files changed
+109 -30

No files matched your search

@@ -143,7 +143,7 @@ public class HardOrderController {
// 判断是否为合作超市管理员工
if (!hardManagerService.isSuperMarketAdmin(user)) return R.ok(new Page());
// 查询用户属于的商户
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId()).getData();
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId(), MerchantTypeEnum.CANTEEN).getData();
if (ObjectUtil.isEmpty(mch)) throw new RuntimeException("该用户下不存在商户");
// 查询商户和下面的子商户
List<Long> mchDtoIds = new java.util.ArrayList<>(List.of(mch.getId()));
@@ -11,6 +11,7 @@ import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
@@ -74,7 +75,7 @@ public class HardOrderTotalController {
// 判断是否为合作超市管理员工
if (!hardManagerService.isSuperMarketAdmin(user)) return R.ok(new Page());
// 查询用户属于的商户
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId()).getData();
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId(), MerchantTypeEnum.CANTEEN).getData();
if (ObjectUtil.isEmpty(mch)) throw new RuntimeException("该用户下不存在商户");
List<Long> mchDtoIds = new ArrayList<>(List.of(mch.getId()));
// 查询商户和下面的子商户
@@ -96,7 +97,7 @@ public class HardOrderTotalController {
// 判断是否为合作超市管理员工
if (!hardManagerService.isSuperMarketAdmin(user)) return R.ok(new Page());
// 查询用户属于的商户
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId()).getData();
MchManageVo mch = mchService.getFirstMchByDeptId(userInfo.getSysUser().getDeptId(), MerchantTypeEnum.CANTEEN).getData();
if (ObjectUtil.isEmpty(mch)) throw new RuntimeException("该用户下不存在商户");
List<Long> mchDtoIds = new ArrayList<>(List.of(mch.getId()));
// 查询商户和下面的子商户
@@ -40,6 +40,10 @@ import java.util.Set;
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.UPMS_SERVICE)
public interface RemoteUserService {
@NoToken
@PostMapping("/user/inner/sync-user-canteen")
R syncUserCanteen(@RequestParam(required = false) Long userId, @RequestParam(required = false) Long deptId, @RequestParam(required = false) Boolean foure);
@NoToken
@PostMapping("/user/inner-page")
R<List<UserVO>> getRemoteUserPage(@RequestParam Long current, @RequestParam Long size, @RequestBody UserDTO userDTO);
@@ -86,6 +86,18 @@ public class SysUserController {
/* ************************************* end 回调 end ************************************* */
/* ************************************* start 远程调用 start ************************************* */
@Inner()
@PostMapping("/inner/sync-user-canteen")
public R syncUserCanteen(@RequestParam(required = false) Long userId, @RequestParam(required = false) Long deptId, @RequestParam(required = false) Boolean foure) {
if (ObjectUtil.isEmpty(foure)) foure = true;
userService.syncUserCanteen(userId, deptId, foure);
return R.ok();
}
/* ************************************* end 远程调用 end ************************************* */
@Operation(summary = "同步用户食堂信息", description = "同步用户食堂信息")
@PostMapping("/sync-user-canteen")
public R syncUserCanteen() {
@@ -222,6 +222,7 @@ public interface SysUserService extends IService<SysUser> {
/**
* 根据部门id/姓名,获取用户信息
*
* @param deptId
* @param name
* @return
@@ -229,7 +230,17 @@ public interface SysUserService extends IService<SysUser> {
List<SimpleUserListVO> listUserIdByDeptId(Long deptId, String name);
/**
* 同步用户食堂信息
* 同步所有用户食堂信息
*/
void syncUserCanteen();
/**
* 按条件同步用户食堂信息
*/
void syncUserCanteen(Long userId, Long deptId, boolean foure);
/**
* 获取用户食堂id
*/
Long getUserCanteenId(Long deptId);
}
@@ -53,6 +53,7 @@ import com.bsd.pjcloud.common.audit.annotation.Audit;
import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.common.core.constant.CommonConstants;
import com.bsd.pjcloud.common.core.constant.CommonRoleConstant;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.exception.ErrorCodes;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.MsgUtils;
@@ -174,6 +175,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
sysUser.setUpdateBy(userDto.getUsername());
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
sysUser.setPasswordModifyTime(LocalDateTime.now());
// 获取用户食堂id
sysUser.setCanteenId(getUserCanteenId(sysUser.getDeptId()));
baseMapper.insert(sysUser);
// 保存用户岗位信息
Optional.ofNullable(userDto.getPost()).ifPresent(posts -> {
@@ -209,7 +212,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
// 创建钱包
remoteWalletService.createWallet(sysUser.getUserId());
// 通知钱包
remoteWalletService.userChange(sysUser.getUserId(), Boolean.FALSE);
});
}
@@ -890,6 +895,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
updateUser.setUserId(detail.getUserId());
updateUser.setProcessStatus(processStatus);
updateUser.setProcessTime(LocalDateTime.now());
if (isConsent) updateUser.setCanteenId(getUserCanteenId(detail.getDeptId()));
baseMapper.updateById(updateUser);
if (isConsent) {
// 创建用户默认钱包
@@ -961,6 +967,35 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
}
}
/**
* 按条件同步用户食堂信息
*/
@Override
public void syncUserCanteen(Long userId, Long deptId, boolean foure) {
SysUser userDto = new SysUser();
userDto.setUserId(userId);
userDto.setDeptId(deptId);
Long current = 1L;
while (true) {
boolean result = syncUserCanteenGroup(current, userDto, foure);
if (!result) break;
current++;
}
}
/**
* 获取用户食堂id
*/
@Override
public Long getUserCanteenId(Long deptId) {
if (ObjectUtil.isEmpty(deptId)) return -1L;
MchManageVo mchDetail = remoteMchService.getFirstMchByDeptId(deptId, MerchantTypeEnum.CANTEEN).getData();
if (ObjectUtil.isNotEmpty(mchDetail) && ObjectUtil.isNotEmpty(mchDetail.getTypes()) && ObjectUtil.equals(mchDetail.getTypes(), MerchantTypeEnum.CANTEEN.getType())) {
return mchDetail.getId();
}
return -1L;
}
public boolean syncUserCanteenGroup(Long current, SysUser userDto, boolean foure) {
Page page = new Page<>();
page.setCurrent(current);
@@ -977,14 +1012,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
for (SysUser v : pageList.getRecords()) {
if (!foure && ObjectUtil.isNotEmpty(v.getCanteenId())) continue;
MchManageVo mchDetail = remoteMchService.getFirstMchByDeptId(v.getDeptId()).getData();
if (ObjectUtil.isEmpty(mchDetail)) {
noneMchUserSum++;
continue;
}
SysUser item = new SysUser();
item.setUserId(v.getUserId());
item.setCanteenId(mchDetail.getId());
Long mchId = getUserCanteenId(v.getDeptId());
if (ObjectUtil.equals(mchId, -1L)) {
item.setCanteenId(-1L);
noneMchUserSum++;
} else {
item.setCanteenId(mchId);
}
updateUserList.add(item);
}
baseMapper.updateById(updateUserList);
@@ -205,6 +205,7 @@ public class SysUserTransactionServiceImpl extends ServiceImpl<SysUserTransactio
SysUser userUpdateObj = new SysUser();
userUpdateObj.setUserId(detail.getUserId());
userUpdateObj.setDeptId(detail.getTargetDeptId());
userUpdateObj.setCanteenId(sysUserService.getUserCanteenId(detail.getTargetDeptId()));
sysUserService.updateById(userUpdateObj);
// 通知正元
if (ObjectUtil.equals(detail.getBizType(), UserTransactionEnum.INNER_TRANSFER.getType())) {
@@ -36,9 +36,9 @@ public interface RemoteMchService {
@NoToken
@GetMapping("/mch-manage/get-first-mch")
R<MchManageVo> getFirstMch(@RequestParam List<Long> deptIds);
R<MchManageVo> getFirstMch(@RequestParam List<Long> deptIds, @RequestParam MerchantTypeEnum mchType);
@NoToken
@GetMapping("/mch-manage/get-first-mch-by-dept-id")
R<MchManageVo> getFirstMchByDeptId(@RequestParam Long deptId);
R<MchManageVo> getFirstMchByDeptId(@RequestParam Long deptId, @RequestParam MerchantTypeEnum mchType);
}
@@ -90,16 +90,16 @@ public class MchManageController {
@Inner
@GetMapping("/get-first-mch")
public R<MchManageVo> getFirstMch(@RequestParam List<Long> deptIds) {
MchManageVo mchManage = mchManageService.getFirstMch(deptIds);
public R<MchManageVo> getFirstMch(@RequestParam List<Long> deptIds, @RequestParam MerchantTypeEnum mchType) {
MchManageVo mchManage = mchManageService.getFirstMch(deptIds, mchType);
if (ObjectUtil.isEmpty(mchManage)) return R.failed("商户不存在");
return R.ok(mchManage);
}
@Inner
@GetMapping("/get-first-mch-by-dept-id")
public R<MchManageVo> getFirstMchByDeptId(@RequestParam Long deptId) {
MchManageVo mchManage = mchManageService.getFirstMchByDeptId(deptId);
public R<MchManageVo> getFirstMchByDeptId(@RequestParam Long deptId, @RequestParam MerchantTypeEnum mchType) {
MchManageVo mchManage = mchManageService.getFirstMchByDeptId(deptId, mchType);
if (ObjectUtil.isEmpty(mchManage)) return R.failed("商户不存在");
return R.ok(mchManage);
}
@@ -37,9 +37,9 @@ public interface MchManageService extends IService<MchManageEntity> {
MchManageVo getByDeptId(Long deptId, MerchantTypeEnum type);
MchManageVo getFirstMch(List<Long> deptIds);
MchManageVo getFirstMch(List<Long> deptIds, MerchantTypeEnum mchType);
MchManageVo getFirstMchByDeptId(Long deptId);
MchManageVo getFirstMchByDeptId(Long deptId, MerchantTypeEnum mchType);
/**
* 刷新商户二维码
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
@@ -159,7 +160,7 @@ public class WalletActiveServiceImpl extends ServiceImpl<WalletActiveMapper, Wal
public void createAndActiveCard(WalletManageEntity wallet) {
if (ObjectUtil.isEmpty(wallet) || ObjectUtil.isNotEmpty(wallet.getCardNumber())) return;
// 查询用户所属于的商户
MchManageVo mch = mchManageService.getFirstMchByDeptId(wallet.getDeptId());
MchManageVo mch = mchManageService.getFirstMchByDeptId(wallet.getDeptId(), MerchantTypeEnum.CANTEEN);
if (ObjectUtil.isEmpty(mch)) return;
LambdaQueryWrapper<WalletActiveEntity> wrapper = new LambdaQueryWrapper<WalletActiveEntity>()
.isNull(WalletActiveEntity::getUserId)
@@ -23,6 +23,7 @@ import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.common.core.constant.CommonRoleConstant;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
@@ -461,8 +462,8 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
.eq(WalletManageEntity::getUserId, sysUser.getUserId())
);
// 修改钱包冻结开卡商户
// 查询用户所属于的商户
MchManageVo mch = mchManageService.getFirstMchByDeptId(sysUser.getDeptId());
// 查询用户所属于的食堂商户
MchManageVo mch = mchManageService.getFirstMchByDeptId(sysUser.getDeptId(), MerchantTypeEnum.CANTEEN);
if (ObjectUtil.isNotEmpty(mch)) {
walletActiveService.update(new LambdaUpdateWrapper<WalletActiveEntity>()
.set(WalletActiveEntity::getMerchantId, mch.getId())
@@ -8,6 +8,7 @@ import com.bsd.pjcloud.admin.api.dto.DeptAllListDto;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.wallet.api.dto.mch.MchDeptDto;
import com.bsd.pjcloud.wallet.api.entity.mch.MchDeptEntity;
@@ -57,7 +58,7 @@ public class MchDeptServiceImpl extends ServiceImpl<MchDeptUserMapper, MchDeptEn
item.setDeptId(v.getDeptId());
// 查询所属的商户
try {
MchManageVo mch = mchManageService.getFirstMchByDeptId(v.getDeptId());
MchManageVo mch = mchManageService.getFirstMchByDeptId(v.getDeptId(), MerchantTypeEnum.CANTEEN);
if (ObjectUtil.isEmpty(mch)) continue;
item.setMchId(mch.getId());
} catch (Exception e) {
@@ -46,6 +46,8 @@ import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
@@ -53,7 +55,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* 商户管理
@@ -274,13 +276,21 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
@Override
public MchManageVo getFirstMch(List<Long> deptIds) {
List<MchManageEntity> merchantList = baseMapper.selectList(new LambdaQueryWrapper<MchManageEntity>());
public MchManageVo getFirstMch(List<Long> deptIds, MerchantTypeEnum mchType) {
List<MchManageEntity> merchantList = baseMapper.selectList(new LambdaQueryWrapper<MchManageEntity>()
.eq(ObjectUtil.isNotEmpty(mchType), MchManageEntity::getTypes, mchType.getType())
);
if (ObjectUtil.isEmpty(merchantList)) return null;
for (Long id : deptIds) {
for (MchManageEntity merchant : merchantList) {
if (ObjectUtil.equals(merchant.getDeptId(), id)) {
return BeanUtils.toBean(merchant, MchManageVo.class);
if (ObjectUtil.isNotEmpty(mchType)) {
if (ObjectUtil.equals(merchant.getTypes(), mchType.getType())) {
return BeanUtils.toBean(merchant, MchManageVo.class);
}
} else {
return BeanUtils.toBean(merchant, MchManageVo.class);
}
}
}
}
@@ -288,13 +298,13 @@ public class MchManageServiceImpl extends ServiceImpl<MchManageMapper, MchManage
}
@Override
public MchManageVo getFirstMchByDeptId(Long deptId) {
public MchManageVo getFirstMchByDeptId(Long deptId, MerchantTypeEnum mchType) {
List<SysDept> parentDeptIdList = remoteDeptService.getParentDeptList(deptId).getData();
if (ObjectUtil.isEmpty(parentDeptIdList)) {
return null;
}
List<Long> deptIds = parentDeptIdList.stream().map(SysDept::getDeptId).toList();
return getFirstMch(deptIds);
return getFirstMch(deptIds, mchType);
}
/**
@@ -15,6 +15,7 @@ import com.bsd.pjcloud.admin.api.feign.RemoteRoleService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.vo.UserVO;
import com.bsd.pjcloud.common.core.constant.CommonRoleConstant;
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdZyService;
import com.bsd.pjcloud.thirdparty.dto.zy.mer.ZyMerSyncAccClassInfoDto;
@@ -115,7 +116,7 @@ public class WalletThirdZyServiceImpl implements WalletThirdZyService {
public void syncAllDept(Long deptId, Boolean isDel) {
MchManageDto dto = new MchManageDto();
if (ObjectUtil.isNotEmpty(deptId)) {
MchManageVo mchManageVo = mchManageService.getFirstMchByDeptId(deptId);
MchManageVo mchManageVo = mchManageService.getFirstMchByDeptId(deptId, MerchantTypeEnum.CANTEEN);
if (ObjectUtil.isNotEmpty(mchManageVo)) {
dto.setDeptId(mchManageVo.getDeptId());
}
@@ -268,7 +269,7 @@ public class WalletThirdZyServiceImpl implements WalletThirdZyService {
log.error("|{}|syncAllUserGroup用户没有自动创建钱包权限|{}|", TAG, JSONUtil.toJsonStr(v));
continue;
}
MchManageVo mch = mchManageService.getFirstMchByDeptId(v.getDeptId());
MchManageVo mch = mchManageService.getFirstMchByDeptId(v.getDeptId(), MerchantTypeEnum.CANTEEN);
// 查询是在商户下
if (ObjectUtil.isEmpty(mch)) {
log.error("|{}|syncAllUserGroup用户部门商户id为空WalletManageVo|{}|", TAG, JSONUtil.toJsonStr(v));