You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
6.4 KiB
Java
146 lines
6.4 KiB
Java
2 years ago
|
package com.glxp.api.controller.inv;
|
||
|
|
||
|
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.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.inv.*;
|
||
|
import com.glxp.api.res.PageSimpleResponse;
|
||
|
import com.glxp.api.service.inv.StockCompareDetailService;
|
||
|
import com.glxp.api.service.inv.StockCompareService;
|
||
|
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.validation.Valid;
|
||
|
|
||
|
@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("添加成功");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 立即对比
|
||
|
*
|
||
|
* @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, "对比记录不存在");
|
||
|
}
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
|
||
|
@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()));
|
||
|
}
|
||
|
stockCompareDetailService.remove(Wrappers.lambdaQuery(StockCompareDetailEntity.class)
|
||
|
.eq(StockCompareDetailEntity::getCompareId, param.getCompareId())
|
||
|
.eq(StockCompareDetailEntity::getProductId, param.getProductId())
|
||
|
.eq(StockCompareDetailEntity::getMainAction, param.getMainAction())
|
||
|
);
|
||
|
return ResultVOUtils.successMsg("移除成功");
|
||
|
}
|
||
|
|
||
|
}
|