/*
|
* 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.stock.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.stock.vo.StocksVO;
|
import org.springblade.modules.stockrecord.entity.Stockrecord;
|
import org.springblade.modules.stockrecord.service.IStockrecordService;
|
import org.springblade.modules.system.entity.DictBiz;
|
import org.springblade.modules.system.service.IDictBizService;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import org.springblade.modules.stock.entity.Stock;
|
import org.springblade.modules.stock.vo.StockVO;
|
import org.springblade.modules.stock.service.IStockService;
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
import java.util.List;
|
|
/**
|
* 农资库存表 控制器
|
*
|
* @author BladeX
|
* @since 2022-05-11
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/stock/stock")
|
@Api(value = "农资库存表", tags = "农资库存表接口")
|
public class StockController extends BladeController {
|
|
private final IStockService stockService;
|
private final IStockrecordService stockrecordService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入stock")
|
public R<Stock> detail(Stock stock) {
|
Stock detail = stockService.getOne(Condition.getQueryWrapper(stock));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页 农资库存表
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入stock")
|
public R<IPage<Stock>> list(Stock stock, Query query) {
|
IPage<Stock> pages = stockService.page(Condition.getPage(query), Condition.getQueryWrapper(stock));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页 农资库存表
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入stock")
|
public R<IPage<StockVO>> page(StockVO stock, Query query) {
|
IPage<StockVO> pages = stockService.selectLists(Condition.getPage(query), stock);
|
for (int i = 0; i < pages.getRecords().size(); i++) {
|
String specs = pages.getRecords().get(i).getSpecs();
|
Integer amount = pages.getRecords().get(i).getAmount();
|
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 = "传入stock")
|
public R save(@Valid @RequestBody Stock stock) {
|
stock.setState("0");
|
stock.setSp1("stockSpecs1");
|
stock.setSp2("stockSpecs2");
|
boolean save = stockService.save(stock);
|
//农资记录表
|
Stockrecord stockrecord = new Stockrecord();
|
//农资ID
|
stockrecord.setSid(stock.getId());
|
stockrecord.setStockId1(stock.getStockId());
|
stockrecord.setAmount1(stock.getAmount());
|
stockrecord.setTime1(stock.getTime());
|
stockrecord.setType1(stock.getType());
|
stockrecord.setStockType1(1);
|
stockrecord.setPicture1(stock.getPicture());
|
stockrecord.setRemarks1(stock.getRemarks());
|
stockrecord.setSpecs1(stock.getSpecs());
|
stockrecord.setSpecsVal1(stock.getSpecsValue1());
|
stockrecord.setSpecsVal2(stock.getSpecsValue2());
|
stockrecord.setSp1("stockSpecs1");
|
stockrecord.setSp2("stockSpecs2");
|
//统计公斤
|
Integer amount = stock.getAmount();
|
Integer specsValue1 = stock.getSpecsValue1();
|
double v = 0;
|
//克
|
if (specsValue1 == 0) {
|
v = amount * 0.001;
|
}
|
//斤
|
if (specsValue1 == 1) {
|
v = amount * 0.5;
|
}
|
//公斤
|
if (specsValue1 == 2) {
|
v = amount;
|
}
|
//吨
|
if (specsValue1 == 3) {
|
v = amount * 1000;
|
}
|
//毫升
|
if (specsValue1 == 4) {
|
//毫升换成升
|
double s = amount * 0.001;
|
//升换成公斤
|
v = s;
|
}
|
//升
|
if (specsValue1 == 5) {
|
v = amount;
|
}
|
stockrecord.setCensus(v);
|
stockrecordService.save(stockrecord);
|
return R.status(save);
|
}
|
|
/**
|
* 修改 农资库存表
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入stock")
|
public R update(@Valid @RequestBody Stock stock) {
|
return R.status(stockService.updateById(stock));
|
}
|
|
/**
|
* 新增或修改 农资库存表
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入stock")
|
public R submit(@Valid @RequestBody Stock stock) {
|
return R.status(stockService.saveOrUpdate(stock));
|
}
|
|
|
/**
|
* 删除 农资库存表
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 7)
|
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(stockService.deleteLogic(Func.toLongList(ids)));
|
}
|
|
/**
|
* 数据统计
|
*
|
* @param stock
|
* @param query
|
* @return
|
*/
|
@PostMapping("/pagenum")
|
public R<IPage<StocksVO>> pagenum(StocksVO stock, Query query) {
|
IPage<StocksVO> pages = stockService.slectNum(Condition.getPage(query), stock);
|
for (int i = 0; i < pages.getRecords().size(); i++) {
|
Double cgnum = pages.getRecords().get(i).getCgnum();
|
Double dbrknum = pages.getRecords().get(i).getDbrknum();
|
double v = cgnum + dbrknum;
|
pages.getRecords().get(i).setRknum(v);
|
Double lycknum = pages.getRecords().get(i).getLycknum();
|
Double dbcknum = pages.getRecords().get(i).getDbcknum();
|
Double bfcknum = pages.getRecords().get(i).getBfcknum();
|
double v1 = lycknum + dbcknum + bfcknum;
|
pages.getRecords().get(i).setCknum(v1);
|
}
|
|
return R.data(pages);
|
}
|
|
|
}
|