This commit is contained in:
zds
2022-08-04 08:33:21 +08:00
parent 47723a23a5
commit dc53ad0aee
5 changed files with 226 additions and 140 deletions

View File

@@ -91,6 +91,13 @@ public class DailyplanServiceImpl implements DailyplanService {
map.put("flag", "2");
JSONArray jret = WQL.getWO("QPDM_PRODUCTDAILYPLAN")
.addParamMap(map).process().getResultJSONArray(0);
if(jret.size()>0){
JSONObject form = new JSONObject();
form.put("rows",jret);
this.submit2(form);
}
jret = WQL.getWO("QPDM_PRODUCTDAILYPLAN")
.addParamMap(map).process().getResultJSONArray(0);
JSONArray ja = new JSONArray();
for(int i=0;i<jret.size();i++){
@@ -282,158 +289,197 @@ public class DailyplanServiceImpl implements DailyplanService {
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject PCS_IF_ProductPlanProc = WQLObject.getWQLObject("PCS_IF_ProductPlanProc");
WQLObject MPS_BD_ProductDailyPlan = WQLObject.getWQLObject("MPS_BD_ProductDailyPlan");
WQLObject MD_ME_ProducMaterialExt = WQLObject.getWQLObject("MD_ME_ProducMaterialExt");
WQLObject MPS_BD_CapacityTemplateSeries = WQLObject.getWQLObject("MPS_BD_CapacityTemplateSeries");
JSONArray ja = form.getJSONArray("rows");
JSONObject json = form.getJSONObject("query");
String captemplate_id = json.getString("captemplate_id");
if (StrUtil.isEmpty(captemplate_id)) {
JSONObject captemplate = WQL.getWO("QPDM_PRODUCTPLANPROC")
.addParam("flag","4").process().uniqueResult(0);
if (captemplate == null) {
throw new BadRequestException("排产模板不能为空!");
}
String checked = json.getString("checked");
if (StrUtil.isEmpty(checked)) {
checked = "false";
}
//已经生成日计划的月计划列表
HashMap<String,String> used_map = new HashMap<String,String>();
String captemplate_id = captemplate.getString("id");
JSONArray ja = form.getJSONArray("rows");
//分组
HashMap<String,JSONArray> device_map = new HashMap<String,JSONArray>();
JSONObject last = MPS_BD_ProductDailyPlan.query("device_id='"+ja.getJSONObject(0).getString("device_id")+"' and status='01'","planstart_date").uniqueResult(0);
if(last ==null ){
throw new BadRequestException("日计划表此分组设备的最早一个日计划为空,没有可重排数据!");
}
JSONArray ja_new = new JSONArray();
for (int i = 0; i < ja.size(); i++) {
JSONObject jo = ja.getJSONObject(i);
String device_id = jo.getString("device_id");
if (StrUtil.isEmpty(device_id)) {
throw new BadRequestException("关键设备不能为空!");
}
if(device_map.containsKey(device_id)){
JSONArray rows = device_map.get(device_id);
rows.add(jo);
device_map.put(device_id,rows);
}else{
JSONArray rows = new JSONArray();
rows.add(jo);
device_map.put(device_id,rows);
JSONObject jo_new = MPS_BD_ProductDailyPlan.query("dailyplan_id='"+jo.getString("dailyplan_id")+"' and status='01'").uniqueResult(0);
if (jo_new!=null) {
ja_new.add(jo);
MPS_BD_ProductDailyPlan.delete(jo);
}
}
//排序
HashMap<String,JSONArray> device_map2 = new HashMap<String,JSONArray>();
device_map.forEach((key,rows)->{
List<JSONObject> list = JSONObject.parseArray(rows.toJSONString(), JSONObject.class);
Collections.sort(list, (JSONObject o1, JSONObject o2) -> {
String s1 = o1.getString("plan_finish_date");
//转成JSON对象中保存的值类型
double a = Double.parseDouble(s1.replace("-",""));
double b = Double.parseDouble(o2.getString("plan_finish_date").replace("-",""));
String nowstart_date = last.getString("planstart_date");
Date date = DateUtil.parse(nowstart_date);
//当天产能是否有剩余
double pcsn_num_day = 0;
String s1_old_mark = o1.getString("old_mark");
String s2_old_mark = o2.getString("old_mark");
JSONArray ja_day = new JSONArray();
for(int i=0;i<ja_new.size();i++){
JSONObject jo = ja_new.getJSONObject(i);
String s1_material_code = o1.getString("material_code");
String s2_material_code = o2.getString("material_code");
// 如果a, b数据类型为int可直接 return a - b ;(升序,降序为 return b - a;)
if (a > b) { //降序排列升序改成a>b
return 1;
} else if(a == b) {
if (s1_old_mark.compareTo(s2_old_mark)>0) { //降序排列升序改成a>b
return 1;
} else if(s1_old_mark.compareTo(s2_old_mark) == 0) {
double fact_weight = jo.getDouble("product_weight");
double standard_weight = jo.getDouble("standard_weight");
if (s1_material_code.compareTo(s2_material_code)>0) { //降序排列升序改成a>b
return 1;
} else if(s1_material_code.compareTo(s2_material_code) == 0) {
return 0;
} else {
return -1;
}
} else {
return -1;
double pcsn_num = Math.ceil(fact_weight/standard_weight);
JSONObject series = MPS_BD_CapacityTemplateSeries.query("captemplate_id='"+captemplate_id+"' and product_series_id='"+jo.getString("product_series")+"'").uniqueResult(0);
if(series ==null){
throw new BadRequestException("系列模板产能未配置!");
}
//最大产能批次
int totalproducecapacity_qty = series.getInteger("totalproducecapacity_qty");
//第一条查数据库
if(StrUtil.isNotEmpty(nowstart_date)){
JSONObject last2 = MPS_BD_ProductDailyPlan.query("device_id='"+jo.getString("device_id")+"'","planstart_date desc,create_time desc").uniqueResult(0);
String old_mark = jo.getString("old_mark");
if(last2 != null ){
nowstart_date = last2.getString("planstart_date");
date = DateUtil.parse(nowstart_date);
JSONObject mater = MD_ME_ProducMaterialExt.query("material_id='"+last2.getString("material_id")+"'").uniqueResult(0);
old_mark = mater.getString("old_mark");
}
if(jo.getString("old_mark").equals(old_mark)) {
JSONObject total_last = WQL.getWO("QPDM_PRODUCTPLANPROC")
.addParam("flag", "6")
.addParam("device_id", jo.getString("device_id"))
.addParam("planstart_date", DateUtil.formatDate(date))
.process()
.uniqueResult(0);
String total_product_num = total_last.getString("total_product_num");
if (StrUtil.isEmpty(total_product_num)) {
pcsn_num_day = totalproducecapacity_qty;
}else{
pcsn_num_day = totalproducecapacity_qty - Integer.parseInt(total_product_num);
}
} else {
return -1;
if (pcsn_num_day <= 0) {
date = DateUtil.offsetDay(date, 1);
}
}else{
date = DateUtil.offsetDay(date,1);
pcsn_num_day = 0;
}
});
rows = JSONArray.parseArray(JSON.toJSONString(list));
device_map2.put(key,rows);
});
while(pcsn_num > 0){
JSONObject ProcessRoute = WQL.getWO("QPDM_PRODUCTPLANPROC").addParam("flag","5")
.addParam("material_code",jo.getString("material_id")).process().uniqueResult(0);
if(ProcessRoute==null){
throw new BadRequestException("产品工艺路线未设置不允许预排!");
}
int total_plan_time = ProcessRoute.getInteger("total_plan_time");
BigDecimal days = NumberUtil.round(total_plan_time/24,0);
String finalChecked = checked;
device_map2.forEach((key, rows)->{
String nowstart_date = json.getString("nowstart_date");
Date date = DateUtil.parse(nowstart_date);
for(int i=0;i<rows.size();i++){
JSONObject jo = rows.getJSONObject(i);
double fact_weight = jo.getDouble("fact_weight");
double standard_weight = jo.getDouble("standard_weight");
//批次数
BigDecimal pcsn_num = NumberUtil.round(fact_weight/standard_weight,0);
JSONObject series = MPS_BD_CapacityTemplateSeries.query("captemplate_id='"+captemplate_id+"' and product_series_id='"+jo.getString("product_series")+"'").uniqueResult(0);
if(series ==null){
throw new BadRequestException("系列模板产能未配置!");
}
//最大产能批次
int totalproducecapacity_qty = series.getInteger("totalproducecapacity_qty");
//若初始日期不为空,取此初始日期
if(finalChecked.equals("true") && StrUtil.isNotEmpty(nowstart_date)){
while(pcsn_num.intValue() > 0){
JSONObject ProcessRoute = WQL.getWO("QPDM_PRODUCTPLANPROC").addParam("flag","5")
.addParam("material_code",jo.getString("material_id")).process().uniqueResult(0);
if(ProcessRoute==null){
throw new BadRequestException("产品工艺路线未设置不允许预排!");
}
int total_plan_time = ProcessRoute.getInteger("total_plan_time");
BigDecimal days = NumberUtil.round(total_plan_time/24,0);
if(pcsn_num.intValue() > totalproducecapacity_qty){
if(pcsn_num_day > 0){
if(pcsn_num > pcsn_num_day){
jo.put("workorder_type","01");
jo.put("product_weight",totalproducecapacity_qty*standard_weight);
jo.put("product_num",totalproducecapacity_qty);
jo.put("product_weight",pcsn_num_day*standard_weight);
jo.put("product_num",pcsn_num_day);
jo.put("product_series_id",jo.getString("product_series"));
jo.put("planstart_date",DateUtil.formatDate(date));
Date planstart_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planstart_date",DateUtil.formatDate(planstart_date));
//this.createDay(jo);
Date planend_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planend_date",DateUtil.formatDate(planend_date));
this.createDay(jo);
date = DateUtil.offsetDay(date,1);
pcsn_num = BigDecimal.valueOf(pcsn_num.intValue() - totalproducecapacity_qty);
pcsn_num = pcsn_num - pcsn_num_day;
fact_weight = fact_weight - pcsn_num_day*standard_weight;
pcsn_num_day =0;
}else{
jo.put("workorder_type","01");
jo.put("product_weight",pcsn_num.intValue()*standard_weight);
jo.put("product_num",pcsn_num.intValue());
jo.put("product_weight",fact_weight);
jo.put("product_num",pcsn_num);
jo.put("product_series_id",jo.getString("product_series"));
jo.put("planstart_date",DateUtil.formatDate(date));
Date planstart_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planend_date",DateUtil.formatDate(planstart_date));
//this.createDay(jo);
Date planend_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planend_date",DateUtil.formatDate(planend_date));
this.createDay(jo);
date = DateUtil.offsetDay(date,1);
pcsn_num = BigDecimal.valueOf(0);
pcsn_num_day = pcsn_num_day - pcsn_num;
if(pcsn_num_day <= 0){
date = DateUtil.offsetDay(date,1);
}
pcsn_num = 0;
fact_weight = 0;
if(pcsn_num == 0){
break;
}
}
}
}else{//若初始日期为空,获取日计划表设备标识=此分组设备的最后一个计划
if(pcsn_num > totalproducecapacity_qty){
jo.put("workorder_type","01");
jo.put("product_weight",totalproducecapacity_qty*standard_weight);
jo.put("product_num",totalproducecapacity_qty);
jo.put("product_series_id",jo.getString("product_series"));
jo.put("planstart_date",DateUtil.formatDate(date));
Date planend_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planend_date",DateUtil.formatDate(planend_date));
this.createDay(jo);
date = DateUtil.offsetDay(date,1);
pcsn_num =pcsn_num - totalproducecapacity_qty;
fact_weight = fact_weight - totalproducecapacity_qty*standard_weight;
pcsn_num_day = 0;
}else{
jo.put("workorder_type","01");
jo.put("product_weight",fact_weight);
jo.put("product_num",pcsn_num);
jo.put("product_series_id",jo.getString("product_series"));
jo.put("planstart_date",DateUtil.formatDate(date));
Date planend_date = DateUtil.offsetDay(date,days.intValue()-1);
jo.put("planend_date",DateUtil.formatDate(planend_date));
this.createDay(jo);
pcsn_num_day = totalproducecapacity_qty - pcsn_num;
if(pcsn_num_day <= 0){
date = DateUtil.offsetDay(date,1);
}
pcsn_num = 0;
fact_weight = 0;
}
}
}
});
for (int i = 0; i < ja.size(); i++) {
JSONObject jo = ja.getJSONObject(i);
JSONObject jsonMst = PCS_IF_ProductPlanProc.query("plan_id ='" + jo.getString("plan_id") + "' and is_proc = '1'").uniqueResult(0);
if (jsonMst == null) {
throw new BadRequestException(jo.getString("task_code")+"当前记录状态异常,操作失败!");
}
HashMap<String, String> map = new HashMap<>();
map.put("is_proc", "2");
map.put("update_optid", currentUserId + "");
map.put("update_optname", nickName);
map.put("update_time", now);
PCS_IF_ProductPlanProc.update(map, "plan_id ='" + jo.getString("plan_id") + "'");
}
}
@Transactional(rollbackFor = Exception.class)
public void createDay(JSONObject json) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
JwtUserDto currentUser = (JwtUserDto) SecurityUtils.getCurrentUser();
Long deptId = currentUser.getDeptId();
WQLObject pdm_bi_productdeptpcsn = WQLObject.getWQLObject("pdm_bi_productdeptpcsn");
WQLObject MPS_BD_ProductDailyPlan = WQLObject.getWQLObject("MPS_BD_ProductDailyPlan");
WQLObject MD_ME_ProducMaterialExt = WQLObject.getWQLObject("MD_ME_ProducMaterialExt"); // 工艺路线主表
// 插入主表
json.put("dailyplan_id", IdUtil.getSnowflake(1, 1).nextId());
String workorder_code = CodeUtil.getNewCode("R_CODE");
json.put("plan_code", workorder_code);
json.put("weight_unit_id", "1");
json.put("weight_unit_name", "千克\\公斤");
json.put("status", "01");
json.put("create_id", currentUserId);
json.put("create_name", nickName);
json.put("create_time", now);
JSONObject product = pdm_bi_productdeptpcsn.query("org_code='"+json.getString("plan_org_code")+"'").uniqueResult(0);
json.put("plan_org_name", product.getString("org_name"));
json.put("product_series", json.getString("product_series_id"));
MPS_BD_ProductDailyPlan.insert(json);
}
@Override
public void download(Map whereJson, HttpServletResponse response) throws IOException {

View File

@@ -493,7 +493,7 @@ public class ProducetaskprocServiceImpl implements ProducetaskprocService {
if(last ==null ){
throw new BadRequestException("日计划表此分组设备的最后一个计划为空!");
}
JSONObject mater = MD_ME_ProducMaterialExt.query("material_id='"+jo.getString("material_id")+"'").uniqueResult(0);
JSONObject mater = MD_ME_ProducMaterialExt.query("material_id='"+last.getString("material_id")+"'").uniqueResult(0);
String old_mark = mater.getString("old_mark");
if(jo.getString("old_mark").equals(old_mark)) {

View File

@@ -106,6 +106,7 @@
deviceinfo.device_name,
classstandard.class_name AS product_series_name,
classstandard2.class_name AS mater_product_series_name,
ProductPlanProc.task_code,
productdeptpcsn.org_id
FROM
MPS_BD_ProductDailyPlan pp
@@ -115,6 +116,7 @@
LEFT JOIN em_bi_deviceinfo deviceinfo ON deviceinfo.device_id = pp.device_id
LEFT JOIN md_pb_classstandard classstandard ON classstandard.class_id = pp.product_series_id
LEFT JOIN md_pb_classstandard classstandard2 ON classstandard2.class_id = ext.product_series
LEFT JOIN PCS_IF_ProductPlanProc ProductPlanProc ON ProductPlanProc.plan_id = pp.plan_id
WHERE
1=1