ezhizao_zx 5 months ago
parent
commit
32cb2251f2

+ 21 - 1
src/main/java/cn/ezhizao/project/business/supplier/controller/BizSupplierController.java

@@ -11,6 +11,7 @@ import cn.ezhizao.project.business.outsourceBalanceAccount.service.IBizOutsource
 import cn.ezhizao.project.business.supplier.domain.*;
 import cn.ezhizao.project.business.supplier.service.*;
 import cn.ezhizao.project.system.domain.SysDept;
+import cn.ezhizao.project.system.service.ISysDeptService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import org.springframework.web.bind.annotation.*;
@@ -45,6 +46,8 @@ public class BizSupplierController extends BaseController {
     @Resource
     private IBizOutsourceBalanceAccountService iBizOutsourceBalanceAccountService;
     @Resource
+    private ISysDeptService sysDeptService;
+    @Resource
     private HttpServletRequest request;
 
     /**
@@ -75,7 +78,7 @@ public class BizSupplierController extends BaseController {
     @Log(title = "查询内部外协工段", businessType = BusinessType.SELECT)
     public AjaxResult getOutsourceDept(BizSupplier supplier) {
         return success(iBizSupplierService.getOutsourceDept(supplier));
-    }
+    }/////
 
     /**
      * 获取外协商详细信息
@@ -94,6 +97,7 @@ public class BizSupplierController extends BaseController {
     @Log(title = "外协商单位保存", businessType = BusinessType.INSERT)
     @PostMapping(value = "/save")
     public AjaxResult save(@RequestBody BizSupplier bizSupplier) throws NoSuchFieldException, IllegalAccessException, JsonProcessingException {
+
         final String tenantId = request.getHeader("tenantId");
         bizSupplier.setTenantId(Long.valueOf(tenantId));
 
@@ -109,6 +113,22 @@ public class BizSupplierController extends BaseController {
             if (!supplierList.isEmpty()) {
                 return AjaxResult.error("助记码不能重复");
             }
+        } else {
+            BizSupplier prev = iBizSupplierService.getById(bizSupplier.getId());
+            if (!prev.getIsInnerOutsource().equals(bizSupplier.getIsInnerOutsource()) && prev.getIsInnerOutsource().equals(1)) {
+                // 判断是否所有发出单都收回
+                if (!iBizSupplierService.checkAllReturn(bizSupplier)) {
+                    return AjaxResult.error("有发出单未收回,不能修改");
+                }
+                // 修改工段关联的外协
+                SysDept conditions = new SysDept();
+                conditions.setSupplierId(bizSupplier.getId());
+                List<SysDept> sysDepts = sysDeptService.selectDeptList(conditions);
+                sysDepts.forEach(l -> {
+                    l.setSupplierId(0L);
+                    sysDeptService.updateDept(l);
+                });
+            }
         }
         long currentSupplierId = 0L;
 

+ 2 - 0
src/main/java/cn/ezhizao/project/business/supplier/mapper/BizSupplierMapper.java

@@ -27,4 +27,6 @@ public interface BizSupplierMapper extends BaseMapper<BizSupplier> {
     public List<BizSupplier> getList(BizSupplier data);
     public List<BizSupplier> getListByDept(SysDept data);
     public List<BizSupplier> getOutsourceDept(BizSupplier data);
+
+    boolean checkAllReturn(BizSupplier bizSupplier);
 }

+ 2 - 0
src/main/java/cn/ezhizao/project/business/supplier/service/IBizSupplierService.java

@@ -27,4 +27,6 @@ public interface IBizSupplierService extends IService<BizSupplier> {
     List<BizSupplier> getList(BizSupplier data);
     List<BizSupplier> getListByDept(SysDept data);
     List<BizSupplier> getOutsourceDept(BizSupplier data);
+
+    boolean checkAllReturn(BizSupplier bizSupplier);
 }

+ 5 - 0
src/main/java/cn/ezhizao/project/business/supplier/service/impl/BizSupplierServiceImpl.java

@@ -50,4 +50,9 @@ public class BizSupplierServiceImpl extends ServiceImpl<BizSupplierMapper, BizSu
         return bizSupplierMapper.getOutsourceDept(data);
     }
 
+    @Override
+    public boolean checkAllReturn(BizSupplier bizSupplier) {
+        return bizSupplierMapper.checkAllReturn(bizSupplier);
+    }
+
 }

+ 4 - 0
src/main/resources/mybatis/business/supplier/BizSupplierMapper.xml

@@ -53,4 +53,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        <!-- 删除条件为其他外键可以在这里加 -->
         </trim>
     </delete>
+
+    <select id="checkAllReturn" resultType="java.lang.Boolean">
+        select  case when count(1) > 0 then false else true end from biz_outsourced_order_detail t left join biz_return_receipt_detail r on r.outsource_detail_id = t.id and r.deleted = 0 and r.is_audit = 1 where t.deleted = 0 and t.supplier_id = #{id} and r.id is null
+    </select>
 </mapper>

+ 3 - 0
src/main/resources/mybatis/system/SysDeptMapper.xml

@@ -70,6 +70,9 @@
 		<if test="workshopId != null  and workshopId != 0">
 			AND d.workshop_id = #{workshopId}
 		</if>
+		<if test="supplierId != null">
+			AND d.supplier_id = #{supplierId}
+		</if>
 		<if test="hasPackageLine != null and hasPackageLine == 1">
 			AND exists (select 1 from biz_package_resource_group prg where prg.deleted = 0 and prg.dept_id = d.dept_id)
 		</if>