@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
import com.bs.common.annotation.Anonymous ;
import com.bs.common.core.domain.entity.SysUser ;
import com.bs.common.utils.SecurityUtils ;
import com.bs.df.domain.* ;
import com.bs.df.service.* ;
import com.bs.df.utils.HtmlUtils ;
@ -69,7 +70,18 @@ public class DfProductInfoController extends BaseController {
LambdaQueryWrapper < DfProductInfo > queryWrapper = new LambdaQueryWrapper ( ) ;
String brokerIds = dfProductInfo . getBrokerIds ( ) ;
if ( "1" . equals ( dfProductInfo . getSelectByBroker ( ) ) ) {
queryWrapper . inSql ( DfProductInfo : : getId , "select product_id from df_broker_product where broker_id in (" + brokerIds + ") and del_flag = '0'" ) ;
queryWrapper . inSql ( DfProductInfo : : getId , "select product_id from df_broker_product where broker_id in (" + brokerIds + ") and del_flag = '0' and staus = '1'" ) ;
}
if ( ! SecurityUtils . isAdmin ( SecurityUtils . getUserId ( ) ) ) {
List < Long > productIdsByBrokerId = dfBrokerService . getProductIdsByBrokerId ( ) ;
if ( productIdsByBrokerId . size ( ) = = 0 ) {
productIdsByBrokerId . add ( 0 L ) ;
}
if ( ! "1" . equals ( dfProductInfo . getSelectByBroker ( ) ) ) {
queryWrapper . in ( DfProductInfo : : getId , productIdsByBrokerId )
. or ( )
. in ( DfProductInfo : : getCreateDept , SecurityUtils . getDeptId ( ) ) ;
}
}
condition ( queryWrapper , dfProductInfo ) ;
List < DfProductInfo > list = dfProductInfoService . list ( queryWrapper ) ;
@ -98,32 +110,19 @@ public class DfProductInfoController extends BaseController {
cityMap . put ( city . getAreaId ( ) , city . getName ( ) ) ;
}
Map < Long , String > brokerProductMap = new HashMap < > ( ) ;
DfBroker byId = null ;
if ( "1" . equals ( dfProductInfo . getSelectByBroker ( ) ) ) {
List < DfBroker > listBroker = dfBrokerService . list ( ) ;
Map < Long , String > brokerMap = new HashMap < > ( ) ;
for ( DfBroker broker : listBroker ) {
brokerMap . put ( broker . getId ( ) , broker . getBrokerName ( ) ) ;
}
List < DfBrokerProduct > listBrokerProduct = dfBrokerProductService . list ( ) ;
for ( DfBrokerProduct brokerProduct : listBrokerProduct ) {
String brokerName = brokerMap . get ( brokerProduct . getBrokerId ( ) ) ;
brokerProduct . setBrokerName ( brokerName ) ;
}
for ( DfBrokerProduct brokerProduct : listBrokerProduct ) {
brokerProductMap . put ( brokerProduct . getProductId ( ) , brokerProduct . getBrokerName ( ) ) ;
}
byId = dfBrokerService . getById ( brokerIds ) ;
}
for ( DfProductInfo productInfo : list ) {
productInfo . setInterestRate ( productInfo . getInterestRateBegin ( ) + "%-" + productInfo . getInterestRateEnd ( ) + "%" ) ;
productInfo . setProductIntro ( HtmlUtils . stripHtmlTags ( productInfo . getProductIntro ( ) ) ) ;
productInfo . setProductDetail ( HtmlUtils . stripHtmlTags ( productInfo . getProductDetail ( ) ) ) ;
// 获取原始的城市ID字符串
String businessCity = productInfo . getBusinessCity ( ) ;
if ( Validator . isNotEmpty ( businessCity ) ) {
String [ ] cityIds = businessCity . split ( "," ) ;
StringBuilder translatedCities = new StringBuilder ( ) ;
for ( String cityId : cityIds ) {
// 从 Map 中获取城市名称
String cityName = cityMap . get ( cityId ) ;
if ( cityName ! = null ) {
translatedCities . append ( cityName ) . append ( "," ) ;
@ -135,7 +134,8 @@ public class DfProductInfoController extends BaseController {
productInfo . setBusinessCity ( translatedCities . toString ( ) ) ;
}
if ( "1" . equals ( dfProductInfo . getSelectByBroker ( ) ) ) {
productInfo . setBrokerName ( brokerProductMap . get ( productInfo . getId ( ) ) ) ;
productInfo . setBrokerName ( byId . getBrokerName ( ) ) ;
// productInfo.setBrokerName(brokerProductMap.get(productInfo.getId()));
}
}
return getDataTable ( list ) ;
@ -158,6 +158,57 @@ public class DfProductInfoController extends BaseController {
return success ( list ) ;
}
/ * *
* 根 据 代 理 商 经 纪 id 查 询 产 品 信 息 列 表
* /
@ApiOperation ( "根据代理商经纪id查询产品信息列表" )
@GetMapping ( "/listByBroker" )
public AjaxResult listByBroker ( DfProductInfo dfProductInfo ) {
// Long userId = SecurityUtils.getUserId();
LambdaQueryWrapper < DfProductInfo > queryWrapper = new LambdaQueryWrapper ( ) ;
DfBroker broker = dfBrokerService . getById ( dfProductInfo . getBrokerId ( ) ) ;
if ( Validator . isEmpty ( broker . getParentId ( ) ) ) {
List < DfBrokerProduct > listBrokerProduct = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( )
. eq ( DfBrokerProduct : : getBrokerId , broker . getId ( ) )
. eq ( DfBrokerProduct : : getStaus , "1" ) ) ;
List < Long > productIds = listBrokerProduct . stream ( )
. map ( DfBrokerProduct : : getProductId )
. collect ( Collectors . toList ( ) ) ;
productIds . removeIf ( id - > id . equals ( dfProductInfo . getId ( ) ) ) ;
if ( null ! = productIds & & productIds . size ( ) = = 0 ) {
productIds . add ( 0 L ) ;
}
queryWrapper . notIn ( DfProductInfo : : getId , productIds ) ;
} else {
List < DfBrokerProduct > listBrokerProduct = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( )
. eq ( DfBrokerProduct : : getBrokerId , broker . getParentId ( ) )
. eq ( DfBrokerProduct : : getStaus , "1" ) ) ;
List < Long > productIds = listBrokerProduct . stream ( )
. map ( DfBrokerProduct : : getProductId )
. collect ( Collectors . toList ( ) ) ;
if ( null ! = productIds & & productIds . size ( ) = = 0 ) {
productIds . add ( 0 L ) ;
}
queryWrapper . in ( DfProductInfo : : getId , productIds ) ;
List < DfBrokerProduct > listProduct = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( )
. eq ( DfBrokerProduct : : getBrokerId , broker . getId ( ) )
. eq ( DfBrokerProduct : : getStaus , "1" ) ) ;
List < Long > productIdsNew = listProduct . stream ( )
. map ( DfBrokerProduct : : getProductId )
. collect ( Collectors . toList ( ) ) ;
productIdsNew . removeIf ( id - > id . equals ( dfProductInfo . getId ( ) ) ) ;
if ( null ! = productIdsNew & & productIdsNew . size ( ) = = 0 ) {
productIdsNew . add ( 0 L ) ;
}
queryWrapper . notIn ( DfProductInfo : : getId , productIdsNew ) ;
}
queryWrapper . eq ( DfProductInfo : : getStatus , "1" ) ;
condition ( queryWrapper , dfProductInfo ) ;
List < DfProductInfo > list = dfProductInfoService . list ( queryWrapper ) ;
return success ( list ) ;
}
/ * *
* 导 出 产 品 信 息 列 表
* /
@ -237,6 +288,33 @@ public class DfProductInfoController extends BaseController {
return success ( byId ) ;
}
/ * *
* 根 据 代 理 商 获 取 产 品 信 息 详 细 信 息
* /
@ApiOperation ( "根据代理商获取产品信息详细信息" )
@PutMapping ( value = "/getInfoByBroker" )
@Anonymous
public AjaxResult getInfoByBroker ( @RequestBody DfProductInfo dfProductInfo ) {
DfProductInfo byId = dfProductInfoService . getById ( dfProductInfo . getId ( ) ) ;
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( )
. eq ( DfBrokerProduct : : getBrokerId , dfProductInfo . getBrokerId ( ) )
. eq ( DfBrokerProduct : : getProductId , dfProductInfo . getId ( ) ) ) ;
if ( list . size ( ) > 0 & & list ! = null ) {
byId . setBrokerId ( list . get ( 0 ) . getBrokerId ( ) ) ;
}
String businessCity = byId . getBusinessCity ( ) ;
if ( Validator . isEmpty ( businessCity ) ) {
return success ( byId ) ;
}
List < String > businessCityList = Arrays . asList ( businessCity . split ( "," ) ) ;
List < DfArea > douAreas = dfAreaService . listByIds ( businessCityList ) ;
String concatenatedNames = douAreas . stream ( )
. map ( DfArea : : getName )
. collect ( Collectors . joining ( "," ) ) ;
byId . setBusinessCityByName ( concatenatedNames ) ;
return success ( byId ) ;
}
/ * *
* 新 增 产 品 信 息
* /
@ -268,9 +346,16 @@ public class DfProductInfoController extends BaseController {
@DeleteMapping ( "/{ids}" )
public AjaxResult remove ( @PathVariable List < Long > ids ) {
List < DfProductPoster > list = dfProductPosterService . list ( new LambdaQueryWrapper < DfProductPoster > ( ) . in ( DfProductPoster : : getProductId , ids ) ) ;
List < DfProductInfo > infos = dfProductInfoService . list ( new LambdaQueryWrapper < DfProductInfo > ( ) . in ( DfProductInfo : : getId , ids ) ) ;
for ( DfProductInfo dfProductInfo : infos ) {
if ( "1" . equals ( dfProductInfo . getStatus ( ) ) ) {
return AjaxResult . warn ( "该产品已经上架,请先下架再删除" ) ;
}
}
if ( list . size ( ) > 0 ) {
return AjaxResult . warn ( "该产品下有海报,请先删除海报" ) ;
}
return toAjax ( dfProductInfoService . removeBatchByIds ( ids ) ) ;
}
@ -290,10 +375,35 @@ public class DfProductInfoController extends BaseController {
dfProductInfoNew . setStatus ( status ) ;
dfProductInfos . add ( dfProductInfoNew ) ;
}
if ( "0" . equals ( status ) ) {
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . in ( DfBrokerProduct : : getProductId , ids ) ) ;
for ( DfBrokerProduct dfBrokerProduct : list ) {
dfBrokerProduct . setStaus ( "0" ) ;
}
dfBrokerProductService . updateBatchById ( list ) ;
}
if ( "1" . equals ( dfProductInfo . getIsBroker ( ) ) ) {
if ( "1" . equals ( status ) ) {
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . in ( DfBrokerProduct : : getProductId , ids ) ) ;
for ( DfBrokerProduct dfBrokerProduct : list ) {
dfBrokerProduct . setStaus ( "1" ) ;
}
dfBrokerProductService . updateBatchById ( list ) ;
}
}
return toAjax ( dfProductInfoService . updateBatchById ( dfProductInfos ) ) ;
}
/ * *
* 获 取 产 品 相 关 代 理 商 数 量
* /
@ApiOperation ( "获取产品相关代理商数量" )
@GetMapping ( value = "/getBrokerNum/{ids}" )
public AjaxResult getBrokerNum ( @PathVariable ( "ids" ) List < Long > ids ) {
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . in ( DfBrokerProduct : : getProductId , ids ) ) ;
list . size ( ) ;
return success ( list . size ( ) ) ;
}
/ * *
@ -305,12 +415,15 @@ public class DfProductInfoController extends BaseController {
public AjaxResult editByBroker ( @RequestBody DfProductInfo dfProductInfo ) {
Long productInfoId = dfProductInfo . getId ( ) ;
Long brokerId = dfProductInfo . getBrokerId ( ) ;
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . eq ( DfBrokerProduct : : getProductId , productInfoId ) ) ;
List < DfBrokerProduct > list = dfBrokerProductService . list ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . eq ( DfBrokerProduct : : getProductId , productInfoId )
. eq ( DfBrokerProduct : : getBrokerId , brokerId ) ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
DfBrokerProduct dfBrokerProduct = new DfBrokerProduct ( ) . setBrokerId ( brokerId ) . setProductId ( productInfoId ) . setId ( list . get ( 0 ) . getId ( ) ) ;
dfBrokerProduct . setStaus ( "1" ) ;
return toAjax ( dfBrokerProductService . updateById ( dfBrokerProduct ) ) ;
} else {
DfBrokerProduct dfBrokerProduct = new DfBrokerProduct ( ) . setBrokerId ( brokerId ) . setProductId ( productInfoId ) ;
dfBrokerProduct . setStaus ( "1" ) ;
return toAjax ( dfBrokerProductService . save ( dfBrokerProduct ) ) ;
}
}
@ -320,11 +433,24 @@ public class DfProductInfoController extends BaseController {
* /
@ApiOperation ( "移除代理产品权限" )
@Log ( title = "代理产品权限移除" , businessType = BusinessType . DELETE )
@DeleteMapping ( "/removeByBroker/{ids}" )
public AjaxResult removeByBroker ( @PathVariable List < Long > ids ) {
return toAjax ( dfBrokerProductService . remove ( new LambdaQueryWrapper < DfBrokerProduct > ( ) . in ( DfBrokerProduct : : getProductId , ids ) ) ) ;
@PutMapping ( "/removeByBroker" )
public AjaxResult removeByBroker ( @RequestBody DfProductInfo dfProductInfo ) {
Long [ ] ids = dfProductInfo . getIds ( ) ;
Long brokerId = dfProductInfo . getBrokerId ( ) ;
// List<DfBroker> list = dfBrokerService.list(new LambdaQueryWrapper<DfBroker>().eq(DfBroker::getParentId, brokerId));
List < DfBroker > allSubordinates = dfBrokerService . findAllSubordinates ( brokerId ) ;
// List<DfBroker> allSubordinates = findAllSubordinates(brokerId);
List < Long > brokerIds = allSubordinates . stream ( )
. map ( DfBroker : : getId )
. collect ( Collectors . toList ( ) ) ;
brokerIds . add ( brokerId ) ;
boolean remove = dfBrokerProductService . remove ( new LambdaQueryWrapper < DfBrokerProduct > ( )
. in ( DfBrokerProduct : : getProductId , ids )
. in ( DfBrokerProduct : : getBrokerId , brokerIds ) ) ;
return toAjax ( remove ) ;
}
/ * *
* 条 件 设 置
* /