package cn.stylefeng.guns.modular.zsx.bs.workshop.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.zsx.bs.workshop.entity.WorkshopInfo;
import cn.stylefeng.guns.modular.zsx.bs.workshop.mapper.WorkshopInfoMapper;
import cn.stylefeng.guns.modular.zsx.bs.workshop.model.params.WorkshopInfoParam;
import cn.stylefeng.guns.modular.zsx.bs.workshop.model.result.WorkshopInfoResult;
import cn.stylefeng.guns.modular.zsx.bs.workshop.service.WorkshopInfoService;
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 ruimin
* @since 2023-08-19
*/
@Service
public class WorkshopInfoServiceImpl extends ServiceImpl implements WorkshopInfoService {
@Override
public void add(WorkshopInfoParam param){
param.setCreateUser(LoginContextHolder.getContext().getUser().getName());
WorkshopInfo entity = getEntity(param);
this.save(entity);
}
@Override
public void delete(WorkshopInfoParam param){
this.removeById(getKey(param));
}
@Override
public void update(WorkshopInfoParam param){
param.setUpdateUser(LoginContextHolder.getContext().getUser().getName());
WorkshopInfo oldEntity = getOldEntity(param);
WorkshopInfo newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
}
@Override
public WorkshopInfoResult findBySpec(WorkshopInfoParam param){
return null;
}
@Override
public List findListBySpec(WorkshopInfoParam param){
return null;
}
@Override
public LayuiPageInfo findPageBySpec(WorkshopInfoParam param){
Page pageContext = getPageContext();
IPage page = this.baseMapper.customPageList(pageContext, param);
return LayuiPageFactory.createPageInfo(page);
}
private Serializable getKey(WorkshopInfoParam param){
return param.getId();
}
private Page getPageContext() {
return LayuiPageFactory.defaultPage();
}
private WorkshopInfo getOldEntity(WorkshopInfoParam param) {
return this.getById(getKey(param));
}
private WorkshopInfo getEntity(WorkshopInfoParam param) {
WorkshopInfo entity = new WorkshopInfo();
ToolUtil.copyProperties(param, entity);
return entity;
}
}