diff --git a/modules/i3plus-ext-mes-api/src/main/java/cn/estsh/i3plus/ext/mes/api/base/IMesProductionRecordService.java b/modules/i3plus-ext-mes-api/src/main/java/cn/estsh/i3plus/ext/mes/api/base/IMesProductionRecordService.java index b74f17a..fc6c76d 100644 --- a/modules/i3plus-ext-mes-api/src/main/java/cn/estsh/i3plus/ext/mes/api/base/IMesProductionRecordService.java +++ b/modules/i3plus-ext-mes-api/src/main/java/cn/estsh/i3plus/ext/mes/api/base/IMesProductionRecordService.java @@ -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 findMesProductionRecord(String organizeCode, String sn); + + ListPager queryRecordGroupByPartNoWorkCellCode(MesProductionRecord mesProductionRecord, Pager pager); } diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/base/MesProductionRecordController.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/base/MesProductionRecordController.java new file mode 100644 index 0000000..a61d402 --- /dev/null +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/controller/base/MesProductionRecordController.java @@ -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{ + @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); + } + } + +} diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesProductionRecordServiceImpl.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesProductionRecordServiceImpl.java index 2067bf6..20367cd 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesProductionRecordServiceImpl.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/MesProductionRecordServiceImpl.java @@ -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 implements IMesProductionRecordService { + @Autowired + private EntityManager entityManager; @Override public List 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 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 queryERPMaterialStockHqlPager(MesProductionRecord mesProductionRecord, Pager pager) { + String org = mesProductionRecord.getOrganizeCode(); + String startTime = mesProductionRecord.getCompleteDateTimeStart(); + String endTime = mesProductionRecord.getCompleteDateTimeEnd(); + List 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> hashMaps = queryObject.getResultList(); + + for (HashMap hashMap : hashMaps) { + try { + mesProductionRecordList.add((MesProductionRecord) BeanUtil.populateBean(hashMap, MesProductionRecord.class)); + } catch (Exception e) { + e.printStackTrace(); + } + } + return new ListPager(mesProductionRecordList, pager); + + } + } diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/BeanUtil.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/BeanUtil.java new file mode 100644 index 0000000..0b5a300 --- /dev/null +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/utils/BeanUtil.java @@ -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; + + +/** + * Map转Object 工具类 + */ +public class BeanUtil { + + public static Object populateBean(Map map, Class clazz) throws Exception { + Object obj = clazz.newInstance(); + BeanUtils.populate(obj, map); + return obj; + } + + public static List popListToList(Object object, List> list) throws Exception { + + List listRetun = new ArrayList(); + for (Map 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 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)); + } + } + +}