| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- package com.trade.purchase.dealer;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
- import com.baomidou.mybatisplus.core.toolkit.StringUtils;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
- import com.trade.purchase.order.dto.OrderSubmitDto;
- import com.trade.purchase.order.entity.Order;
- import com.trade.purchase.order.entity.OrderFees;
- import com.trade.purchase.order.entity.OrderFiles;
- import com.trade.purchase.order.entity.OrderItems;
- import com.trade.purchase.order.enums.OrderTypeEnum;
- import com.trade.purchase.order.service.IOrderFeesService;
- import com.trade.purchase.order.service.IOrderFilesService;
- import com.trade.purchase.order.service.IOrderItemsService;
- import com.trade.purchase.order.service.IOrderService;
- import com.trade.purchase.order.vo.OrderDTO;
- import com.trade.purchase.order.vo.OrderVO;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import lombok.AllArgsConstructor;
- import org.springblade.client.entity.CorpsDesc;
- import org.springblade.client.entity.StorageDesc;
- import org.springblade.client.feign.ICorpsDescClient;
- import org.springblade.client.feign.IGoodsDescClient;
- import org.springblade.client.feign.IStorageClient;
- import org.springblade.client.vo.GoodsDescVO;
- import org.springblade.core.boot.ctrl.BladeController;
- import org.springblade.core.secure.utils.AuthUtil;
- import org.springblade.core.tool.api.R;
- import org.springblade.core.tool.utils.CollectionUtil;
- import org.springblade.core.tool.utils.Func;
- import org.springblade.system.user.entity.User;
- import org.springblade.system.user.feign.IUserClient;
- import org.springframework.web.bind.annotation.*;
- import javax.validation.Valid;
- import java.math.BigDecimal;
- import java.util.Collections;
- import java.util.Date;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 进口采购订单表 控制器
- *
- * @author BladeX
- * @since 2021-09-26
- */
- @RestController
- @AllArgsConstructor
- @RequestMapping("/dealer/purchaseOrder")
- @Api(value = "经销商采购订单", tags = "经销商采购订单")
- public class PurchaseDealerOrderController extends BladeController {
- private final IOrderService orderService;
- private final IOrderFeesService orderFeesService;
- private final IOrderFilesService orderFilesService;
- private final IOrderItemsService orderItemsService;
- private final String ERROR_MSG = "缺少查询信息";
- private ICorpsDescClient corpsDescClient;//获取客户信息
- private IGoodsDescClient goodsDescClient;
- private IUserClient userClient;
- private IStorageClient iStorageClient;//库区信息
- /**
- * 详情
- */
- @GetMapping("/{id}")
- @ApiOperationSupport(order = 1)
- @ApiOperation(value = "采购订单查看详情", notes = "传入order")
- public R<OrderVO> detail(@PathVariable(value = "id") String id) {
- R<OrderVO> orderMessage = orderService.getOrderMessage(id);
- if(orderMessage.isSuccess()&&orderMessage.getData()!=null)
- {
- R<User> user1 = userClient.userInfoById(orderMessage.getData().getUpdateUser());
- if (user1.isSuccess() && user1.getData() != null){
- orderMessage.getData().setUpdateUserName(user1.getData().getName());
- }
- R<User> user = userClient.userInfoById(orderMessage.getData().getCreateUser());
- if (user.isSuccess() && user.getData() != null){
- orderMessage.getData().setCreateUserName(user.getData().getName());
- }
- List<OrderItems> orderItemsList = orderMessage.getData().getOrderItemsList();
- if (CollectionUtil.isNotEmpty(orderItemsList)) {
- orderItemsList.forEach(e->{
- R<User> user2 = userClient.userInfoById(e.getUpdateUser());
- if (user2.isSuccess() && user2.getData() != null){
- e.setUpdateUserName(user2.getData().getName());
- }
- R<User> user3 = userClient.userInfoById(e.getCreateUser());
- if (user3.isSuccess() && user3.getData() != null){
- e.setCreateUserName(user3.getData().getName());
- }
- });
- }
- }
- return orderMessage;
- }
- /**
- * 分页 销售或采购订单表
- */
- @GetMapping("/list")
- @ApiOperationSupport(order = 2)
- @ApiOperation(value = "采购订单表列表(内贸 外贸 出口)", notes = "传入order")
- public R<?> list( @RequestParam(name = "current", defaultValue = "1") Integer current,
- @RequestParam(name = "size", defaultValue = "10") Integer size,
- @RequestParam(value = "billNo",required = false) String billNo,//提单号
- @RequestParam(value = "orderNo",required = false) String orderNo,//合同号
- @RequestParam(value = "tradeType",required = false) String tradeType,//贸易类型
- @RequestParam(value = "strCorpName",required = false) String strCorpName,//供应商名称
- @RequestParam(value = "corpId",required = false) String corpId,//供应商id
- @RequestParam(value = "strPurchaserName",required = false) String strPurchaserName,//采购商名称
- @RequestParam(value = "salesName",required = false) String salesName,//业务员
- @RequestParam(value = "banksAccountName",required = false) String banksAccountName,//公司户头
- @RequestParam(value = "packageRemarks",required = false) String packageRemarks,//包装要求
- @RequestParam(value = "createUser",required = false) Long createUser,//制单人
- @RequestParam(value = "paymentType",required = false) String paymentType,//付款方式
- @RequestParam(value = "createStartTime",required = false) String createStartTime,//制单日期
- @RequestParam(value = "createEndTime",required = false) String createEndTime,//制单日期
- @RequestParam(value = "businesStartDate",required = false) String businesStartDate,//订单开始时间 busines_date
- @RequestParam(value = "businesEndDate",required = false) String businesEndDate,//订单结束时间
- @RequestParam(value = "accountsCollectionStartDate",required = false) String accountsCollectionStartDate,//应收(付)款开始时间 accounts_collection_date
- @RequestParam(value = "accountsCollectionEndDate",required = false) String accountsCollectionEndDate,//应收(付)款结束时间
- @RequestParam(value = "dateOfStartArrival",required = false) String dateOfStartArrival,//实际到港开始日期 date_of_arrival
- @RequestParam(value = "dateOfEndArrival",required = false) String dateOfEndArrival,//实际到港结束时间,
- @RequestParam(value = "requiredDeliveryStartDate",required = false) String requiredDeliveryStartDate,//要求发货开始日期 required_delivery_date
- @RequestParam(value = "requiredDeliveryEndDate",required = false) String requiredDeliveryEndDate,//要求发货结束时间
- @RequestParam(value = "requiredArrivalStartDate",required = false) String requiredArrivalStartDate,//要求到货开始日期 required_arrival_date
- @RequestParam(value = "requiredArrivalEndDate",required = false) String requiredArrivalEndDate,//要求到货结束日期
- @RequestParam(value = "creditStartDate",required = false) String creditStartDate,//信用证到期日-开始日期 credit_date
- @RequestParam(value = "creditEndDate",required = false) String creditEndDate,//信用证到期日-结束时间
- @RequestParam(value = "storageId",required = false) Long storageId,//仓库id
- Order order
- )
- {
- QueryWrapper<Order> queryWrapper =new QueryWrapper<>();
- //供应商
- if(StringUtils.isNotBlank(strCorpName))
- {
- List<CorpsDesc> corpsDescs = corpsDescClient.listCorpByName(strCorpName);
- if(CollectionUtils.isNotEmpty(corpsDescs))
- {
- List<Long> corpIds = corpsDescs.stream().map(CorpsDesc::getId).collect(Collectors.toList());
- queryWrapper.in("corp_id",corpIds);
- }
- else
- {
- return R.data(Collections.EMPTY_LIST,"暂无相关数据");
- }
- }
- //采购商
- if(StringUtils.isNotBlank(strPurchaserName))
- {
- List<CorpsDesc> corpsDescs = corpsDescClient.listCorpByName(strPurchaserName);
- if(CollectionUtils.isNotEmpty(corpsDescs))
- {
- List<Long> purchaserIds = corpsDescs.stream().map(CorpsDesc::getId).collect(Collectors.toList());
- queryWrapper.in("purchaser_id",purchaserIds);
- }
- else
- {
- return R.data(Collections.EMPTY_LIST,"暂无相关数据");
- }
- }
- queryWrapper.like(StringUtils.isNotBlank(banksAccountName),"banks_account_name",banksAccountName);
- queryWrapper.like(StringUtils.isNotBlank(packageRemarks),"package_remarks",packageRemarks);
- queryWrapper.like(StringUtils.isNotBlank(salesName),"sales_name",salesName);
- queryWrapper.like(StringUtils.isNotBlank(orderNo),"order_no",orderNo);
- queryWrapper.like(StringUtils.isNotBlank(paymentType),"payment_type",paymentType);
- queryWrapper.eq(StringUtils.isNotBlank(corpId),"corp_id",corpId);
- queryWrapper.eq(storageId != null,"storage_id",storageId);//仓库id
- queryWrapper.eq("tenant_id",AuthUtil.getTenantId());
- queryWrapper.eq(createUser!=null,"create_user",createUser);
- queryWrapper.eq("bill_type",OrderTypeEnum.PURCHASE.getType());
- queryWrapper.eq("trade_type",OrderTypeEnum.DEALER.getType());
- queryWrapper.like(StringUtils.isNotBlank(billNo),"bill_no",billNo);
- queryWrapper.between(StringUtils.isNotBlank(createStartTime)&&StringUtils.isNotBlank(createEndTime),"create_time",createStartTime,createEndTime);
- queryWrapper.between(StringUtils.isNotBlank(businesStartDate)&&StringUtils.isNotBlank(businesEndDate),"busines_date",businesStartDate,businesEndDate);
- queryWrapper.between(StringUtils.isNotBlank(accountsCollectionStartDate)&&StringUtils.isNotBlank(accountsCollectionEndDate),"accounts_collection_date",accountsCollectionStartDate,accountsCollectionEndDate);
- queryWrapper.between(StringUtils.isNotBlank(dateOfStartArrival)&&StringUtils.isNotBlank(dateOfEndArrival),"date_of_arrival",dateOfStartArrival,dateOfEndArrival);
- queryWrapper.between(StringUtils.isNotBlank(requiredDeliveryStartDate)&&StringUtils.isNotBlank(requiredDeliveryEndDate),"required_delivery_date",requiredDeliveryStartDate,requiredDeliveryEndDate);
- queryWrapper.between(StringUtils.isNotBlank(requiredArrivalStartDate)&&StringUtils.isNotBlank(requiredArrivalEndDate),"required_arrival_date",requiredArrivalStartDate,requiredArrivalEndDate);
- queryWrapper.between(StringUtils.isNotBlank(creditStartDate)&&StringUtils.isNotBlank(creditEndDate),"credit_date",creditStartDate,creditEndDate);
- queryWrapper.orderByDesc("create_time");
- Page<Order> page=new Page<>(current,size);
- IPage<Order> pages = orderService.page(page,queryWrapper);
- List<Order> records = pages.getRecords();
- if(CollectionUtils.isNotEmpty(records))
- {
- records.forEach(e->{
- if(e.getBelongToCorpId()!=null)
- {
- R<CorpsDesc> corpMessage3 = corpsDescClient.getCorpMessage(e.getBelongToCorpId());
- if(corpMessage3.getData()!=null)
- {
- e.setBelongToCorpName(corpMessage3.getData().getCname());
- }
- }
- //制单人名字
- if(e.getCreateUser()!=null)
- {
- R<User> userR = userClient.userInfoById(e.getCreateUser());
- if(userR.isSuccess())
- {
- e.setCreateUserName(userR.getData().getRealName());
- }
- }
- //修改制单人名字
- if(e.getUpdateUser()!=null)
- {
- R<User> userR = userClient.userInfoById(e.getUpdateUser());
- if(userR.isSuccess())
- {
- e.setUpdateUserName(userR.getData().getRealName());
- }
- }
- //获取供应商中文名
- if (e.getCorpId() != null){
- R<CorpsDesc> corpMessage1 = corpsDescClient.getCorpMessage(e.getCorpId());
- if(corpMessage1.getData()!=null)
- {
- e.setStrCorpName(corpMessage1.getData().getCname());
- }
- }
- //获取采购商中文名
- if (e.getPurchaserId() != null){
- R<CorpsDesc> corpMessage2 = corpsDescClient.getCorpMessage(e.getPurchaserId());
- if(corpMessage2.getData()!=null)
- {
- e.setStrPurchaserName(corpMessage2.getData().getCname());
- }
- }
- //仓库信息
- StorageDesc storageDesc = iStorageClient.findById(e.getStorageId());
- if(storageDesc!=null)
- {
- e.setStorageName(storageDesc.getCname());
- }
- List<OrderItems> orderItemsList = orderItemsService.list(new LambdaQueryWrapper<OrderItems>().eq(OrderItems::getIsDeleted, 0).eq(OrderItems::getPid, e.getId()));
- //是否有子项
- Boolean flag=orderItemsService.count(new LambdaQueryWrapper<OrderItems>().eq(OrderItems::getPid,e.getId()))>0?true:false;
- if(CollectionUtils.isNotEmpty(orderItemsList))
- {
- //子项总件数
- BigDecimal orderQuantity = orderItemsList.stream().filter(it -> it.getOrderQuantity() != null)
- .map(OrderItems::getOrderQuantity)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- e.setOrderQuantity(orderQuantity);
- //已收重量
- BigDecimal actualWeight = orderItemsList.stream().filter(it -> it.getAmount() != null)
- .map(OrderItems::getAmount)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- e.setAmount(actualWeight);
- }
- });
- }
- return R.data(pages);
- }
- /* *//**
- * 自定义分页 销售或采购订单表
- *//*
- @GetMapping("/page")
- @ApiOperationSupport(order = 3)
- @ApiOperation(value = "分页", notes = "传入order")
- public R<IPage<OrderVO>> page(OrderVO order, Query query) {
- order.setIsDeleted(0);
- order.setTenantId(AuthUtil.getTenantId());
- order.setBillType(OrderTypeEnum.PURCHASE.getType());
- order.setTradeType(OrderTypeEnum.IMPORT.getType());
- IPage<OrderVO> pages = orderService.selectOrderPage(Condition.getPage(query), order);
- return R.data(pages);
- }*/
- /**
- * 新增 销售或采购订单表
- */
- /*@PostMapping("/save")
- @ApiOperationSupport(order = 4)
- @ApiOperation(value = "新增", notes = "传入order")
- public R<String> save(@Valid @RequestBody OrderSubmitDto submitDto) {
- return orderService.saveOrderMessage(submitDto);
- }*/
- /**
- * 修改 销售或采购订单表
- */
- /*@PostMapping("/update")
- @ApiOperationSupport(order = 5)
- @ApiOperation(value = "修改", notes = "传入order")
- public R<String> update(@Valid @RequestBody Order order) {
- if (order.getId() == null) {
- return R.fail(ERROR_MSG);
- }
- order.setIsDeleted(1);
- return R.status(orderService.updateById(order));
- }*/
- /**
- * 新增或修改 销售或采购订单表
- */
- @PostMapping("/submit")
- @ApiOperationSupport(order = 6)
- @ApiOperation(value = "新增或修改", notes = "传入order")
- public R<String> submit(@Valid @RequestBody OrderSubmitDto submitDto)
- {
- /*if(ObjectUtil.isEmpty(submitDto.getBillType())||ObjectUtil.isEmpty(submitDto.getSrcId())||ObjectUtil.isEmpty(submitDto.getBusinesDate()))
- {
- throw new ServiceException("来源、合同日期、贸易类型不能为空!");
- }*/
- submitDto.setOrderTypeEnum(OrderTypeEnum.PURCHASE);
- submitDto.setBillType(OrderTypeEnum.PURCHASE.getType());
- submitDto.setTradeType(OrderTypeEnum.DEALER.getType());
- return orderService.submitOrderMessage(submitDto);
- }
- /**
- * 删除 销售或采购订单表
- */
- @PostMapping("/remove")
- @ApiOperationSupport(order = 7)
- @ApiOperation(value = "删除", notes = "传入ids")
- public R<String> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
- return R.status(orderService.removeByIds(Func.toLongList(ids)));
- }
- /**
- * 删除采购明细信息
- */
- @PostMapping("/removeByItem")
- @ApiOperationSupport(order = 8)
- @ApiOperation(value = "删除采购明细信息", notes = "传入order")
- public R<String> update(@Valid @RequestBody OrderItems items) {
- if (items.getId() == null) {
- return R.fail(ERROR_MSG);
- }
- return R.status(orderItemsService.removeById(items.getId()));
- }
- /**
- * 删除费用信息
- */
- @PostMapping("/removeByFees")
- @ApiOperationSupport(order = 8)
- @ApiOperation(value = "删除费用信息", notes = "传入order")
- public R<String> update(@Valid @RequestBody OrderFees order) {
- if (order.getId() == null) {
- return R.fail(ERROR_MSG);
- }
- return R.status(orderFeesService.removeById(order.getId()));
- }
- /**
- * 删除订单文件信息
- *
- * @param order
- * @return
- */
- @PostMapping("/removeByFiles")
- @ApiOperationSupport(order = 9)
- @ApiOperation(value = "删除文件信息", notes = "传入order")
- public R<String> update(@Valid @RequestBody OrderFiles order) {
- if (order.getId() == null) {
- return R.fail(ERROR_MSG);
- }
- return R.status(orderFilesService.removeById(order.getId()));
- }
- @GetMapping("getItemByPid")
- @ApiOperation(value = "查询采购订单的子明细", notes = "通过采购订单的id查询")
- public R getItemByPid(@RequestParam(value = "id",required = true)Long id)
- {
- LambdaQueryWrapper<OrderItems> lambdaQueryWrapper=new LambdaQueryWrapper<>();
- lambdaQueryWrapper.eq(OrderItems::getPid,id);
- List<OrderItems> itemsList = orderItemsService.list(lambdaQueryWrapper);
- return R.data(itemsList);
- }
- @GetMapping("getSysNo")
- @ApiOperation(value = "采购订单获取系统编号prefix=GN JK CK", notes = "采购订单获取系统编号prefix=GN JK CK")
- public R getSysNo(@RequestParam(value = "prefix",required = true)String prefix,
- @RequestParam(value = "tradeType",required = true)String tradeType)
- {
- return orderService.getSysNo(prefix,tradeType);
- }
- @GetMapping("getItemListByConditions")
- @ApiOperation(value = "收发单-获取商品明细", notes = "收发单-获取商品明细")
- public R getItemListByConditions(@RequestParam(name = "current", defaultValue = "1") Integer current,
- @RequestParam(name = "size", defaultValue = "10") Integer size,
- @RequestParam(name = "tradeType", required = true) String tradeType,
- @RequestParam(name = "orderNo", required = false) String orderNo,
- @RequestParam(name = "corpId", required = false) Long corpId,
- @RequestParam(name = "startDate", required = false) String startDate,
- @RequestParam(name = "endDate", required = false) String endDate
- )
- {
- Page<OrderDTO> page=new Page<>(current,size);
- IPage<OrderDTO> iPage = orderService.listOrderItem(page, tradeType, orderNo, corpId, startDate, endDate);
- if(CollectionUtils.isNotEmpty(iPage.getRecords()))
- {
- iPage.getRecords().forEach(e->{
- //商品信息
- R<GoodsDescVO> goodsDescVOR = goodsDescClient.selectGoodsMessage(e.getItemId());
- if(goodsDescVOR.isSuccess())
- {
- GoodsDescVO descVO = goodsDescVOR.getData();
- if(descVO!=null)
- {
- e.setPriceCategoryNames(descVO.getCname());
- }
- }
- //供应商信息
- if (e.getCorpId() != null){
- R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(e.getCorpId());
- if(corpMessage.getData()!=null)
- {
- e.setCorpName(corpMessage.getData().getCname());
- }
- }
- });
- }
- return R.data(iPage);
- }
- /**
- * 更改打印时间和打印次数
- */
- @GetMapping("/print")
- @ApiOperationSupport(order = 11)
- @ApiOperation(value = "更改打印时间和打印次数", notes = "传入order")
- public R<Order> print(Order order) {
- if (order.getId() == null){
- throw new SecurityException("请选择要打印的单据");
- }
- Order service = orderService.getById(order.getId());
- service.setPrintNumber(service.getPrintNumber() +1);
- service.setPrintTime(new Date());
- return R.status(orderService.updateById(service));
- }
- /**
- * 确认或取消订单
- */
- @GetMapping("/dealerSubmit")
- @ApiOperationSupport(order = 12)
- @ApiOperation(value = "确认或取消订单", notes = "传入order")
- public R<Order> dealerSubmit(Order order) {
- if (order.getDealer() != 1 && order.getDealer() != 2){
- throw new SecurityException("缺少必要的参数");
- }
- if (order.getId() == null){
- throw new SecurityException("缺少必要的参数");
- }
- return orderService.dealerSubmit(order);
- }
- }
|