|
|
|
package com.glxp.api.controller.inv;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
import com.glxp.api.controller.BaseController;
|
|
|
|
import com.glxp.api.entity.inv.InvCpLocalProductEntity;
|
|
|
|
import com.glxp.api.entity.inv.InvCpThrProuductEntity;
|
|
|
|
import com.glxp.api.entity.inv.StockCompareDetailEntity;
|
|
|
|
import com.glxp.api.entity.inv.StockCompareEntity;
|
|
|
|
import com.glxp.api.entity.thrsys.ThrSystemEntity;
|
|
|
|
import com.glxp.api.enums.StockCompareStatusEnum;
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
import com.glxp.api.req.inout.FilterOrderDetailResultRequest;
|
|
|
|
import com.glxp.api.req.inv.*;
|
|
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
|
|
import com.glxp.api.res.inout.IoOrderDetailResultResponse;
|
|
|
|
import com.glxp.api.res.inout.IoOrderDetailVo;
|
|
|
|
import com.glxp.api.res.inv.StockCompareDetailVo;
|
|
|
|
import com.glxp.api.service.inv.InvCpLocalProductService;
|
|
|
|
import com.glxp.api.service.inv.InvCpThrProuductService;
|
|
|
|
import com.glxp.api.service.inv.StockCompareDetailService;
|
|
|
|
import com.glxp.api.service.inv.StockCompareService;
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
import com.glxp.api.vo.inv.InvProductDetailSelectVo;
|
|
|
|
import com.glxp.api.vo.inv.StockCompareVo;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping
|
|
|
|
@Slf4j
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
public class StockCompareController extends BaseController {
|
|
|
|
|
|
|
|
private final StockCompareService stockCompareService;
|
|
|
|
private final StockCompareDetailService stockCompareDetailService;
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/page")
|
|
|
|
public BaseResponse page(@RequestBody StockCompareQuery query) {
|
|
|
|
|
|
|
|
Page<StockCompareVo> page = stockCompareService.pageVo(query);
|
|
|
|
|
|
|
|
PageInfo<StockCompareVo> pageInfo;
|
|
|
|
pageInfo = new PageInfo<>(page.getRecords());
|
|
|
|
PageSimpleResponse<StockCompareVo> pageSimpleResponse = new PageSimpleResponse<>();
|
|
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
|
|
pageSimpleResponse.setList(page.getRecords());
|
|
|
|
return ResultVOUtils.success(pageInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/selectInvProductDetail")
|
|
|
|
public BaseResponse selectInvProductDetail(@RequestBody @Valid InvProductDetailSelectRequest param) {
|
|
|
|
StockCompareEntity stockCompare = stockCompareService.getById(param.getCompareId());
|
|
|
|
if (stockCompare == null) {
|
|
|
|
return ResultVOUtils.error(500, "对比记录不存在");
|
|
|
|
}
|
|
|
|
|
|
|
|
InvProductDetailSelectQuery invProductDetailSelectQuery = new InvProductDetailSelectQuery(stockCompare.getInvCode(), stockCompare.getMainAction()
|
|
|
|
, stockCompare.getAction(), stockCompare.getCompareStartDate(), stockCompare.getCompareEndDate()
|
|
|
|
, stockCompare.getThirdTableField(), null);
|
|
|
|
|
|
|
|
invProductDetailSelectQuery.setPage(param.getPage());
|
|
|
|
invProductDetailSelectQuery.setLimit(param.getLimit());
|
|
|
|
Page<InvProductDetailSelectVo> page = stockCompareDetailService.invProductDetailSelectPage(invProductDetailSelectQuery);
|
|
|
|
PageSimpleResponse<InvProductDetailSelectVo> simplePage = new PageSimpleResponse<>((int) page.getTotal(), page.getRecords());
|
|
|
|
return ResultVOUtils.success(simplePage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/save")
|
|
|
|
public BaseResponse save(@RequestBody StockCompareParam param) {
|
|
|
|
Long id = stockCompareService.save(super.getUserId(), param);
|
|
|
|
return ResultVOUtils.success("保存成功", id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@DeleteMapping("/udiwms/stockCompare/delete/{compareId}")
|
|
|
|
public BaseResponse delete(@PathVariable Long compareId) {
|
|
|
|
stockCompareService.delete(compareId);
|
|
|
|
return ResultVOUtils.successMsg("删除成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/addProduct")
|
|
|
|
public BaseResponse addProduct(@RequestBody @Valid StockCompareDetailParam param) {
|
|
|
|
stockCompareService.addProduct(param);
|
|
|
|
return ResultVOUtils.successMsg("添加成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加第三方库存产品明细
|
|
|
|
*/
|
|
|
|
@PostMapping("/udiwms/stockCompare/addThrProduct")
|
|
|
|
public BaseResponse addThrProduct(@RequestBody FilterInvProductRequest invProductRequest) {
|
|
|
|
stockCompareService.dlThrProduct(invProductRequest);
|
|
|
|
return ResultVOUtils.successMsg("添加成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 立即对比
|
|
|
|
*
|
|
|
|
* @param compareId 对比数据id
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@PostMapping("/udiwms/stockCompare/compare/{compareId}")
|
|
|
|
public BaseResponse compare(@PathVariable Long compareId) {
|
|
|
|
StockCompareEntity stockCompare = stockCompareService.getById(compareId);
|
|
|
|
if (stockCompare == null) {
|
|
|
|
return ResultVOUtils.error(500, "对比记录不存在");
|
|
|
|
}
|
|
|
|
stockCompare.setStatus(StockCompareStatusEnum.FINISHED);
|
|
|
|
stockCompareService.updateById(stockCompare);
|
|
|
|
List<StockCompareDetailEntity> stockCompareDetailEntities = stockCompareService.getCompareResult(compareId);
|
|
|
|
stockCompareDetailService.remove(new QueryWrapper<StockCompareDetailEntity>().eq("compareId", compareId));
|
|
|
|
stockCompareDetailService.saveBatch(stockCompareDetailEntities);
|
|
|
|
return ResultVOUtils.successMsg("对比成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/detail/page")
|
|
|
|
public BaseResponse stockCompareDetailPage(@RequestBody @Valid InvProductDetailSelectRequest param) {
|
|
|
|
StockCompareEntity stockCompare = stockCompareService.getById(param.getCompareId());
|
|
|
|
if (stockCompare == null) {
|
|
|
|
return ResultVOUtils.error(500, "对比记录不存在");
|
|
|
|
}
|
|
|
|
if (param.getPage() != null) {
|
|
|
|
int offset = (param.getPage() - 1) * param.getLimit();
|
|
|
|
PageHelper.offsetPage(offset, param.getLimit());
|
|
|
|
}
|
|
|
|
Page<StockCompareDetailEntity> page = stockCompareDetailService.page(param.getPageObj()
|
|
|
|
, Wrappers.lambdaQuery(StockCompareDetailEntity.class)
|
|
|
|
.eq(StockCompareDetailEntity::getCompareId, param.getCompareId())
|
|
|
|
.orderByAsc(StockCompareDetailEntity::getProductId, StockCompareDetailEntity::getMainAction)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
PageInfo<StockCompareDetailEntity> pageInfo;
|
|
|
|
pageInfo = new PageInfo<>(page.getRecords());
|
|
|
|
PageSimpleResponse<StockCompareDetailEntity> pageSimpleResponse = new PageSimpleResponse<>();
|
|
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
|
|
pageSimpleResponse.setList(page.getRecords());
|
|
|
|
return ResultVOUtils.success(pageSimpleResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
InvCpLocalProductService localProductService;
|
|
|
|
@Resource
|
|
|
|
InvCpThrProuductService thrProuductService;
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/detail/result")
|
|
|
|
public BaseResponse realDeatilPage(@RequestBody @Valid InvProductDetailSelectRequest param) {
|
|
|
|
StockCompareEntity stockCompare = stockCompareService.getById(param.getCompareId());
|
|
|
|
if (stockCompare == null) {
|
|
|
|
return ResultVOUtils.error(500, "对比记录不存在");
|
|
|
|
}
|
|
|
|
return ResultVOUtils.success(stockCompareService.getCompareResult(param.getCompareId()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/udiwms/stockCompare/detail/del")
|
|
|
|
public BaseResponse stockCompareDetailPage(@RequestBody @Valid StockCompareDetailDelParam param) {
|
|
|
|
StockCompareEntity stockCompare = stockCompareService.getById(param.getCompareId());
|
|
|
|
if (stockCompare == null) {
|
|
|
|
return ResultVOUtils.error(500, "对比记录不存在");
|
|
|
|
}
|
|
|
|
if (stockCompare.getStatus() != StockCompareStatusEnum.DRAFT) {
|
|
|
|
throw new JsonException(500, String.format("非%s状态无法移除", StockCompareStatusEnum.DRAFT.getDesc()));
|
|
|
|
}
|
|
|
|
|
|
|
|
localProductService.remove(Wrappers.lambdaQuery(InvCpLocalProductEntity.class)
|
|
|
|
.eq(InvCpLocalProductEntity::getCompareId, param.getCompareId())
|
|
|
|
.eq(InvCpLocalProductEntity::getProductId, param.getProductId())
|
|
|
|
.eq(InvCpLocalProductEntity::getBatchNo, param.getBatchNo()));
|
|
|
|
|
|
|
|
// stockCompareDetailService.remove(Wrappers.lambdaQuery(StockCompareDetailEntity.class)
|
|
|
|
// .eq(StockCompareDetailEntity::getCompareId, param.getCompareId())
|
|
|
|
// .eq(StockCompareDetailEntity::getProductId, param.getProductId())
|
|
|
|
// .eq(StockCompareDetailEntity::getMainAction, param.getMainAction())
|
|
|
|
// );
|
|
|
|
return ResultVOUtils.successMsg("移除成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/udiwms/stockCompare/compare/exportExcel")
|
|
|
|
public void selectExportExcel(@RequestBody InvProductDetailSelectRequest invProductDetailSelectRequest, HttpServletResponse response) throws IOException {
|
|
|
|
// 模拟数据库获取数据
|
|
|
|
|
|
|
|
List<StockCompareDetailEntity> stockCompareDetailEntities = stockCompareDetailService.list(new QueryWrapper<StockCompareDetailEntity>().eq("compareId", invProductDetailSelectRequest.getCompareId()));
|
|
|
|
|
|
|
|
List<StockCompareDetailVo> stockCompareDetailVos =
|
|
|
|
BeanUtil.copyToList(stockCompareDetailEntities, StockCompareDetailVo.class);
|
|
|
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
|
|
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
|
response.setHeader("Content-Disposition",
|
|
|
|
"attachment;filename=" + URLEncoder.encode("库存对比明细" + DateUtil.format(new Date(), "yyyy-MM-dd") + ".xlsx", StandardCharsets.UTF_8.name()));
|
|
|
|
|
|
|
|
EasyExcel.write(response.getOutputStream(), StockCompareDetailVo.class).sheet().doWrite(stockCompareDetailVos);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|