Helius
2022-05-10 80163ed89afd4d656b168070ced82d4f0cab0c7e
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
package com.xcong.excoin.modules.otc.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.otc.dao.OtcBlackListDao;
import com.xcong.excoin.modules.otc.dao.OtcOrderDao;
import com.xcong.excoin.modules.otc.dto.AddBlackDto;
import com.xcong.excoin.modules.otc.dto.BlackListDto;
import com.xcong.excoin.modules.otc.entity.OtcBlackList;
import com.xcong.excoin.modules.otc.entity.OtcOrder;
import com.xcong.excoin.modules.otc.vo.BlackListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@Slf4j
@Validated
@RestController
@RequestMapping(value = "/api/black")
@Api(value = "OtcBlackListController", tags = "otc黑名单列表接口类")
public class OtcBlackListController {
 
    @Autowired
    private OtcBlackListDao otcBlackListDao;
    @Autowired
    private OtcOrderDao otcOrderDao;
 
    @ApiOperation(value = "添加黑名单")
    @PostMapping(value = "/add")
    public Result add(@RequestBody AddBlackDto addBlackDto) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
 
        OtcOrder otcOrder = otcOrderDao.selectById(addBlackDto.getId());
        if (otcOrder == null) {
            return Result.fail("订单不存在");
        }
 
        OtcBlackList isExist = otcBlackListDao.selectByMemberIdAndBlackMemberId(member.getId(), otcOrder.getEntrustMemberId());
        if (isExist != null) {
            return Result.fail("请勿重复拉黑");
        }
 
        if (member.getId().equals(otcOrder.getEntrustMemberId())) {
            return Result.fail("不能拉黑自己");
        }
 
        OtcBlackList otcBlackList = new OtcBlackList();
        otcBlackList.setMemberId(member.getId());
        otcBlackList.setBlackMemberId(otcOrder.getEntrustMemberId());
        otcBlackList.setReasons(addBlackDto.getReason());
        otcBlackListDao.insert(otcBlackList);
        return Result.ok("拉黑成功");
    }
 
    @ApiOperation(value = "黑名单列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = BlackListVo.class)
    })
    @PostMapping(value = "/blackList")
    public Result blackList(@RequestBody BlackListDto blackListDto) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        Page<BlackListVo> page = new Page<>(blackListDto.getPageNum(), blackListDto.getPageSize());
        IPage<BlackListVo> result = otcBlackListDao.selectBlackListInPage(member.getId(), page);
        return Result.ok(result.getRecords());
    }
 
    @ApiOperation(value = "删除黑名单")
    @PostMapping(value = "/del")
    public Result del(@RequestBody AddBlackDto addBlackDto) {
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        if (addBlackDto.getType() == null) {
            return Result.fail("参数错误");
        }
 
        if (addBlackDto.getType() == 1) {
            OtcOrder otcOrder = otcOrderDao.selectById(addBlackDto.getId());
            if (otcOrder == null) {
                return Result.fail("订单不存在");
            }
 
            OtcBlackList otcBlackList = otcBlackListDao.selectByMemberIdAndBlackMemberId(member.getId(), otcOrder.getEntrustMemberId());
            otcBlackListDao.deleteById(otcBlackList.getId());
        } else {
            otcBlackListDao.deleteById(addBlackDto.getId());
        }
 
        return Result.ok("解除成功");
    }
}