Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -27,4 +27,5 @@ public interface FactoryMapper extends BaseMapperX<FactoryDO> {
|
||||
.orderByDesc(FactoryDO::getId));
|
||||
}
|
||||
|
||||
String selectMaxCode();
|
||||
}
|
||||
@@ -36,6 +36,17 @@ public class FactoryServiceImpl implements FactoryService {
|
||||
public FactoryRespVO createFactory(FactorySaveReqVO createReqVO) {
|
||||
// 插入
|
||||
FactoryDO factory = BeanUtils.toBean(createReqVO, FactoryDO.class);
|
||||
// 工厂编码自动生成,格式 GC-0001,依次新增
|
||||
String maxCode = factoryMapper.selectMaxCode();
|
||||
if (maxCode == null) {
|
||||
factory.setNumber("GC-0001");
|
||||
} else {
|
||||
String prefix = "GC-";
|
||||
String numberPart = maxCode.substring(prefix.length());
|
||||
int nextNumber = Integer.parseInt(numberPart) + 1;
|
||||
String nextCode = prefix + String.format("%04d", nextNumber);
|
||||
factory.setNumber(nextCode);
|
||||
}
|
||||
factoryMapper.insert(factory);
|
||||
// 返回
|
||||
return BeanUtils.toBean(factory, FactoryRespVO.class);
|
||||
@@ -59,12 +70,12 @@ public class FactoryServiceImpl implements FactoryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFactoryListByIds(List<Long> ids) {
|
||||
public void deleteFactoryListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateFactoryExists(ids);
|
||||
// 删除
|
||||
factoryMapper.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateFactoryExists(List<Long> ids) {
|
||||
List<FactoryDO> list = factoryMapper.selectByIds(ids);
|
||||
@@ -92,7 +103,7 @@ public class FactoryServiceImpl implements FactoryService {
|
||||
@Override
|
||||
public void enableFactoryList(List<FactoryRespVO> saveReqVOS) {
|
||||
List<FactoryDO> updateObj = BeanUtils.toBean(saveReqVOS, FactoryDO.class);
|
||||
List<BatchResult> count = factoryMapper.updateById(updateObj);
|
||||
List<BatchResult> count = factoryMapper.updateById(updateObj);
|
||||
if (CollUtil.isEmpty(count)) {
|
||||
throw exception(FACTORY_NOT_EXISTS);
|
||||
}
|
||||
|
||||
@@ -9,4 +9,7 @@
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<select id="selectMaxCode" resultType="java.lang.String">
|
||||
SELECT MAX(NUM) FROM sply_fact
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user