package com.consum.base.controller;
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
import cn.hutool.core.util.ReflectUtil;
|
import com.consum.base.BaseController;
|
import com.consum.base.core.utils.CommonUtil;
|
import com.consum.base.core.utils.PageUtil;
|
import com.consum.base.pojo.LWhFormProcureGoodsInfoParam;
|
import com.consum.base.pojo.LWhFormProcureParam;
|
import com.consum.base.pojo.dto.GoodModelInfoDTO;
|
import com.consum.base.pojo.excel.ProcureExcelTemplate;
|
import com.consum.base.pojo.query.FormProcureQry;
|
import com.consum.base.pojo.response.*;
|
import com.consum.base.service.LWhFormProcureGoodsService;
|
import com.consum.base.service.LWhFormProcureService;
|
import com.consum.base.service.LWhProcureModelService;
|
import com.consum.base.service.impl.LWhFormProcureCoreService;
|
import com.consum.model.po.FinSysTenantUser;
|
import com.consum.model.po.LWhFormProcure;
|
import com.consum.model.po.LWhFormProcureGoods;
|
import com.iplatform.model.po.S_user_core;
|
import com.walker.db.page.GenericPager;
|
import com.walker.infrastructure.utils.CollectionUtils;
|
import com.walker.infrastructure.utils.DateUtils;
|
import com.walker.web.ResponseValue;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.commons.compress.utils.Lists;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.lang.reflect.Field;
|
import java.util.*;
|
|
/**
|
* @ClassName LWhFormProcureController
|
* @Date 2023/10/27
|
* @Description
|
* @Version 1.0
|
**/
|
@Api(value = "仓库表单采购", tags = "仓库表单采购")
|
@RestController
|
@RequestMapping("/pc/whForm/procure")
|
public class LWhFormProcureController extends BaseController {
|
|
@Resource
|
private LWhFormProcureService lWhFormProcureService;
|
@Resource
|
private LWhFormProcureGoodsService lWhFormProcureGoodsServiceImpl;
|
@Resource
|
private LWhFormProcureCoreService lWhFormProcureCoreService;
|
@Resource
|
private LWhProcureModelService lWhProcureModelService;
|
|
/**
|
* @Description 新增
|
*/
|
@PostMapping("/add")
|
public ResponseValue add() {
|
LWhFormProcureParam param = CommonUtil.getObjFromReqBody(LWhFormProcureParam.class);
|
LWhFormProcureParam param2 = new LWhFormProcureParam();
|
CommonUtil.copyProperties(param, param2);
|
param = param2;
|
return this.add(param);
|
}
|
|
private ResponseValue add(LWhFormProcureParam param) {
|
if (param.getWarehouseId() == null) {
|
return ResponseValue.error("仓库ID不能为空");
|
}
|
|
List<LWhFormProcureGoodsInfoParam> procureGoods = param.getProcureGoods();
|
if (CollectionUtils.isEmpty(procureGoods)) {
|
return ResponseValue.error("采购单不能为空");
|
}
|
FinSysTenantUser sysTenantUser = this.getSysInfo();
|
S_user_core currentUser = this.getCurrentUser();
|
lWhFormProcureService.add(param, sysTenantUser, currentUser);
|
return ResponseValue.success();
|
}
|
|
/**
|
* @Description 列表查询
|
*/
|
@ApiOperation(value = "采购单列表查询", notes = "采购单列表查询")
|
@ApiImplicitParams({@ApiImplicitParam(name = "param", value = "采购查询条件", required = true,
|
dataType = "FormProcureQryDto", paramType = "query")})
|
@GetMapping("/list")
|
public ResponseValue queryFormProcureList() {
|
FormProcureQry param = CommonUtil.getObjFromReq(FormProcureQry.class);
|
FormProcureQry param2 = new FormProcureQry();
|
CommonUtil.copyProperties(param, param2);
|
param = param2;
|
S_user_core currentUser = this.getCurrentUser();
|
if (currentUser == null) {
|
return ResponseValue.error("登录用户信息不存在");
|
}
|
/*当前登录人只能看到自己机构下的列表*/
|
FinSysTenantUser sysInfo = this.getSysInfo();
|
String tenantId = sysInfo.getTenantId();
|
if (param.getAgencyId() == null) {
|
param.setAgencyId(Long.valueOf(tenantId));
|
}
|
PageUtil genericPager = lWhFormProcureService.queryFormProcureList(param);
|
List<LWhFormProcure> data = genericPager.getDatas();
|
ArrayList<FormProcureVO> result = new ArrayList<>();
|
if (!CollectionUtils.isEmpty(data)) {
|
data.forEach(item -> {
|
FormProcureVO fromProcureVO = new FormProcureVO();
|
BeanUtils.copyProperties(item, fromProcureVO);
|
|
// 查询型号数量
|
List<GoodsTemplateCountVO> procureCount =
|
lWhProcureModelService.getProcureCountByBusinessId(item.getId());
|
fromProcureVO.setFromProcureTemplateInfoList(procureCount);
|
|
result.add(fromProcureVO);
|
});
|
}
|
try {
|
Field fieldDatas = GenericPager.class.getDeclaredField("datas");
|
// fieldDatas.setAccessible(true);
|
// fieldDatas.set(genericPager, result);
|
ReflectUtil.setFieldValue(genericPager, fieldDatas, result);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
genericPager.setDatas(result);
|
return ResponseValue.success(genericPager);
|
}
|
|
/**
|
* @Description 编辑
|
*/
|
@PostMapping("/edit")
|
public ResponseValue edit() {
|
LWhFormProcureParam param = CommonUtil.getObjFromReqBody(LWhFormProcureParam.class);
|
LWhFormProcureParam param2 = new LWhFormProcureParam();
|
CommonUtil.copyProperties(param, param2);
|
param = param2;
|
ResponseValue delFlag = delById(param.getId());
|
if (delFlag.getCode() == ResponseValue.CODE_SUCCESS) {
|
return this.add(param);
|
}
|
return ResponseValue.error("编辑失败!");
|
}
|
|
/**
|
* @Description 根据id删除
|
*/
|
@DeleteMapping("/del")
|
public ResponseValue delById(Long id) {
|
if (id == null) {
|
return ResponseValue.error("参数不能为空!");
|
}
|
LWhFormProcure lWhFormProcure = lWhFormProcureService.get(new LWhFormProcure(id));
|
if (lWhFormProcure == null) {
|
return ResponseValue.error("删除失败!");
|
}
|
if (lWhFormProcure.getStates() != 1) {
|
return ResponseValue.error("待入库状态才能删除!");
|
}
|
int num = lWhFormProcureService.delete(new LWhFormProcure(id));
|
if (num == 0) {
|
return ResponseValue.error("删除失败!");
|
}
|
lWhFormProcureGoodsServiceImpl.update("delete from L_WH_FORM_PROCURE_GOODS where WH_FORM_PROCURE_ID=" + id);
|
|
lWhProcureModelService.update("delete from L_WH_PROCURE_MODEL where BUSINESS_TYPE =1 and BUSINESS_ID=" + id);
|
return ResponseValue.success(1);
|
}
|
|
/**
|
* 入库操作
|
*/
|
@PostMapping("/income")
|
public ResponseValue income(Long id) {
|
String errMsg = lWhFormProcureCoreService.doProcure(id, getCurrentUser());
|
if (errMsg == null) {
|
return ResponseValue.success();
|
}
|
return ResponseValue.error(errMsg);
|
}
|
|
/**
|
* 根据id查询详情
|
*/
|
@GetMapping("/detail")
|
public ResponseValue getById(Long id) throws IllegalAccessException {
|
if (id == null) {
|
return ResponseValue.error("采购单id为空");
|
}
|
LWhFormProcure lWhFormProcure = lWhFormProcureService.get(new LWhFormProcure(id));
|
if (lWhFormProcure == null) {
|
return ResponseValue.error("采购单不存在");
|
}
|
LWhFormProcureExtendVO lWhFormProcureExtendVO = new LWhFormProcureExtendVO();
|
BeanUtils.copyProperties(lWhFormProcure, lWhFormProcureExtendVO);
|
|
// 物品
|
LWhFormProcureGoods lWhFormProcureGoods = new LWhFormProcureGoods();
|
lWhFormProcureGoods.setWhFormProcureId(id);
|
List<LWhFormProcureGoods> formProcureGoods = lWhFormProcureGoodsServiceImpl.select(lWhFormProcureGoods);
|
|
List<GoodsTemplateInfoVO> goodsTemplateInfoList = new ArrayList<>();
|
for (LWhFormProcureGoods formProcureGood : formProcureGoods) {
|
GoodsTemplateInfoVO goodsTemplateInfoVO = new GoodsTemplateInfoVO();
|
BeanUtils.copyProperties(formProcureGood, goodsTemplateInfoVO);
|
|
List<GoodModelInfoDTO> goodsModelInfoList =
|
lWhProcureModelService.getGoodsModelListByBusinessId(null, formProcureGood.getId());
|
if (CollectionUtils.isEmpty(goodsModelInfoList)) {
|
continue;
|
}
|
GoodModelInfoDTO goodModelInfoDTO = goodsModelInfoList.stream().findFirst().orElse(null);
|
if (goodModelInfoDTO != null) {
|
goodsTemplateInfoVO.setBaseCategoryName(goodModelInfoDTO.getCategoryName());
|
}
|
List<GoodsModelVO> goodsModelList = Lists.newArrayList();
|
for (GoodModelInfoDTO goodModelInfo : goodsModelInfoList) {
|
GoodsModelVO goodsModelVO = getGoodsModelVO(goodModelInfo);
|
goodsModelList.add(goodsModelVO);
|
}
|
|
ReflectUtil.setFieldValue(goodsTemplateInfoVO, "models", goodsModelList);
|
|
goodsTemplateInfoList.add(goodsTemplateInfoVO);
|
}
|
lWhFormProcureExtendVO.setProcureGoods(goodsTemplateInfoList);
|
return ResponseValue.success("查询成功!", lWhFormProcureExtendVO);
|
}
|
|
private GoodsModelVO getGoodsModelVO(GoodModelInfoDTO goodModelInfo) {
|
GoodsModelVO goodsModelVO = new GoodsModelVO();
|
|
goodsModelVO.setId(goodModelInfo.getId());
|
goodsModelVO.setBaseGoodsModelsName(goodModelInfo.getBaseGoodsModelsName());
|
goodsModelVO.setUnit(goodModelInfo.getUnit());
|
goodsModelVO.setCounts(goodModelInfo.getCounts());
|
goodsModelVO.setTotalAmount(
|
goodModelInfo.getTotalAmount() != null ? goodModelInfo.getTotalAmount().doubleValue() : null);
|
goodsModelVO.setWorehouseCount(goodModelInfo.getWorehouseCount());
|
goodsModelVO.setPrice(goodModelInfo.getPrice());
|
goodsModelVO.setBaseGoodsModelsId(goodModelInfo.getBaseGoodsModelsId());
|
return goodsModelVO;
|
}
|
|
@ApiOperation(value = "采购单明细查询", notes = "采购单明细查询")
|
@ApiImplicitParams({@ApiImplicitParam(name = "param", value = "采购单明细查询", required = true,
|
dataType = "FormProcureQryDto", paramType = "query")})
|
@GetMapping("detail/list")
|
public ResponseValue queryFormProcureDetailList() {
|
FormProcureQry formProcureQry = CommonUtil.getObjFromReq(FormProcureQry.class);
|
FormProcureQry param2 = new FormProcureQry();
|
CommonUtil.copyProperties(formProcureQry, param2);
|
formProcureQry = param2;
|
|
FinSysTenantUser sysInfo = this.getSysInfo();
|
if (sysInfo == null) {
|
return ResponseValue.error("登录用户信息不存在");
|
}
|
formProcureQry.setAgencyId(Long.valueOf(sysInfo.getTenantId()));
|
GenericPager genericPager = lWhFormProcureService.queryFormProcureDetailList(formProcureQry);
|
return ResponseValue.success(genericPager);
|
}
|
|
@ApiOperation(value = "采购单导出", notes = "采购单导出")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "采购单id", required = true, dataType = "Long", paramType = "query")})
|
@GetMapping("/list/export")
|
public void export(Long id, HttpServletResponse response) throws Exception {
|
TemplateExportParams params = new TemplateExportParams("import/采购入库单.xls");
|
params.setHeadingStartRow(2);
|
FinSysTenantUser sysInfo = this.getSysInfo();
|
if (sysInfo == null) {
|
throw new RuntimeException("登录用户信息不存在");
|
}
|
|
List<ProcureExcelTemplate> exportList = lWhFormProcureService.getExportList(id);
|
if (CollectionUtils.isEmpty(exportList)) {
|
throw new RuntimeException("数据为空");
|
}
|
|
int countNum =
|
exportList.stream().filter(item -> item.getNum() != null).mapToInt(ProcureExcelTemplate::getNum).sum();
|
double totalAmount = exportList.stream().filter(export -> export.getTotalAmount() != null)
|
.mapToDouble(ProcureExcelTemplate::getAmount).sum();
|
Optional<ProcureExcelTemplate> first = exportList.stream().findFirst();
|
ProcureExcelTemplate templateExcelExport = first.get();
|
String businessFormCode = templateExcelExport.getBusinessFormCode();
|
Long createTime = templateExcelExport.getCreateTime();
|
String operatorName = templateExcelExport.getOperatorName();
|
|
Map<String, Object> map = new HashMap<>();
|
map.put("code", businessFormCode);
|
map.put("date", DateUtils.toShowDate(createTime));
|
map.put("name", operatorName);
|
map.put("countNum", countNum);
|
map.put("totalAmount", totalAmount);
|
|
Workbook workbook = ExcelExportUtil.exportExcel(params, ProcureExcelTemplate.class, exportList, map);
|
downLoadExcel("采购入库单", response, workbook);
|
|
}
|
}
|