/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.soldr.controller;
|
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import lombok.AllArgsConstructor;
|
|
import javax.validation.Valid;
|
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.soldr.vo.SoldrVOs;
|
import org.springblade.modules.soldrecord.service.ISoldrecordService;
|
import org.springblade.modules.stock.entity.Stock;
|
import org.springblade.modules.stock.service.IStockService;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import org.springblade.modules.soldr.entity.Soldr;
|
import org.springblade.modules.soldr.vo.SoldrVO;
|
import org.springblade.modules.soldr.service.ISoldrService;
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
/**
|
* 已出库存数量记录表 控制器
|
*
|
* @author BladeX
|
* @since 2022-05-27
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/soldr/soldr")
|
@Api(value = "已出库存数量记录表", tags = "已出库存数量记录表接口")
|
public class SoldrController extends BladeController {
|
|
private final ISoldrService soldrService;
|
private final ISoldrecordService soldrecordService;
|
private final IStockService stockService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入soldr")
|
public R<Soldr> detail(Soldr soldr) {
|
Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页 已出库存数量记录表
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入soldr")
|
public R<IPage<Soldr>> list(Soldr soldr, Query query) {
|
IPage<Soldr> pages = soldrService.page(Condition.getPage(query), Condition.getQueryWrapper(soldr));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页 已出库存数量记录表
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入soldr")
|
public R<IPage<SoldrVO>> page(SoldrVO soldr, Query query) {
|
IPage<SoldrVO> pages = soldrService.selectLists(Condition.getPage(query), soldr);
|
for (int i = 0; i < pages.getRecords().size(); i++) {
|
String specs = pages.getRecords().get(i).getSpecs1();
|
Integer amount = pages.getRecords().get(i).getAmount1();
|
Integer num = Integer.parseInt(specs);
|
String dic1 = pages.getRecords().get(i).getDic1();
|
String dic2 = pages.getRecords().get(i).getDic2();
|
String s = specs + dic1 + "/" + dic2;
|
pages.getRecords().get(i).setSpn(s);
|
pages.getRecords().get(i).setCnum(num * amount);
|
|
}
|
return R.data(pages);
|
}
|
|
/**
|
* 新增 已出库存数量记录表
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入soldr")
|
public R save(@Valid @RequestBody Soldr soldr) {
|
return R.status(soldrService.save(soldr));
|
}
|
|
/**
|
* 修改 已出库存数量记录表
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入soldr")
|
public R update(@Valid @RequestBody Soldr soldr) {
|
return R.status(soldrService.updateById(soldr));
|
}
|
|
/**
|
* 新增或修改 已出库存数量记录表
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入soldr")
|
public R submit(@Valid @RequestBody Soldr soldr) {
|
return R.status(soldrService.saveOrUpdate(soldr));
|
}
|
|
|
/**
|
* 删除 已出库存数量记录表
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 7)
|
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(soldrService.deleteLogic(Func.toLongList(ids)));
|
}
|
|
|
@PostMapping("/out")
|
public R out(Integer num, Long id, Integer type) {
|
//如果等于就修改并删除
|
if (type == 0) {
|
Stock stock = new Stock();
|
stock.setId(id);
|
Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
|
Integer amount = detail1.getAmount();
|
stock.setAmount(amount + num);
|
stockService.Updaet(stock);
|
//删除
|
soldrService.del(id);
|
}
|
//如果小于就修改
|
else {
|
Soldr soldr = new Soldr();
|
soldr.setSid(id);
|
Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
|
Integer amount1 = detail.getAmount1();
|
soldrecordService.updateSold(amount1 - num, id);
|
Stock stock = new Stock();
|
stock.setId(id);
|
Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
|
Integer amount = detail1.getAmount();
|
stock.setAmount(amount + num);
|
stockService.Updaet(stock);
|
}
|
return R.success("退回成功");
|
}
|
|
|
@GetMapping("/outs")
|
public R outs(SoldrVOs soldrVOs) {
|
//如果等于就修改并删除
|
if (soldrVOs.getType().equals("0")) {
|
Stock stock = new Stock();
|
stock.setId(soldrVOs.getId());
|
Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
|
Integer amount = detail1.getAmount();
|
stock.setAmount(amount + soldrVOs.getNum());
|
stockService.Updaet(stock);
|
//删除
|
soldrService.del(soldrVOs.getId());
|
}
|
//如果小于就修改
|
else {
|
Soldr soldr = new Soldr();
|
soldr.setSid(soldrVOs.getId());
|
Soldr detail = soldrService.getOne(Condition.getQueryWrapper(soldr));
|
Integer amount1 = detail.getAmount1();
|
soldrecordService.updateSold(amount1 - soldrVOs.getNum(), soldrVOs.getId());
|
Stock stock = new Stock();
|
stock.setId(soldrVOs.getId());
|
Stock detail1 = stockService.getOne(Condition.getQueryWrapper(stock));
|
Integer amount = detail1.getAmount();
|
stock.setAmount(amount + soldrVOs.getNum());
|
stockService.Updaet(stock);
|
}
|
return R.success("退回成功");
|
}
|
|
}
|