@ -21,13 +21,15 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
import java.text.SimpleDateFormat ;
import java.text.SimpleDateFormat ;
import java.time.Instant ;
import java.time.LocalDateTime ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.time.ZoneId ;
import java.time.ZonedDateTime ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.* ;
import java.util.regex.Matcher ;
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
import java.util.regex.Pattern ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
@Slf4j
@Slf4j
@RequiredArgsConstructor
@RequiredArgsConstructor
@ -183,9 +185,14 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
}
}
public List < ModelClue > getModelClueBySql ( String sql , Integer modelId ) {
public List < ModelClue > getModelClueBySql ( String sql , Integer modelId ) {
List < String > oldUniqueKeys = this . listObjs ( new LambdaQueryWrapper < ModelClue > ( ) . select ( ModelClue : : getUniqueKey ) . eq ( ModelClue : : getStatus , 0 ) , String : : valueOf ) ;
List < ModelClue > modelClues = new ArrayList < > ( ) ;
List < ModelClue > modelClues = modelClueDataMapper . selectDataByDynamicSql ( sql ) ;
if ( modelId = = 2 ) { // 2号模型:行政、刑事案件受立案不及时问题监督模型
return getModelCluesForModel2 ( modelClues ) ;
} else {
modelClues = modelClueDataMapper . selectDataByDynamicSql ( sql ) ;
}
List < String > uniqueKeys = modelClues . stream ( ) . map ( ModelClue : : getUniqueKey ) . filter ( k - > k ! = null & & ! k . isEmpty ( ) ) . toList ( ) ;
List < String > uniqueKeys = modelClues . stream ( ) . map ( ModelClue : : getUniqueKey ) . filter ( k - > k ! = null & & ! k . isEmpty ( ) ) . toList ( ) ;
List < String > oldUniqueKeys = this . listObjs ( new LambdaQueryWrapper < ModelClue > ( ) . select ( ModelClue : : getUniqueKey ) . eq ( ModelClue : : getStatus , 0 ) , String : : valueOf ) ;
List < String > changeStatusIds = oldUniqueKeys . stream ( ) . filter ( item - > ! uniqueKeys . contains ( item ) ) . toList ( ) ;
List < String > changeStatusIds = oldUniqueKeys . stream ( ) . filter ( item - > ! uniqueKeys . contains ( item ) ) . toList ( ) ;
if ( ! changeStatusIds . isEmpty ( ) ) {
if ( ! changeStatusIds . isEmpty ( ) ) {
modelClueMapper . update ( null , new LambdaUpdateWrapper < ModelClue > ( ) . in ( ModelClue : : getUniqueKey , changeStatusIds ) . set ( ModelClue : : getStatus , 1 ) ) ;
modelClueMapper . update ( null , new LambdaUpdateWrapper < ModelClue > ( ) . in ( ModelClue : : getUniqueKey , changeStatusIds ) . set ( ModelClue : : getStatus , 1 ) ) ;
@ -204,11 +211,11 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
if ( Objects . equals ( keyColumn , modelClue . getUniqueKey ( ) ) ) {
if ( Objects . equals ( keyColumn , modelClue . getUniqueKey ( ) ) ) {
modelClue . setData ( JSONObject . toJSONString ( data ) ) ;
modelClue . setData ( JSONObject . toJSONString ( data ) ) ;
modelClue . setStatus ( 0 ) ;
modelClue . setStatus ( 0 ) ;
List < Integer > modelNos = new ArrayList < > ( List . of ( 1 ) ) ;
List < Integer > modelNos = new ArrayList < > ( List . of ( 1 ) ) ; // 1号模型:行政、刑事案件受理30天仍未立案问题监督模型
if ( modelNos . contains ( modelId ) ) {
if ( modelNos . contains ( modelId ) ) {
String thingDesc = modelClue . getThingDesc ( ) ;
String thingDesc = modelClue . getThingDesc ( ) ;
modelClue . setThingDesc ( "该" + data . get ( "AJBZmc" )
modelClue . setThingDesc ( "该" + data . get ( "AJBZmc" )
+ "案件 编号为" + data . get ( "AJBH" )
+ "案件编号为" + data . get ( "AJBH" )
+ ",报案日期为" + getDateString ( data . get ( "BARQ" ) )
+ ",报案日期为" + getDateString ( data . get ( "BARQ" ) )
+ ",受理日期为" + getDateString ( data . get ( "SLRQ" ) )
+ ",受理日期为" + getDateString ( data . get ( "SLRQ" ) )
+ ",当前案件状态为“" + data . get ( "AJZTmc" )
+ ",当前案件状态为“" + data . get ( "AJZTmc" )
@ -222,21 +229,92 @@ public class ModelClueService extends ServiceImpl<ModelClueMapper, ModelClue> {
return needsInsertModelClues ;
return needsInsertModelClues ;
}
}
private List < ModelClue > getModelCluesForModel2 ( List < ModelClue > modelClues ) {
List < ModelClue > modelClues1 = new ArrayList < > ( ) ;
String preSql = "SELECT a.jjdbh AS uniqueKey, a.jjdbh AS negative_id, a.gxdwmc AS involve_depart_name, a.gxdwdm AS involve_depart_id FROM dwd_asj_zhtx_jjd a WHERE a.jqxzdm NOT LIKE '11%' AND a.jqxzdm NOT LIKE '99%' AND a.bjnr LIKE '%" ;
String postSql = "%' AND NOT EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.BARLXDH = a.bjdh) AND a.cjsj BETWEEN '2024-01-01 00:00:00' AND '2024-10-23 00:00:00';" ;
genarateModelCluesForModel2 ( preSql , postSql , modelClues1 ) ;
List < String > uniqueKeys = modelClues1 . stream ( ) . map ( ModelClue : : getUniqueKey ) . filter ( k - > k ! = null & & ! k . isEmpty ( ) ) . toList ( ) ;
if ( ! uniqueKeys . isEmpty ( ) ) {
String newSql = "SELECT a.* FROM dwd_asj_zhtx_jjd a LEFT JOIN dwd_asj_sjjhygx_jjcjxxb b ON b.BARLXDH = a.bjdh WHERE a.jjdbh IN " + "(" + uniqueKeys . stream ( ) . map ( k - > "'" + k + "'" ) . collect ( Collectors . joining ( "," ) ) + ");" ;
List < Map < String , Object > > allData = modelClueDataMapper . selectByUniqueKeys ( newSql ) ;
for ( ModelClue modelClue : modelClues1 ) {
for ( Map < String , Object > data : allData ) {
String keyColumn = ( String ) data . get ( "jjdbh" ) ;
if ( Objects . equals ( keyColumn , modelClue . getUniqueKey ( ) ) ) {
modelClue . setData ( JSONObject . toJSONString ( data ) ) ;
modelClue . setStatus ( 0 ) ;
modelClue . setThingDesc ( "该" + data . get ( "jqxzmc" )
+ "案件 接警单编号为" + data . get ( "jjdbh" )
+ ",报案时间为" + getDateString ( data . get ( "bjsj" ) )
+ ",没有匹配到立案时间,受立案不及时。" ) ;
break ;
}
}
}
modelClues . addAll ( modelClues1 ) ;
}
List < ModelClue > modelClues2 = new ArrayList < > ( ) ;
String preSql2 = "SELECT a.jjdbh AS uniqueKey, a.jjdbh AS negative_id, a.gxdwmc AS involve_depart_name, a.gxdwdm AS involve_depart_id FROM dwd_asj_zhtx_jjd a WHERE a.jqxzdm NOT LIKE '11%' AND a.jqxzdm NOT LIKE '99%' AND a.bjnr LIKE '%" ;
String postSql2 = "%' AND EXISTS (SELECT 1 FROM dwd_asj_sjjhygx_jjcjxxb b WHERE b.lasj IS NOT NULL AND b.basj < DATE_SUB(STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') , INTERVAL 7 DAY) AND b.BARLXDH = a.bjdh AND STR_TO_DATE(b.lasj, '%Y%m%d%H%i%s') > a.cjsj) ORDER BY a.cjsj desc LIMIT 1;" ;
genarateModelCluesForModel2 ( preSql2 , postSql2 , modelClues2 ) ;
List < String > uniqueKeys2 = modelClues2 . stream ( ) . map ( ModelClue : : getUniqueKey ) . filter ( k - > k ! = null & & ! k . isEmpty ( ) ) . toList ( ) ;
if ( ! uniqueKeys2 . isEmpty ( ) ) {
String newSql2 = "SELECT a.*, b.ajbh, b.lasj FROM dwd_asj_zhtx_jjd a LEFT JOIN dwd_asj_sjjhygx_jjcjxxb b ON b.BARLXDH = a.bjdh WHERE a.jjdbh IN " + "(" + uniqueKeys2 . stream ( ) . map ( k - > "'" + k + "'" ) . collect ( Collectors . joining ( "," ) ) + ");" ;
List < Map < String , Object > > allData2 = modelClueDataMapper . selectByUniqueKeys ( newSql2 ) ;
for ( ModelClue modelClue : modelClues2 ) {
for ( Map < String , Object > data : allData2 ) {
String keyColumn = ( String ) data . get ( "jjdbh" ) ;
if ( Objects . equals ( keyColumn , modelClue . getUniqueKey ( ) ) ) {
modelClue . setData ( JSONObject . toJSONString ( data ) ) ;
modelClue . setStatus ( 0 ) ;
modelClue . setThingDesc ( "该" + data . get ( "jqxzmc" )
+ "案件 编号为" + data . get ( "ajbh" )
+ ",接警单编号为" + data . get ( "jjdbh" )
+ ",报案时间为" + getDateString ( data . get ( "bjsj" ) )
+ ",立案时间为" + data . get ( "lasj" )
+ ",立案时间与报案时间超过7天,受立案不及时。" ) ;
break ;
}
}
}
modelClues . addAll ( modelClues2 ) ;
}
return modelClues ;
}
private void genarateModelCluesForModel2 ( String preSql , String postSql , List < ModelClue > modelClues ) {
List < ModelClue > modelClues1 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "盗" + postSql ) ;
List < ModelClue > modelClues2 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "骗" + postSql ) ;
List < ModelClue > modelClues3 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "强奸" + postSql ) ;
List < ModelClue > modelClues4 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "抢" + postSql ) ;
List < ModelClue > modelClues5 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "10岁" + postSql ) ;
List < ModelClue > modelClues6 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "11岁" + postSql ) ;
List < ModelClue > modelClues7 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "12岁" + postSql ) ;
List < ModelClue > modelClues8 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "13岁" + postSql ) ;
List < ModelClue > modelClues9 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "14岁" + postSql ) ;
List < ModelClue > modelClues10 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "15岁" + postSql ) ;
List < ModelClue > modelClues11 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "16岁" + postSql ) ;
List < ModelClue > modelClues12 = modelClueDataMapper . selectDataByDynamicSql ( preSql + "未成年" + postSql ) ;
modelClues . addAll ( Stream . of ( modelClues1 , modelClues2 , modelClues3 , modelClues4 , modelClues5 , modelClues6 , modelClues7 , modelClues8 , modelClues9 , modelClues10 , modelClues11 , modelClues12 )
. flatMap ( List : : stream )
. collect ( Collectors . toMap ( ModelClue : : getUniqueKey , data - > data , ( existing , replacement ) - > existing ) )
. values ( ) ) ;
}
private static String getDateString ( Object param ) {
private static String getDateString ( Object param ) {
if ( param ! = null ) {
if ( param ! = null ) {
// try {
String time = null ;
// Date date = (Date) param;
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// return formatter.format(date);
// } catch (Exception ignored) {}
try {
try {
LocalDateTime localDateTime = ( LocalDateTime ) param ;
time = String . valueOf ( param ) ;
ZonedDateTime zonedDateTime = localDateTime . atZone ( ZoneId . systemDefault ( ) ) ;
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ss" ) ;
Date date = Date . from ( zonedDateTime . toInstant ( ) ) ;
Date parse = sdf . parse ( time ) ;
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
Instant instant = parse . toInstant ( ) ;
return formatter . format ( date ) ;
ZoneId zoneId = ZoneId . systemDefault ( ) ;
LocalDateTime localDateTime = instant . atZone ( zoneId ) . toLocalDateTime ( ) ;
DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( "yyyy-MM-dd HH:mm:ss" ) ; return formatter . format ( localDateTime ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
log . info ( "日期转换异常" , e ) ;
log . info ( "日期转换异常{} " , time , e ) ;
}
}
}
}
return " " ;
return " " ;