|
|
@@ -0,0 +1,391 @@
|
|
|
+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.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("/purchaseContract")
|
|
|
+@Api(value = "经销商采购合同", tags = "经销商采购合同")
|
|
|
+public class PurchaseContract {
|
|
|
+ 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_CONTRACT.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);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 新增或修改 经销商采购合同
|
|
|
+ */
|
|
|
+ @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_CONTRACT);
|
|
|
+ submitDto.setBillType(OrderTypeEnum.PURCHASE_CONTRACT.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("/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));
|
|
|
+ }
|
|
|
+ //经销商采购合同审批
|
|
|
+ //经销商采购合同提交平台生成平台销售订单
|
|
|
+}
|