package cn.stylefeng.guns.modular.rm.recipeManage.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.collectionParamConf.entity.CollectionParamConf;
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
import cn.stylefeng.guns.modular.rm.recipeManage.entity.RecipeManage;
import cn.stylefeng.guns.modular.rm.recipeManage.mapper.RecipeManageMapper;
import cn.stylefeng.guns.modular.rm.recipeManage.model.params.RecipeManageParam;
import cn.stylefeng.guns.modular.rm.recipeManage.model.result.RecipeManageResult;
import cn.stylefeng.guns.modular.rm.recipeManage.service.RecipeManageService;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
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.security.core.parameters.P;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
*
* 配方管理 服务实现类
*
*
* @author ruimin
* @since 2023-08-04
*/
@Service
public class RecipeManageServiceImpl extends ServiceImpl implements RecipeManageService {
@Autowired
RecipeManageService recipeManageService;
//物料追溯
@Autowired
MaterialTraceabilityService materialTraceabilityService;
//设备产品过程参数采集
@Autowired
ParamCollectionService paramCollectionService;
//参数采集配置基础数据表
@Autowired
CollectionParamConfService collectionParamConfService;
@Override
public void add(RecipeManageParam param){
RecipeManage entity = getEntity(param);
this.save(entity);
}
@Override
public void delete(RecipeManageParam param){
this.removeById(getKey(param));
}
@Override
public void update(RecipeManageParam param){
RecipeManage oldEntity = getOldEntity(param);
RecipeManage newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
}
@Override
public RecipeManageResult findBySpec(RecipeManageParam param){
return null;
}
@Override
public List findListBySpec(RecipeManageParam param){
return null;
}
@Override
public LayuiPageInfo findPageBySpec(RecipeManageParam param){
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
List result = page.getRecords();
try {
for (RecipeManageResult recipeManageResult : result) {
switch (recipeManageResult.getOperationType()){
case "1":
recipeManageResult.setOperationType("扫描产品条码类");
break;
case "2":
recipeManageResult.setOperationType("扫描物料类");
break;
case "3":
recipeManageResult.setOperationType("拧紧类");
break;
default:
}
}
}catch (Exception e){
e.printStackTrace();
}
return LayuiPageFactory.createPageInfo(page);
}
@Override
public LayuiPageInfo viewList(RecipeManageParam param) {
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
return LayuiPageFactory.createPageInfo(page);
}
@Override
public String editItemView(RecipeManageParam param) {
List list = listRecipeManage(param);
Integer i = 0;
for (RecipeManage recipeManage : list) {
if(recipeManage.getSpareField3().equals("OK")){
i = i+1;
}
}
if(list.size() == i){
return "已全部扫描完成请确认!";
}
for (RecipeManage recipeManage : list) {
if(recipeManage.getSpareField3().equals("NG")){
switch(recipeManage.getOperationType()){
case "2":
if(param.getSoketData().contains(recipeManage.getMaterialCode())){
recipeManage.setSpareField1(param.getSoketData());
recipeManage.setSpareField3("OK");
recipeManageService.saveOrUpdate(recipeManage);
}else {
recipeManage.setSpareField1(param.getSoketData());
recipeManage.setSpareField3("NG");
recipeManageService.saveOrUpdate(recipeManage);
return "您扫描的条码不对结果为NG"+param.getSoketData();
}
break;
case "3" :
String[] parmCode;
String delimiter = ",";// 指定分割字符
parmCode = param.getSoketData().split(delimiter);
if(parmCode[2].equals("1")){
recipeManage.setSpareField2(param.getSoketData());
recipeManage.setSpareField3("OK");
recipeManageService.saveOrUpdate(recipeManage);
}else {
recipeManage.setSpareField2(param.getSoketData());
recipeManage.setSpareField3("NG");
recipeManageService.saveOrUpdate(recipeManage);
return "扫描的拧紧数结果NG!请重新扫描";
}
break;
default:
}
return "扫描成功";
}
if(recipeManage.getSpareField3()==null||recipeManage.getSpareField3().equals("")){
switch(recipeManage.getOperationType()){
case "1":
recipeManage.setSpareField1(param.getSoketData());
recipeManage.setSpareField3("OK");
break;
case "2":
if(param.getSoketData().contains(recipeManage.getMaterialCode())){
recipeManage.setSpareField1(param.getSoketData());
recipeManage.setSpareField3("OK");
}else {
recipeManage.setSpareField1(param.getSoketData());
recipeManage.setSpareField3("NG");
// return "您扫描的物料条码为"+param.getSoketData()+"文本格式不对,请重新扫描";
}
break;
case "3" :
if(param.getSoketData().contains(",")){
String[] parmCode;
String delimiter = ",";// 指定分割字符
parmCode = param.getSoketData().split(delimiter);
if(parmCode[2].equals("1")){
recipeManage.setSpareField2(param.getSoketData());
recipeManage.setSpareField3("OK");
recipeManageService.saveOrUpdate(recipeManage);
return "扫描成功";
}else {
// return "您扫描的拧紧枪数据为"+param.getSoketData()+"结果NG请重新扫描";
recipeManage.setSpareField2(param.getSoketData());
recipeManage.setSpareField3("NG");
recipeManageService.saveOrUpdate(recipeManage);
return "扫描的拧紧数结果NG!请重新扫描";
}
}else {
// return "您扫描的拧紧枪数据为"+param.getSoketData()+"文本格式不对,请重新扫描";
recipeManage.setSpareField2(param.getSoketData());
recipeManage.setSpareField3("NG");
recipeManageService.saveOrUpdate(recipeManage);
return "扫描的拧紧数据格式不对!请重新扫描";
}
// break;
default:
}
// recipeManage.setSpareField3("OK");
recipeManageService.saveOrUpdate(recipeManage);
break;
}
// else {
// return "已全部扫描请确认完成!";
// }
}
return "扫描成功";
}
@Override
public Integer finish(RecipeManageParam param) {
String sfc = "";
Integer i = 0;
List recipeManages = listRecipeManage(param);
for (RecipeManage recipeManage : recipeManages) {
if(recipeManage.getSpareField3()==null||recipeManage.getSpareField3().equals("")){
i+=1;
}
}
if(i>0){
return i;
}else {
//保存需要的表
for (RecipeManage recipeManage : recipeManages) {
if(recipeManage.getSpareField3()!=null||!recipeManage.getSpareField3().equals("")) {
switch (recipeManage.getOperationType()) {
case "1":
sfc = recipeManage.getSpareField1();
break;
case "2":
MaterialTraceabilityParam materialParam = new MaterialTraceabilityParam();
materialParam.setProductNo(recipeManage.getSpareField1());
materialParam.setWorkOrderNo(param.getWorkOrderNo());
materialParam.setProductCode(param.getProductCode());
materialParam.setLineCode(param.getLineCode());
materialParam.setMaterialCode(recipeManage.getMaterialCode());
materialParam.setLocationCode(param.getLocationCode());
materialParam.setAssemblyTime(new Date());
materialParam.setAssemblyUser(LoginContextHolder.getContext().getUser().getName());
materialTraceabilityService.add(materialParam);
break;
case "3":
String[] temp;
String[] parmCode;
String delimiter = ",";// 指定分割字符
temp = recipeManage.getSpareField2().split(delimiter);// 分割字符串
parmCode = recipeManage.getParamCode().split(delimiter);
for (int i1 = 0; i1 < 3; i1++) {
CollectionParamConf paramOne = collectionParamConfService.getOne(new QueryWrapper().eq("param_code", parmCode[i1]));
ParamCollectionParam deviceParam = new ParamCollectionParam();
deviceParam.setSfcCode(sfc);
deviceParam.setWorkOrderNo(param.getWorkOrderNo());
deviceParam.setProductCode(param.getProductCode());
deviceParam.setLocationCode(param.getLocationCode());
deviceParam.setProductionLine(param.getLineCode());
deviceParam.setParamValue(temp[i1]);
deviceParam.setParamCode(parmCode[i1]);
deviceParam.setCollectionTime(new Date());
deviceParam.setParamName(paramOne.getParamName());
deviceParam.setUnit(paramOne.getUnit());
deviceParam.setParamUpper(paramOne.getParamUpper());
deviceParam.setParamLower(paramOne.getParamLower());
deviceParam.setParamStandard(paramOne.getParamCentral());
paramCollectionService.add(deviceParam);
}
break;
default:
}
}
}
//删除数据重新加载列表
List list = listRecipeManage(param);
for (RecipeManage recipeManage : list) {
recipeManage.setSpareField1("");
recipeManage.setSpareField2("");
recipeManage.setSpareField3("");
recipeManageService.saveOrUpdate(recipeManage);
}
if(list.size() == 0){
return 980;
}
return i;
}
}
@Override
public void heavyLoad(RecipeManageParam recipeManageParam) {
List list = listRecipeManage(recipeManageParam);
for (RecipeManage recipeManage : list) {
recipeManage.setSpareField1("");
recipeManage.setSpareField2("");
recipeManage.setSpareField3("");
recipeManageService.saveOrUpdate(recipeManage);
}
}
@Override
public void singleRowDelete(RecipeManageParam recipeManageParam) {
RecipeManage byId = recipeManageService.getById(recipeManageParam.getId());
byId.setSpareField1("");
byId.setSpareField2("");
byId.setSpareField3("");
recipeManageService.saveOrUpdate(byId);
}
public List listRecipeManage(RecipeManageParam param) {
List list = recipeManageService.list(new QueryWrapper()
.eq("location_code", param.getLocationCode())
.eq("product_code", param.getProductCode())
.orderByAsc("step_sort")
);
return list;
}
private Serializable getKey(RecipeManageParam param){
return param.getId();
}
private Page getPageContext() {
return LayuiPageFactory.defaultPage();
}
private RecipeManage getOldEntity(RecipeManageParam param) {
return this.getById(getKey(param));
}
private RecipeManage getEntity(RecipeManageParam param) {
RecipeManage entity = new RecipeManage();
ToolUtil.copyProperties(param, entity);
return entity;
}
}