package cn.exrick.xboot.your.controller; import cn.exrick.xboot.core.common.utils.PageUtil; import cn.exrick.xboot.core.common.utils.ResultUtil; import cn.exrick.xboot.core.common.vo.PageVo; import cn.exrick.xboot.core.common.vo.Result; import cn.exrick.xboot.your.entity.Customer; import cn.exrick.xboot.your.entity.CustomerReceive; import cn.exrick.xboot.your.service.ICustomerReceiveService; import cn.exrick.xboot.your.service.ICustomerService; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @author zhangzeli */ @Slf4j @RestController @Api(tags = "商户表管理接口") @RequestMapping("/xboot/customer") @Transactional public class CustomerController { @Autowired private ICustomerService iCustomerService; @Autowired private ICustomerReceiveService iCustomerReceiveService; @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) @ApiOperation(value = "通过id获取") public Result get(@PathVariable String id) { Customer customer = iCustomerService.getById(id); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("customer_id",id); wrapper.eq("customer_id",id); List list = iCustomerReceiveService.list(wrapper); customer.setReceives(list); return new ResultUtil().setData(customer); } @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "获取全部数据") public Result> getAll() { List list = iCustomerService.list(); return new ResultUtil>().setData(list); } @RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "" + "") public Result> getByPage(String areaSectionId,String name,PageVo page) { QueryWrapper wrapper = new QueryWrapper<>(); if (!StrUtil.isEmpty(areaSectionId)) wrapper.eq("area_section_id",areaSectionId); if (!StrUtil.isEmpty(name)) wrapper.like("name","%"+name+"%"); IPage data = iCustomerService.page(PageUtil.initMpPage(page),wrapper); return new ResultUtil>().setData(data); } @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST) @ApiOperation(value = "编辑或更新数据") public Result saveOrUpdate(Customer customer) { if (iCustomerService.saveOrUpdate(customer)) { return new ResultUtil().setData(customer); } return new ResultUtil().setErrorMsg("操作失败"); } @RequestMapping(value = "/update", method = RequestMethod.POST) @ApiOperation(value = "更新数据") public Result update(String customerId,String lng,String lat,String address,String headImg) { Customer customer = iCustomerService.getById(customerId); if(StrUtil.isNotEmpty(lng)){ customer.setLng(lng); } if(StrUtil.isNotEmpty(lat)){ customer.setLat(lat); } if(StrUtil.isNotEmpty(address)){ customer.setRegisteredAddress(address); } if(StrUtil.isNotEmpty(headImg)){ customer.setHeadImg(headImg); } if (iCustomerService.saveOrUpdate(customer)) { return new ResultUtil().setData(customer); } return new ResultUtil().setErrorMsg("操作失败"); } @RequestMapping(value = "/delByIds", method = RequestMethod.POST) @ApiOperation(value = "批量通过id删除") public Result delAllByIds(@RequestParam String[] ids) { for (String id : ids) { iCustomerService.removeById(id); } return ResultUtil.success("批量通过id删除数据成功"); } }