package com.qianwen.smartman.modules.cps.service.impl; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import java.lang.invoke.SerializedLambda; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.core.mp.service.impl.BladeServiceImpl; import com.qianwen.core.mp.support.Condition; import com.qianwen.core.mp.support.Query; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.cps.convert.StockInTypeConvert; import com.qianwen.smartman.modules.cps.entity.StockInType; import com.qianwen.smartman.modules.cps.mapper.StockInTypeMapper; import com.qianwen.smartman.modules.cps.service.IStockInTypeService; import com.qianwen.smartman.modules.cps.utils.ThrowFun; import com.qianwen.smartman.modules.cps.vo.StockInTypeVO; import org.springframework.stereotype.Service; @Service public class StockInTypeServiceImpl extends BladeServiceImpl implements IStockInTypeService { @Override // org.springblade.modules.cps.service.IStockInTypeService public StockInType createStockInType(StockInTypeVO vo) { validTheSame(null, vo.getCode(), vo.getName()); StockInType stockInType = StockInTypeConvert.INSTANCE.convert(vo); save(stockInType); return stockInType; } private void validTheSame(Long id, String code, String name) { long codeCount = count(Wrappers.lambdaQuery(StockInType.class) .eq(Func.isNotBlank(code), StockInType::getCode, code) .eq(StockInType::getStatus, CommonConstant.ENABLE) .ne(Func.isNotEmpty(id), StockInType::getId, id)); /* long codeCount = count(((LambdaQueryWrapper) Wrappers.lambdaQuery(StockInType.class).eq(Func.isNotBlank(code), (v0) -> { return v0.getCode(); }, code).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE)).ne(Func.isNotEmpty(id), (v0) -> { return v0.getId(); }, id));*/ ThrowFun.isTrue(codeCount > 0).throwMessage(MessageUtils.message("cps.stock.in.type.code.already.exists", new Object[0])); long codeCountDisable = count(Wrappers.lambdaQuery(StockInType.class) .eq(Func.isNotBlank(code), StockInType::getCode, code) .eq(StockInType::getStatus, CommonConstant.DEACTIVATE).ne(Func.isNotEmpty(id), StockInType::getId, id)); ThrowFun.isTrue(codeCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.in.type.code.unable.already.exists", new Object[0])); long nameCount = count(Wrappers.lambdaQuery(StockInType.class).eq(Func.isNotBlank(name), (v0) -> { return v0.getName(); }, name).eq((v0) -> { return v0.getStatus(); }, CommonConstant.ENABLE).ne(Func.isNotEmpty(id), (v0) -> { return v0.getId(); }, id)); ThrowFun.isTrue(nameCount > 0).throwMessage(MessageUtils.message("cps.stock.in.type.name.already.exists", new Object[0])); long nameCountDisable = count(Wrappers.lambdaQuery(StockInType.class) .eq(Func.isNotBlank(name),StockInType::getName, name) .eq(StockInType::getStatus, CommonConstant.DEACTIVATE) .ne(Func.isNotEmpty(id), StockInType::getId, id)); ThrowFun.isTrue(nameCountDisable > 0).throwMessage(MessageUtils.message("cps.stock.in.type.name.unable.already.exists", new Object[0])); } @Override // org.springblade.modules.cps.service.IStockInTypeService public IPage pageStockInType(Query query, String key, Integer status) { IPage page = page(Condition.getPage(query), Wrappers.lambdaQuery().eq(StockInType::getStatus, status) .and(Func.isNotBlank(key), c -> { c.likeRight(StockInType::getCode, key).or().likeRight(Func.isNotBlank(key), StockInType::getName, key); }).orderByDesc(StockInType::getCreateTime)); return StockInTypeConvert.INSTANCE.convert(page); } @Override // org.springblade.modules.cps.service.IStockInTypeService public StockInTypeVO updateStockIn(StockInTypeVO vo) { Long id = vo.getId(); validTheSame(id, vo.getCode(), vo.getName()); StockInType stockInType = StockInTypeConvert.INSTANCE.convert(vo); updateById(stockInType); return StockInTypeConvert.INSTANCE.convert(stockInType); } }