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.
udi-spms-java/src/main/java/com/glxp/api/controller/inout/IoOrderInvoiceController.java

197 lines
9.7 KiB
Java

package com.glxp.api.controller.inout;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.annotation.Log;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BusinessType;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
import com.glxp.api.entity.inout.IoOrderDetailCodeEntity;
import com.glxp.api.entity.inout.IoOrderEntity;
import com.glxp.api.entity.inout.IoOrderInvoiceEntity;
import com.glxp.api.req.inout.FilterOrderDetailCodeRequest;
import com.glxp.api.req.inout.IoOrderInvoiceRequest;
import com.glxp.api.req.inout.RefreshInoiceRequest;
import com.glxp.api.req.system.DeleteRequest;
import com.glxp.api.res.inout.IoOrderDetailCodeResponse;
import com.glxp.api.res.inout.IoOrderInvoiceResponse;
import com.glxp.api.res.inout.IoOrderResponse;
import com.glxp.api.res.inout.RefreshInoiceResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.inout.IoOrderDetailBizService;
import com.glxp.api.service.inout.IoOrderDetailCodeService;
import com.glxp.api.service.inout.impl.IoOrderInvoiceService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
public class IoOrderInvoiceController {
@Resource
IoOrderInvoiceService ioOrderInvoiceService;
@Resource
IoOrderDetailCodeService orderDetailCodeService;
@Resource
CustomerService customerService;
@Resource
IoOrderDetailBizService orderDetailBizService;
@AuthRuleAnnotation("")
@PostMapping("/udiwms/inout/order/refrshInvoice")
@Log(title = "发票", businessType = BusinessType.INSERT)
public BaseResponse addBizProduct(@RequestBody RefreshInoiceRequest refreshInoiceRequest) {
IoOrderInvoiceRequest orderInvoiceRequest = new IoOrderInvoiceRequest();
BeanUtils.copyProperties(refreshInoiceRequest, orderInvoiceRequest);
List<IoOrderInvoiceEntity> orderInvoiceEntities = ioOrderInvoiceService.findByBillNo(orderInvoiceRequest.getOrderIdFk());
List<IoOrderDetailCodeEntity> orderDetailCodeEntities = orderDetailCodeService.findByOrderId(orderInvoiceRequest.getOrderIdFk());
RefreshInoiceResponse response = new RefreshInoiceResponse();
response.setOrderInvoiceEntities(orderInvoiceEntities);
response.setOrderDetailCodeEntities(orderDetailCodeEntities);
if (CollUtil.isEmpty(orderInvoiceEntities))
return ResultVOUtils.error(500, "查无发票信息!");
return ResultVOUtils.success(response);
}
//分组查询发票列表
@AuthRuleAnnotation("")
@GetMapping("/udiwms/inout/order/group/invoice")
public BaseResponse filterGroup(IoOrderInvoiceRequest orderInvoiceRequest) {
List<IoOrderInvoiceResponse> orderInvoiceEntities = ioOrderInvoiceService.filterGroupBy(orderInvoiceRequest);
PageInfo<IoOrderInvoiceResponse> pageInfo = new PageInfo<>(orderInvoiceEntities);
return ResultVOUtils.page(pageInfo);
}
//发票对应产品信息汇总
@AuthRuleAnnotation("")
@GetMapping("/udiwms/inout/invoice/product/detail")
public BaseResponse productDetail(IoOrderInvoiceRequest orderInvoiceRequest) {
if (StrUtil.isEmpty(orderInvoiceRequest.getInvoiceEncode()))
return ResultVOUtils.error(500, "发票编码不能为空!");
List<IoOrderInvoiceResponse> orderInvoiceEntities = ioOrderInvoiceService.filterInvoice(orderInvoiceRequest);
//计算金额
for (IoOrderInvoiceResponse orderInvoiceEntity : orderInvoiceEntities) {
if (orderInvoiceEntity.getPrice() != null && orderInvoiceEntity.getReCount() != 0) {
orderInvoiceEntity.setAmout(new BigDecimal(orderInvoiceEntity.getPrice()).multiply(new BigDecimal(orderInvoiceEntity.getReCount())));
}
}
PageInfo<IoOrderInvoiceResponse> pageInfo = new PageInfo<>(orderInvoiceEntities);
return ResultVOUtils.page(pageInfo);
}
//发票对应所有单据
@AuthRuleAnnotation("")
@GetMapping("/udiwms/inout/invoice/order/detail")
public BaseResponse orderDetail(IoOrderInvoiceRequest orderInvoiceRequest) {
List<IoOrderResponse> orderInvoiceEntities = ioOrderInvoiceService.filterByInvoiceCode(orderInvoiceRequest);
for (IoOrderResponse orderInvoiceEntity : orderInvoiceEntities) {
ioOrderInvoiceService.findRegStausByBillNo(orderInvoiceEntity);
}
PageInfo<IoOrderResponse> pageInfo = new PageInfo<>(orderInvoiceEntities);
return ResultVOUtils.page(pageInfo);
}
@AuthRuleAnnotation("")
@PostMapping("/udiwms/inout/invoice/delete")
@Log(title = "发票删除", businessType = BusinessType.DELETE)
public BaseResponse deleteInvoice(@RequestBody DeleteRequest deleteRequest) {
if (StrUtil.isEmpty(deleteRequest.getInvoiceEncode()))
return ResultVOUtils.error(500, "发票编码不能为空");
boolean b = ioOrderInvoiceService.remove(new QueryWrapper<IoOrderInvoiceEntity>().eq("invoiceEncode", deleteRequest.getInvoiceEncode()));
if (b)
return ResultVOUtils.success("删除成功!");
else
return ResultVOUtils.error(500, "删除失败!");
}
@AuthRuleAnnotation("")
@PostMapping("/udiwms/inout/invoice/saveInvoice")
@Log(title = "发票增加", businessType = BusinessType.INSERT)
public BaseResponse saveInvoice(@RequestBody IoOrderInvoiceRequest ioOrderInvoiceRequest) {
List<String> orderFkList = ioOrderInvoiceRequest.getOrderFkList();
List<IoOrderInvoiceEntity> ioOrderInvoiceEntityList = new ArrayList<>();
for (String orderFk : orderFkList) {
//查询单据详情
FilterOrderDetailCodeRequest orderDetailBizRequest = new FilterOrderDetailCodeRequest();
orderDetailBizRequest.setOrderIdFk(orderFk);
List<IoOrderDetailCodeResponse> ioOrderDetailCodeResponses = orderDetailBizService.getfilterOrderList(orderDetailBizRequest);
for (IoOrderDetailCodeResponse ioOrderDetailCodeRespons : ioOrderDetailCodeResponses) {
IoOrderInvoiceEntity ioOrderInvoiceEntity = new IoOrderInvoiceEntity();
BeanUtils.copyProperties(ioOrderInvoiceRequest, ioOrderInvoiceEntity);
ioOrderInvoiceEntity.setId(IdUtil.getSnowflakeNextId());
ioOrderInvoiceEntity.setOrderIdFk(orderFk);
ioOrderInvoiceEntity.setUpdateTime(new Date());
ioOrderInvoiceEntity.setCreateTime(new Date());
ioOrderInvoiceEntity.setCreateUser(customerService.getUserId() + "");
ioOrderInvoiceEntity.setUpdateUser(customerService.getUserId() + "");
ioOrderInvoiceEntity.setBindRlFk(ioOrderDetailCodeRespons.getBindRlFk() + "");
ioOrderInvoiceEntity.setBatchNo(ioOrderDetailCodeRespons.getBatchNo());
ioOrderInvoiceEntity.setProductDate(ioOrderDetailCodeRespons.getProductDate());
ioOrderInvoiceEntity.setExpireDate(ioOrderDetailCodeRespons.getExpireDate());
ioOrderInvoiceEntityList.add(ioOrderInvoiceEntity);
}
}
boolean b = ioOrderInvoiceService.saveBatch(ioOrderInvoiceEntityList);
if (b)
return ResultVOUtils.success("选入成功!");
else
return ResultVOUtils.error(500, "选入失败!");
}
@PostMapping("/udiwms/inout/invoice/uploadInvoice")
@Log(title = "发票管理", businessType = BusinessType.UPDATE)
public BaseResponse uploadInvoice(@RequestBody IoOrderInvoiceEntity ioOrderInvoice) {
List<IoOrderInvoiceEntity> ioOrderInvoiceEntityList=ioOrderInvoiceService.list(new QueryWrapper<IoOrderInvoiceEntity>().eq("invoiceEncode",ioOrderInvoice.getInvoiceEncode()));
for (IoOrderInvoiceEntity ioOrderInvoiceEntity : ioOrderInvoiceEntityList) {
ioOrderInvoiceEntity.setInvoiceDate(ioOrderInvoice.getInvoiceDate());
ioOrderInvoiceEntity.setPrice(ioOrderInvoice.getPrice());
ioOrderInvoiceEntity.setLicenseUrl(ioOrderInvoice.getLicenseUrl());
ioOrderInvoiceEntity.setRemark(ioOrderInvoice.getRemark());
ioOrderInvoiceEntity.setMachineNo(ioOrderInvoice.getMachineNo());
ioOrderInvoiceEntity.setInvoiceCode(ioOrderInvoice.getInvoiceCode());
ioOrderInvoiceEntity.setUpdateTime(new Date());
}
ioOrderInvoiceService.updateBatchById(ioOrderInvoiceEntityList);
return ResultVOUtils.success("成功");
}
@AuthRuleAnnotation("")
@PostMapping("/udiwms/inout/invoice/deleteInvoiceByOrderFk")
@Log(title = "发票删除", businessType = BusinessType.DELETE)
public BaseResponse deleteInvoiceByOrderFk(@RequestBody DeleteRequest deleteRequest) {
if (StrUtil.isEmpty(deleteRequest.getInvoiceEncode()))
return ResultVOUtils.error(500, "发票编码不能为空");
boolean b = ioOrderInvoiceService.remove(new QueryWrapper<IoOrderInvoiceEntity>().eq("invoiceEncode", deleteRequest.getInvoiceEncode()).eq("orderIdFk",deleteRequest.getBillNo()));
if (b)
return ResultVOUtils.success("删除成功!");
else
return ResultVOUtils.error(500, "删除失败!");
}
}