@ -5,6 +5,7 @@ import com.ruoyi.dhc.domain.DhcDataAuth;
@@ -5,6 +5,7 @@ import com.ruoyi.dhc.domain.DhcDataAuth;
import com.ruoyi.dhc.domain.DhcDataAuthDetail ;
import com.ruoyi.dhc.mapper.DhcDataAuthMapper ;
import com.ruoyi.dhc.service.IDhcDataAuthService ;
import org.apache.commons.collections4.CollectionUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -72,6 +73,7 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService
@@ -72,6 +73,7 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService
@Override
public int insertDhcDataAuth ( DhcDataAuth dhcDataAuth )
{
/ *
if ( dhcDataAuth . getDataAuthId ( ) ! = null ) {
dhcDataAuthMapper . deleteDhcDataAuthByDataAuthId ( dhcDataAuth . getDataAuthId ( ) ) ;
dhcDataAuthMapper . deleteDataAuthDetailByDataAuthIds ( dhcDataAuth ) ;
@ -81,6 +83,36 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService
@@ -81,6 +83,36 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService
item . setDataAuthId ( dhcDataAuth . getDataAuthId ( ) ) ;
} ) ;
dhcDataAuthMapper . batchAddDataAuthDetail ( dhcDataAuth . getDetailList ( ) ) ;
* /
Long dataAuthId ;
int count = 0 ;
// 首先按条件找现有已存在的头表,如果已经有了,就不用再建了。
List < DhcDataAuth > dhcDataAuthList = dhcDataAuthMapper . selectDhcDataAuthList ( dhcDataAuth ) ;
if ( CollectionUtils . isNotEmpty ( dhcDataAuthList ) ) {
DhcDataAuth first = dhcDataAuthList . get ( 0 ) ;
dataAuthId = first . getDataAuthId ( ) ;
} else {
dhcDataAuthMapper . insertDhcDataAuth ( dhcDataAuth ) ;
dataAuthId = dhcDataAuth . getDataAuthId ( ) ;
}
// 找到现有的所有明细
DhcDataAuth params = new DhcDataAuth ( ) ;
params . setDataAuthId ( dataAuthId ) ;
params . setDetailType ( "0" ) ;
List < DhcDataAuthDetail > detailList = dhcDataAuthMapper . selectDhcDataAuthDetailList ( params ) ;
// 遍历明细,检查是否存在,只对不存在的进行插入
List < DhcDataAuthDetail > newDetailList = dhcDataAuth . getDetailList ( ) . stream ( )
. filter ( itemToAdd - > detailList . stream ( ) . noneMatch ( item - > item . getDetailCode ( ) . equals ( itemToAdd . getDetailCode ( ) ) ) )
. peek ( item - > item . setDataAuthId ( dataAuthId ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollectionUtils . isNotEmpty ( newDetailList ) ) {
dhcDataAuthMapper . batchAddDataAuthDetail ( newDetailList ) ;
}
return count ;
}