基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
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
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.MarsTranOrder;
import com.yami.shop.bean.model.MarsWantbuy;
import com.yami.shop.bean.vo.mars.MarsWantbuyVo;
import com.yami.shop.common.constants.DictConstant;
import com.yami.shop.common.constants.ResultMsg;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.CdnConfigService;
import com.yami.shop.service.MarsTranOrderService;
import com.yami.shop.service.MarsWantbuyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author LGH
 */
@RestController
@RequestMapping("/p/wantBuy")
@Tag(name = "寄售(求购表)接口")
@AllArgsConstructor
public class MarsWantBuyController {
 
    @Resource
    private MarsWantbuyService marsWantbuyService;
    @Resource
    private CdnConfigService cdnConfigService;
    @Resource
    private MarsTranOrderService marsTranOrderService;
 
    @GetMapping("/page")
    @Operation(summary = "分页查询在线寄售(求购表)列表信息")
    public ServerResponseEntity<IPage<MarsWantbuyVo>> page(PageParam<MarsWantbuy> page,MarsWantbuy wantbuy) {
        IPage<MarsWantbuyVo> userInvoicePage = marsWantbuyService.getPage(page,wantbuy );
        return ServerResponseEntity.success(userInvoicePage);
    }
 
    @GetMapping("/getMarsWantbuyPage")
    @Operation(summary = "分页查询寄售(求购表)列表信息")
    public ServerResponseEntity<IPage<MarsWantbuy>> getMarsWantbuyPage(PageParam<MarsWantbuy> page,MarsWantbuy wantbuy) {
        IPage<MarsWantbuy> userInvoicePage = marsWantbuyService.getMarsWantbuyPage(page,wantbuy );
        return ServerResponseEntity.success(userInvoicePage);
    }
 
    @GetMapping("/info/{id}")
    @Operation(summary = "通过寄售(求购表)id查询寄售(求购表)信息")
    @Parameter(name = "id", description = "寄售(求购表)id" , required = true)
    public ServerResponseEntity<MarsWantbuy> getMarsWantbuyById(@PathVariable("id") Long id) {
        MarsWantbuy card = marsWantbuyService.getById(id);
        return ServerResponseEntity.success(card);
    }
 
    @PostMapping("/getMarsWantbuys")
    @Operation(summary = "获取寄售(求购表)信息")
    public ServerResponseEntity<List<MarsWantbuy>> getMarsWantbuys(@RequestBody  MarsWantbuy wantbuy) {
        List<MarsWantbuy> list = marsWantbuyService.getMarsWantbuys(wantbuy);
        return ServerResponseEntity.success(list);
    }
 
    @PostMapping("/saveMarsWantbuy")
    @Operation(summary = "新增寄售(求购表)信息")
    public ServerResponseEntity<String> saveMarsWantbuy(@RequestBody MarsWantbuy wantbuy) {
        String maxTranNum = cdnConfigService.selectValueByName(DictConstant.MAX_TRAN_NUM);
        String userId = SecurityUtils.getUser().getUserId();
        wantbuy.setWantUerId(userId);
        wantbuy.setResiTranPrice(wantbuy.getWantRealPrice());
        wantbuy.setResiTranNum(new BigDecimal(maxTranNum));
        Integer num = marsWantbuyService.saveMarsWantbuy(wantbuy);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @PostMapping("/cancelMarsWantbuy")
    @Operation(summary = "求购人取消寄售(求购表)信息")
    public ServerResponseEntity<String> cancelMarsWantbuy(@RequestBody  MarsWantbuy wantbuy) {
        MarsTranOrder marsTranOrder = new MarsTranOrder();
        marsTranOrder.setProductId(String.valueOf(wantbuy.getId()));
        List<String> statusList = new ArrayList<>();
        statusList.add(DictConstant.ORDER_STATUS_1);
        statusList.add(DictConstant.ORDER_STATUS_2);
        statusList.add(DictConstant.ORDER_STATUS_3);
        statusList.add(DictConstant.ORDER_STATUS_4);
        statusList.add(DictConstant.ORDER_STATUS_6);
        List<MarsTranOrder> orders = marsTranOrderService.getMarsTranOrders(marsTranOrder);
        if(null != orders && orders.size() > 0){
            return ServerResponseEntity.showFailMsg(ResultMsg.BUSSINESS_BEING);
        }
        wantbuy.setWantStatus(DictConstant.WANT_STATUS_5);
        Integer num = marsWantbuyService.updateMarsWantbuy(wantbuy);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @PostMapping("/updateMarsWantbuy")
    @Operation(summary = "修改寄售(求购表)信息")
    public ServerResponseEntity<String> updateMarsWantbuy(@RequestBody  MarsWantbuy wantbuy) {
        Integer num = marsWantbuyService.updateMarsWantbuy(wantbuy);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @GetMapping("/delete/{id}")
    @Operation(summary = "通过寄售流水id查询寄售信息")
    @Parameter(name = "id", description = "寄售id" , required = true)
    public ServerResponseEntity<String> deleteMarsWantbuyById(@PathVariable("id") Long id) {
        Integer num = marsWantbuyService.deleteMarsWantbuy(id);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
}