164 lines
7.5 KiB
Plaintext
164 lines
7.5 KiB
Plaintext
package com.cmeim.stock.controller;
|
|
|
|
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.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.domain.TUserInfo;
|
|
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.OrderInfo;
|
|
import com.cmeim.stock.po.StationInfo;
|
|
import com.cmeim.stock.repository.OrderInfoRepository;
|
|
import com.cmeim.stock.repository.StationInfoRepository;
|
|
import com.cmeim.stock.service.OrderService;
|
|
import com.cmeim.stock.vo.FindOrderByStationVo;
|
|
import com.cmeim.stock.vo.OrderQueryVo;
|
|
import com.google.common.collect.Lists;
|
|
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.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.*;
|
|
|
|
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/26
|
|
*/
|
|
@Api(tags = "生产任务单")
|
|
@RestController
|
|
@RequestMapping(value = "order")
|
|
@Slf4j
|
|
public class OrderController extends GenericController {
|
|
@Autowired
|
|
private OrderService orderService;
|
|
@Autowired
|
|
private OrderInfoRepository orderInfoRepository;
|
|
@Autowired
|
|
private StationInfoRepository stationInfoRepository;
|
|
|
|
@ApiOperation(value = "列表")
|
|
@GetMapping(value = "list")
|
|
public Respond list(PageVo pv, OrderInfo orderInfo) {
|
|
PageRequest pageRequest = PageRequest.of(pv.getPageNo() - 1, pv.getPageSize(),
|
|
Sort.by(sortOrder(orderInfo.getOrders())));
|
|
Page page = orderInfoRepository.findAll(buildSpecification(orderInfo), pageRequest);
|
|
List<OrderInfo> list = page.getContent();
|
|
pv.setRecordsTotal(page.getTotalElements());
|
|
pv.setData(list);
|
|
return buildSuccess(pv);
|
|
}
|
|
|
|
@ApiOperation(value = "通过站位查询工单信息")
|
|
@GetMapping(value = "findOrderByStation")
|
|
public Respond findOrderByStation(String stationCode) {
|
|
StationInfo stationInfo = stationInfoRepository.findByStationCode(stationCode);
|
|
if (stationInfo == null) {
|
|
return buildFailure("该站位无工单信息");
|
|
}
|
|
OrderInfo orderInfo = orderInfoRepository.findByProductionTask(stationInfo.getProductionTask());
|
|
FindOrderByStationVo vo = BeanUtil.copyProperties(orderInfo, FindOrderByStationVo.class);
|
|
vo.setStationStatus(stationInfo.getStationStatus());
|
|
vo.setStationCode(stationInfo.getStationCode());
|
|
vo.setStationName(stationInfo.getStationName());
|
|
vo.setStationType(stationInfo.getStationType());
|
|
return buildSuccess(vo);
|
|
}
|
|
|
|
@ApiOperation(value = "新增")
|
|
@Log(title = "生产任务单", businessType = BusinessType.INSERT)
|
|
@PostMapping(value = "add")
|
|
public Respond add(@RequestBody OrderInfo orderInfo) {
|
|
OrderInfo info = orderInfoRepository.findByProductionTask(orderInfo.getProductionTask());
|
|
if (info == null) {
|
|
orderInfo.setInQty(0);
|
|
orderInfo.setOngoingQty(0);
|
|
orderInfo.setOutQty(0);
|
|
orderInfo.setOnoutingCheckQty(0);
|
|
orderInfo.setWaitCheckQty(0);
|
|
orderInfo.setFinishCheckQty(0);
|
|
orderInfo.setCheckQty(0);
|
|
orderInfo.setProductInQty(0);
|
|
orderInfo.setProductOngoingQty(0);
|
|
orderInfo.setProductOutQty(0);
|
|
orderInfo.setProductOnoutingQty(0);
|
|
orderInfoRepository.save(orderInfo);
|
|
}
|
|
//绑定工位和任务单
|
|
StationInfo stationInfo = stationInfoRepository.findByStationCode(orderInfo.getStationCode());
|
|
if (stationInfo == null) {
|
|
stationInfo.setStationStatus(orderInfo.getStationStatus());
|
|
stationInfo.setProductionTask(orderInfo.getProductionTask());
|
|
stationInfo.setUpdatedDt(orderInfo.getCreatedDt());
|
|
stationInfo.setUpdatedBy(orderInfo.getCreatedBy());
|
|
stationInfoRepository.save(stationInfo);
|
|
}
|
|
return buildSuccess();
|
|
}
|
|
|
|
@ApiOperation(value = "通过甲方接口获取单据列表")
|
|
@PostMapping(value = "findByOrderQueryVo")
|
|
public Respond findByOrderQueryVo(@RequestBody OrderQueryVo orderQueryVo) {
|
|
List<OrderInfo> orderInfoList = orderService.findByOrderQueryVo(orderQueryVo);
|
|
return buildSuccess(orderInfoList);
|
|
}
|
|
|
|
private Specification buildSpecification(OrderInfo orderInfo) {
|
|
Specification<OrderInfo> specification = new Specification<OrderInfo>() {
|
|
@Override
|
|
public Predicate toPredicate(Root<OrderInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
|
|
List<Predicate> predicates = Lists.newArrayList();
|
|
if (orderInfo.getMaterialCode() != null) {
|
|
predicates.add(cb.like(root.get("materialCode").as(String.class), "%" + orderInfo.getMaterialCode() + "%"));
|
|
}
|
|
if (orderInfo.getMaterialName() != null) {
|
|
predicates.add(cb.like(root.get("materialName").as(String.class), "%" + orderInfo.getMaterialName() + "%"));
|
|
}
|
|
if (orderInfo.getMaterialSpec() != null) {
|
|
predicates.add(cb.like(root.get("materialSpec").as(String.class), "%" + orderInfo.getMaterialSpec() + "%"));
|
|
}
|
|
if (orderInfo.getOrderStatus() != null) {
|
|
predicates.add(cb.equal(root.get("orderStatus").as(Integer.class), orderInfo.getOrderStatus()));
|
|
}
|
|
if (orderInfo.getProductionTask() != null) {
|
|
predicates.add(cb.like(root.get("productionTask").as(String.class), "%" + orderInfo.getProductionTask() + "%"));
|
|
}
|
|
if (orderInfo.getSaleOrder() != null) {
|
|
predicates.add(cb.like(root.get("saleOrder").as(String.class), "%" + orderInfo.getSaleOrder() + "%"));
|
|
}
|
|
if (StringUtils.isNotBlank(orderInfo.getPlannedCompletionDateStart())) {
|
|
predicates.add(cb.greaterThanOrEqualTo(root.get("plannedCompletionDate").as(String.class), orderInfo.getPlannedCompletionDateStart()));
|
|
}
|
|
if (StringUtils.isNotBlank(orderInfo.getPlannedCompletionDateEnd())) {
|
|
predicates.add(cb.lessThanOrEqualTo(root.get("plannedCompletionDate").as(String.class), orderInfo.getPlannedCompletionDateEnd()));
|
|
}
|
|
if (orderInfo.getOrderStatusArr() != null) {
|
|
CriteriaBuilder.In<Integer> in = cb.in(root.get("orderStatus").as(Integer.class));
|
|
for (Integer dictStatus : orderInfo.getOrderStatusArr()) {
|
|
in.value(dictStatus);
|
|
}
|
|
predicates.add(in);
|
|
}
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
}
|
|
};
|
|
|
|
return specification;
|
|
}
|
|
}
|