package cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.impl; import cn.stylefeng.guns.base.auth.context.LoginContextHolder; import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.entity.SalesOrder; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.mapper.SalesOrderMapper; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.params.SalesOrderParam; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.result.SalesOrderResult; import cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.SalesOrderService; import cn.stylefeng.guns.modular.zsx.pm.salesOrderChild.entity.SalesOrderChild; import cn.stylefeng.guns.modular.zsx.pm.salesOrderChild.service.SalesOrderChildService; import cn.stylefeng.guns.modular.zsx.pm.workOrder.entity.WorkOrder; import cn.stylefeng.guns.modular.zsx.pm.workOrder.service.WorkOrderService; import cn.stylefeng.roses.core.util.ToolUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.Serializable; import java.util.List; /** *

* 生产订单 服务实现类 *

* * @author ruimin * @since 2023-08-26 */ @Service public class SalesOrderServiceImpl extends ServiceImpl implements SalesOrderService { @Autowired private WorkOrderService workOrderService; @Autowired private SalesOrderChildService salesOrderChildService; @Override public void add(SalesOrderParam param){ param.setCreateUser(LoginContextHolder.getContext().getUser().getName()); SalesOrder entity = getEntity(param); this.save(entity); } @Override public void delete(SalesOrderParam param){ this.removeById(getKey(param)); } @Override public void update(SalesOrderParam param){ param.setUpdateUser(LoginContextHolder.getContext().getUser().getName()); SalesOrder oldEntity = getOldEntity(param); SalesOrder newEntity = getEntity(param); ToolUtil.copyProperties(newEntity, oldEntity); this.updateById(newEntity); } @Override public SalesOrderResult findBySpec(SalesOrderParam param){ return null; } @Override public List findListBySpec(SalesOrderParam param){ return null; } @Override public LayuiPageInfo findPageBySpec(SalesOrderParam param){ Page pageContext = getPageContext(); IPage page = this.baseMapper.customPageList(pageContext, param); return LayuiPageFactory.createPageInfo(page); } @Override public LayuiPageInfo breakDownOrders(SalesOrderParam param) { if(param.getFlag().equals("true")){ SalesOrder salesOrder = this.getById(param.getId()); salesOrder.setPlanNumber(salesOrder.getPlanNumber()-param.getSplitNumber()); this.saveOrUpdate(salesOrder); salesOrder.setPlanNumber(param.getSplitNumber()); this.save(salesOrder); } Page pageContext = getPageContext(); IPage page = this.baseMapper.salesOrderNotinId(pageContext, param); return LayuiPageFactory.createPageInfo(page); } @Override public void DistributeSalesOrder(SalesOrderParam salesOrderParam) { SalesOrder byId = this.getById(salesOrderParam.getId()); switch(byId.getState()){ case "1" : WorkOrder workOrder = new WorkOrder(); workOrder.setWorkOrderCode(workOrderService.getOrderCode()); workOrder.setSalesOrderCode(byId.getSalesOrderCode()); workOrder.setProductCode(byId.getProductCode()); workOrder.setProductName(byId.getProductName()); workOrder.setPlanQty(byId.getPlanNumber()); workOrder.setPlanStartTime(byId.getPlanStartTime()); workOrder.setPlanEndTime(byId.getPlanEndTime()); workOrder.setWorkshopCode(byId.getWorkshopCode()); workOrder.setLineCode(byId.getLineCode()); workOrder.setState("1"); workOrder.setRouteCode(salesOrderParam.getRouteCode()); workOrder.setBomCode(salesOrderParam.getBomCode()); workOrder.setRecipeCode(salesOrderParam.getRecipeCode()); workOrderService.save(workOrder); break; case "2" : List salesOrderChild = salesOrderChildService.list(new QueryWrapper().eq("sales_order_code", byId.getSalesOrderCode())); for (SalesOrderChild order : salesOrderChild) { WorkOrder workOrderChild = new WorkOrder(); workOrderChild.setWorkOrderCode(workOrderService.getOrderCode()); workOrderChild.setSalesOrderCode(order.getSalesOrderCode()); workOrderChild.setProductCode(order.getProductCode()); workOrderChild.setProductName(order.getProductName()); workOrderChild.setPlanQty(order.getPlanNumber()); workOrderChild.setPlanStartTime(order.getPlanStartTime()); workOrderChild.setPlanEndTime(order.getPlanEndTime()); workOrderChild.setWorkshopCode(order.getWorkshopCode()); workOrderChild.setLineCode(order.getLineCode()); workOrderChild.setState("1"); workOrderChild.setRouteCode(salesOrderParam.getRouteCode()); workOrderChild.setBomCode(salesOrderParam.getBomCode()); workOrderChild.setRecipeCode(salesOrderParam.getRecipeCode()); workOrderService.save(workOrderChild); } break; default : } //更新订单表下发状态 byId.setState("3"); this.saveOrUpdate(byId); } private Serializable getKey(SalesOrderParam param){ return param.getId(); } private Page getPageContext() { return LayuiPageFactory.defaultPage(); } private SalesOrder getOldEntity(SalesOrderParam param) { return this.getById(getKey(param)); } private SalesOrder getEntity(SalesOrderParam param) { SalesOrder entity = new SalesOrder(); ToolUtil.copyProperties(param, entity); return entity; } }