Mapper层: int delZfbInfo ( @Param ( "ids" ) List< String> zfbInfos) ;
Service层: int delZfbInfo ( String[ ] infoId) ;
@Override
public int delZfbInfo ( String[ ] infoId) {
int count = zfbInfoMapper. delZfbInfo ( Arrays. asList ( infoId) ) ;
if ( count == 0 ) {
return 0 ;
}
return 1 ;
}
@PostMapping ( "/delZfbInfo" )
@ApiOperation ( value = "批量删除账户" , produces = "application/json" )
public Message< Users> delZfbInfo ( String[ ] infoId, HttpServletRequest request) {
Users user = this . getUserByToken ( request) ;
Users users = usersMapper. selectByUserId ( user. getUserId ( ) ) ;
for ( int i = 0 ; i < infoId. length; i++ ) {
if ( infoId[ i] . equals ( users. getInfoId ( ) ) ) {
return MessageUtils. getFail ( "删除失败,需留有收款账户" ) ;
}
}
int i = zfbGatheringService. delZfbInfo ( infoId) ;
if ( i == 1 ) {
return MessageUtils. getSuccess ( "success" ) ;
}
return MessageUtils. getSuccess ( "删除失败" ) ;
}
< update id= "delZfbInfo" parameterType= "java.util.List" >
< foreach collection= "ids" index= "index" item= "item" open= "" close= "" separator= ";" >
update zfb_info
< set>
is_delete= 2 ,
delete_time= unix_timestamp ( now ( ) )
< / set>
< where>
info_id = #{ item}
< / where>
< / foreach>
< / update>
批量增加
mapper: int add ( List< 实体类中间表> maintainerAndPowerrooms) ;
< insert id= "add" >
insert into maintainer_and_powerroom ( maintainer_id, powerroom_id, create_time) values
< foreach item= "item" index= "index" collection= "list" separator= "," >
( #{ item. maintainerId} , #{ item. powerroomId} , #{ item. createTime, jdbcType= BIGINT} )
< / foreach>
< / insert>
service: int add ( String maintainerId, String powerroomIds) ;
@Override
public int add ( String maintainerId, String powerroomIds) {
String[ ] pIds = Convert. toStrArray ( powerroomIds) ;
List< MaintainerAndPowerroom> list = new ArrayList < > ( ) ;
for ( String powerroomId : pIds) {
MaintainerAndPowerroom maintainerAndPowerroom = new MaintainerAndPowerroom ( ) ;
maintainerAndPowerroom. setMaintainerId ( maintainerId) ;
maintainerAndPowerroom. setPowerroomId ( powerroomId) ;
maintainerAndPowerroom. setCreateTime ( System. currentTimeMillis ( ) ) ;
list. add ( maintainerAndPowerroom) ;
}
return maintainerAndPowerroomMapper. add ( list) ;
}
@PostMapping ( "/add" )
public Resp add ( String maintainerId, String powerroomIds) {
int i = maintainerService. add ( maintainerId, powerroomIds) ;
if ( i != 0 ) {
return Resp. success ( "添加成功" ) ;
}
return Resp. fail ( "添加失败" ) ;
}
< delete id= "deleteMaintainerAndPowerroom" >
delete from maintainer_and_powerroom where maintainer_id= #{ maintainerId} and powerroom_id in
< foreach collection= "powerroomIds" item= "powerroomId" open= "(" separator= "," close= ")" >
#{ powerroomId}
< / foreach>
< / delete>
< insert id= "batchMaintainerAndPowerroom" >
insert into maintainer_and_powerroom ( maintainer_id, powerroom_id, create_time) values
< foreach item= "item" index= "index" collection= "list" separator= "," >
( #{ item. maintainerId} , #{ item. powerroomId} , #{ item. createTime, jdbcType= BIGINT} )
< / foreach>
< / insert>
< delete id= "deleteMaintainerAndPowerroom" >
delete from maintainer_and_powerroom where maintainer_id= #{ maintainerId} and powerroom_id in
< foreach collection= "powerroomIds" item= "powerroomId" open= "(" separator= "," close= ")" >
#{ powerroomId}
< / foreach>
< / delete>
mapper
int batchMaintainerAndPowerroom ( List< MaintainerAndPowerroom> maintainerAndPowerrooms) ;
int deleteMaintainerAndPowerroom ( @Param ( "maintainerId" ) String maintainerId, @Param ( "powerroomIds" ) String[ ] powerroomIds) ;
service: int addMaintainerAndPowerroom ( String maintainerId, String powerroomIds) ;
public int addMaintainerAndPowerroom ( String maintainerId, String powerroomIds) {
List< MaintainerAndPowerroom> maintainerAndPowerrooms = maintainerAndPowerroomMapper. getList ( maintainerId) ;
if ( maintainerAndPowerrooms. size ( ) == 0 ) {
String[ ] pIds = Convert. toStrArray ( powerroomIds) ;
List< MaintainerAndPowerroom> list = new ArrayList < > ( ) ;
for ( String powerroomId : pIds) {
MaintainerAndPowerroom maintainerAndPowerroom = new MaintainerAndPowerroom ( ) ;
maintainerAndPowerroom. setMaintainerId ( maintainerId) ;
maintainerAndPowerroom. setPowerroomId ( powerroomId) ;
maintainerAndPowerroom. setCreateTime ( System. currentTimeMillis ( ) ) ;
list. add ( maintainerAndPowerroom) ;
}
return maintainerAndPowerroomMapper. batchMaintainerAndPowerroom ( list) ;
} else {
List< String> roomId = maintainerAndPowerrooms. stream ( ) . map ( p - > p. getPowerroomId ( ) ) . collect ( Collectors. toList ( ) ) ;
maintainerAndPowerroomMapper. deleteMaintainerAndPowerroom ( maintainerId, Convert. toStrArray ( roomId) ) ;
String[ ] pIds = Convert. toStrArray ( powerroomIds) ;
List< MaintainerAndPowerroom> list = new ArrayList < > ( ) ;
for ( String powerroomId : pIds) {
MaintainerAndPowerroom maintainerAndPowerroom = new MaintainerAndPowerroom ( ) ;
maintainerAndPowerroom. setMaintainerId ( maintainerId) ;
maintainerAndPowerroom. setPowerroomId ( powerroomId) ;
maintainerAndPowerroom. setCreateTime ( System. currentTimeMillis ( ) ) ;
list. add ( maintainerAndPowerroom) ;
}
return maintainerAndPowerroomMapper. batchMaintainerAndPowerroom ( list) ;
}
}
controller
public Resp addMaintainerAndPowerroom ( String maintainerId, String powerroomIds) {
int i = maintainerService. addMaintainerAndPowerroom ( maintainerId, powerroomIds) ;
if ( i != 0 ) {
return Resp. success ( "添加成功" ) ;
}
return Resp. fail ( "添加失败" ) ;
}