374 lines
15 KiB
Plaintext
374 lines
15 KiB
Plaintext
package com.cmeim.biz.controller;
|
||
|
||
import com.cmeim.biz.po.MmOtheroutBill;
|
||
import com.cmeim.biz.po.MmOtheroutBillDetail;
|
||
import com.cmeim.biz.po.MmOtheroutBillItem;
|
||
import com.cmeim.biz.po.MmPickBill;
|
||
import com.cmeim.biz.po.MmSporadicPickBill;
|
||
import com.cmeim.biz.po.MmSporadicPickBillDetail;
|
||
import com.cmeim.biz.repository.MmOtheroutBillRepository;
|
||
import com.cmeim.biz.repository.MmPickBillRepository;
|
||
import com.cmeim.biz.service.OtheroutBillService;
|
||
import com.cmeim.biz.service.PickBillService;
|
||
import com.cmeim.biz.vo.BarVo;
|
||
import com.cmeim.biz.vo.MmOtheroutBillVo;
|
||
import com.cmeim.biz.vo.MmPickBillVo;
|
||
import com.cmeim.common.core.exception.ServiceException;
|
||
import com.cmeim.common.core.utils.ExcelExportUtil;
|
||
import com.cmeim.common.core.web.controller.GenericController;
|
||
import com.cmeim.common.core.web.domain.Respond;
|
||
import com.cmeim.common.core.web.domain.RespondEnum;
|
||
import com.cmeim.common.core.web.page.PageVo;
|
||
import com.cmeim.erp.service.api.ErpUploadService;
|
||
import com.cmeim.kafka.api.dto.output.SyncPickBillDto;
|
||
import com.cmeim.stock.service.RemoteService;
|
||
import com.google.common.collect.Lists;
|
||
import io.swagger.annotations.Api;
|
||
import io.swagger.annotations.ApiImplicitParam;
|
||
import io.swagger.annotations.ApiImplicitParams;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.data.domain.Page;
|
||
import org.springframework.data.domain.PageRequest;
|
||
import org.springframework.data.domain.Sort;
|
||
import org.springframework.data.jpa.domain.Specification;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
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.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import javax.persistence.criteria.CriteriaBuilder;
|
||
import javax.persistence.criteria.CriteriaQuery;
|
||
import javax.persistence.criteria.Join;
|
||
import javax.persistence.criteria.JoinType;
|
||
import javax.persistence.criteria.Path;
|
||
import javax.persistence.criteria.Predicate;
|
||
import javax.persistence.criteria.Root;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.util.List;
|
||
|
||
@Api(value = "其他出库单")
|
||
@RestController
|
||
@RequestMapping(value = "output/otheroutBill")
|
||
public class OtheroutBillController extends GenericController {
|
||
@Autowired
|
||
private OtheroutBillService billService;
|
||
@Autowired
|
||
private PickBillService pickBillService;
|
||
@Autowired
|
||
private MmPickBillRepository pickBillRepository;
|
||
@Autowired
|
||
private MmOtheroutBillRepository repository;
|
||
@Autowired
|
||
private ErpUploadService erpUploadService;
|
||
@Autowired
|
||
private RemoteService remoteService;
|
||
|
||
/**
|
||
* 列表
|
||
*/
|
||
@ApiOperation(value = "列表")
|
||
@GetMapping(value = "list")
|
||
public Respond list(PageVo pv, MmOtheroutBillVo query) {
|
||
if (pv.getOrders() == null || pv.getOrders().length == 0) {
|
||
String[] orders = {"createdDt desc"};
|
||
pv.setOrders(orders);
|
||
}
|
||
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(),
|
||
Sort.by(sortOrder(pv.getOrders())));
|
||
Page page = repository.findAll(buildSpecification(query), pageRequest);
|
||
List<MmOtheroutBill> list = page.getContent();
|
||
pv.setRecordsTotal(page.getTotalElements());
|
||
for (MmOtheroutBill otheroutBill : list) {
|
||
otheroutBill.setCreater(remoteService.getNickName(otheroutBill.getCreatedBy()));
|
||
otheroutBill.setModifier(remoteService.getNickName(otheroutBill.getUpdatedBy()));
|
||
for (MmOtheroutBillDetail item : otheroutBill.getItems()) {
|
||
item.setCreater(remoteService.getNickName(item.getCreatedBy()));
|
||
item.setModifier(remoteService.getNickName(item.getUpdatedBy()));
|
||
}
|
||
}
|
||
pv.setData(list);
|
||
return buildSuccess(pv);
|
||
}
|
||
|
||
/**
|
||
* 入库单创建时间更改
|
||
*/
|
||
@ApiOperation(value = "入库单创建时间更改")
|
||
@PostMapping(value = "updateCreateTime")
|
||
@Transactional
|
||
public Respond updateCreateTime(@RequestBody List<String> ids) {
|
||
ids.forEach(id -> {
|
||
final MmOtheroutBill mmInputBill = repository.findById(Long.parseLong(id.split(";")[0])).get();
|
||
mmInputBill.setCreatedDt(id.split(";")[1]);
|
||
mmInputBill.getItems().forEach(e -> {
|
||
e.setCreatedDt(id.split(";")[1]);
|
||
});
|
||
repository.save(mmInputBill);
|
||
|
||
});
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 明细列表
|
||
*/
|
||
@ApiOperation(value = "明细列表")
|
||
@GetMapping(value = "list/dtls")
|
||
public Respond listDtls(PageVo pv, MmOtheroutBillDetail query) {
|
||
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(), Sort.by(Sort.Order.desc("id")));
|
||
Page page = billService.findDetails(query, pageRequest);
|
||
pv.setRecordsTotal(page.getTotalElements());
|
||
pv.setData(page.getContent());
|
||
return buildSuccess(pv);
|
||
}
|
||
|
||
/**
|
||
* 领取记录列表
|
||
*/
|
||
@ApiOperation(value = "领取记录列表")
|
||
@GetMapping(value = "list/items")
|
||
public Respond listItems(PageVo pv, MmOtheroutBillItem query) {
|
||
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(), Sort.by(Sort.Order.desc("id")));
|
||
Page page = billService.findItems(query, pageRequest);
|
||
pv.setRecordsTotal(page.getTotalElements());
|
||
pv.setData(page.getContent());
|
||
return buildSuccess(pv);
|
||
}
|
||
|
||
/**
|
||
* 详情
|
||
*/
|
||
@ApiOperation(value = "详情")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "outId", value = "其他出库单ID", required = true)
|
||
})
|
||
@GetMapping(value = "queryById")
|
||
public Respond queryById(Long outId) {
|
||
if (outId == null) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单Id为空");
|
||
}
|
||
return buildSuccess(billService.get(outId));
|
||
}
|
||
|
||
/**
|
||
* 创建其他出库单
|
||
*/
|
||
@ApiOperation(value = "创建其他出库单")
|
||
@PostMapping(value = "add")
|
||
public Respond add(@RequestBody MmOtheroutBill bill) {
|
||
if (bill.getItems() == null || bill.getItems().size() == 0) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单明细为空");
|
||
}
|
||
for (MmOtheroutBillDetail detail : bill.getItems()) {
|
||
if (detail.getPlanQty() == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("物料【%s】数量【空】异常",
|
||
detail.getMaterialCode()));
|
||
}
|
||
if (detail.getPlanQty().doubleValue() <= 0) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("物料【%s】数量【%d】异常",
|
||
detail.getMaterialCode(), detail.getPlanQty()));
|
||
}
|
||
}
|
||
billService.create(bill, this.getCurrentUser());
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 其他出库单明细
|
||
*/
|
||
@ApiOperation(value = "其他出库单明细")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "number", value = "其他出库单编码", required = true)
|
||
})
|
||
@GetMapping(value = "number")
|
||
public Respond number(String number) {
|
||
if (StringUtils.isBlank(number)) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单编码为空");
|
||
}
|
||
return buildSuccess(billService.findByNumber(number));
|
||
}
|
||
|
||
|
||
/**
|
||
* 其他出库完成
|
||
*/
|
||
@ApiOperation(value = "其他出库完成")
|
||
@ApiImplicitParams({
|
||
@ApiImplicitParam(name = "outId", value = "其他出库单Id", required = true)
|
||
})
|
||
@PostMapping(value = "finish")
|
||
public Respond finish(Long outId) {
|
||
if (outId == null) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单Id为空");
|
||
}
|
||
billService.finish(outId, this.getCurrentUser());
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
*/
|
||
@ApiOperation(value = "删除")
|
||
@PostMapping(value = "delete")
|
||
public Respond delete(@RequestBody List<Long> outIds) {
|
||
if (outIds == null || outIds.isEmpty()) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单Id为空");
|
||
}
|
||
for (Long outId : outIds) {
|
||
MmOtheroutBill mmOtheroutBill = repository.findById(outId).get();
|
||
if (StringUtils.isNotBlank(mmOtheroutBill.getErpNumber())) {
|
||
throw new ServiceException(
|
||
RespondEnum.PARAMETER_ERROR, "其他出库单【" + mmOtheroutBill.getOutBillNumber() + "已上传erp,不能删除");
|
||
}
|
||
}
|
||
billService.delete(outIds);
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 出库条码校验
|
||
*/
|
||
@ApiOperation(value = "出库条码校验")
|
||
@GetMapping(value = "validateBarOut")
|
||
public Respond validateBarOut(String bar) {
|
||
|
||
MmPickBill pickingBill = pickBillRepository.findByPickBillNumber(bar);
|
||
if (pickingBill != null) {
|
||
BarVo vo = new BarVo();
|
||
vo.setBarType("PICK");
|
||
vo.setData(pickingBill);
|
||
return buildSuccess(vo);
|
||
}
|
||
|
||
return buildFailure("条码【" + bar + "】无效!");
|
||
}
|
||
|
||
/**
|
||
* 其他出库单修改
|
||
*/
|
||
@ApiOperation(value = "其他出库单修改")
|
||
@PostMapping(value = "update")
|
||
@Transactional
|
||
public Respond update(@RequestBody MmOtheroutBill otheroutBill) {
|
||
List<MmOtheroutBillDetail> items = otheroutBill.getItems();
|
||
if (items == null || items.size() == 0) {
|
||
throw new ServiceException(RespondEnum.PARAMETER_ERROR, "其他出库单明细为空");
|
||
}
|
||
if (StringUtils.isNotBlank(otheroutBill.getErpNumber())) {
|
||
throw new ServiceException(
|
||
RespondEnum.PARAMETER_ERROR, "其他出库单【" + otheroutBill.getOutBillNumber() + "已上传erp,不能修改");
|
||
}
|
||
return buildSuccess(billService.update(otheroutBill, this.getCurrentUser()));
|
||
}
|
||
|
||
/**
|
||
* 导出其他出库单列表
|
||
*/
|
||
@ApiOperation(value = "导出其他出库单列表")
|
||
@GetMapping(value = "exportExcel")
|
||
public void exportExcel(MmOtheroutBillVo otheroutBillVo, HttpServletResponse response) throws Exception {
|
||
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
||
SXSSFSheet sheet = workbook.createSheet("其他出库单");
|
||
|
||
List<MmOtheroutBill> list = billService.findAllExp(otheroutBillVo);
|
||
|
||
String[] cloumns = new String[]{"序号", "其他出库单号", "单据类型", "状态", "部门编码", "部门名称",
|
||
"出库完成时间", "仓库编码", "仓库名称", "业务员编码", "业务员名称",
|
||
"物料编码", "物料名称", "物料规格", "计量单位", "批次", "库区代码", "库区名称", "计划出库数量", "实际出库数量",
|
||
"创建人", "创建时间", "更新人", "更新时间"};
|
||
List<Object[]> datalist = billService.initPrintData(list, cloumns);
|
||
ExcelExportUtil.getExportWorkbook(workbook, sheet, cloumns, datalist);
|
||
ExcelExportUtil.sendHttpResponse(response, "otherOutBill", workbook);
|
||
}
|
||
|
||
/**
|
||
* 同步其他出库单到智能仓储柜
|
||
*/
|
||
@ApiOperation(value = "同步其他出库单到智能仓储柜")
|
||
@PostMapping(value = "sync")
|
||
public Respond sync(@RequestBody SyncPickBillDto syncPickBillDto) {
|
||
pickBillService.syncPickBill(syncPickBillDto);
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 推送ERP
|
||
*/
|
||
@ApiOperation(value = "推送ERP")
|
||
@PostMapping(value = "sendToErp")
|
||
public Respond sendToErp(@RequestBody List<String> billNumber) {
|
||
for (String s : billNumber) {
|
||
erpUploadService.sendToErpForOtherOutput(s);
|
||
}
|
||
return buildSuccess();
|
||
}
|
||
|
||
private Specification buildSpecification(final MmOtheroutBillVo entity) {
|
||
Specification specification = new Specification<MmPickBillVo>() {
|
||
@Override
|
||
public Predicate toPredicate(Root<MmPickBillVo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
||
List<Predicate> predicates = Lists.newArrayList();
|
||
if (entity.getDictStatusArr() != null) {
|
||
Path path;
|
||
Join join = root.join("items", JoinType.LEFT);
|
||
path = join.get("dictStatus");
|
||
CriteriaBuilder.In<Integer> in = cb.in(path);
|
||
for (Integer status : entity.getDictStatusArr()) {
|
||
in.value(status);
|
||
}
|
||
predicates.add(in);
|
||
}
|
||
if (entity.getDictTypeArr() != null) {
|
||
CriteriaBuilder.In<Integer> in = cb.in(root.get("dictType").as(Integer.class));
|
||
for (Integer status : entity.getDictTypeArr()) {
|
||
in.value(status);
|
||
}
|
||
predicates.add(in);
|
||
}
|
||
|
||
if (StringUtils.isNotBlank(entity.getOutBillNumber())) {
|
||
predicates.add(cb.like(root.get("outBillNumber").as(String.class),
|
||
"%" + entity.getOutBillNumber() + "%"));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getErpNumber())) {
|
||
predicates.add(cb.like(root.get("erpNumber").as(String.class),
|
||
"%" + entity.getErpNumber() + "%"));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getSalesmanCode())) {
|
||
predicates.add(cb.equal(root.get("salesmanCode").as(String.class), entity.getSalesmanCode()));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getWarehouseCode())) {
|
||
predicates.add(cb.equal(root.get("warehouseCode").as(String.class), entity.getWarehouseCode()));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getMaterialCode())) {
|
||
Path path;
|
||
Join join = root.join("items", JoinType.LEFT);
|
||
path = join.get("materialCode");
|
||
predicates.add(cb.like(path, "%" + entity.getMaterialCode() + "%"));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getMaterialName())) {
|
||
Path path;
|
||
Join join = root.join("items", JoinType.LEFT);
|
||
path = join.get("materialName");
|
||
predicates.add(cb.like(path, "%" + entity.getMaterialName() + "%"));
|
||
}
|
||
if (StringUtils.isNotBlank(entity.getMaterialSpec())) {
|
||
Path path;
|
||
Join join = root.join("items", JoinType.LEFT);
|
||
path = join.get("materialSpec");
|
||
predicates.add(cb.like(path, "%" + entity.getMaterialSpec() + "%"));
|
||
}
|
||
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
||
}
|
||
};
|
||
return specification;
|
||
}
|
||
|
||
}
|