package com.nuvole.four.controller.pc; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageHelper; import com.nuvole.base.domain.SysUser; import com.nuvole.common.domain.result.CommonResult; import com.nuvole.common.domain.result.PageBean; import com.nuvole.four.client.ShopServiceClient; import com.nuvole.four.contants.Contants; import com.nuvole.four.controller.BaseController; import com.nuvole.four.domain.ActivityShopRecord; import com.nuvole.four.domain.ChannelInfo; import com.nuvole.four.domain.dto.ActivityShopRecordDto; import com.nuvole.four.domain.params.ActivityShopRecordParam; import com.nuvole.four.domain.query.ActivityShopRecordQuery; import com.nuvole.four.service.ActivityShopRecordService; import com.nuvole.four.service.ChannelInfoService; import com.nuvole.four.util.SystemUtil; import com.nuvole.util.CommonUtil; import com.walker.infrastructure.utils.CollectionUtils; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.*; import java.util.stream.Collectors; /** * @Description 活动补贴—上报商户管理 * @Author dqh * @Date 2024-04-13 21:39:14 */ @Api(value = "活动补贴—上报商户管理接口", tags = "活动补贴—上报商户管理接口") @EnableTransactionManagement @RestController @RequestMapping("/v1/four/pc/activity/shop/record") @RequiredArgsConstructor public class ActivityShopRecordController extends BaseController { private final ActivityShopRecordService activityShopRecordService; private final ChannelInfoService channelInfoService; private final ShopServiceClient shopServiceClient; @ApiOperation(value = "查询列表", notes = "查询列表") @ApiImplicitParams({@ApiImplicitParam(name = "ActivityShopRecordQuery")}) @GetMapping("/getList") public CommonResult getList(@ApiParam(name = "pageNumber", value = "分页页码", required = true) Integer pageNumber, @ApiParam(name = "pageSize", value = "每页展示数", required = true) Integer pageSize) { ActivityShopRecordQuery copy = CommonUtil.getObjFromReq(ActivityShopRecordQuery.class); ActivityShopRecordQuery query = new ActivityShopRecordQuery(); BeanUtils.copyProperties(copy, query); PageHelper.startPage(pageNumber, pageSize); PageHelper.orderBy("create_time desc"); List list = activityShopRecordService.getList(query); CommonResult result = new CommonResult<>(new PageBean(list)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } /** * 方法描述:批量添加上报 * * @date 2024-04-15 9:41 **/ @ApiOperation(value = "添加上报", notes = "添加上报") @ApiImplicitParams({ @ApiImplicitParam(name = "recordArray") }) @PostMapping("/add") public CommonResult add(String recordArray) { List recordList = new ArrayList<>(); if (StrUtil.isNotBlank(recordArray)) { Object object = JSON.parse(recordArray); if (object instanceof JSONArray) { recordList = JSONArray.parseArray(recordArray, ActivityShopRecord.class); } } CommonResult result = new CommonResult<>(activityShopRecordService.batchInsert(recordList)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } @ApiOperation(value = "根据id查询", notes = "根据id查询") @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id")}) @GetMapping("/get") public CommonResult get(Long id) { CommonResult result = new CommonResult<>(activityShopRecordService.get(id)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } @ApiOperation(value = "删除", notes = "删除") @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id")}) @PostMapping("/del") public CommonResult del(Long id) { CommonResult result = new CommonResult<>(activityShopRecordService.del(id)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } @ApiOperation(value = "根据店铺id查询活动费率", notes = "根据店铺id查询活动费率") @ApiImplicitParams({@ApiImplicitParam(name = "店铺id", value = "店铺id")}) @GetMapping("/getActRateByShopIdAndChannelId") public CommonResult getActRateByShopIdAndChannelId(Long shopId, Long channelId) { ChannelInfo channelInfo = channelInfoService.getChannelInfo(channelId); HashMap channelRateMap = new HashMap<>(); if (channelInfo != null) { channelRateMap.put("onlineAgreeWxRate", channelInfo.getOnlineAgreeWxRate()); channelRateMap.put("onlineAgreeZfbRate", channelInfo.getOnlineAgreeZfbRate()); channelRateMap.put("onlineAgreeUnionpayRate", channelInfo.getOnlineAgreeUnionpayRate()); channelRateMap.put("offlineAgreeWxRate", channelInfo.getOfflineAgreeWxRate()); channelRateMap.put("offlineAgreeZfbRate", channelInfo.getOfflineAgreeZfbRate()); channelRateMap.put("offlineAgreeUnionpayRate", channelInfo.getOfflineAgreeUnionpayRate()); } Map actRateMap = activityShopRecordService.getActRateByShopIdAndChannelId(shopId, channelId); if (actRateMap != null) { channelRateMap.putAll(actRateMap); } CommonResult result = new CommonResult<>(channelRateMap); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } @ApiOperation(value = "更新店铺使用额度", notes = "根据店铺id查询活动费率") @ApiImplicitParams({@ApiImplicitParam(name = "店铺id", value = "店铺id")}) @PostMapping("/updShopSurplusFee") public CommonResult updShopSurplusFee(Long activityId, Long merchantShopId, Long channelId, Integer useFee) { CommonResult result = new CommonResult<>(activityShopRecordService.updShopSurplusFee(activityId, merchantShopId, channelId, useFee)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } /** * 方法描述:上报商户列表 * 调用service-shop * @date 2024-04-14 19:04 **/ @ApiOperation(value = "上报商户列表", notes = "上报商户列表") @GetMapping("/getToMerchantList") public CommonResult getToMerchantList( @ApiParam(name = "queryOrgCode", value = "机构code") String queryOrgCode, @ApiParam(name = "merchantId", value = "所属商户id") String merchantId, @ApiParam(name = "shopName", value = "店铺名称") String shopName, @ApiParam(name = "managerName", value = "客户经理名称") String managerName, @ApiParam(name = "channelId", value = "通道id") String channelId, @ApiParam(name = "activityId", value = "活动ID") Long activityId, @ApiParam(name = "pageNumber", value = "分页页码", required = true) Integer pageNumber, @ApiParam(name = "pageSize", value = "每页展示数", required = true) Integer pageSize) { SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC); if(StrUtil.isBlank(queryOrgCode)){ queryOrgCode = user.getOrgCode(); } CommonResult> mapResult = shopServiceClient.getMerchantShopExtendList(queryOrgCode,merchantId,shopName,managerName,channelId,"channelIdNotNull",pageNumber,pageSize); List mapList = mapResult.getData().getRows(); if(!CollectionUtils.isEmpty(mapList)){ String[] idsArr = mapList.stream() .map(map -> { Object idObject = map.get("id"); if (idObject != null) { return idObject.toString(); } else { // 如果 idObject 为 null,跳过该值;且在filter中过滤掉为null的值 return null; } }) .filter(Objects::nonNull).toArray(String[]::new); //匹配是否已上报,并添加返回标识字段 List recordList = activityShopRecordService.selectByCondition(idsArr,activityId); //existsShopIds = 已上报的shopIds List existsShopIds = recordList.stream() .map(ActivityShopRecord::getMerchantShopId) .collect(Collectors.toList()); mapList.forEach(map -> { Object idObject = map.get("id"); Long id = Long.parseLong(idObject.toString()); if(existsShopIds.contains(id)){ //已上报过的商户 map.put("existsOrNot",1); }else{ //未上报的商户 map.put("existsOrNot",0); } }); } PageBean pageBean = new PageBean(); pageBean.setPageNumber(pageNumber); pageBean.setPageSize(pageSize); pageBean.setRows(mapList); pageBean.setTotal(mapResult.getData().getTotal()); CommonResult result = new CommonResult<>(pageBean); return result; } /** * 方法描述:已上报商户列表 * * @date 2024-04-14 20:35 **/ @ApiOperation(value = "已上报商户列表", notes = "已上报商户列表") @ApiImplicitParams({ @ApiImplicitParam(name = "ActivityShopRecordParam") }) @GetMapping("/getAlreadyMerchantList") public CommonResult getAlreadyMerchantList( @ApiParam(name = "pageNumber", value = "分页页码", required = true) Integer pageNumber, @ApiParam(name = "pageSize", value = "每页展示数", required = true) Integer pageSize) { ActivityShopRecordParam copy = CommonUtil.getObjFromReq(ActivityShopRecordParam.class); ActivityShopRecordParam param = new ActivityShopRecordParam(); BeanUtils.copyProperties(copy, param); PageHelper.startPage(pageNumber, pageSize); PageHelper.orderBy("create_time desc"); List list = activityShopRecordService.getAlreadyMerchantList(param); CommonResult result = new CommonResult<>(new PageBean(list)); CommonResult result1 = new CommonResult<>(); BeanUtils.copyProperties(result, result1); result = result1; return result; } }