xuekang
2024-05-13 15a0280ae9e7db96fdf0744c722d214d2cb5a0e5
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package com.nuvole.four.controller.pc;
 
 
import cn.hutool.core.util.StrUtil;
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.ActivityDistributeRecord;
import com.nuvole.four.domain.ActivityFee;
import com.nuvole.four.domain.SysOrg;
import com.nuvole.four.domain.dto.ActivityFeeDetailDto;
import com.nuvole.four.domain.query.ActivityFeeQuery;
import com.nuvole.four.service.ActivityFeeService;
import com.nuvole.four.service.impl.ActivityDistributeRecordServiceImpl;
import com.nuvole.four.service.impl.SysOrgServiceImpl;
import com.nuvole.four.util.SystemUtil;
import com.nuvole.util.CommonUtil;
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.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @Description 费率补贴活动管理
 * @Author dqh
 * @Date 2024-04-13 21:33:08
 */
@Api(value = "费率补贴活动管理接口", tags = "费率补贴活动管理接口")
@EnableTransactionManagement
@RestController
@RequestMapping("/v1/four/pc/acitivity/fee")
@RequiredArgsConstructor
public class ActivityFeeController extends BaseController {
 
    private final ActivityFeeService activityFeeService;
    private final SysOrgServiceImpl sysOrgService;
    private final ActivityDistributeRecordServiceImpl activityDistributeRecordService;
    private final ShopServiceClient shopServiceClient;
 
 
    /**
     * 方法描述:查询费率补贴活动列表
     *
     * @date  2024-04-13 21:46
     **/
    @ApiOperation(value = "查询列表", notes = "查询列表")
    @ApiImplicitParams({ @ApiImplicitParam(name = "AcitivityFeeQuery") })
    @GetMapping("/getList")
    public CommonResult<PageBean> getList(@ApiParam(name = "pageNumber", value = "分页页码", required = true) Integer pageNumber,
                                           @ApiParam(name = "pageSize", value = "每页展示数", required = true) Integer pageSize) {
        ActivityFeeQuery copy = CommonUtil.getObjFromReq(ActivityFeeQuery.class);
        ActivityFeeQuery query = new ActivityFeeQuery();
        BeanUtils.copyProperties(copy, query);
        PageHelper.startPage(pageNumber, pageSize);
 
        PageHelper.orderBy("create_time desc");
        List<ActivityFee> list = activityFeeService.getList(query);
        CommonResult result = new CommonResult<>(new PageBean(list));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述: 费率补贴活动添加
     *
     * @date  2024-04-13 21:46
     **/
    @ApiOperation(value = "添加", notes = "添加")
    @ApiImplicitParams({ @ApiImplicitParam(name = "AcitivityFee") })
    @PostMapping("/add")
    public CommonResult<Integer> add() {
        ActivityFee copy = CommonUtil.getObjFromReq(ActivityFee.class);
        ActivityFee activityFee = new ActivityFee();
        BeanUtils.copyProperties(copy, activityFee);
 
        CommonResult result = new CommonResult<>(activityFeeService.addSelective(activityFee));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述:根据id查询分配预算详情
     *
     * @date  2024-04-13 22:02
     **/
    @ApiOperation(value = "查询分配预算详情", notes = "根据id查询分配预算详情")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id") })
    @GetMapping("/get")
    public CommonResult<ActivityFee> get(Long id) {
        CommonResult result = new CommonResult();
        result = new CommonResult<>(activityFeeService.get(id));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述:查询分配额度信息
     *
     **/
    @ApiOperation(value = "查询分配额度信息", notes = "查询分配额度信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id") })
    @GetMapping("/getFeeMsg")
    public CommonResult getFeeMsg(Long id) {
        SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC);
        CommonResult result = new CommonResult();
        //super用户直接查询活动本身
        if(user.getLoginName().equalsIgnoreCase("super") && user.getOrgId() == null){
            return new CommonResult(activityFeeService.get(id));
        }
        if(user.getOrgId() != null){
            SysOrg sysOrg = sysOrgService.getById(user.getOrgId());
            //查询机构分配的预算额度
            ActivityDistributeRecord record = activityDistributeRecordService.getFeeByCondition(id, sysOrg.getId());
            result = new CommonResult<>(record);
            if(record == null){
                //查询活动本身的预算额度
                result = new CommonResult<>(activityDistributeRecordService.getActivityFeeByIdAndOrgId(id, sysOrg.getId()));
            }
        }
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述: 查询活动详情-活动数据
     *
     * @date  2024-04-15 13:17
     **/
    @ApiOperation(value = "查询活动详情-活动数据", notes = "查询活动详情-活动数据")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id") })
    @GetMapping("/getDetail")
    public CommonResult<ActivityFeeDetailDto> getActivityFeeDetail(Long id) {
        ActivityFeeDetailDto detailDto = activityFeeService.getActivityFeeDetail(id);
        return new CommonResult<>(detailDto);
    }
 
    /**
     * 方法描述: 查询活动详情-商户活动数据
     *
     * @date  2024-04-15 16:47
     **/
    @ApiOperation(value = "查询活动详情-商户活动数据", notes = "查询活动详情-商户活动数据")
    @GetMapping("/merchantActivityList")
    public CommonResult merchantActivityList(
            @ApiParam(name = "orgCode", value = "机构code") String orgCode,
            @ApiParam(name = "channelId", value = "通道id") Long channelId,
            @ApiParam(name = "activityId", value = "活动ID", required = true) Long activityId,
            @ApiParam(name = "startDate", value = "交易时间") Date startDate,
            @ApiParam(name = "endDate", value = "交易结束时间") Date endDate,
            @ApiParam(name = "pageNumber", value = "分页页码", required = true) Integer pageNumber,
            @ApiParam(name = "pageSize", value = "每页展示数", required = true) Integer pageSize) {
        if(activityId == null){
            throw new IllegalArgumentException("活动ID不能为空");
        }
        if(StrUtil.isBlank(orgCode)){
            SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC);
            orgCode = user.getOrgCode();
        }
        CommonResult<PageBean<Map>> mapResult = shopServiceClient.merchantActivityList(orgCode, channelId, activityId, startDate,endDate, pageNumber, pageSize);
        return mapResult;
    }
 
