143 lines
6.3 KiB
Plaintext
143 lines
6.3 KiB
Plaintext
package com.cmeim.stock.controller;
|
|
|
|
import com.cmeim.common.core.exception.ServiceException;
|
|
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.common.log.annotation.Log;
|
|
import com.cmeim.common.log.enums.BusinessType;
|
|
import com.cmeim.stock.po.ContainerInfo;
|
|
import com.cmeim.stock.po.OrderInfo;
|
|
import com.cmeim.stock.po.ShelfInfo;
|
|
import com.cmeim.stock.po.StationInfo;
|
|
import com.cmeim.stock.repository.OrderInfoRepository;
|
|
import com.cmeim.stock.repository.ShelfInfoRepository;
|
|
import com.google.common.collect.Lists;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
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.Predicate;
|
|
import javax.persistence.criteria.Root;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author 李俊辉
|
|
* @version 1.0
|
|
* date: 2023/6/28
|
|
*/
|
|
@Api(tags = "货架")
|
|
@RestController
|
|
@RequestMapping(value = "shelf")
|
|
@Slf4j
|
|
public class ShelfController extends GenericController {
|
|
@Autowired
|
|
private ShelfInfoRepository shelfInfoRepository;
|
|
@Autowired
|
|
private OrderInfoRepository orderInfoRepository;
|
|
|
|
@ApiOperation(value = "列表")
|
|
@GetMapping(value = "list")
|
|
public Respond list(PageVo pv, ShelfInfo shelfInfo) {
|
|
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(),
|
|
Sort.by(sortOrder(shelfInfo.getOrders())));
|
|
Page page = shelfInfoRepository.findAll(buildSpecification(shelfInfo), pageRequest);
|
|
List<ShelfInfo> list = page.getContent();
|
|
pv.setRecordsTotal(page.getTotalElements());
|
|
pv.setData(list);
|
|
return buildSuccess(pv);
|
|
}
|
|
|
|
@ApiOperation(value = "修改货架状态")
|
|
@Log(title = "货架", businessType = BusinessType.UPDATE)
|
|
@PostMapping(value = "updateShelfStatus")
|
|
public Respond updateStationStatus(ShelfInfo shelfInfo) {
|
|
ShelfInfo shelf = shelfInfoRepository.findByShelfCode(shelfInfo.getShelfCode());
|
|
if (shelf == null) {
|
|
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
|
exception.setErrorMessage("未找到该货架");
|
|
throw exception;
|
|
}
|
|
shelf.setShelfStatus(shelfInfo.getShelfStatus());
|
|
//出库完成则清空任务单和优先级
|
|
if (shelf.getShelfStatus() == 35) {
|
|
//修改任务单的出库中数量和出库数量
|
|
OrderInfo orderInfo = orderInfoRepository.findByProductionTask(shelf.getProductionTask());
|
|
orderInfo.setProductOnoutingQty(orderInfo.getProductOnoutingQty() - shelfInfo.getQty());
|
|
orderInfo.setProductOutQty(orderInfo.getProductOutQty() + shelfInfo.getQty());
|
|
orderInfoRepository.save(orderInfo);
|
|
shelf.setQty(0);
|
|
shelf.setProductionTask(null);
|
|
shelf.setPriority(0);
|
|
shelf.setUpdatedBy(shelfInfo.getUpdatedBy());
|
|
shelf.setUpdatedDt(shelfInfo.getUpdatedDt());
|
|
shelfInfoRepository.save(shelf);
|
|
} else {
|
|
shelf.setQty(shelfInfo.getQty());
|
|
shelf.setUpdatedBy(shelfInfo.getUpdatedBy());
|
|
shelf.setUpdatedDt(shelfInfo.getUpdatedDt());
|
|
shelfInfoRepository.save(shelf);
|
|
}
|
|
return buildSuccess();
|
|
}
|
|
|
|
@ApiOperation(value = "修改任务单优先级")
|
|
@Log(title = "货架", businessType = BusinessType.UPDATE)
|
|
@PostMapping(value = "updateShelfPriority")
|
|
public Respond updateShelfPriority(String productionTask) {
|
|
List<ShelfInfo> shelfInfoList = shelfInfoRepository.findByProductionTask(productionTask);
|
|
if (shelfInfoList.size() == 0) {
|
|
ServiceException exception = new ServiceException(RespondEnum.FAILURE);
|
|
exception.setErrorMessage("未找到该该任务对应的货架");
|
|
throw exception;
|
|
}
|
|
for (ShelfInfo shelfInfo : shelfInfoList) {
|
|
shelfInfo.setPriority(1);
|
|
}
|
|
shelfInfoRepository.saveAll(shelfInfoList);
|
|
return buildSuccess();
|
|
}
|
|
|
|
private Specification buildSpecification(ShelfInfo shelfInfo) {
|
|
Specification<ShelfInfo> specification = new Specification<ShelfInfo>() {
|
|
@Override
|
|
public Predicate toPredicate(Root<ShelfInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
|
List<Predicate> predicates = Lists.newArrayList();
|
|
if (shelfInfo.getShelfCode() != null) {
|
|
predicates.add(cb.like(root.get("shelfCode").as(String.class), "%" + shelfInfo.getShelfCode() + "%"));
|
|
}
|
|
if (shelfInfo.getProductionTask() != null) {
|
|
predicates.add(cb.like(root.get("productionTask").as(String.class), "%" + shelfInfo.getProductionTask() + "%"));
|
|
}
|
|
if (shelfInfo.getShelfStatus() != null) {
|
|
predicates.add(cb.equal(root.get("shelfStatus").as(Integer.class), shelfInfo.getShelfStatus()));
|
|
}
|
|
if (shelfInfo.getOrderStatus() != null) {
|
|
predicates.add(cb.equal(root.get("orderStatus").as(Integer.class), shelfInfo.getOrderStatus()));
|
|
}
|
|
if (shelfInfo.getOrderStatusArr() != null) {
|
|
CriteriaBuilder.In<Integer> in = cb.in(root.get("orderStatus").as(Integer.class));
|
|
for (Integer status : shelfInfo.getOrderStatusArr()) {
|
|
in.value(status);
|
|
}
|
|
predicates.add(in);
|
|
}
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
}
|
|
};
|
|
return specification;
|
|
}
|
|
}
|