87 lines
3.0 KiB
Java
87 lines
3.0 KiB
Java
package com.klp.service.impl;
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
import com.klp.common.helper.LoginHelper;
|
|
import com.klp.domain.DrMillProcessPass;
|
|
import com.klp.domain.DrMillProcessRecipeVersion;
|
|
import com.klp.mapper.DrMillProcessPassMapper;
|
|
import com.klp.mapper.DrMillProcessRecipeVersionMapper;
|
|
import com.klp.service.IDrMillProcessRecipeVersionService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
|
|
@DS("double-rack")
|
|
@RequiredArgsConstructor
|
|
@Service
|
|
public class DrMillProcessRecipeVersionServiceImpl implements IDrMillProcessRecipeVersionService {
|
|
|
|
private final DrMillProcessRecipeVersionMapper versionMapper;
|
|
private final DrMillProcessPassMapper passMapper;
|
|
|
|
@Override
|
|
public List<DrMillProcessRecipeVersion> listByRecipeId(Long recipeId) {
|
|
return versionMapper.selectByRecipeId(recipeId);
|
|
}
|
|
|
|
@Override
|
|
public DrMillProcessRecipeVersion getDetailById(Long versionId) {
|
|
DrMillProcessRecipeVersion v = versionMapper.selectById(versionId);
|
|
if (v != null) {
|
|
v.setPassList(passMapper.selectByVersionId(versionId));
|
|
}
|
|
return v;
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Long save(DrMillProcessRecipeVersion version) {
|
|
String user = LoginHelper.getUsername();
|
|
version.setCreateBy(user);
|
|
version.setUpdateBy(user);
|
|
versionMapper.insert(version);
|
|
savePassList(version);
|
|
return version.getVersionId();
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void update(DrMillProcessRecipeVersion version) {
|
|
version.setUpdateBy(LoginHelper.getUsername());
|
|
versionMapper.update(version);
|
|
passMapper.deleteByVersionId(version.getVersionId());
|
|
savePassList(version);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void activate(Long versionId) {
|
|
DrMillProcessRecipeVersion v = versionMapper.selectById(versionId);
|
|
if (v == null) throw new RuntimeException("版本不存在");
|
|
versionMapper.deactivateOthers(v.getRecipeId(), versionId);
|
|
versionMapper.activate(versionId);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void deleteById(Long versionId) {
|
|
passMapper.deleteByVersionId(versionId);
|
|
versionMapper.deleteById(versionId);
|
|
}
|
|
|
|
private void savePassList(DrMillProcessRecipeVersion version) {
|
|
List<DrMillProcessPass> list = version.getPassList();
|
|
if (list == null || list.isEmpty()) return;
|
|
String user = LoginHelper.getUsername();
|
|
for (DrMillProcessPass p : list) {
|
|
p.setRecipeId(version.getRecipeId());
|
|
p.setVersionId(version.getVersionId());
|
|
p.setCreateBy(user);
|
|
p.setUpdateBy(user);
|
|
}
|
|
passMapper.insertBatch(list);
|
|
}
|
|
}
|