1
zj
2024-08-22 9f3859466f402f3e4145dbdd405a8da2da14015e
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
package com.nq.controller.admin;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.util.StringUtil;
import com.nq.common.ServerResponse;
import com.nq.dao.CurrencyBeanMapper;
import com.nq.pojo.CurrencyBean;
import com.nq.pojo.CurrencyBeanVo;
import com.nq.service.CurrencyBeanService;
import com.nq.utils.ConverterUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xmlunit.util.Convert;
 
import java.util.List;
 
/**
 * @program: dabaogp
 * @description:数字货币管理
 * @create: 2024-08-21 16:55
 **/
@Controller
@RequestMapping({"/admin/currency"})
public class AdminCurrencyController {
 
    @Autowired
    private CurrencyBeanService service;
 
    @Autowired
    private CurrencyBeanMapper mapper;
 
    /**
     * 新增币种
     */
    @RequestMapping({"add.do"})
    @ResponseBody
    public ServerResponse add(CurrencyBeanVo beanVo) {
        if(StringUtil.isEmpty(beanVo.getSc()) ||
                StringUtil.isEmpty(beanVo.getDn()) ||
                StringUtil.isEmpty(beanVo.getBcdn()) ||
                StringUtil.isEmpty(beanVo.getQcdn())){
            return ServerResponse.createByErrorMsg("字段不能为空");
        }
        Long scCount = getScCount(beanVo.getSc(),null);
        if(scCount > 0){
            return ServerResponse.createByErrorMsg("币种已存在");
        }
        CurrencyBean currencyBean = ConverterUtil.convert(beanVo, CurrencyBean.class);
        service.save(currencyBean);
        return ServerResponse.createBySuccess();
    }
 
    /**
     * 修改币种
     */
    @RequestMapping({"update.do"})
    @ResponseBody
    public ServerResponse update(CurrencyBeanVo beanVo) {
        CurrencyBean byId = service.getById(beanVo.getId());
        if(null == byId){
            return ServerResponse.createByErrorMsg("币种不存在");
        }
        Long scCount = getScCount(beanVo.getSc(),beanVo.getId());
        if(scCount > 0){
            return ServerResponse.createByErrorMsg("币种已存在");
        }
        CurrencyBean currencyBean = ConverterUtil.convert(beanVo, CurrencyBean.class);
        service.updateById(currencyBean);
        return ServerResponse.createBySuccess();
    }
 
    /**
     * 查询币种
     */
    @RequestMapping({"select.do"})
    @ResponseBody
    public ServerResponse select(@RequestParam(value = "sc", required = false) String sc,
                                 @RequestParam("pageNum") int pageNum,
                                 @RequestParam("pageSize") int pageSize) {
 
        Page<CurrencyBean> page = new Page<>(pageNum, pageSize);
        Page<CurrencyBean> beanPage = mapper.selectPage(page, new LambdaQueryWrapper<>(CurrencyBean.class)
                .like(StringUtil.isNotEmpty(sc), CurrencyBean::getSc, sc)
        );
        return ServerResponse.createBySuccess(beanPage);
    }
 
    public Long getScCount(String sc,Integer id){
        Long count = mapper.selectCount(new LambdaQueryWrapper<>(CurrencyBean.class).eq(CurrencyBean::getSc, sc).ne(null != id,CurrencyBean::getId,id));
        return count;
    }
 
}