package cn.stylefeng.guns.modular.zsx.pm.workOrder.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.pm.workOrder.entity.WorkOrder;
|
import cn.stylefeng.guns.modular.zsx.pm.workOrder.mapper.WorkOrderMapper;
|
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.params.WorkOrderParam;
|
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.result.WorkOrderResult;
|
import cn.stylefeng.guns.modular.zsx.pm.workOrder.service.WorkOrderService;
|
import cn.stylefeng.guns.modular.zsx.sys.codingRule.entity.CodingRule;
|
import cn.stylefeng.guns.modular.zsx.sys.codingRule.service.CodingRuleService;
|
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.apache.commons.lang3.StringUtils;
|
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;
|
|
/**
|
* <p>
|
* 生产工单 服务实现类
|
* </p>
|
*
|
* @author ruimin
|
* @since 2023-08-26
|
*/
|
@Service
|
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService {
|
@Autowired
|
private CodingRuleService codingRuleService;
|
|
@Override
|
public void add(WorkOrderParam param){
|
param.setCreateUser(LoginContextHolder.getContext().getUser().getName());
|
WorkOrder entity = getEntity(param);
|
this.save(entity);
|
}
|
|
@Override
|
public void delete(WorkOrderParam param){
|
this.removeById(getKey(param));
|
}
|
|
@Override
|
public void update(WorkOrderParam param){
|
param.setUpdateUser(LoginContextHolder.getContext().getUser().getName());
|
WorkOrder oldEntity = getOldEntity(param);
|
WorkOrder newEntity = getEntity(param);
|
ToolUtil.copyProperties(newEntity, oldEntity);
|
this.updateById(newEntity);
|
}
|
|
@Override
|
public WorkOrderResult findBySpec(WorkOrderParam param){
|
return null;
|
}
|
|
@Override
|
public List<WorkOrderResult> findListBySpec(WorkOrderParam param){
|
return null;
|
}
|
|
@Override
|
public LayuiPageInfo findPageBySpec(WorkOrderParam param){
|
Page pageContext = getPageContext();
|
IPage page = this.baseMapper.customPageList(pageContext, param);
|
return LayuiPageFactory.createPageInfo(page);
|
}
|
|
@Override
|
public String getOrderCode() {
|
CodingRule codingRule = codingRuleService.getCodingCode("WORK_ORDER");
|
String result = "";
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(codingRule.getDateType());
|
String dateString = sdf.format(new Date());
|
List<WorkOrder> oneOrder = this.list(new QueryWrapper<WorkOrder>().eq("work_order_code",codingRule.getCurrentCode()));
|
if(oneOrder.size() == 0){
|
result = codingRule.getCurrentCode();
|
}else {
|
List<WorkOrder> workOrderCode = this.list(new QueryWrapper<WorkOrder>().like("work_order_code", dateString));
|
result = codingRule.getCodingRulePrefix()+simpleDateFormat.format(new Date())+StringUtils.leftPad(String.valueOf(workOrderCode.size()+1), codingRule.getCodeLength(), "0");
|
}
|
return result;
|
}
|
|
private Serializable getKey(WorkOrderParam param){
|
return param.getId();
|
}
|
|
private Page getPageContext() {
|
return LayuiPageFactory.defaultPage();
|
}
|
|
private WorkOrder getOldEntity(WorkOrderParam param) {
|
return this.getById(getKey(param));
|
}
|
|
private WorkOrder getEntity(WorkOrderParam param) {
|
WorkOrder entity = new WorkOrder();
|
ToolUtil.copyProperties(param, entity);
|
return entity;
|
}
|
|
}
|