duhuizhe
2024-05-15 aa2c3d4deba76ade0958ff3ced88396e226a4964
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
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<PageBean> 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<ActivityShopRecord> 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<Integer> add(String recordArray) {
        List<ActivityShopRecord> 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<ActivityShopRecord> 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<Integer> 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<Map> getActRateByShopIdAndChannelId(Long shopId, Long channelId) {
        ChannelInfo channelInfo = channelInfoService.getChannelInfo(channelId);
        HashMap<Object, Object> 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<Map> 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<PageBean<Map>> mapResult = shopServiceClient.getMerchantShopExtendList(queryOrgCode,merchantId,shopName,managerName,channelId,"channelIdNotNull",pageNumber,pageSize);
        CommonResult<PageBean<Map>> mapResult = new CommonResult<>();
        List<Map> 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<ActivityShopRecord> recordList = activityShopRecordService.selectByCondition(idsArr,activityId);
            //existsShopIds = 已上报的shopIds
            List<Long> 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<PageBean> 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<ActivityShopRecordDto> list = activityShopRecordService.getAlreadyMerchantList(param);
        CommonResult result = new CommonResult<>(new PageBean(list));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
 
}