package com.chinaztt.mes.production.service.impl;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
import com.chinaztt.mes.basic.entity.Location;
|
import com.chinaztt.mes.basic.entity.Part;
|
import com.chinaztt.mes.common.numgen.NumberGenerator;
|
import com.chinaztt.mes.plan.entity.ManufacturingOrder;
|
import com.chinaztt.mes.production.dto.HandymanTypeDTO;
|
import com.chinaztt.mes.production.entity.ArtificialInformationRelation;
|
import com.chinaztt.mes.production.entity.HandymanType;
|
import com.chinaztt.mes.production.excel.HandymanTypeData;
|
import com.chinaztt.mes.production.mapper.ArtificialInformationRelationMapper;
|
import com.chinaztt.mes.production.mapper.HandymanTypeMapper;
|
import com.chinaztt.mes.production.service.HandymanTypeService;
|
import com.chinaztt.mes.warehouse.entity.Stock;
|
import com.chinaztt.mes.warehouse.excel.StockData;
|
import com.chinaztt.ztt.common.core.util.R;
|
import io.micrometer.core.instrument.util.StringUtils;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 杂工类型维护
|
*
|
* @author cxf
|
* @date 2020-12-01 13:13:44
|
*/
|
@Service
|
@AllArgsConstructor
|
@Transactional(rollbackFor = Exception.class)
|
public class HandymanTypeServiceImpl extends ServiceImpl<HandymanTypeMapper, HandymanType> implements HandymanTypeService {
|
private NumberGenerator<HandymanType> handymanTypeNumberGenerator;
|
private ArtificialInformationRelationMapper artificialInformationRelationMapper;
|
|
@Override
|
public boolean save(HandymanType handymanType) {
|
checkHandymanNo(handymanType);
|
return SqlHelper.retBool(baseMapper.insert(handymanType));
|
}
|
|
@Override
|
public boolean updateById(HandymanType handymanType) {
|
checkHandymanNo(handymanType);
|
return SqlHelper.retBool(baseMapper.updateById(handymanType));
|
}
|
|
private void checkHandymanNo(HandymanType handymanType) {
|
if (StringUtils.isBlank(handymanType.getHandymanNo())) {
|
// 1. 自动生成人工编号
|
handymanType.setHandymanNo(handymanTypeNumberGenerator.generateNumberWithPrefix(HandymanType.DIGIT, HandymanType.PREFIX + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATE_PATTERN) + "-", HandymanType::getHandymanNo));
|
} else {
|
// 2.判断是否重复
|
List<HandymanType> repeatNumbers = baseMapper.selectList(Wrappers.<HandymanType>query().lambda().eq(HandymanType::getHandymanNo, handymanType.getHandymanNo()).ne(HandymanType::getId, handymanType.getId()));
|
if (CollectionUtil.isNotEmpty(repeatNumbers)) {
|
throw new RuntimeException("编号重复");
|
}
|
}
|
}
|
|
@Override
|
public IPage<List<HandymanType>> getHandymanType(Page page, QueryWrapper<HandymanType> gen, Long id) {
|
return baseMapper.getHandymanType(page, gen, id);
|
}
|
|
@Override
|
public IPage<List<HandymanType>> getHandyman(Page page, QueryWrapper<HandymanType> gen, Long id) {
|
return baseMapper.getHandyman(page, gen, id);
|
}
|
|
@Override
|
public R<Boolean> delHandyTypeRelation(Long id, Long id1) {
|
artificialInformationRelationMapper.delete(Wrappers.<ArtificialInformationRelation>lambdaQuery().eq(ArtificialInformationRelation::getProductionHandymanJoinId, id1).eq(ArtificialInformationRelation::getProductionHandymanId, id));
|
return R.ok();
|
}
|
|
@Override
|
public void importExcel(List<HandymanTypeData> list) {
|
if (CollectionUtil.isEmpty(list)) {
|
return;
|
}
|
for (HandymanTypeData data : list) {
|
baseMapper.insert(data);
|
}
|
}
|
|
@Override
|
public IPage<List<HandymanTypeDTO>> fetchListByTemplateId(Page page, QueryWrapper<HandymanTypeDTO> gen) {
|
return baseMapper.fetchListByTemplateId(page, gen);
|
}
|
|
@Override
|
public IPage<List<HandymanTypeDTO>> fetchListFilterTemplateId(Page page, QueryWrapper<HandymanTypeDTO> gen, Long handymanTemplateId) {
|
return baseMapper.fetchListFilterTemplateId(page, gen, handymanTemplateId);
|
}
|
|
@Override
|
public HandymanTypeDTO getHandymanTypeById(Long id) {
|
return baseMapper.getHandymanTypeById(id);
|
}
|
}
|