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("操作失败");
|
}
|
|
}
|