package org.springblade.modules.farmplant.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.springblade.core.boot.ctrl.BladeController;
|
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.farmplant.entity.FarmProductStock;
|
import org.springblade.modules.farmplant.service.FarmProductStockService;
|
import org.springblade.modules.farmplant.vo.FarmProductStockVO;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.text.DecimalFormat;
|
import java.util.*;
|
|
/**
|
* 农产品库存控制器
|
*
|
* @author zhongrj
|
* @since 2022-05-18
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/farmProductStock")
|
public class FarmProductStockController extends BladeController {
|
|
private final FarmProductStockService farmProductStockService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入farmProductStock")
|
public R<FarmProductStock> detail(FarmProductStock farmProductStock) {
|
FarmProductStock detail = farmProductStockService.getOne(Condition.getQueryWrapper(farmProductStock));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入farmProductStock")
|
public R<IPage<FarmProductStock>> list(FarmProductStock farmProductStock, Query query) {
|
IPage<FarmProductStock> pages = farmProductStockService.page(Condition.getPage(query), Condition.getQueryWrapper(farmProductStock));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入farmProductStock")
|
public R<IPage<FarmProductStockVO>> page(FarmProductStockVO farmProductStock, Query query) {
|
IPage<FarmProductStockVO> pages = farmProductStockService.selectFarmProductStockPage(Condition.getPage(query), farmProductStock);
|
return R.data(pages);
|
}
|
|
/**
|
* 统计产量
|
*
|
* @param farmProductStock
|
* @return
|
*/
|
@GetMapping("/statisticsProduct")
|
public R<FarmProductStockVO> statisticsProduct(FarmProductStockVO farmProductStock) {
|
return R.data(farmProductStockService.statisticsProduct(farmProductStock));
|
}
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入farmProductStock")
|
public R save(@Valid @RequestBody FarmProductStock farmProductStock) {
|
farmProductStock.setCreateTime(new Date());
|
return R.status(farmProductStockService.save(farmProductStock));
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入farmProductStock")
|
public R update(@Valid @RequestBody FarmProductStock farmProductStock) {
|
//更新并返回
|
return R.status(farmProductStockService.updateById(farmProductStock));
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入farmProductStock")
|
public R submit(@Valid @RequestBody FarmProductStock farmProductStock) {
|
return R.status(farmProductStockService.saveOrUpdate(farmProductStock));
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 7)
|
@ApiOperation(value = "逻辑删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(farmProductStockService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/**
|
* 大屏产量统计
|
*/
|
@PostMapping("/selctProductCount")
|
public R selctProductCount(String year) {
|
return R.data(farmProductStockService.selctProductCount(year));
|
}
|
|
/**
|
* 小程序统计产量详情
|
*
|
* @param farmProductStock
|
* @return
|
*/
|
@GetMapping("/statisticsProductx")
|
public R statisticsProductx(FarmProductStockVO farmProductStock, Query query) {
|
Double zwei = 0.0;
|
IPage<FarmProductStockVO> pages = farmProductStockService.statisticsProductx(Condition.getPage(query), farmProductStock);
|
for (int i = 0; i < pages.getRecords().size(); i++) {
|
String weight = pages.getRecords().get(i).getWeight();
|
Double a=Double.parseDouble(weight);
|
DecimalFormat df = new DecimalFormat("#.00");
|
String format = df.format(a);
|
//产量
|
Double wei = Double.parseDouble(format);
|
pages.getRecords().get(i).setWeight(format);
|
zwei += wei;
|
}
|
Map map = new HashMap();
|
List list = new ArrayList();
|
DecimalFormat df = new DecimalFormat("#.00");
|
String format = df.format(zwei);
|
map.put("zwei", format);
|
list.add(map);
|
list.add(pages);
|
return R.data(list);
|
}
|
|
}
|