|
|
@@ -0,0 +1,566 @@
|
|
|
+package com.zhongzheng.framework.web.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.zhongzheng.common.core.domain.entity.*;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.bs.system.bo.*;
|
|
|
+import com.zhongzheng.modules.bs.system.domain.*;
|
|
|
+import com.zhongzheng.modules.bs.system.mapper.BsSysRoleMenuMapper;
|
|
|
+import com.zhongzheng.modules.bs.system.mapper.BsSysTenantMapper;
|
|
|
+import com.zhongzheng.modules.bs.system.service.*;
|
|
|
+import com.zhongzheng.modules.bs.system.vo.BsSysTenantAccountVo;
|
|
|
+import com.zhongzheng.modules.bs.system.vo.BsSysTenantBankAccountVo;
|
|
|
+import com.zhongzheng.modules.bs.system.vo.BsSysTenantVo;
|
|
|
+import com.zhongzheng.modules.order.domain.Order;
|
|
|
+import com.zhongzheng.modules.order.service.IOrderService;
|
|
|
+import com.zhongzheng.modules.system.bo.*;
|
|
|
+import com.zhongzheng.modules.system.domain.SysRoleMenu;
|
|
|
+import com.zhongzheng.modules.system.domain.SysTenant;
|
|
|
+import com.zhongzheng.modules.system.mapper.SysRoleMenuMapper;
|
|
|
+import com.zhongzheng.modules.system.mapper.SysTenantMapper;
|
|
|
+import com.zhongzheng.modules.system.service.*;
|
|
|
+import com.zhongzheng.modules.system.vo.SysTenantAccountVo;
|
|
|
+import com.zhongzheng.modules.system.vo.SysTenantBankAccountVo;
|
|
|
+import com.zhongzheng.modules.system.vo.SysTenantVo;
|
|
|
+import com.zhongzheng.modules.top.goods.domain.TopOldOrder;
|
|
|
+import com.zhongzheng.modules.top.goods.service.ITopOldOrderService;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 系统商户Service业务层处理
|
|
|
+ *
|
|
|
+ * @author hjl
|
|
|
+ * @date 2021-08-03
|
|
|
+ */
|
|
|
+@Service //指定数据源
|
|
|
+public class BsSysTenantServiceImpl extends ServiceImpl<BsSysTenantMapper, BsSysTenant> implements IBsSysTenantService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBsSysUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBsSysMenuService menuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBsSysRoleService roleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BsSysRoleMenuMapper sysRoleMenuMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBsSysDictDataService iSysDictDataService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IBsSysDictTypeService iSysDictTypeService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BsSysTenantVo queryById(Long tenantId){
|
|
|
+ BsSysTenant db = this.baseMapper.selectById(tenantId);
|
|
|
+ return BeanUtil.toBean(db, BsSysTenantVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BsSysTenantVo> queryList(BsSysTenantQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<BsSysTenant> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.ne(BsSysTenant::getStatus, -1);
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getTenantName()), BsSysTenant::getTenantName, bo.getTenantName());
|
|
|
+ lqw.eq(ObjectUtils.isNotNull(bo.getTenantid()),BsSysTenant::getTenantId, bo.getTenantid());
|
|
|
+ lqw.orderByDesc(BsSysTenant::getSort);
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<BsSysTenantVo> entity2Vo(Collection<BsSysTenant> collection) {
|
|
|
+ List<BsSysTenantVo> voList = collection.stream()
|
|
|
+ .map(any -> {
|
|
|
+ BsSysTenantVo sysTenantVo = BeanUtil.toBean(any, BsSysTenantVo.class);
|
|
|
+ if (StringUtils.isNotBlank(any.getAccountInformation())){
|
|
|
+ String accountInformation = any.getAccountInformation();
|
|
|
+ List<BsSysTenantAccountVo> accountVo = JSONArray.parseArray(accountInformation, BsSysTenantAccountVo.class);
|
|
|
+ sysTenantVo.setAccountList(accountVo);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(any.getInvoiceInformation())){
|
|
|
+ BsSysTopTenantInvoiceBo invoiceBo = JSONObject.parseObject(any.getInvoiceInformation(), BsSysTopTenantInvoiceBo.class);
|
|
|
+ sysTenantVo.setInvoiceBo(invoiceBo);
|
|
|
+ }
|
|
|
+ return sysTenantVo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<BsSysTenant> page = (Page<BsSysTenant>)collection;
|
|
|
+ Page<BsSysTenantVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByAddBo(BsSysTenantAddBo bo) {
|
|
|
+ return this.createTenant(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(BsSysTenantEditBo bo) {
|
|
|
+ BsSysTenant update = BeanUtil.toBean(bo, BsSysTenant.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(BsSysTenant entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ if(checkNameUnique(entity)){
|
|
|
+ throw new CustomException("公司名已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Long createTenantAdmin(BsSysTenantAdminBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getTenantName())){
|
|
|
+ throw new CustomException("没有企业名称");
|
|
|
+ }
|
|
|
+ //中正后台企业ID
|
|
|
+ Long tenantId = 867735392558919680L;
|
|
|
+ //设置新机构
|
|
|
+ BsSysTenant sysTenant = getById(tenantId);
|
|
|
+ sysTenant.setTenantName(bo.getTenantName());
|
|
|
+ sysTenant.setHostPc(bo.getHostPc());
|
|
|
+ sysTenant.setHostH5(bo.getHostH5());
|
|
|
+ sysTenant.setHostLive(bo.getHostLive());
|
|
|
+ sysTenant.setHostH5Seller(null);
|
|
|
+ sysTenant.setHostAdmin(null);
|
|
|
+ //生成tenantId
|
|
|
+ Long newTenantId = createTenantId();
|
|
|
+ sysTenant.setTenantId(newTenantId);
|
|
|
+ if (!save(sysTenant)){
|
|
|
+ throw new CustomException("创建企业失败");
|
|
|
+ }
|
|
|
+ //创建账号
|
|
|
+ BsSysUser admin = userService.selectUserByTenant("admin",tenantId);
|
|
|
+ admin.setTenantId(newTenantId);
|
|
|
+ admin.setUserId(null);
|
|
|
+ if(Validator.isNotEmpty(bo.getPassword())){
|
|
|
+ admin.setPassword(SecurityUtils.encryptPassword(bo.getPassword()));
|
|
|
+ }
|
|
|
+ if (!userService.save(admin)){
|
|
|
+ throw new CustomException("创建后台账号失败");
|
|
|
+ }
|
|
|
+ //创建菜单
|
|
|
+ List<BsSysMenu> list = menuService.listSysMenuByTenant(tenantId);
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return newTenantId;
|
|
|
+ }
|
|
|
+ List<BsSysMenu> oldMenus = list.stream().map(item -> BeanUtil.toBean(item, BsSysMenu.class)).collect(Collectors.toList());
|
|
|
+ list.forEach(item -> {
|
|
|
+ item.setMenuId(null);
|
|
|
+ item.setTenantId(newTenantId);
|
|
|
+ });
|
|
|
+ if (!menuService.saveBatch(list)){
|
|
|
+ throw new CustomException("添加菜单失败");
|
|
|
+ }
|
|
|
+ //新菜单
|
|
|
+ List<BsSysMenu> newMenus = menuService.listSysMenuByTenant(newTenantId);
|
|
|
+ //匹配parent_id
|
|
|
+ for (BsSysMenu newMenu : newMenus) {
|
|
|
+ if (newMenu.getParentId() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<BsSysMenu> collect = oldMenus.stream().filter(x -> x.getMenuName().equals(newMenu.getMenuName())
|
|
|
+ && x.getCreateTime().equals(newMenu.getCreateTime()) && x.getOrderNum().equals(newMenu.getOrderNum())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(collect) || collect.size() > 1){
|
|
|
+ throw new CustomException("菜单匹配失败:"+newMenu.getMenuName());
|
|
|
+ }
|
|
|
+ BsSysMenu sysMenu = collect.stream().findFirst().orElse(null);
|
|
|
+ BsSysMenu parentMenu = oldMenus.stream().filter(x -> x.getMenuId().equals(sysMenu.getParentId())).findFirst().orElse(null);
|
|
|
+ List<BsSysMenu> collect2 = newMenus.stream().filter(x -> x.getMenuName().equals(parentMenu.getMenuName())
|
|
|
+ && x.getCreateTime().equals(parentMenu.getCreateTime()) && x.getOrderNum().equals(parentMenu.getOrderNum())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(collect2) || collect2.size() > 1){
|
|
|
+ throw new CustomException("菜单匹配失败:"+newMenu.getMenuName());
|
|
|
+ }
|
|
|
+ newMenu.setParentId(collect2.get(0).getMenuId());
|
|
|
+ }
|
|
|
+ //修改父ID
|
|
|
+// menuService.updateBatchById(newMenus);
|
|
|
+ newMenus.forEach(item -> {
|
|
|
+ menuService.updateParentById(item);
|
|
|
+ });
|
|
|
+
|
|
|
+ //新增分销角色
|
|
|
+ initRoles(newTenantId,tenantId);
|
|
|
+
|
|
|
+ //初始化配置和字典
|
|
|
+ initConfigAndDict(newTenantId,tenantId);
|
|
|
+ return newTenantId;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long createTenantId(){
|
|
|
+ String randomNumeric = RandomStringUtils.randomNumeric(15);
|
|
|
+ int count = count(new LambdaQueryWrapper<BsSysTenant>()
|
|
|
+ .eq(BsSysTenant::getTenantId, Long.valueOf(randomNumeric)));
|
|
|
+ if (count == 0){
|
|
|
+ return Long.valueOf(randomNumeric);
|
|
|
+ }else {
|
|
|
+ createTenantId();
|
|
|
+ }
|
|
|
+ return Long.valueOf(randomNumeric);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkNameUnique(BsSysTenant entity) {
|
|
|
+ BsSysTenant info = getOne(new LambdaQueryWrapper<BsSysTenant>()
|
|
|
+ .eq(BsSysTenant::getTenantName,entity.getTenantName())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (Validator.isNotNull(info)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean createTenant(BsSysTenantAddBo bo){
|
|
|
+ BsSysTenant add = BeanUtil.toBean(bo, BsSysTenant.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ this.save(add);
|
|
|
+ //创建属于新公司的admin用户
|
|
|
+ Long tenantId = add.getTenantId();
|
|
|
+ ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId",String.valueOf(tenantId));
|
|
|
+ BsSysUser user = new BsSysUser();
|
|
|
+ user.setUserName("admin");
|
|
|
+ user.setNickName(bo.getTenantName());
|
|
|
+ user.setCreateBy("SAAS-"+SecurityUtils.getUsername());
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(bo.getPassword()));
|
|
|
+ userService.insertUser(user);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long findTenantId(BsSysTenantQueryBo bo) {
|
|
|
+ return baseMapper.findTenantId(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+
|
|
|
+ public List<BsSysTenant> getListSysTenant() {
|
|
|
+ return list(new LambdaQueryWrapper<BsSysTenant>().eq(BsSysTenant::getStatus, 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createTenantAdminOld(BsSysTenantAdminOldBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getTenantName())){
|
|
|
+ throw new CustomException("没有企业名称");
|
|
|
+ }
|
|
|
+ //中正后台企业ID
|
|
|
+ Long tenantId = 867735392558919680L;
|
|
|
+ //设置新机构
|
|
|
+ BsSysTenant sysTenant = getById(tenantId);
|
|
|
+ sysTenant.setTenantName(bo.getTenantName());
|
|
|
+ //生成tenantId
|
|
|
+// Long newTenantId = createTenantId();
|
|
|
+ Long newTenantId = bo.getTenantId();
|
|
|
+ sysTenant.setTenantId(newTenantId);
|
|
|
+ sysTenant.setHostH5("");
|
|
|
+ sysTenant.setHostPc("");
|
|
|
+ sysTenant.setHostLive("");
|
|
|
+ sysTenant.setHostH5Seller("");
|
|
|
+ if (!save(sysTenant)){
|
|
|
+ throw new CustomException("创建企业失败");
|
|
|
+ }
|
|
|
+ //创建账号
|
|
|
+ BsSysUser admin = userService.selectUserByTenant("admin",tenantId);
|
|
|
+ admin.setTenantId(newTenantId);
|
|
|
+ admin.setUserId(null);
|
|
|
+
|
|
|
+ if (!userService.save(admin)){
|
|
|
+ throw new CustomException("创建后台账号失败");
|
|
|
+ }
|
|
|
+ //创建菜单
|
|
|
+ List<BsSysMenu> list = menuService.listSysMenuByTenant(tenantId);
|
|
|
+ if (CollectionUtils.isEmpty(list)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BsSysMenu> oldMenus = list.stream().map(item -> BeanUtil.toBean(item, BsSysMenu.class)).collect(Collectors.toList());
|
|
|
+ list.forEach(item -> {
|
|
|
+ item.setMenuId(null);
|
|
|
+ item.setTenantId(newTenantId);
|
|
|
+ });
|
|
|
+ if (!menuService.saveBatch(list)){
|
|
|
+ throw new CustomException("添加菜单失败");
|
|
|
+ }
|
|
|
+ //新菜单
|
|
|
+ List<BsSysMenu> newMenus = menuService.listSysMenuByTenant(newTenantId);
|
|
|
+ //匹配parent_id
|
|
|
+ for (BsSysMenu newMenu : newMenus) {
|
|
|
+ if (newMenu.getParentId() == 0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<BsSysMenu> collect = oldMenus.stream().filter(x -> x.getMenuName().equals(newMenu.getMenuName())
|
|
|
+ && x.getCreateTime().equals(newMenu.getCreateTime()) && x.getOrderNum().equals(newMenu.getOrderNum())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(collect) || collect.size() > 1){
|
|
|
+ throw new CustomException("菜单匹配失败:"+newMenu.getMenuName());
|
|
|
+ }
|
|
|
+ BsSysMenu sysMenu = collect.stream().findFirst().orElse(null);
|
|
|
+ BsSysMenu parentMenu = oldMenus.stream().filter(x -> x.getMenuId().equals(sysMenu.getParentId())).findFirst().orElse(null);
|
|
|
+ List<BsSysMenu> collect2 = newMenus.stream().filter(x -> x.getMenuName().equals(parentMenu.getMenuName())
|
|
|
+ && x.getCreateTime().equals(parentMenu.getCreateTime()) && x.getOrderNum().equals(parentMenu.getOrderNum())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(collect2) || collect2.size() > 1){
|
|
|
+ throw new CustomException("菜单匹配失败:"+newMenu.getMenuName());
|
|
|
+ }
|
|
|
+ newMenu.setParentId(collect2.get(0).getMenuId());
|
|
|
+ }
|
|
|
+ //修改父ID
|
|
|
+// menuService.updateBatchById(newMenus);
|
|
|
+ newMenus.forEach(item -> {
|
|
|
+ menuService.updateParentById(item);
|
|
|
+ });
|
|
|
+
|
|
|
+ //新增分销角色
|
|
|
+ initRoles(newTenantId,tenantId);
|
|
|
+
|
|
|
+ //初始化配置和字典
|
|
|
+ initConfigAndDict(newTenantId,tenantId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initConfigAndDict(Long newTenantId, Long tenantId) {
|
|
|
+ //字典
|
|
|
+ List<BsSysDictType> dictTypes = iSysDictTypeService.getListByTenant(tenantId);
|
|
|
+ if (CollectionUtils.isEmpty(dictTypes)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<BsSysDictType> dictTypeList = dictTypes.stream().map(item -> {
|
|
|
+ item.setDictId(null);
|
|
|
+ item.setTenantId(newTenantId);
|
|
|
+ return item;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ iSysDictTypeService.saveBatch(dictTypeList);
|
|
|
+ List<BsSysDictData> dictDatas = iSysDictDataService.getListByTenant(tenantId);
|
|
|
+ if (CollectionUtils.isEmpty(dictDatas)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (BsSysDictData dictData : dictDatas) {
|
|
|
+ BsSysDictType dictType = iSysDictTypeService.getByIdTenant(dictData.getDictTypeId(),tenantId);
|
|
|
+ if (ObjectUtils.isNull(dictType)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BsSysDictType dictType1 = dictTypeList.stream().filter(item -> item.getDictType().equals(dictType.getDictType())).findFirst().orElse(null);
|
|
|
+ if (ObjectUtils.isNull(dictType1)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ dictData.setDictCode(null);
|
|
|
+ dictData.setDictTypeId(dictType1.getDictId());
|
|
|
+ dictData.setTenantId(newTenantId.toString());
|
|
|
+ }
|
|
|
+ iSysDictDataService.saveBatch(dictDatas);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateRoleTenant(List<Long> tenantIds) {
|
|
|
+ Long oldTenantId = 867735392558919680L;
|
|
|
+ for (Long tenantId : tenantIds) {
|
|
|
+ initRoles(tenantId,oldTenantId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateDictTenant(List<Long> tenantIds) {
|
|
|
+ Long oldTenantId = 867735392558919680L;
|
|
|
+ for (Long tenantId : tenantIds) {
|
|
|
+ initConfigAndDict(tenantId,oldTenantId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BsSysTenantBankAccountVo> getBankAccountList(String tenantId) {
|
|
|
+ BsSysTenant tenant = getById(Long.valueOf(tenantId));
|
|
|
+ if (ObjectUtils.isNull(tenant)){
|
|
|
+ throw new CustomException("机构信息获取失败!");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(tenant.getAccountInformation())){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ String accountInformation = tenant.getAccountInformation();
|
|
|
+ return JSONArray.parseArray(accountInformation,BsSysTenantBankAccountVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean addTopTenant(BsSysTopTenantAddBo bo) {
|
|
|
+ BsSysTenant add = BeanUtil.toBean(bo, BsSysTenant.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setTenantId(createTenantId());
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setStatus(1);
|
|
|
+ if (ObjectUtils.isNotNull(bo.getAccountList())){
|
|
|
+ add.setAccountInformation(JSONArray.toJSONString(bo.getAccountList()));
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(bo.getInvoiceBo())){
|
|
|
+ add.setInvoiceInformation(JSONObject.toJSONString(bo.getInvoiceBo()));
|
|
|
+ }
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean editTopTenant(BsSysTopTenantEditBo bo) {
|
|
|
+ BsSysTenant tenant = getById(bo.getTenantId());
|
|
|
+ if (ObjectUtils.isNull(tenant)){
|
|
|
+ throw new CustomException("机构信息有误");
|
|
|
+ }
|
|
|
+ tenant.setTenantName(bo.getTenantName());
|
|
|
+// if(checkNameUnique(tenant)){
|
|
|
+// throw new CustomException("公司名已存在");
|
|
|
+// }
|
|
|
+ tenant.setHostH5(bo.getHostH5());
|
|
|
+ tenant.setHostPc(bo.getHostPc());
|
|
|
+ tenant.setBillType(bo.getBillType());
|
|
|
+ tenant.setBillDay(bo.getBillDay());
|
|
|
+ tenant.setAccountInformation(JSONArray.toJSONString(bo.getAccountList()));
|
|
|
+ tenant.setInvoiceInformation(JSONObject.toJSONString(bo.getInvoiceBo()));
|
|
|
+ tenant.setEduPhone(bo.getEduPhone());
|
|
|
+ return updateById(tenant);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteTopTenant(BsSysTopTenantEditBo bo) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BsSysTenant> getListNoTenant(Long tenantId) {
|
|
|
+ return baseMapper.getListNoTenant(tenantId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BsSysTenant> getExamRoomTenant() {
|
|
|
+ return baseMapper.getExamRoomTenant();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initRoles(Long newTenantId,Long tenantId) {
|
|
|
+ List<String> roleKey = new ArrayList<>();
|
|
|
+ roleKey.add("seller");
|
|
|
+ roleKey.add("seller_admin");
|
|
|
+ roleKey.add("supervisory");
|
|
|
+ roleKey.add("cashier");
|
|
|
+ roleKey.add("accounting");
|
|
|
+ roleKey.add("boss");
|
|
|
+ roleKey.add("edu");
|
|
|
+ roleKey.forEach(key -> {
|
|
|
+ BsSysRole tenantRole = roleService.getRoleByTenantKey(key,newTenantId);
|
|
|
+ if (ObjectUtils.isNull(tenantRole)){
|
|
|
+ //新增
|
|
|
+ BsSysRole role = roleService.getRoleByTenantKey(key, tenantId);
|
|
|
+ if (ObjectUtils.isNull(role)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ role.setRoleId(null);
|
|
|
+ role.setTenantId(newTenantId.toString());
|
|
|
+ roleService.save(role);
|
|
|
+ tenantRole = role;
|
|
|
+ }
|
|
|
+ //角色菜单
|
|
|
+ BsSysRole oldRole = roleService.getRoleByTenantKey(tenantRole.getRoleKey(), tenantId);
|
|
|
+ List<BsSysRoleMenu> sysRoleMenus = sysRoleMenuMapper.listByTenant(oldRole.getRoleId(),tenantId);
|
|
|
+ if (CollectionUtils.isNotEmpty(sysRoleMenus)){
|
|
|
+ List<BsSysRoleMenu> roleMenus = new ArrayList<>();
|
|
|
+ for (BsSysRoleMenu menu : sysRoleMenus) {
|
|
|
+ BsSysMenu oldSysMenu = menuService.getMenuById(menu.getMenuId(),tenantId);
|
|
|
+ if (ObjectUtils.isNull(oldSysMenu)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long menuId = menuService.getMenuByTenant(oldSysMenu.getMenuName(),oldSysMenu.getOrderNum(),oldSysMenu.getCreateTime(),newTenantId);
|
|
|
+ if (ObjectUtils.isNull(menuId)){
|
|
|
+ oldSysMenu.setMenuId(null);
|
|
|
+ oldSysMenu.setTenantId(newTenantId);
|
|
|
+ //查询父ID
|
|
|
+ Long parentId = getParentId(oldSysMenu,tenantId,newTenantId);
|
|
|
+ oldSysMenu.setParentId(parentId);
|
|
|
+ menuService.save(oldSysMenu);
|
|
|
+ menuId = oldSysMenu.getMenuId();
|
|
|
+ }
|
|
|
+ BsSysRoleMenu sysRoleMenu = new BsSysRoleMenu();
|
|
|
+ sysRoleMenu.setRoleId(tenantRole.getRoleId());
|
|
|
+ sysRoleMenu.setMenuId(menuId);
|
|
|
+ sysRoleMenu.setTenantId(newTenantId.toString());
|
|
|
+ roleMenus.add(sysRoleMenu);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(roleMenus)){
|
|
|
+ roleMenus.forEach(item -> {
|
|
|
+ sysRoleMenuMapper.insert(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getParentId(BsSysMenu oldSysMenu, Long tenantId, Long newTenantId) {
|
|
|
+ if (oldSysMenu.getParentId() == 0){
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ BsSysMenu sysMenu = menuService.getMenuById(oldSysMenu.getParentId(),tenantId);
|
|
|
+ if (ObjectUtils.isNull(oldSysMenu)){
|
|
|
+ return 0L;
|
|
|
+ }
|
|
|
+ Long menuId = menuService.getMenuByTenant(sysMenu.getMenuName(),sysMenu.getOrderNum(),sysMenu.getCreateTime(),newTenantId);
|
|
|
+ if (ObjectUtils.isNull(menuId)){
|
|
|
+ oldSysMenu.setMenuId(null);
|
|
|
+ oldSysMenu.setTenantId(newTenantId);
|
|
|
+ //查询父ID
|
|
|
+ Long parentId = getParentId(sysMenu,tenantId,newTenantId);
|
|
|
+ oldSysMenu.setParentId(parentId);
|
|
|
+ menuService.save(oldSysMenu);
|
|
|
+ menuId = oldSysMenu.getMenuId();
|
|
|
+ }
|
|
|
+ return menuId;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|