392 lines
18 KiB
Plaintext
392 lines
18 KiB
Plaintext
package com.cmeim.biz.controller.app;
|
||
|
||
import com.cmeim.basic.api.dto.BaCrWarehouseRelationshipDto;
|
||
import com.cmeim.basic.api.dto.MaterialDto;
|
||
import com.cmeim.biz.po.*;
|
||
import com.cmeim.biz.repository.MmArriveBillRepository;
|
||
import com.cmeim.biz.repository.MmInputBillDetailRepository;
|
||
import com.cmeim.biz.repository.MmInputBillRepository;
|
||
import com.cmeim.biz.repository.MmMaterialBarRepository;
|
||
import com.cmeim.biz.repository.SaomaRepository;
|
||
import com.cmeim.biz.service.InputAppService;
|
||
import com.cmeim.biz.service.InputMaterialBarService;
|
||
import com.cmeim.biz.service.InputRemoteService;
|
||
import com.cmeim.biz.service.ProdInBillService;
|
||
import com.cmeim.biz.service.SaomaService;
|
||
import com.cmeim.biz.vo.MaterialBarVo;
|
||
import com.cmeim.biz.vo.SemiProduckParm;
|
||
import com.cmeim.biz.vo.app.AnalysisBarVo;
|
||
import com.cmeim.biz.vo.app.ProduckStockInVo;
|
||
import com.cmeim.common.core.exception.ServiceException;
|
||
import com.cmeim.common.core.utils.BeanUtil;
|
||
import com.cmeim.common.core.utils.DateUtil;
|
||
import com.cmeim.common.core.utils.SecurityUtils;
|
||
import com.cmeim.common.core.web.controller.GenericController;
|
||
import com.cmeim.common.core.web.domain.Respond;
|
||
import com.cmeim.biz.vo.WCSLampArray;
|
||
import com.cmeim.common.core.web.domain.RespondEnum;
|
||
import com.cmeim.stock.dto.MmStockDto;
|
||
import com.cmeim.stock.po.*;
|
||
import com.cmeim.stock.repository.*;
|
||
import com.cmeim.stock.service.StockService;
|
||
import io.swagger.annotations.Api;
|
||
import io.swagger.annotations.ApiOperation;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
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 java.math.BigDecimal;
|
||
import java.util.List;
|
||
import java.util.stream.Collectors;
|
||
|
||
@Slf4j
|
||
@Api(value = "app", tags = "APP通用模块")
|
||
@RestController
|
||
@RequestMapping(value = "input/app/general")
|
||
public class InputAppGeneralController extends GenericController {
|
||
|
||
@Autowired
|
||
private InputAppService service;
|
||
@Autowired
|
||
private InputMaterialBarService materialBarService;
|
||
@Autowired
|
||
private ProdInBillService prodInBillService;
|
||
@Autowired
|
||
private StockService stockService;
|
||
@Autowired
|
||
private MmInputBillDetailRepository inputBillDetailRepository;
|
||
@Autowired
|
||
private MmArriveBillRepository mmArriveBillRepository;
|
||
@Autowired
|
||
private InputRemoteService remoteService;
|
||
@Autowired
|
||
private MmMaterialBarRepository mmMaterialBarRepository;
|
||
@Autowired
|
||
private SaomaRepository saomaRepository;
|
||
@Autowired
|
||
private MmStockRepository mmStockRepository;
|
||
@Autowired
|
||
private MmStockSummaryRepository mmStockSummaryRepository;
|
||
@Autowired
|
||
private MmInputBillRepository inputBillRepository;
|
||
@Autowired
|
||
private MmStockBizRepository mmStockBizRepository;
|
||
@Autowired
|
||
private MmStockCheckBizRepository mmStockCheckBizRepository;
|
||
@Autowired
|
||
private MmStockAreaRepository areaRepository;
|
||
@Autowired
|
||
private SaomaService saomaService;
|
||
@Autowired
|
||
private BaWareHouseRepository baWareHouseRepository;
|
||
@Autowired
|
||
private MmStockElectronRepository electronRepository;
|
||
@Autowired
|
||
private BalocationRepository balocationRepository;
|
||
|
||
@ApiOperation(value = "APP查询新老接口表")
|
||
@GetMapping(value = "getBarSaoMaAndBar")
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public Respond getBarSaoMaAndBar(String materialBar) {
|
||
if (mmMaterialBarRepository.existsByMaterialBar(materialBar)) {
|
||
return buildSuccess(BeanUtil.copyProperties(mmMaterialBarRepository.findByMaterialBar(materialBar),
|
||
MaterialBarVo.class));
|
||
}
|
||
if (saomaRepository.existsByMessage(materialBar)) {
|
||
Saoma saoma = saomaRepository.findByMessage(materialBar);
|
||
MmStock mmStock = mmStockRepository.findByMaterialBar(materialBar);
|
||
//如果扫码表和库存都有,则新增条码(不应该出现该种状况,导数据或者是程序开口)
|
||
if (mmStock != null) {
|
||
MmMaterialBar mmMaterialBar = new MmMaterialBar();
|
||
mmMaterialBar.setMaterialBar(materialBar);
|
||
mmMaterialBar.setMaterialId(mmStock.getMaterialId());
|
||
mmMaterialBar.setMaterialCode(mmStock.getMaterialCode());
|
||
mmMaterialBar.setMaterialName(mmStock.getMaterialName());
|
||
mmMaterialBar.setMaterialQty(mmStock.getQty());
|
||
mmMaterialBar.setMaterialSpec(mmStock.getMaterialSpec());
|
||
mmMaterialBar.setLocationId(mmStock.getLocationId());
|
||
mmMaterialBar.setLocationCode(mmStock.getLocationCode());
|
||
mmMaterialBar.setDictStatus(30);
|
||
mmMaterialBarRepository.save(mmMaterialBar);
|
||
return buildSuccess(BeanUtil.copyProperties(mmMaterialBarRepository.findByMaterialBar(materialBar),
|
||
MaterialBarVo.class));
|
||
}
|
||
MaterialBarVo materialBarVo = new MaterialBarVo();
|
||
materialBarVo.setMaterialBar(saoma.getMessage());
|
||
materialBarVo.setMaterialQty(BigDecimal.valueOf(saoma.getShuliang()));
|
||
materialBarVo.setBatchNo(saoma.getBatch());
|
||
materialBarVo.setMaterialCode(saoma.getLiaohao());
|
||
mmMaterialBarRepository.save(BeanUtil.copyProperties(materialBarVo, MmMaterialBar.class));
|
||
return buildSuccess(materialBarVo);
|
||
}
|
||
return buildSuccess(service.autoCreateBar(materialBar));
|
||
}
|
||
|
||
|
||
@ApiOperation(value = "IF-005:根据料盘条码获取条码信息接口")
|
||
@GetMapping(value = "queryMaterialByMaterialBar")
|
||
public Respond getDetailByBar(String materialBar) {
|
||
MaterialBarVo barVo = materialBarService.getDetailByBar(materialBar);
|
||
String inputBillNumber = barVo.getInputBillNumber();
|
||
Long arriveBillDetailId = barVo.getArriveBillDetailId();
|
||
String batchNo = barVo.getBatchNo();
|
||
if (StringUtils.isNotEmpty(inputBillNumber) && null != arriveBillDetailId && StringUtils.isNotEmpty(batchNo)) {
|
||
MmInputBillDetail inputBillDetail =
|
||
inputBillDetailRepository.findByInputBillNumberAndArriveBillDetailIdAndBatchNo(inputBillNumber,
|
||
arriveBillDetailId, batchNo);
|
||
if (null != inputBillDetail) {
|
||
barVo.setInputPlanQty(inputBillDetail.getPlanQty());
|
||
barVo.setInputRealQty(inputBillDetail.getRealQty());
|
||
}
|
||
|
||
}
|
||
if (StringUtils.isNotEmpty(inputBillNumber)) {
|
||
MmInputBill byInputBillNumber = inputBillRepository.findByInputBillNumber(inputBillNumber);
|
||
if (byInputBillNumber != null) {
|
||
barVo.setWarehouseCode(byInputBillNumber.getWarehouseCode() + " " + byInputBillNumber.getWarehouseName());
|
||
}
|
||
}
|
||
|
||
if (barVo.getWarehouseCode() == null) {
|
||
if (StringUtils.isNotEmpty(barVo.getArriveBillNumber())) {
|
||
MmArriveBill ar = mmArriveBillRepository.findByArriveBillNumber(barVo.getArriveBillNumber());
|
||
if (ar != null) {
|
||
if (StringUtils.isNotEmpty(ar.getCustomerCode())) {
|
||
BaCrWarehouseRelationshipDto ba = new BaCrWarehouseRelationshipDto();
|
||
ba.setCustomerCode(ar.getCustomerCode());
|
||
ba.setDictMaterialAttr(ar.getDictMaterialAttr());
|
||
ba.setIsInspect(ar.getIsInspect());
|
||
baWareHouseRepository.findByWarehouseCode(ba.getCustomerCode());
|
||
String warehouseCode = remoteService.queryCu(ba);
|
||
barVo = service.isEmpty(warehouseCode, barVo);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return buildSuccess(barVo);
|
||
}
|
||
|
||
|
||
/**
|
||
* 条码类型判断接口&IF-111:海康条码解析接口
|
||
*
|
||
* @param code 海康条码
|
||
* @return 解析数据
|
||
*/
|
||
@ApiOperation(value = "IF-007:条码类型判断接口&IF-111:海康条码解析接口")
|
||
@GetMapping(value = "analysisBar")
|
||
public Respond analysisBar(String code) {
|
||
log.info(code);
|
||
AnalysisBarVo vo = service.analysisBar(code);
|
||
if (vo == null) {
|
||
return buildFailure("解析错误,请检查传入的数据");
|
||
} else {
|
||
return buildSuccess(vo);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 半成品入库检验
|
||
*
|
||
* @param vo 入库参数
|
||
* @return 入库结果
|
||
*/
|
||
@ApiOperation(value = "IF-061:半成品入库检验")
|
||
@PostMapping(value = "semiProduckCheck")
|
||
public Respond semiProduckCheck(@RequestBody ProduckStockInVo vo) {
|
||
String orderWorkNumber = vo.getOrderWorkNumber();
|
||
BigDecimal materialQty = vo.getMaterialQty();
|
||
List<SemiProduckParm> semiProduckParms = prodInBillService.semiProduck(orderWorkNumber, materialQty);
|
||
return buildSuccess(semiProduckParms);
|
||
}
|
||
|
||
|
||
/**
|
||
* 根据物料条码推荐库位
|
||
*
|
||
* @param materialBar 物料条码
|
||
* @return 推荐数据
|
||
*/
|
||
@ApiOperation(value = "根据物料条码推荐库位")
|
||
@GetMapping(value = "getRecommendLocation")
|
||
public Respond getRecommendLocation(String materialBar) {
|
||
MaterialBarVo detailByBar = materialBarService.getDetailByBar(materialBar);
|
||
|
||
MmStockDto mmStockDto = new MmStockDto();
|
||
mmStockDto.setMaterialCode(detailByBar.getMaterialCode());
|
||
mmStockDto.setBatchNo(detailByBar.getBatchNo());
|
||
List<MmStock> stockList = mmStockRepository.findByMaterialCodeAndBatchNo(mmStockDto.getMaterialCode(),
|
||
mmStockDto.getBatchNo());
|
||
List<MmStockDto> mmStockDtoList = BeanUtil.copyProperties(stockList, MmStockDto.class);
|
||
if (mmStockDtoList.size() > 0) {
|
||
List<String> collect =
|
||
mmStockDtoList.stream().map(MmStockDto::getLocationCode).collect(Collectors.toList());
|
||
String join = String.join("/", collect);
|
||
return buildSuccess(join);
|
||
}
|
||
return buildFailure("没有相关库存");
|
||
}
|
||
|
||
/**
|
||
* 亮灯
|
||
*
|
||
* @param lamp 亮灯参数
|
||
* @return 操作结果
|
||
*/
|
||
@ApiOperation(value = "亮灯")
|
||
@PostMapping(value = "lightUp")
|
||
public Respond lightUp(@RequestBody WCSLampArray lamp) {
|
||
service.lightUp(lamp);
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 熄灯
|
||
*
|
||
* @param lamp 熄灯参数
|
||
* @return 操作结果
|
||
*/
|
||
@ApiOperation(value = "熄灯")
|
||
@PostMapping(value = "lightOff")
|
||
public Respond lightOff(@RequestBody WCSLampArray lamp) {
|
||
service.lightOff(lamp);
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* 复位
|
||
*
|
||
* @param locationCode 库位码
|
||
* @return 操作结果
|
||
*/
|
||
@ApiOperation(value = "复位")
|
||
@GetMapping(value = "lightReset")
|
||
public Respond lightReset(String locationCode) {
|
||
service.lightReset(locationCode);
|
||
return buildSuccess();
|
||
}
|
||
|
||
/**
|
||
* APP直接改变条码数量,老条码表和新条码表
|
||
*
|
||
*/
|
||
@ApiOperation(value = "APP直接改变条码数量,老条码表和新条码表")
|
||
@GetMapping(value = "changeBarQty")
|
||
@Transactional(rollbackFor = Exception.class)
|
||
public Respond changeBarQty(String materialBar,BigDecimal Qty,Long warehouseId,String warehouseCode,String warehouseName, String batchNo, String locationCode, Long locationId) {
|
||
|
||
|
||
boolean existFlag = false;
|
||
String newBar = null;
|
||
String materialCode = null;
|
||
//先判断条码表
|
||
MmMaterialBar mmMaterialBar = null;
|
||
if (mmMaterialBarRepository.existsByMaterialBar(materialBar)) {
|
||
mmMaterialBar = mmMaterialBarRepository.findByMaterialBar(materialBar);
|
||
MaterialDto materialDto = remoteService.findByMaterialCode(mmMaterialBar.getMaterialCode());
|
||
mmMaterialBar.setMaterialId(materialDto.getId());
|
||
mmMaterialBar.setMaterialName(materialDto.getMaterialName());
|
||
mmMaterialBar.setMaterialSpec(materialDto.getMaterialSpec());
|
||
mmMaterialBar.setMaterialQty(Qty);
|
||
mmMaterialBar.setBatchNo(batchNo);
|
||
mmMaterialBar.setLocationCode(locationCode);
|
||
mmMaterialBar.setLocationId(locationId);
|
||
mmMaterialBar.setWarehouseId(baWareHouseRepository.findByWarehouseCode(warehouseCode).getId());
|
||
mmMaterialBar.setWarehouseCode(warehouseCode);
|
||
mmMaterialBar.setWarehouseName(warehouseName);
|
||
mmMaterialBar.setStockSaveType(1);
|
||
MmMaterialBar save = mmMaterialBarRepository.save(mmMaterialBar);
|
||
existFlag = true;
|
||
newBar = save.getMaterialCode() + "@" + batchNo + "@" + warehouseCode + "@10@" + locationCode;
|
||
}
|
||
//只要查到存在,再去判断库存情况,修改库存数量
|
||
if (existFlag) {
|
||
MmStock byMaterialBar1 = mmStockRepository.findByMaterialBar(materialBar);
|
||
if (byMaterialBar1 != null) {
|
||
mmStockRepository.delete(byMaterialBar1);
|
||
}
|
||
MmStockArea byMaterialBar2 = areaRepository.findByMaterialBar(materialBar);
|
||
if (byMaterialBar2 != null) {
|
||
areaRepository.delete(byMaterialBar2);
|
||
}
|
||
MmStock mmStock = mmStockRepository.findByMaterialBar(newBar);
|
||
//库存存在,直接在库存上进行数量的操作,生成事务
|
||
if (mmStock != null) {
|
||
//如果库存表的数量<该条码的数量;直接数量叠加
|
||
if (mmStock.getQty().compareTo(Qty) == -1) {
|
||
mmStock.setQty(mmStock.getQty().add(Qty));
|
||
MmStockBiz stockBiz = BeanUtil.copyProperties(mmStock, MmStockBiz.class);
|
||
stockBiz.setId(null);
|
||
stockBiz.setStockId(mmStock.getId());
|
||
stockBiz.setBeforeQty(mmStock.getQty());
|
||
stockBiz.setAfterQty(mmStock.getQty().add(Qty));
|
||
stockBiz.setQty(stockBiz.getAfterQty().subtract(stockBiz.getBeforeQty()));
|
||
stockBiz.setCreatedBy(SecurityUtils.getUsername());
|
||
stockBiz.setCreatedDt(DateUtil.getCurrentDate());
|
||
stockBiz.setUpdatedBy(null);
|
||
stockBiz.setUpdatedDt(null);
|
||
mmStock.setUpdatedBy(SecurityUtils.getUsername());
|
||
mmStock.setUpdatedDt(DateUtil.getCurrentDate());
|
||
mmStockCheckBizRepository.save(BeanUtil.copyProperties(stockBiz, MmStockCheckBiz.class));
|
||
mmStockBizRepository.save(stockBiz);
|
||
mmStockRepository.save(mmStock);
|
||
}
|
||
} else {
|
||
//库存不存在,直接新增一个库存进去,生成事务
|
||
mmStock = new MmStock();
|
||
mmStock.setMaterialBar(newBar);
|
||
MaterialDto materialDto = remoteService.findByMaterialCode(mmMaterialBar.getMaterialCode());
|
||
mmStock.setMaterialId(materialDto.getId());
|
||
mmStock.setMaterialCode(mmMaterialBar.getMaterialCode());
|
||
mmStock.setMaterialName(materialDto.getMaterialName());
|
||
mmStock.setMaterialSpec(materialDto.getMaterialSpec());
|
||
mmStock.setUnitOfMeasure(mmMaterialBar.getUnitOfMeasure());
|
||
if (StringUtils.isNotBlank(mmMaterialBar.getBatchNo())) {
|
||
mmStock.setBatchNo(batchNo);
|
||
}
|
||
mmStock.setQty(Qty);
|
||
mmStock.setWarehouseId(warehouseId);
|
||
mmStock.setWarehouseCode(warehouseCode);
|
||
mmStock.setWarehouseName(warehouseName);
|
||
mmStock.setWarehouseType(10);
|
||
mmStock.setLocationCode(locationCode);
|
||
mmStock.setLocationId(locationId);
|
||
mmStock.setLocationCode(locationCode);
|
||
BaLocation byLocationCode = balocationRepository.findByLocationCode(locationCode);
|
||
if (byLocationCode == null) {
|
||
throw new ServiceException(RespondEnum.FAILURE, String.format("库位【%s】为空",locationCode));
|
||
}
|
||
mmStock.setLocationName(byLocationCode.getLocationName());
|
||
mmStock.setCreatedBy(SecurityUtils.getUsername());
|
||
mmStock.setCreatedDt(DateUtil.getCurrentDate());
|
||
mmStock.setStockSaveType(1);
|
||
|
||
MmStockBiz stockBiz = BeanUtil.copyProperties(mmStock, MmStockBiz.class);
|
||
stockBiz.setId(null);
|
||
stockBiz.setStockId(mmStock.getId());
|
||
stockBiz.setBeforeQty(BigDecimal.ZERO);
|
||
stockBiz.setAfterQty(Qty);
|
||
stockBiz.setQty(stockBiz.getAfterQty().subtract(stockBiz.getBeforeQty()));
|
||
stockBiz.setCreatedBy(SecurityUtils.getUsername());
|
||
stockBiz.setCreatedDt(DateUtil.getCurrentDate());
|
||
stockBiz.setUpdatedBy(null);
|
||
stockBiz.setUpdatedDt(null);
|
||
stockBiz.setDictBiztype(47);
|
||
log.info("操作人:"+SecurityUtils.getUsername()+"在时间:"+DateUtil.getCurrentDate()+"进行条码修改");
|
||
mmStockBizRepository.save(stockBiz);
|
||
mmStockRepository.save(mmStock);
|
||
mmStockCheckBizRepository.save(BeanUtil.copyProperties(stockBiz, MmStockCheckBiz.class));
|
||
}
|
||
}
|
||
|
||
return buildSuccess();
|
||
}
|
||
|
||
}
|