add:在制品物料统计
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
package org.nl.wms.analysis_manage.workmaterial.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.anno.Log;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.IPdmBiWorkmaterialService;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.impl.WorkmaterialQty;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,8 +26,28 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @since 2023-10-24
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/pdmBiWorkmaterial")
|
||||
@RequestMapping("api/pdmBiWorkmaterial")
|
||||
public class PdmBiWorkmaterialController {
|
||||
|
||||
@Autowired
|
||||
private IPdmBiWorkmaterialService workmaterialService;
|
||||
|
||||
@GetMapping()
|
||||
@Log("查询在制品日库存")
|
||||
public ResponseEntity<Object> byMaterial(WorkmaterialQty query, PageQuery page) {
|
||||
Page<Object> result = PageHelper.startPage(page.getPage() + 1, page.getSize());
|
||||
List<Map> list = workmaterialService.query(query);
|
||||
TableDataInfo build = TableDataInfo.build(list);
|
||||
build.setTotalElements(result.getTotal());
|
||||
return new ResponseEntity<>(build, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/sync")
|
||||
@Log("同步日库区")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> sync(String time){
|
||||
workmaterialService.syncQty(time);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.nl.wms.analysis_manage.workmaterial.service;
|
||||
|
||||
import org.nl.wms.analysis_manage.scrapRate.service.dto.ScrapRateQuery;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.dao.PdmBiWorkmaterial;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.impl.WorkmaterialQty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +18,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface IPdmBiWorkmaterialService extends IService<PdmBiWorkmaterial> {
|
||||
|
||||
/**
|
||||
* 统计每天的工单物料
|
||||
*/
|
||||
void syncQty(String time);
|
||||
|
||||
List<Map> query(WorkmaterialQty query);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,8 +17,10 @@ import lombok.EqualsAndHashCode;
|
||||
* @since 2023-10-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("pdm_bi_workmaterial")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PdmBiWorkmaterial implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -45,9 +47,29 @@ public class PdmBiWorkmaterial implements Serializable {
|
||||
private String workprocedure_id;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
* 计划数量
|
||||
*/
|
||||
private BigDecimal qty;
|
||||
private BigDecimal plan_qty;
|
||||
/**
|
||||
* 实际数量
|
||||
*/
|
||||
private BigDecimal real_qty;
|
||||
/**
|
||||
* 电气数量
|
||||
*/
|
||||
private BigDecimal dq_real_qty;
|
||||
/**
|
||||
* 今日计划数量
|
||||
*/
|
||||
private BigDecimal today_plan_qty;
|
||||
/**
|
||||
* 今日实际数量
|
||||
*/
|
||||
private BigDecimal today_real_qty;
|
||||
/**
|
||||
* 今日电气数量
|
||||
*/
|
||||
private BigDecimal today_dq_real_qty;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
@@ -58,6 +80,14 @@ public class PdmBiWorkmaterial implements Serializable {
|
||||
* 创建时间
|
||||
*/
|
||||
private String create_time;
|
||||
/**
|
||||
* 需改时间
|
||||
*/
|
||||
private String update_time;
|
||||
/**
|
||||
* 工单集合
|
||||
*/
|
||||
private String workorder_code;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package org.nl.wms.analysis_manage.workmaterial.service.dao.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.dao.PdmBiWorkmaterial;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.impl.WorkmaterialQty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +19,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface PdmBiWorkmaterialMapper extends BaseMapper<PdmBiWorkmaterial> {
|
||||
|
||||
|
||||
List<Map> selectDailyIvt(@Param("confirm_time") String confirm_time);
|
||||
|
||||
@Select("select * from pdm_bi_workmaterial where create_time = (select create_time from pdm_bi_workmaterial where create_time < #{end_time} order by create_time desc limit 1)")
|
||||
List<PdmBiWorkmaterial> selectLastData(@Param("end_time") String end_time);
|
||||
|
||||
List<Map> query(@Param("qty")WorkmaterialQty qty);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,4 +2,65 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.wms.analysis_manage.workmaterial.service.dao.mapper.PdmBiWorkmaterialMapper">
|
||||
|
||||
<select id="query" resultType="java.util.Map">
|
||||
SELECT
|
||||
pdm_bi_workmaterial.*,
|
||||
pdm_bi_workprocedure.workprocedure_code,
|
||||
pdm_bi_workprocedure.workprocedure_name,
|
||||
md_me_materialbase.material_code,
|
||||
md_me_materialbase.material_spec
|
||||
FROM
|
||||
pdm_bi_workmaterial
|
||||
LEFT JOIN md_me_materialbase ON pdm_bi_workmaterial.material_id = md_me_materialbase.material_id
|
||||
LEFT JOIN pdm_bi_workprocedure ON pdm_bi_workmaterial.workprocedure_id = pdm_bi_workprocedure.workprocedure_id
|
||||
where 1=1
|
||||
<if test="qty.product_area != null and qty.product_area != ''">
|
||||
and pdm_bi_workmaterial.product_area like #{qty.product_area}
|
||||
</if>
|
||||
<if test="qty.workprocedure_id != null and qty.workprocedure_id != ''">
|
||||
and pdm_bi_workmaterial.workprocedure_id like #{qty.workprocedure_id}
|
||||
</if>
|
||||
<if test="qty.product_area != null and qty.product_area != ''">
|
||||
and pdm_bi_workmaterial.product_area like #{qty.product_area}
|
||||
</if>
|
||||
<if test="qty.material_id != null and qty.material_id != ''">
|
||||
and pdm_bi_workmaterial.material_id like #{qty.material_id}
|
||||
</if>
|
||||
<if test="qty.start_time != null and qty.start_time != ''">
|
||||
and pdm_bi_workmaterial.create_time >= #{qty.start_time}
|
||||
</if>
|
||||
<if test="qty.end_time != null and qty.end_time != ''">
|
||||
and #{qty.end_time} >= pdm_bi_workmaterial.create_time
|
||||
</if>
|
||||
order by pdm_bi_workmaterial.create_time desc
|
||||
</select>
|
||||
<select id="selectDailyIvt" resultType="java.util.Map">
|
||||
(SELECT
|
||||
SUM( plan_qty ) plan_qty,SUM( real_qty ) real_qty,SUM( dq_real_qty ) dq_real_qty,
|
||||
material_id,workprocedure_id,product_area,GROUP_CONCAT( workorder_code ) workorder_code,DATE_FORMAT( confirm_time, '%Y-%m-%d') create_time
|
||||
FROM pdm_produce_workorder
|
||||
WHERE
|
||||
confirm_time IS NOT NULL and DATE_FORMAT(confirm_time, '%Y-%m-%d') = #{confirm_time}
|
||||
GROUP BY material_id,workprocedure_id,DATE_FORMAT( confirm_time, '%Y-%m-%d')
|
||||
ORDER BY create_time DESC) union all
|
||||
(SELECT
|
||||
sum( sch_base_task.material_qty ) AS plan_qty,
|
||||
sum( sch_base_task.material_qty ) AS real_qty,
|
||||
sum( sch_base_task.material_qty ) AS dq_real_qty,
|
||||
sch_base_task.material_id,
|
||||
CONCAT( 'sk', pdm_produce_workorder.workprocedure_id ) AS workprocedure_id,
|
||||
pdm_produce_workorder.product_area,
|
||||
table_fk_id AS workorder_code,
|
||||
DATE_FORMAT( sch_base_task.create_time, '%Y-%m-%d' ) AS create_time
|
||||
FROM
|
||||
sch_base_task
|
||||
LEFT JOIN pdm_produce_workorder ON table_fk_id = workorder_code
|
||||
WHERE
|
||||
task_type = '3'
|
||||
AND table_fk_id IS NOT NULL
|
||||
AND DATE_FORMAT( sch_base_task.create_time, '%Y-%m-%d' ) = #{confirm_time}
|
||||
AND task_Status = '7'
|
||||
GROUP BY
|
||||
table_fk_id)
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
package org.nl.wms.analysis_manage.workmaterial.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.dao.PdmBiWorkmaterial;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.dao.mapper.PdmBiWorkmaterialMapper;
|
||||
import org.nl.wms.analysis_manage.workmaterial.service.IPdmBiWorkmaterialService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.wms.masterdata_manage.storage.service.dailyStructivt.dao.StIvtStructivtDaily;
|
||||
import org.nl.wms.product_manage.service.workprocedure.IPdmBiWorkprocedureService;
|
||||
import org.nl.wms.product_manage.service.workprocedure.dao.PdmBiWorkprocedure;
|
||||
import org.nl.wms.scheduler_manage.service.scheduler.ISchProcessRouteService;
|
||||
import org.nl.wms.scheduler_manage.service.scheduler.SchedulerService;
|
||||
import org.nl.wms.scheduler_manage.service.scheduler.labelConverter.impl.FlowElement;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,4 +38,54 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PdmBiWorkmaterialServiceImpl extends ServiceImpl<PdmBiWorkmaterialMapper, PdmBiWorkmaterial> implements IPdmBiWorkmaterialService {
|
||||
|
||||
@Autowired
|
||||
private IPdmBiWorkprocedureService workprocedureService;
|
||||
@Autowired
|
||||
private SchedulerService schedulerService;
|
||||
@Autowired
|
||||
private ISchProcessRouteService schProcessRouteService;
|
||||
|
||||
@Override
|
||||
public void syncQty(String day) {
|
||||
if (StringUtils.isEmpty(day)){
|
||||
day = DateUtil.today();
|
||||
}
|
||||
List<Map> work_order = this.baseMapper.selectDailyIvt(day);
|
||||
if (!CollectionUtils.isEmpty(work_order)){
|
||||
this.remove(new QueryWrapper<PdmBiWorkmaterial>().eq("create_time", day));
|
||||
List<PdmBiWorkmaterial> old = this.baseMapper.selectLastData(day);
|
||||
List<PdmBiWorkmaterial> today = JSONArray.parseArray(JSON.toJSONString(work_order), PdmBiWorkmaterial.class);
|
||||
Map<String, PdmBiWorkmaterial> groupMap = old.stream().collect(HashMap::new, (k, v) -> k.put(v.getWorkprocedure_id() + v.getMaterial_id(), v), HashMap::putAll);
|
||||
List<PdmBiWorkmaterial> dbs = new ArrayList<>();
|
||||
for (PdmBiWorkmaterial item : today) {
|
||||
PdmBiWorkmaterial target = new PdmBiWorkmaterial();
|
||||
BeanUtils.copyProperties(item,target);
|
||||
String group_field = item.getWorkprocedure_id() + item.getMaterial_id();
|
||||
PdmBiWorkmaterial has = groupMap.remove(group_field);
|
||||
if (has!=null){
|
||||
target.setToday_dq_real_qty(target.getDq_real_qty().add(has.getDq_real_qty()));
|
||||
target.setToday_plan_qty(target.getReal_qty().add(has.getReal_qty()));
|
||||
target.setToday_real_qty(target.getPlan_qty().add(has.getPlan_qty()));
|
||||
}else {
|
||||
target.setToday_dq_real_qty(target.getDq_real_qty());
|
||||
target.setToday_plan_qty(target.getReal_qty());
|
||||
target.setToday_real_qty(target.getPlan_qty());
|
||||
}
|
||||
|
||||
dbs.add(target);
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(groupMap)){
|
||||
dbs.addAll(groupMap.values());
|
||||
}
|
||||
String finalDay = day;
|
||||
dbs.forEach(a->a.setCreate_time(finalDay));
|
||||
this.saveBatch(dbs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> query(WorkmaterialQty query) {
|
||||
return this.baseMapper.query(query);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.nl.wms.analysis_manage.workmaterial.service.impl;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.modules.common.utils.StringUtils;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2023/10/26 13:34
|
||||
*/
|
||||
@Data
|
||||
public class WorkmaterialQty extends BaseQuery {
|
||||
|
||||
/**
|
||||
* 车间
|
||||
*/
|
||||
private String product_area;
|
||||
|
||||
/**
|
||||
* 物料id
|
||||
*/
|
||||
private String material_id;
|
||||
|
||||
/**
|
||||
* 工序id
|
||||
*/
|
||||
private String workprocedure_id;
|
||||
|
||||
|
||||
private String[] create_time;
|
||||
private String start_time;
|
||||
private String end_time;
|
||||
|
||||
public String[] getCreate_time() {
|
||||
return create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(String[] create_time) {
|
||||
this.create_time = create_time;
|
||||
if (create_time!=null && create_time.length == 2){
|
||||
this.start_time = create_time[0];
|
||||
this.end_time =create_time[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user