根据物料工位分组分页查询设备加工记录

tags/yfai-mes-ext-v1.4
gsz 9 months ago
parent 26834c591c
commit 32b76ad88d

@ -1,5 +1,7 @@
package cn.estsh.i3plus.ext.mes.api.base;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import io.swagger.annotations.ApiOperation;
@ -16,4 +18,6 @@ public interface IMesProductionRecordService extends IBaseMesService<MesProducti
@ApiOperation(value = "根据条码查询设备加工记录表")
List<MesProductionRecord> findMesProductionRecord(String organizeCode, String sn);
ListPager queryRecordGroupByPartNoWorkCellCode(MesProductionRecord mesProductionRecord, Pager pager);
}

@ -0,0 +1,49 @@
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesProductionRecordService;
import cn.estsh.i3plus.ext.mes.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Description :
* @Reference :
* @Author : gsz
* @CreateDate 2024/8/10 10:50
* @Modify:
**/
@Api("设备加工记录")
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesProductionRecord")
public class MesProductionRecordController extends BaseMesController<MesProductionRecord>{
@Autowired
private IMesProductionRecordService mesProductionRecordService;
@GetMapping(value = "/group-by-part-cell/query")
@ApiOperation(value = "设备加工记录", notes = "设备加工记录")
public ResultBean queryProductionRecordGroupByPartNoWorkCellCode(MesProductionRecord mesProductionRecord, Pager pager) {
try {
ValidatorBean.beginValid(mesProductionRecord)
.notNull("organizeCode", mesProductionRecord.getOrganizeCode());
return ResultBean.success("查询成功").setListPager(mesProductionRecordService.queryRecordGroupByPartNoWorkCellCode(mesProductionRecord, pager))
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
}

@ -1,15 +1,28 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesProductionRecordService;
import cn.estsh.i3plus.ext.mes.apiservice.utils.BeanUtil;
import cn.estsh.i3plus.ext.mes.apiservice.utils.MesException;
import cn.estsh.i3plus.ext.mes.pojo.util.OverwriteStringJoin;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
@ -22,16 +35,124 @@ import java.util.List;
@Service
@Slf4j
public class MesProductionRecordServiceImpl extends BaseMesService<MesProductionRecord> implements IMesProductionRecordService {
@Autowired
private EntityManager entityManager;
@Override
public List<MesProductionRecord> findMesProductionRecord(String organizeCode, String sn) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(sn, "productSn", packBean);
DdlPreparedPack.getOrderBy("createDatetime", CommonEnumUtil.ASC_OR_DESC.ASC.getValue(),packBean);
DdlPreparedPack.getOrderBy("createDatetime", CommonEnumUtil.ASC_OR_DESC.ASC.getValue(), packBean);
List<MesProductionRecord> produceSnList = baseRDao.findByHqlWhere(packBean);
if (CollectionUtils.isEmpty(produceSnList)) {
MesException.throwMesBusiException("条码【%s】加工记录信息不存在", sn);
}
return produceSnList;
}
@Override
public ListPager queryRecordGroupByPartNoWorkCellCode(MesProductionRecord mesProductionRecord, Pager pager) {
return queryERPMaterialStockHqlPager(mesProductionRecord, pager);
}
private ListPager<MesProductionRecord> queryERPMaterialStockHqlPager(MesProductionRecord mesProductionRecord, Pager pager) {
String org = mesProductionRecord.getOrganizeCode();
String startTime = mesProductionRecord.getCompleteDateTimeStart();
String endTime = mesProductionRecord.getCompleteDateTimeEnd();
List<MesProductionRecord> mesProductionRecordList = new ArrayList<>();
String countSql = "select count(1) ";
String commHql = " SELECT " +
" DISTINCT mpr.id as id," +
" mpr.organize_code as organizeCode," +
" mpr.create_date_time AS createDatetime, " +
" mpr.create_user AS createUser, " +
" mpr.modify_date_time AS modifyDatetime, " +
" mpr.modify_user AS modifyUser, " +
" mpr.part_no as partNo," +
" mpr.part_name as partName," +
" mpr.work_center_code as workCenterCode," +
" mpr.shift_code as shiftCode," +
" mpr.work_cell_code as workCellCode," +
" mpr.equipment_name as equipmentName," +
" mpr.complete_date_time as completeDateTime," +
" count( mpr.qty) as qty ";
String sql = " from mes_production_record mpr" +
" where 1=1 " +
" and mpr.organize_code =:organizeCode " +
" and mpr.is_deleted ='2' " +
" and mpr.is_valid ='1' ";
if (!StringUtil.isEmpty(startTime)) {
sql += " and mpr.complete_date_time >=:startTime ";
}
if (!StringUtil.isEmpty(endTime)) {
sql += " and mpr.complete_date_time <:endTime ";
}
if (!StringUtil.isEmpty(mesProductionRecord.getPartNo())) {
sql += " and mpr.part_no ='" + mesProductionRecord.getPartNo() + "' ";
}
if (!StringUtil.isEmpty(mesProductionRecord.getWorkCenterCode())) {
sql += " and mpr.work_center_code ='" + mesProductionRecord.getWorkCenterCode() + "' ";
}
if (!StringUtil.isEmpty(mesProductionRecord.getShiftCode())) {
sql += " and mpr.shift_code ='" + mesProductionRecord.getShiftCode() + "' ";
}
if (!StringUtil.isEmpty(mesProductionRecord.getWorkCellCode())) {
sql += " and mpr.work_cell_code ='" + mesProductionRecord.getWorkCellCode() + "' ";
}
if (!StringUtil.isEmpty(mesProductionRecord.getEquipmentName())) {
sql += " and mpr.equipment_name like '%" + mesProductionRecord.getEquipmentName() + "%' ";
}
sql += " GROUP BY mpr.part_no,mpr.work_cell_code ORDER BY mpr.complete_date_time desc ";
Query queryObject = entityManager.createNativeQuery(commHql + sql);
queryObject.setParameter("organizeCode", org);
if (!StringUtil.isEmpty(startTime)) {
queryObject.setParameter("startTime", startTime);
}
if (!StringUtil.isEmpty(endTime)) {
queryObject.setParameter("endTime", endTime);
}
Query queryCountObject = entityManager.createNativeQuery(countSql + sql);
queryCountObject.setParameter("organizeCode", org);
if (!StringUtil.isEmpty(startTime)) {
queryCountObject.setParameter("startTime", startTime);
}
if (!StringUtil.isEmpty(endTime)) {
queryCountObject.setParameter("endTime", endTime);
}
queryObject.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
.setMaxResults(pager.getPageSize()).setFirstResult(pager.getStartRow()).getResultList();
queryCountObject.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List resultList = queryCountObject.getResultList();
int countSize = resultList.size();
if (countSize <= 0) {
return new ListPager();
}
pager = PagerHelper.getPager(pager, countSize);
List<HashMap<String, Object>> hashMaps = queryObject.getResultList();
for (HashMap<String, Object> hashMap : hashMaps) {
try {
mesProductionRecordList.add((MesProductionRecord) BeanUtil.populateBean(hashMap, MesProductionRecord.class));
} catch (Exception e) {
e.printStackTrace();
}
}
return new ListPager(mesProductionRecordList, pager);
}
}

@ -0,0 +1,75 @@
package cn.estsh.i3plus.ext.mes.apiservice.utils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.persistence.Column;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* MapObject
*/
public class BeanUtil {
public static Object populateBean(Map<String, ? extends Object> map, Class<? extends Object> clazz) throws Exception {
Object obj = clazz.newInstance();
BeanUtils.populate(obj, map);
return obj;
}
public static List<Object> popListToList(Object object, List<Map<String, Object>> list) throws Exception {
List<Object> listRetun = new ArrayList<Object>();
for (Map<String, Object> map : list) {
listRetun.add(BeanUtil.populateBean(map, object.getClass()));
}
return listRetun;
}
/**
*
*
* @param c
* @return
*/
public static String[] getAllColumnFields(Class c) {
//父子类属性合并
Field[] fields = ArrayUtils.addAll(c.getFields(), c.getDeclaredFields());
//循环所有属性把名称存入数组
List<String> fieldsNameList = new ArrayList<>();
for (Field field : fields) {
field.setAccessible(true);
// 判断是否为数据库字段
if (field.isAnnotationPresent(Column.class)) {
fieldsNameList.add(field.getName());
}
}
return fieldsNameList.toArray(new String[fieldsNameList.size()]);
}
public static String getProperty(Object bean, String name) {
String proVal = null;
try {
proVal = BeanUtils.getProperty(bean, name);
} catch (Exception e) {
MesException.throwMesBusiException("反射获取对象【" + bean.getClass().getName() + "】属性【" + name +
"】值时异常:详情如下" + ExceptionUtils.getStackTrace(e));
}
return proVal;
}
public static void setProperty(Object bean, String name, Object values) {
try {
BeanUtils.setProperty(bean, name, values);
} catch (Exception e) {
MesException.throwMesBusiException("反射设置对象【" + bean.getClass().getName() + "】属性【" + name +
"】值时异常:详情如下" + ExceptionUtils.getStackTrace(e));
}
}
}
Loading…
Cancel
Save