|
@@ -1,16 +1,28 @@
|
|
package com.fjhx.material.service.impl;
|
|
package com.fjhx.material.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
-import com.fjhx.utils.WrapperUtil;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fjhx.base.BaseEntity;
|
|
|
|
+import com.fjhx.classify.service.ClassifyService;
|
|
|
|
+import com.fjhx.constant.LockConstant;
|
|
|
|
+import com.fjhx.constants.ErrorMsgConstant;
|
|
|
|
+import com.fjhx.constants.StatusConstant;
|
|
import com.fjhx.entity.material.Material;
|
|
import com.fjhx.entity.material.Material;
|
|
-import com.fjhx.params.material.MaterialVo;
|
|
|
|
import com.fjhx.material.mapper.MaterialMapper;
|
|
import com.fjhx.material.mapper.MaterialMapper;
|
|
import com.fjhx.material.service.MaterialService;
|
|
import com.fjhx.material.service.MaterialService;
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import com.fjhx.params.material.MaterialVo;
|
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
|
+import com.fjhx.utils.WrapperUtil;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import org.springblade.core.redis.lock.RedisLockClient;
|
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -22,29 +34,86 @@ import java.util.Map;
|
|
* @since 2022-07-06
|
|
* @since 2022-07-06
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
|
|
+@RequiredArgsConstructor
|
|
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
|
|
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
|
|
|
|
|
|
|
|
+ private final ClassifyService classifyService;
|
|
|
|
+
|
|
|
|
+ private final RedisLockClient redisLockClient;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<Material> getPage(Map<String, String> condition) {
|
|
public Page<Material> getPage(Map<String, String> condition) {
|
|
|
|
|
|
QueryWrapper<Material> wrapper = Wrappers.query();
|
|
QueryWrapper<Material> wrapper = Wrappers.query();
|
|
|
|
|
|
WrapperUtil.init(condition, wrapper)
|
|
WrapperUtil.init(condition, wrapper)
|
|
- .eqTenantId()
|
|
|
|
- .createTimeDesc();
|
|
|
|
|
|
+ .keyword("code", "name")
|
|
|
|
+ .eqTenantId();
|
|
|
|
+
|
|
|
|
+ // 编码正序
|
|
|
|
+ wrapper.orderByAsc("code");
|
|
|
|
+
|
|
|
|
+ // 如果传入分类id,查询分类已经分类下级
|
|
|
|
+ String classifyId = condition.get("classifyId");
|
|
|
|
+ if (ObjectUtil.isNotEmpty(classifyId)) {
|
|
|
|
+ List<Long> childrenIdList = classifyService.getChildrenIdList(Long.valueOf(classifyId));
|
|
|
|
+ wrapper.in("classify_id", childrenIdList);
|
|
|
|
+ }
|
|
|
|
|
|
- Page<Material> page = page(condition, wrapper);
|
|
|
|
- return page;
|
|
|
|
|
|
+ return page(condition, wrapper);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void add(MaterialVo materialVo) {
|
|
public void add(MaterialVo materialVo) {
|
|
- save(materialVo);
|
|
|
|
|
|
+ Assert.notEmpty(materialVo.getName(), "物料名称不能为空");
|
|
|
|
+ Assert.notEmpty(materialVo.getCode(), "物料编码不能为空");
|
|
|
|
+ Integer coiled = materialVo.getCoiled();
|
|
|
|
+ Assert.notEmpty(coiled, "是否卷材判断字段不能为空");
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.isEmpty(materialVo.getSafetyStock())) {
|
|
|
|
+ materialVo.setSafetyStock(BigDecimal.ZERO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.isEmpty(materialVo.getCycle())) {
|
|
|
|
+ materialVo.setCycle(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.isEmpty(materialVo.getQualityTestingRate())) {
|
|
|
|
+ materialVo.setQualityTestingRate(BigDecimal.ZERO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ObjectUtil.isEmpty(materialVo.getLoss()) || coiled.equals(StatusConstant.No)) {
|
|
|
|
+ materialVo.setLoss(BigDecimal.ZERO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String tenantId = AuthUtil.getTenantId();
|
|
|
|
+
|
|
|
|
+ // 保证每个租户物料编码唯一
|
|
|
|
+ Boolean flag = redisLockClient.lockFair(LockConstant.MATERIAL_CODE_ONLY_LOCK + tenantId,
|
|
|
|
+ () -> {
|
|
|
|
+ // 判断物料编码不是唯一的
|
|
|
|
+ materialCodeOnly(tenantId, materialVo.getCode(), null);
|
|
|
|
+ save(materialVo);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Assert.eqTrue(flag, ErrorMsgConstant.SYSTEM_BUSY_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void edit(MaterialVo materialVo) {
|
|
public void edit(MaterialVo materialVo) {
|
|
- updateById(materialVo);
|
|
|
|
|
|
+ String tenantId = AuthUtil.getTenantId();
|
|
|
|
+
|
|
|
|
+ // 保证每个租户物料编码唯一
|
|
|
|
+ Boolean flag = redisLockClient.lockFair(LockConstant.MATERIAL_CODE_ONLY_LOCK + tenantId,
|
|
|
|
+ () -> {
|
|
|
|
+ // 判断物料编码不是唯一的
|
|
|
|
+ materialCodeOnly(tenantId, materialVo.getCode(), materialVo.getId());
|
|
|
|
+ updateById(materialVo);
|
|
|
|
+ return true;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ Assert.eqTrue(flag, ErrorMsgConstant.SYSTEM_BUSY_ERROR);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -52,10 +121,20 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
|
|
removeById(materialVo.getId());
|
|
removeById(materialVo.getId());
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public Material detail(MaterialVo materialVo) {
|
|
|
|
- Material result = getById(materialVo.getId());
|
|
|
|
- return result;
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 检查物料编码是否唯一
|
|
|
|
+ *
|
|
|
|
+ * @param tenantId 租户id
|
|
|
|
+ * @param materialCode 物料编码
|
|
|
|
+ * @param excludeId 排除物料id(编辑时不判断自己)
|
|
|
|
+ */
|
|
|
|
+ private void materialCodeOnly(String tenantId, String materialCode, Long excludeId) {
|
|
|
|
+ Integer count = lambdaQuery()
|
|
|
|
+ .eq(BaseEntity::getTenantId, tenantId)
|
|
|
|
+ .eq(Material::getCode, materialCode)
|
|
|
|
+ .ne(ObjectUtil.isNotEmpty(excludeId), BaseEntity::getId, excludeId)
|
|
|
|
+ .count();
|
|
|
|
+ Assert.eqZero(count, "物料编码重复,添加失败");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|