|
@@ -1,6 +1,8 @@
|
|
|
package com.fjhx.service.supplier.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+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.fjhx.entity.supplier.Supplier;
|
|
@@ -8,10 +10,15 @@ import com.fjhx.enums.supplier.AccountPeriodTypeEnum;
|
|
|
import com.fjhx.mapper.supplier.SupplierMapper;
|
|
|
import com.fjhx.params.supplier.SupplierVo;
|
|
|
import com.fjhx.service.supplier.SupplierService;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
+import com.fjhx.utils.FileClientUtil;
|
|
|
+import com.fjhx.utils.RegionClientUtil;
|
|
|
import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
import com.fjhx.utils.wrapperUtil.KeywordData;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -26,6 +33,11 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
|
|
|
|
|
|
+ /**
|
|
|
+ * 默认供应商编码前缀
|
|
|
+ */
|
|
|
+ private final String codePrefix = "GY";
|
|
|
+
|
|
|
@Override
|
|
|
public Page<Map<String, Object>> getPage(Map<String, Object> condition) {
|
|
|
|
|
@@ -65,22 +77,94 @@ public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> i
|
|
|
|
|
|
Page<Map<String, Object>> page = pageMaps(condition, wrapper);
|
|
|
|
|
|
+ List<Map<String, Object>> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值附件
|
|
|
+ FileClientUtil.setFileInfoListMap(records);
|
|
|
+ // 赋值国省市
|
|
|
+ RegionClientUtil.setRegionName(records);
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(SupplierVo supplierVo) {
|
|
|
+ String code = supplierVo.getCode();
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(code)) {
|
|
|
+ supplierVo.setCode(createCode());
|
|
|
+ } else {
|
|
|
+ Long count = count(Supplier::getCode, code);
|
|
|
+ Assert.eqZero(count, "供应商编码已存在");
|
|
|
+ }
|
|
|
+
|
|
|
save(supplierVo);
|
|
|
+ // 绑定附件
|
|
|
+ FileClientUtil.bindingFile(supplierVo.getId(), supplierVo.getFileInfoList());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void edit(SupplierVo supplierVo) {
|
|
|
updateById(supplierVo);
|
|
|
+ // 修改附件绑定信息
|
|
|
+ FileClientUtil.againBindingFile(supplierVo.getId(), supplierVo.getFileInfoList());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void delete(SupplierVo supplierVo) {
|
|
|
removeById(supplierVo.getId());
|
|
|
+ // 删除附件
|
|
|
+ FileClientUtil.relieveBindingFile(supplierVo.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getList(SupplierVo supplierVo) {
|
|
|
+ IWrapper<Supplier> wrapper = IWrapper.getWrapper(supplierVo);
|
|
|
+
|
|
|
+ wrapper.like(Supplier::getName);
|
|
|
+ wrapper.like(Supplier::getCode);
|
|
|
+ wrapper.eq(Supplier::getType);
|
|
|
+ wrapper.select(Supplier::getId, Supplier::getType, Supplier::getCode, Supplier::getName);
|
|
|
+
|
|
|
+ return listMaps(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成供应商编码
|
|
|
+ */
|
|
|
+ private String createCode() {
|
|
|
+
|
|
|
+ Supplier supplier = getOne(Wrappers.<Supplier>lambdaQuery()
|
|
|
+ .likeRight(Supplier::getCode, codePrefix)
|
|
|
+ .orderByDesc(Supplier::getCode)
|
|
|
+ .last("limit 1"));
|
|
|
+
|
|
|
+ if (supplier == null) {
|
|
|
+ return codePrefix + "0001";
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = supplier.getCode();
|
|
|
+
|
|
|
+ Integer codeNum = Convert.toInt(code.substring(codePrefix.length()));
|
|
|
+ Assert.notEmpty(codeNum, "自定义供应商编码与系统自动生成供应商编码规则冲突,暂时自动生成供应商编码,请联系管理员处理");
|
|
|
+
|
|
|
+ codeNum++;
|
|
|
+
|
|
|
+ if (codeNum < 10) {
|
|
|
+ return codePrefix + "000" + codeNum;
|
|
|
+ } else if (codeNum < 100) {
|
|
|
+ return codePrefix + "00" + codeNum;
|
|
|
+ } else if (codeNum < 1000) {
|
|
|
+ return codePrefix + "0" + codeNum;
|
|
|
+ }
|
|
|
+ return codePrefix + codeNum;
|
|
|
}
|
|
|
|
|
|
}
|