yangdamao 2 năm trước cách đây
mục cha
commit
fc1f95ba42

+ 9 - 0
zhongzheng-admin-saas/src/main/java/com/zhongzheng/controller/system/SysTenantController.java

@@ -126,6 +126,15 @@ public class SysTenantController extends BaseController {
         return toAjax(iSysTenantService.editTopTenant(bo) ? 1 : 0);
     }
 
+    /**
+     * 删除机构
+     */
+    @ApiOperation("删除机构")
+    @PostMapping("/delete/top")
+    public AjaxResult<Void> deleteTopTenant(@RequestBody SysTopTenantEditBo bo) {
+        return toAjax(iSysTenantService.deleteTopTenant(bo) ? 1 : 0);
+    }
+
     /**
      * 删除系统商户
      */

+ 35 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/ToolsUtils.java

@@ -454,4 +454,39 @@ public class ToolsUtils {
         return tmpImg ;
     }
 
+    public static String solve(String num) {
+        if (num == null) {
+            return null;
+        }
+        // 判断是否有小数
+        int index = num.indexOf(".");
+        if (index >= 0) {
+            String integer = num.substring(0, index);
+            String decimal = num.substring(index);
+            // 分隔后的整数+小数拼接起来
+            return addSeparator(integer) + decimal;
+        } else {
+            return addSeparator(num);
+        }
+    }
+
+    // 添加分隔符
+    public static String addSeparator(String num) {
+        int length = num.length();
+        ArrayList list = new ArrayList();
+        while (length > 3) {
+            list.add(num.substring(length - 3, length));
+            length = length - 3;
+        }
+        // 将前面小于三位的数字添加到ArrayList中
+        list.add(num.substring(0, length));
+        StringBuffer buffer = new StringBuffer();
+        // 倒序拼接
+        for (int i = list.size() - 1; i > 0; i--) {
+            buffer.append(list.get(i) + ",");
+        }
+        buffer.append(list.get(0));
+        return buffer.toString();
+    }
+
 }

+ 30 - 1
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/SysTenantServiceImpl.java

@@ -7,6 +7,7 @@ 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;
@@ -18,6 +19,8 @@ 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.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;
@@ -27,6 +30,8 @@ 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.stereotype.Service;
@@ -71,6 +76,13 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
     @Autowired
     private ISysDictTypeService iSysDictTypeService;
 
+    @Autowired
+    private ITopOldOrderService topOldOrderService;
+
+    @Autowired
+    private IOrderService orderService;
+
+
     @Override
     public SysTenantVo queryById(Long tenantId){
         SysTenant db = this.baseMapper.selectById(tenantId);
@@ -80,7 +92,7 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
     @Override
     public List<SysTenantVo> queryList(SysTenantQueryBo bo) {
         LambdaQueryWrapper<SysTenant> lqw = Wrappers.lambdaQuery();
-        lqw.eq(bo.getStatus() != null, SysTenant::getStatus, bo.getStatus());
+        lqw.ne(SysTenant::getStatus, -1);
         lqw.like(StrUtil.isNotBlank(bo.getTenantName()), SysTenant::getTenantName, bo.getTenantName());
         return entity2Vo(this.list(lqw));
     }
@@ -455,6 +467,23 @@ public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant
         return updateById(tenant);
     }
 
+    @Override
+    public boolean deleteTopTenant(SysTopTenantEditBo bo) {
+        if (CollectionUtils.isEmpty(bo.getTenantIds())){
+            throw new CustomException("参数错误");
+        }
+        for (Long tenantId : bo.getTenantIds()) {
+            int count = topOldOrderService.count(new LambdaQueryWrapper<TopOldOrder>().eq(TopOldOrder::getTenantId, tenantId));
+            int num = orderService.count(new LambdaQueryWrapper<Order>().eq(Order::getTenantId, tenantId));
+            if (count > 0 || num > 0){
+                throw new CustomException("机构已有订单信息,请勿删除!");
+            }
+        }
+        return update(new LambdaUpdateWrapper<SysTenant>()
+        .in(SysTenant::getTenantId,bo.getTenantIds())
+        .set(SysTenant::getStatus,-1));
+    }
+
     private void initRoles(Long newTenantId,Long tenantId) {
         List<String> roleKey = new ArrayList<>();
         roleKey.add("seller");

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/bo/SysTopTenantEditBo.java

@@ -21,6 +21,8 @@ public class SysTopTenantEditBo {
     @ApiModelProperty("机构ID")
     private Long tenantId;
 
+    private List<Long> tenantIds;
+
     /** 名称 */
     @ApiModelProperty("名称")
     @NotNull(message = "名称不能为空")

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/system/service/ISysTenantService.java

@@ -67,4 +67,7 @@ public interface ISysTenantService extends IService<SysTenant> {
 	boolean addTopTenant(SysTopTenantAddBo bo);
 
 	boolean editTopTenant(SysTopTenantEditBo bo);
+
+	boolean deleteTopTenant(SysTopTenantEditBo bo);
+
 }