package cn.stylefeng.guns.modular.dq.materialTraceability.service.impl;
|
|
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
|
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
|
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
|
import cn.stylefeng.guns.modular.bs.bomInfo.entity.BomInfo;
|
import cn.stylefeng.guns.modular.bs.bomInfo.service.BomInfoService;
|
import cn.stylefeng.guns.modular.bs.lineInfo.entity.LineInfo;
|
import cn.stylefeng.guns.modular.bs.lineInfo.service.LineInfoService;
|
import cn.stylefeng.guns.modular.bs.locationInfo.entity.LocationInfo;
|
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.entity.MaterialTraceability;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.mapper.MaterialTraceabilityMapper;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
|
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.entity.ProductionOrderBatchInfo;
|
import cn.stylefeng.guns.modular.om.productionOrderBatchInfo.model.params.ProductionOrderBatchInfoParam;
|
import cn.stylefeng.roses.core.util.ToolUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.io.Serializable;
|
import java.lang.reflect.Field;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Stream;
|
|
/**
|
* <p>
|
* 物料追溯 服务实现类
|
* </p>
|
*
|
* @author cl
|
* @since 2022-10-29
|
*/
|
@Service
|
public class MaterialTraceabilityServiceImpl extends ServiceImpl<MaterialTraceabilityMapper, MaterialTraceability> implements MaterialTraceabilityService {
|
private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
@Autowired
|
private BomInfoService bomInfoService;
|
|
@Autowired
|
private MaterialTraceabilityService traceabilityService;
|
|
@Autowired
|
private LocationInfoService locationInfoService;
|
|
@Override
|
public void add(MaterialTraceabilityParam param){
|
// param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
|
// param.setAssemblyTime(new Date());
|
// param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
|
MaterialTraceability entity = getEntity(param);
|
this.save(entity);
|
}
|
|
@Override
|
public void lineFeedingAddItem(MaterialTraceabilityParam param) {
|
param.setAssemblyUser(LoginContextHolder.getContext().getUser().getUsername());
|
param.setAssemblyTime(new Date());
|
param.setProductNo(getSfcCode(param.getLocationCode()+"_S_SFC_CODE"));
|
MaterialTraceability entity = getEntity(param);
|
this.save(entity);
|
}
|
|
@Override
|
public List<MaterialTraceabilityResult> exportTable(MaterialTraceabilityParam param) {
|
return this.baseMapper.customList(param);
|
}
|
|
@Override
|
public void delete(MaterialTraceabilityParam param){
|
this.removeById(getKey(param));
|
}
|
|
@Override
|
public void update(MaterialTraceabilityParam param){
|
MaterialTraceability oldEntity = getOldEntity(param);
|
MaterialTraceability newEntity = getEntity(param);
|
ToolUtil.copyProperties(newEntity, oldEntity);
|
this.updateById(newEntity);
|
}
|
|
public static String getSfcCode(String str){
|
String sfcCode = "";
|
try {
|
Class<?> clazz = Class.forName("cn.stylefeng.guns.plcserver.opc.GlobalVariable");
|
Field[] fields = clazz.getFields();
|
for (Field field : fields) {
|
String name = field.getName();
|
if (name.equals(str)) {
|
try {
|
return String.valueOf(field.get(null));
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
return sfcCode;
|
}
|
|
@Override
|
public MaterialTraceabilityResult findBySpec(MaterialTraceabilityParam param){
|
return null;
|
}
|
|
@Override
|
public List<MaterialTraceabilityResult> findListBySpec(MaterialTraceabilityParam param){
|
return this.baseMapper.customList(param);
|
}
|
|
@Override
|
public LayuiPageInfo findPageBySpec(MaterialTraceabilityParam param){
|
Page pageContext = getPageContext();
|
IPage page = this.baseMapper.customPageList(pageContext, param);
|
return LayuiPageFactory.createPageInfo(page);
|
}
|
|
@Override
|
public int barCodeCheck(ProductionOrderBatchInfoParam productionOrderBatchInfoParam) {
|
int i = traceabilityService.count(new QueryWrapper<MaterialTraceability>()
|
.eq("work_order_no", productionOrderBatchInfoParam.getWorkOrderNo())
|
.eq("material_code", productionOrderBatchInfoParam.getMaterialCode())
|
);
|
return i;
|
}
|
|
private Serializable getKey(MaterialTraceabilityParam param){
|
return param.getId();
|
}
|
|
private Page getPageContext() {
|
return LayuiPageFactory.defaultPage();
|
}
|
|
private MaterialTraceability getOldEntity(MaterialTraceabilityParam param) {
|
return this.getById(getKey(param));
|
}
|
|
private MaterialTraceability getEntity(MaterialTraceabilityParam param) {
|
MaterialTraceability entity = new MaterialTraceability();
|
ToolUtil.copyProperties(param, entity);
|
return entity;
|
}
|
@Override
|
public int updateSFC(String sfcCode, String childSfcCode) {
|
return this.baseMapper.updateSFC(sfcCode, childSfcCode);
|
}
|
|
|
}
|