package cn.stylefeng.guns.modular.em.equipmentMaintainPlan.service.impl;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.em.equipmentMaintainPlan.entity.EquipmentMaintainPlan;
import cn.stylefeng.guns.modular.em.equipmentMaintainPlan.mapper.EquipmentMaintainPlanMapper;
import cn.stylefeng.guns.modular.em.equipmentMaintainPlan.model.params.EquipmentMaintainPlanParam;
import cn.stylefeng.guns.modular.em.equipmentMaintainPlan.model.result.EquipmentMaintainPlanResult;
import cn.stylefeng.guns.modular.em.equipmentMaintainPlan.service.EquipmentMaintainPlanService;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.impl.ProductionOrdeInfoServiceImpl;
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.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
*
* 保养计划 服务实现类
*
*
* @author ruimin
* @since 2023-02-20
*/
@Service
public class EquipmentMaintainPlanServiceImpl extends ServiceImpl implements EquipmentMaintainPlanService {
private static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
private static String date = format.format(new Date());
private static String planNum = "P"+date;
@Override
public void add(EquipmentMaintainPlanParam param){
param.setState("2");
EquipmentMaintainPlan entity = getEntity(param);
this.save(entity);
}
@Override
public void delete(EquipmentMaintainPlanParam param){
this.removeById(getKey(param));
}
@Override
public void update(EquipmentMaintainPlanParam param){
EquipmentMaintainPlan oldEntity = getOldEntity(param);
EquipmentMaintainPlan newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
}
@Override
public EquipmentMaintainPlanResult findBySpec(EquipmentMaintainPlanParam param){
return null;
}
@Override
public List findListBySpec(EquipmentMaintainPlanParam param){
return null;
}
@Override
public LayuiPageInfo findPageBySpec(EquipmentMaintainPlanParam param){
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
return LayuiPageFactory.createPageInfo(page);
}
@Override
public String planNumberGenerate(EquipmentMaintainPlanParam equipmentMaintainPlanParam) {
String PlanNum = "";
List planNo = this.baseMapper.selectList(new QueryWrapper().like("plan_no", date));
if(planNo.size() == 0){
PlanNum = planNum+"0001";
}else {
PlanNum = planNum+String.format("%04d", planNo.size()+1);
}
return PlanNum;
}
private Serializable getKey(EquipmentMaintainPlanParam param){
return param.getId();
}
private Page getPageContext() {
return LayuiPageFactory.defaultPage();
}
private EquipmentMaintainPlan getOldEntity(EquipmentMaintainPlanParam param) {
return this.getById(getKey(param));
}
private EquipmentMaintainPlan getEntity(EquipmentMaintainPlanParam param) {
EquipmentMaintainPlan entity = new EquipmentMaintainPlan();
ToolUtil.copyProperties(param, entity);
return entity;
}
}