zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
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
package com.gear.admin.controller.swx;
 
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gear.admin.vo.swx.IdentificationVo;
import com.gear.admin.vo.swx.RechargeRecordVo;
import com.gear.common.builder.WhereBuilder;
import com.gear.common.constant.SwxConstons;
import com.gear.common.vo.Result;
import com.gear.swx.domain.*;
import com.gear.swx.service.*;
import io.jsonwebtoken.lang.Collections;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import com.gear.common.annotation.Log;
import com.gear.common.core.controller.BaseController;
import com.gear.common.enums.BusinessType;
import com.gear.common.utils.poi.ExcelUtil;
 
/**
 * 充值管理Controller
 * 
 * @author czx
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/swx/rechargeRecord")
public class SwxRechargeRecordController extends BaseController
{
    @Autowired
    private ISwxRechargeRecordService swxRechargeRecordService;
 
    @Autowired
    private ISwxUserService swxUserService;
 
    @Autowired
    private ISwxMoneyLogService swxMoneyLogService;
 
    @Autowired
    private ISwxUserLevelService swxUserLevelService;
    @Autowired
    private ISwxSettingsService swxSettingsService;
 
 
    @GetMapping("/getParamByKey/{key}")
    public Result<SwxSettings> getParamByKey(@PathVariable String key){
        return Result.ok(swxSettingsService.getOne(new QueryWrapper<SwxSettings>().lambda().eq(SwxSettings::getParamKey,key)));
    }
 
    /**
     * 查询充值管理列表
     */
    @PreAuthorize("@ss.hasPermi('swx:rechargeRecord:list')")
    @GetMapping("/list")
    public Result<IPage<RechargeRecordVo>> list(RechargeRecordVo swxRechargeRecord,
                                                @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
 
        QueryWrapper<SwxRechargeRecord> queryWrapper = new QueryWrapper<>();
        if(!Strings.isEmpty(swxRechargeRecord.getPhone()) || !Strings.isEmpty(swxRechargeRecord.getUserName()) || !Strings.isEmpty(swxRechargeRecord.getLevel())){
            QueryWrapper<SwxUser> userQueryWrapper = new QueryWrapper<>();
            if(!Strings.isEmpty(swxRechargeRecord.getUserName())){
                userQueryWrapper.lambda().like(SwxUser::getUserName,swxRechargeRecord.getUserName());
            }
            if(!Strings.isEmpty(swxRechargeRecord.getPhone())){
                userQueryWrapper.lambda().like(SwxUser::getPhone,swxRechargeRecord.getPhone());
            }
            if (!Strings.isEmpty(swxRechargeRecord.getLevel())){
                userQueryWrapper.lambda().eq(SwxUser::getLevel,swxRechargeRecord.getLevel());
            }
            List<SwxUser> list = swxUserService.list(userQueryWrapper);
            List<String> ids = new ArrayList<>();
            if(!Collections.isEmpty(list)){
                for (SwxUser item : list){
                    ids.add(item.getId());
                }
            }else{
                ids.add("");
            }
            queryWrapper.lambda().in(SwxRechargeRecord::getUserId,ids);
        }
 
        if(swxRechargeRecord.getStatus() != null){
            queryWrapper.lambda().eq(SwxRechargeRecord::getStatus,swxRechargeRecord.getStatus());
        }
        queryWrapper.lambda().orderByDesc(SwxRechargeRecord::getCreateTime);
        Page<SwxRechargeRecord> page = new Page<SwxRechargeRecord>(pageNo, pageSize);
        IPage<SwxRechargeRecord> pageList = swxRechargeRecordService.page(page, queryWrapper);
        IPage<RechargeRecordVo> result = new Page<>();
        List<RechargeRecordVo> records = new ArrayList<>();
        for(SwxRechargeRecord item : pageList.getRecords()){
            RechargeRecordVo vo = new RechargeRecordVo();
            BeanUtils.copyProperties(item,vo);
            SwxUser swxUser = swxUserService.getById(item.getUserId());
            if(swxUser != null){
                vo.setUserName(swxUser.getUserName());
                vo.setPhone(swxUser.getPhone());
            }
            records.add(vo);
        }
        result.setRecords(records);
        result.setCurrent(pageList.getCurrent());
        result.setPages(pageList.getPages());
        result.setSize(pageList.getSize());
        result.setTotal(pageList.getTotal());
        return Result.OK(result);
    }
 
    /**
     * 导出充值管理列表
     */
    @PreAuthorize("@ss.hasPermi('swx:rechargeRecord:export')")
    @Log(title = "充值管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwxRechargeRecord swxRechargeRecord){
        QueryWrapper<SwxRechargeRecord> queryWrapper = WhereBuilder.build(swxRechargeRecord);
        List<SwxRechargeRecord> list = swxRechargeRecordService.list(queryWrapper);
        ExcelUtil<SwxRechargeRecord> util = new ExcelUtil<SwxRechargeRecord>(SwxRechargeRecord.class);
        util.exportExcel(response, list, "充值管理数据");
    }
 
    /**
     * 获取充值管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('swx:rechargeRecord:query')")
    @GetMapping(value = "/{id}")
    public Result<SwxRechargeRecord>  getInfo(@PathVariable("id") String id){
        SwxRechargeRecord swxRechargeRecord = swxRechargeRecordService.getById(id);
        if(swxRechargeRecord==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(swxRechargeRecord);
    }
    /**
     * 修改充值管理
     */
    @PreAuthorize("@ss.hasPermi('swx:rechargeRecord:edit')")
    @Log(title = "充值管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @Transactional
    public  Result<String> edit(@RequestBody SwxRechargeRecord swxRechargeRecord){
        //判断修改状态
        if(swxRechargeRecord == null || swxRechargeRecord.getStatus() <= 0){
            return Result.error("编辑失败!");
        }
        //充值成功
        if (swxRechargeRecord.getStatus() == SwxConstons.NOMARL_STATUS_YES){
            SwxRechargeRecord old = swxRechargeRecordService.getById(swxRechargeRecord.getId());
            SwxUser swxUser = swxUserService.getById(old.getUserId());
            if(swxUser != null){
                SwxMoneyLog moneyLog = new SwxMoneyLog();
                moneyLog.setInfo("通过"+old.getType()+"充值");
                moneyLog.setStatus(SwxConstons.NOMARL_STATUS_YES);
                moneyLog.setType(SwxConstons.SWX_MONEY_LOG_TYPE_RECHARGE);
                moneyLog.setSymbol(SwxConstons.SWX_MONEY_TYPE_INCOME);
                moneyLog.setTitle("资金充值");
                moneyLog.setOldAmount(swxUser.getAmount());
                swxUser.setAmount(swxUser.getAmount().add(old.getAmount()));
                swxUser.setAllRecharge(swxUser.getAllRecharge().add(old.getAmount()));
                moneyLog.setNowAmount(swxUser.getAmount());
                moneyLog.setUserId(swxUser.getId());
                moneyLog.setBusiId(old.getId());
                moneyLog.setMoney(old.getAmount());
                swxMoneyLogService.save(moneyLog);
                //设置用户等级
                //查询用户等级
                QueryWrapper<SwxUserLevel> userLevelQueryWrapper = new QueryWrapper<>();
                userLevelQueryWrapper.lambda().le(SwxUserLevel::getConditions1,swxUser.getAllRecharge());
                userLevelQueryWrapper.lambda().orderByDesc(SwxUserLevel::getConditions1);
                List<SwxUserLevel> levels = swxUserLevelService.list(userLevelQueryWrapper);
                if (!CollectionUtils.isEmpty(levels)){
                    SwxUserLevel level = levels.get(0);
                    swxUser.setLevel(level.getId());
                }
                swxUserService.updateById(swxUser);
            }
 
        }
 
        swxRechargeRecordService.updateById(swxRechargeRecord);
        return Result.ok("编辑成功!");
    }
 
}