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
package com.panzhihua.service_community.api;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.VolunteerIntegralMerchantVO;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.service_community.entity.VolunteerIntegralMerchant;
import com.panzhihua.service_community.service.VolunteerIntegralMerchantService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
@Slf4j
@RestController
@RequestMapping("/VolunteerIntegralMerchant")
public class VolunteerIntegralMerchantApi  extends BaseController
{
    @Resource
    private VolunteerIntegralMerchantService merchantService;
 
    /**
     * 获取单个详情
     * @param id
     * @return
     */
    @GetMapping("/queryById")
    public R VolunteerIntegralMerchantQueryById(@RequestParam("id") String id)
    {
        return R.ok(merchantService.queryById(id));
    }
 
    /**
     * 分页查询
     * @param
     * @return
     */
    @GetMapping("/queryList")
    public R VolunteerIntegralMerchantQueryList(@RequestParam("pageNum") int pageNum,
                       @RequestParam("pageSize")  int pageSize,
                       @RequestParam("name")  String name,
                       @RequestParam("state")  String state)
    {
        Page page=new Page<VolunteerIntegralMerchant>(pageNum,pageSize);
        return R.ok(merchantService.queryList(page,name,state));
    }
 
    /**
     * 新增
     * @param
     * @return
     */
    @PostMapping("/insertVolunteer")
    public R VolunteerIntegralMerchantInsertVolunteer(@RequestBody VolunteerIntegralMerchantVO vimVO)
    {
        if(vimVO==null)
        {
            return R.fail("参数不能为空");
        }
 
        if(StringUtils.isEmpty(vimVO.getCommunityId()))
        {
            vimVO.setCommunityId(getCommunityId()+"");
        }
 
        if(StringUtils.isEmpty(vimVO.getName()))
        {
            return R.fail("商品名称不能为空");
        }
 
 
        if(StringUtils.isEmpty(vimVO.getIntegral()))
        {
            return R.fail("商品所需积分不能为空");
        }
 
        if(StringUtils.isEmpty(vimVO.getCommodityValue()))
        {
            return R.fail("商品价值不能为空");
        }
 
        //默认下架状态
        vimVO.setState("0");
 
        int num= merchantService.insertVolunteer(vimVO);
        if(num>0)
        {
            return R.ok();
        }
        return R.fail("操作失败");
    }
 
    @PostMapping("/updateById")
    public R  VolunteerIntegralMerchantUpdateById(@RequestBody VolunteerIntegralMerchantVO vimVO)
    {
 
        if(vimVO==null)
        {
            return R.fail("参数不能为空");
        }
 
        VolunteerIntegralMerchant vim= merchantService.queryById(vimVO.getId());
        if(StringUtils.equals("1",vim.getState()))
        {
            return R.fail("商品必须下架才能编辑");
        }
 
        if(StringUtils.isEmpty(vimVO.getCommunityId()))
        {
            vimVO.setCommunityId(getCommunityId()+"");
        }
 
        if(StringUtils.isEmpty(vimVO.getName()))
        {
            return R.fail("商品名称不能为空");
        }
 
 
        if(StringUtils.isEmpty(vimVO.getIntegral()))
        {
            return R.fail("商品所需积分不能为空");
        }
 
        if(StringUtils.isEmpty(vimVO.getCommodityValue()))
        {
            return R.fail("商品价值不能为空");
        }
 
        int num= merchantService.updateById(vimVO);
        if(num>0)
        {
            return R.ok();
        }
        return R.fail("操作失败");
    }
 
    @DeleteMapping("/deleteById")
    public R  VolunteerIntegralMerchantDeleteById(@RequestParam String id)
    {
        int num= merchantService.deleteById(id);
        if(num>0)
        {
            return R.ok();
        }
        return R.fail("操作失败");
    }
 
}