    /**
     * 方法描述: 查询活动详情-商户活动数据-数据汇总
     **/
    @ApiOperation(value = "查询活动详情-商户活动数据-数据汇总", notes = "查询活动详情-商户活动数据-数据汇总")
    @GetMapping("/merchantActivityCollect")
    public CommonResult merchantActivityCollect(
            @ApiParam(name = "orgCode", value = "机构code") String orgCode,
            @ApiParam(name = "channelId", value = "通道id") Long channelId,
            @ApiParam(name = "activityId", value = "活动ID", required = true) Long activityId,
            @ApiParam(name = "startDate", value = "交易开始时间") Date startDate,
            @ApiParam(name = "endDate", value = "交易结束时间") Date endDate) {
        if(activityId == null){
            throw new IllegalArgumentException("活动ID不能为空");
        }
        if(StrUtil.isBlank(orgCode)){
            SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC);
            orgCode = user.getOrgCode();
        }
        CommonResult<Map> mapResult = shopServiceClient.merchantActivityCollect(orgCode, channelId, activityId, startDate,endDate);
        return mapResult;
    }
 
    /**
     * 方法描述: 编辑费率补贴活动
     *
     * @date  2024-04-13 22:01
     **/
    @ApiOperation(value = "修改", notes = "修改")
    @ApiImplicitParams({ @ApiImplicitParam(name = "AcitivityFee") })
    @PostMapping("/upd")
    public CommonResult<Integer> upd() {
        ActivityFee copy = CommonUtil.getObjFromReq(ActivityFee.class);
        ActivityFee activityFee = new ActivityFee();
        BeanUtils.copyProperties(copy, activityFee);
 
        CommonResult result = new CommonResult<>(activityFeeService.editSelective(activityFee));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述: 删除费率补贴活动
     *
     * @date  2024-04-13 22:01
     **/
    @ApiOperation(value = "删除", notes = "删除")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id") })
    @PostMapping("/del")
    public CommonResult<Integer> del(Long id) {
        CommonResult result = new CommonResult<>(activityFeeService.del(id));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
    /**
     * 方法描述: 开始/停止
     * 同步停止活动表、商户活动表、机构预算分配表
     *
     * @date  2024-04-14 15:55
     **/
    @ApiOperation(value = "开始/停止", notes = "开始/停止")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键id"),
                        @ApiImplicitParam(name = "status", value = "状态;1=开始 2=停止(结束)")})
    @PostMapping("/startOrStop")
    public CommonResult<Integer> startOrStop(Long id,Integer status) {
        CommonResult result = new CommonResult<>(activityFeeService.startOrStop(id,status));
        CommonResult result1 = new CommonResult<>();
        BeanUtils.copyProperties(result, result1);
        result = result1;
        return result;
    }
 
}