package com.example.erp.service.pp; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.example.erp.entity.pp.ProductionScheduling; import com.example.erp.entity.sd.OrderDetail; import com.example.erp.mapper.pp.ProductionSchedulingMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service @DS("pp") public class ProductionSchedulingService { @Autowired ProductionSchedulingMapper productionSchedulingMapper; //带时间查询 public Map SelectSchedulingSv(String selectTime1, String selectTime2, String orderId,String processes, Integer state, ProductionScheduling productionScheduling ) { Map map = new HashMap<>(); if (state==2){//已排产 map.put("data", productionSchedulingMapper.SelectOkSchedulingMp(selectTime1, selectTime2,orderId,processes, productionScheduling)); }else if (state==1){//未排产 map.put("data", productionSchedulingMapper.SelectNoSchedulingMp(selectTime1, selectTime2,orderId,processes, productionScheduling)); } return map; } //首次查询排产数据 public Map selectLastScheduling(String selectTime1, String selectTime2,ProductionScheduling productionScheduling ) { Map map = new HashMap<>(); map.put("data", productionSchedulingMapper.selectLastSchedulingMp(selectTime1, selectTime2, productionScheduling)); return map; } //带订单号查询 public Map SelectSchedulingNotSv(String selectTime1, String selectTime2, String orderId, String processes, Integer state, ProductionScheduling productionScheduling) { Map map = new HashMap<>(); map.put("data", productionSchedulingMapper.SelectSchedulingNotMp(selectTime1, selectTime2,orderId,processes, productionScheduling)); return map; } public Boolean AddSchedulingSv(Map object) { String userName = ""; if (object.get("userName") != null) { userName = object.get("userName").toString(); } String processes = ""; if (object.get("processes") != null) { processes = object.get("processes").toString(); } Integer maxId = productionSchedulingMapper.selectMaxId(); //查询订单id,并且自增 String formattedNumber = String.format("%02d", maxId+1); //格式化当前日期 java.util.Date currentDate = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); String formattedDate = dateFormat.format(currentDate); String schedulingId = "PC"+formattedDate+formattedNumber; List schedulinglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("scheduling")), ProductionScheduling.class); if (!schedulinglist.isEmpty()) { for (ProductionScheduling productionScheduling : schedulinglist) { productionSchedulingMapper.insertSelective(schedulingId,productionScheduling.getOrderId(),productionScheduling.getOrderNumber(),processes,productionScheduling.getSchedulingQuantity(),productionScheduling.getScheduledStartTime(),productionScheduling.getPlanEndTime(),productionScheduling.getNotes()); // System.out.println(productionScheduling.getOrderNumber()+"***"+productionScheduling.getOrderId()); } return true; } else { return false; } } }