219 lines
7.4 KiB
Java
219 lines
7.4 KiB
Java
package com.gxwebsoft.shop.controller;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.gxwebsoft.common.core.web.BaseController;
|
|
import com.gxwebsoft.shop.entity.Cart;
|
|
import com.gxwebsoft.shop.service.CashierService;
|
|
import com.gxwebsoft.shop.entity.Cashier;
|
|
import com.gxwebsoft.shop.param.CashierParam;
|
|
import com.gxwebsoft.common.core.web.ApiResult;
|
|
import com.gxwebsoft.common.core.web.PageResult;
|
|
import com.gxwebsoft.common.core.web.BatchParam;
|
|
import com.gxwebsoft.shop.vo.CashierVo;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 收银控制器
|
|
*
|
|
* @author 科技小王子
|
|
* @since 2024-08-04 11:51:43
|
|
*/
|
|
@Api(tags = "收银管理")
|
|
@RestController
|
|
@RequestMapping("/api/shop/cashier")
|
|
public class CashierController extends BaseController {
|
|
@Resource
|
|
private CashierService cashierService;
|
|
|
|
@ApiOperation("分页查询收银")
|
|
@GetMapping("/page")
|
|
public ApiResult<PageResult<Cashier>> page(CashierParam param) {
|
|
// 使用关联查询
|
|
return success(cashierService.pageRel(param));
|
|
}
|
|
|
|
@ApiOperation("查询全部收银")
|
|
@GetMapping()
|
|
public ApiResult<CashierVo> list(CashierParam param) {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
// 附加收银员ID
|
|
param.setCashierId(getLoginUserId());
|
|
// 收银员ID
|
|
// final Set<String> collect = getLoginUser().getRoles().stream().map(Role::getRoleCode).collect(Collectors.toSet());
|
|
// if (!collect.contains("merchantClerk")) {
|
|
// return fail("这个账户没有收银权限",null);
|
|
// }
|
|
return success(cashierService.listRel(param));
|
|
}
|
|
|
|
// @ApiOperation("按groupId分组查询全部收银")
|
|
// @GetMapping("/listByGroupId")
|
|
// public ApiResult<List<CashierVo>> listByGroupId(CashierParam param) {
|
|
// if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
// return success("请先登录",null);
|
|
// }
|
|
// // 附加收银员ID
|
|
// param.setCashierId(getLoginUserId());
|
|
// // 收银员ID
|
|
// return success(cashierService.listRelByGroupId(param));
|
|
// }
|
|
|
|
@PreAuthorize("hasAuthority('shop:cashier:list')")
|
|
@ApiOperation("根据id查询收银")
|
|
@GetMapping("/{id}")
|
|
public ApiResult<Cashier> get(@PathVariable("id") Integer id) {
|
|
// 使用关联查询
|
|
return success(cashierService.getByIdRel(id));
|
|
}
|
|
|
|
@ApiOperation("添加收银")
|
|
@PostMapping()
|
|
public ApiResult<?> save(@RequestBody Cashier cashier) {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
cashier.setCashierId(getLoginUserId());
|
|
// 修正购买数量
|
|
if (ObjectUtil.isEmpty(cashier.getCartNum())) {
|
|
cashier.setCartNum(1);
|
|
}
|
|
// 超出最大限制
|
|
if (cashierService.count(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getCashierId,getLoginUserId())) > 50) {
|
|
return fail("购物车宝贝数量已满,建议您先去结算或清理~");
|
|
}
|
|
// 重复商品叠加数量
|
|
final Cashier one = cashierService.getOne(new LambdaQueryWrapper<Cashier>()
|
|
.eq(Cashier::getCashierId,getLoginUserId())
|
|
.eq(Cashier::getGoodsId,cashier.getGoodsId())
|
|
.eq(Cashier::getSpec,cashier.getSpec())
|
|
.eq(Cashier::getGroupId,0)
|
|
.last("limit 1"));
|
|
|
|
if(ObjectUtil.isNotEmpty(one)){
|
|
return fail("请勿重复添加");
|
|
}
|
|
if (cashierService.save(cashier)) {
|
|
return success("添加成功");
|
|
}
|
|
return fail("添加失败");
|
|
}
|
|
|
|
@ApiOperation("修改收银")
|
|
@PutMapping()
|
|
public ApiResult<?> update(@RequestBody Cashier cashier) {
|
|
if (cashierService.updateById(cashier)) {
|
|
return success("修改成功");
|
|
}
|
|
return fail("修改失败");
|
|
}
|
|
|
|
@ApiOperation("删除收银")
|
|
@DeleteMapping("/{id}")
|
|
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
|
if (cashierService.removeById(id)) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
|
|
@ApiOperation("批量添加收银")
|
|
@PostMapping("/batch")
|
|
public ApiResult<?> saveBatch(@RequestBody List<Cashier> list) {
|
|
if (cashierService.saveBatch(list)) {
|
|
return success("添加成功");
|
|
}
|
|
return fail("添加失败");
|
|
}
|
|
|
|
@ApiOperation("批量修改收银")
|
|
@PutMapping("/batch")
|
|
public ApiResult<?> removeBatch(@RequestBody BatchParam<Cashier> batchParam) {
|
|
if (batchParam.update(cashierService, "id")) {
|
|
return success("修改成功");
|
|
}
|
|
return fail("修改失败");
|
|
}
|
|
|
|
@ApiOperation("批量删除收银")
|
|
@DeleteMapping("/batch")
|
|
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
|
if (cashierService.removeByIds(ids)) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
|
|
@ApiOperation("增加数量")
|
|
@PutMapping("/addCartNum")
|
|
public ApiResult<?> addCartNum(@RequestBody Cashier cashier) {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
cashier.setCartNum(cashier.getCartNum()+1);
|
|
cashierService.updateById(cashier);
|
|
return success("操作成功");
|
|
}
|
|
|
|
@ApiOperation("减少数量")
|
|
@PutMapping("/subCartNum")
|
|
public ApiResult<?> subCartNum(@RequestBody Cashier cashier) {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
cashier.setCartNum(cashier.getCartNum()-1);
|
|
cashierService.updateById(cashier);
|
|
return success("操作成功");
|
|
}
|
|
|
|
@ApiOperation("清空")
|
|
@PutMapping("/cearCartNum")
|
|
public ApiResult<?> removeCartNum(@RequestBody Cashier cashier) {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
cashier.setCartNum(cashier.getCartNum()-1);
|
|
cashierService.updateById(cashier);
|
|
return success("操作成功");
|
|
}
|
|
|
|
@ApiOperation("挂单")
|
|
@PutMapping("/packCashier")
|
|
public ApiResult<?> packCashier() {
|
|
if (ObjectUtil.isEmpty(getLoginUser())) {
|
|
return success("请先登录",null);
|
|
}
|
|
final long timeMillis = System.currentTimeMillis();
|
|
final boolean update = cashierService.update(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getGroupId, 0).eq(Cashier::getCashierId, getLoginUserId()).set(Cashier::getGroupId, timeMillis/1000));
|
|
|
|
return success("操作成功",update);
|
|
}
|
|
|
|
@ApiOperation("取单")
|
|
@PutMapping("/getByGroup/{id}")
|
|
public ApiResult<?> getByGroup(@PathVariable("id") Integer id) {
|
|
if (cashierService.update(new LambdaUpdateWrapper<Cashier>().eq(Cashier::getGroupId,id).set(Cashier::getGroupId,0))) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
|
|
@ApiOperation("删除整单")
|
|
@DeleteMapping("/removeByGroup/{id}")
|
|
public ApiResult<?> removeByGroup(@PathVariable("id") Integer id) {
|
|
if (cashierService.remove(new LambdaQueryWrapper<Cashier>().eq(Cashier::getGroupId,id))) {
|
|
return success("删除成功");
|
|
}
|
|
return fail("删除失败");
|
|
}
|
|
}
|