package cn.stylefeng.guns.modular.bs.materialInfo.service.impl;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.bs.materialInfo.entity.MaterialInfo;
import cn.stylefeng.guns.modular.bs.materialInfo.mapper.MaterialInfoMapper;
import cn.stylefeng.guns.modular.bs.materialInfo.model.params.MaterialInfoParam;
import cn.stylefeng.guns.modular.bs.materialInfo.model.result.MaterialInfoResult;
import cn.stylefeng.guns.modular.bs.materialInfo.service.MaterialInfoService;
import cn.stylefeng.roses.core.util.ToolUtil;
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.stereotype.Service;
import java.io.Serializable;
import java.util.List;
/**
*
* 物料信息 服务实现类
*
*
* @author zrm
* @since 2023-02-15
*/
@Service
public class MaterialInfoServiceImpl extends ServiceImpl implements MaterialInfoService {
@Override
public void add(MaterialInfoParam param){
MaterialInfo entity = getEntity(param);
this.save(entity);
}
@Override
public void delete(MaterialInfoParam param){
this.removeById(getKey(param));
}
@Override
public void update(MaterialInfoParam param){
MaterialInfo oldEntity = getOldEntity(param);
MaterialInfo newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
}
@Override
public MaterialInfoResult findBySpec(MaterialInfoParam param){
return null;
}
@Override
public List findListBySpec(MaterialInfoParam param){
return null;
}
@Override
public LayuiPageInfo findPageBySpec(MaterialInfoParam param){
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
return LayuiPageFactory.createPageInfo(page);
}
private Serializable getKey(MaterialInfoParam param){
return param.getId();
}
private Page getPageContext() {
return LayuiPageFactory.defaultPage();
}
private MaterialInfo getOldEntity(MaterialInfoParam param) {
return this.getById(getKey(param));
}
private MaterialInfo getEntity(MaterialInfoParam param) {
MaterialInfo entity = new MaterialInfo();
ToolUtil.copyProperties(param, entity);
return entity;
}
}