package cn.stylefeng.guns.modular.sc.repairManageInfo.service.impl;
import cn.stylefeng.guns.base.auth.context.LoginContext;
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.om.productionOrdeInfo.entity.ProductionOrdeInfo;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
import cn.stylefeng.guns.modular.rm.recipeManage.model.result.RecipeManageResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.entity.RepairManageInfo;
import cn.stylefeng.guns.modular.sc.repairManageInfo.mapper.RepairManageInfoMapper;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
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.api.R;
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.util.Date;
import java.util.List;
/**
*
* 返修管理表 服务实现类
*
*
* @author ruimin
* @since 2023-07-31
*/
@Service
public class RepairManageInfoServiceImpl extends ServiceImpl implements RepairManageInfoService {
@Autowired
private RepairManageInfoService repairManageInfoService;
@Autowired
private ProductionOrdeInfoService ordeInfoService;
@Override
public void add(RepairManageInfoParam param){
param.setOperateTime(new Date());
param.setOperateUser(LoginContextHolder.getContext().getUser().getName());
RepairManageInfo entity = getEntity(param);
this.save(entity);
}
@Override
public void delete(RepairManageInfoParam param){
this.removeById(getKey(param));
}
@Override
public void update(RepairManageInfoParam param){
RepairManageInfo oldEntity = getOldEntity(param);
RepairManageInfo newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
}
@Override
public RepairManageInfoResult findBySpec(RepairManageInfoParam param){
return null;
}
@Override
public List findListBySpec(RepairManageInfoParam param){
return this.baseMapper.customList(param);
}
@Override
public LayuiPageInfo findPageBySpec(RepairManageInfoParam param){
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
List result = page.getRecords();
try {
for (RepairManageInfoResult repairManageInfoResult : result) {
switch (repairManageInfoResult.getManageType()){
case "2":
repairManageInfoResult.setManageType("产品上线");
break;
case "1":
repairManageInfoResult.setManageType("产品下线");
break;
default:
}
}
}catch (Exception e){
e.printStackTrace();
}
return LayuiPageFactory.createPageInfo(page);
}
@Override
public void editGoLive(RepairManageInfo repairManageInfo) {
QueryWrapper wrapper = new QueryWrapper<>();
wrapper.eq("sfc",repairManageInfo.getSfc());
try {
String line = repairManageInfo.getProductionLine();
if(line.equals("BOP")||line.equals("COP")){
ProductionOrdeInfo orderStatus = ordeInfoService.getOne(new QueryWrapper().eq("order_status", "3"));
if(orderStatus!=null){
repairManageInfo.setWorkOrderNo(orderStatus.getWorkOrderNo());
repairManageInfo.setProductCode(orderStatus.getMaterialCode());
repairManageInfo.setProductName(orderStatus.getMaterialName());
repairManageInfo.setOperateTime(new Date());
repairManageInfo.setOperateUser(LoginContextHolder.getContext().getUser().getName());
}
}
}catch (Exception e){
e.printStackTrace();
}
repairManageInfoService.saveOrUpdate(repairManageInfo,wrapper);
}
private Serializable getKey(RepairManageInfoParam param){
return param.getId();
}
private Page getPageContext() {
return LayuiPageFactory.defaultPage();
}
private RepairManageInfo getOldEntity(RepairManageInfoParam param) {
return this.getById(getKey(param));
}
private RepairManageInfo getEntity(RepairManageInfoParam param) {
RepairManageInfo entity = new RepairManageInfo();
ToolUtil.copyProperties(param, entity);
return entity;
}
}