|
@@ -16,11 +16,34 @@
|
|
|
*/
|
|
|
package com.fjhx.supplier.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.attachment.StockAttachment;
|
|
|
+import com.fjhx.attachment.enums.AttachmentTypeEnum;
|
|
|
+import com.fjhx.attachment.service.StockAttachmentService;
|
|
|
import com.fjhx.supplier.entity.Supplier;
|
|
|
+import com.fjhx.supplier.entity.SupplierBank;
|
|
|
+import com.fjhx.supplier.entity.SupplierContacts;
|
|
|
+import com.fjhx.supplier.entity.SupplierKeep;
|
|
|
import com.fjhx.supplier.mapper.SupplierMapper;
|
|
|
+import com.fjhx.supplier.service.ISupplierBankService;
|
|
|
+import com.fjhx.supplier.service.ISupplierContactsService;
|
|
|
+import com.fjhx.supplier.service.ISupplierKeepService;
|
|
|
import com.fjhx.supplier.service.ISupplierService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.common.utils.CodeUtil;
|
|
|
+import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.tool.utils.StringUtil;
|
|
|
+import org.springblade.system.user.entity.User;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 供应商 服务实现类
|
|
@@ -31,5 +54,162 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StockAttachmentService stockAttachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISupplierContactsService supplierContactsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISupplierBankService supplierBankService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISupplierKeepService supplierKeepService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserClient iUserClient;
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @param supplier
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addSupplier(Supplier supplier) {
|
|
|
+ supplier.setCreate();
|
|
|
+ //生成code
|
|
|
+ if(StringUtil.isEmpty(supplier.getCode())){
|
|
|
+ Supplier sCode = getOne(Wrappers.<Supplier>query().lambda().orderByDesc(Supplier::getCode).last("limit 1"));
|
|
|
+ if(ObjectUtil.isEmpty(sCode)){
|
|
|
+ supplier.setCode("C001");
|
|
|
+ }else{
|
|
|
+ supplier.setCode(sCode.getCode()==null?"c001": CodeUtil.generateWmsCode(sCode.getCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //生成用户
|
|
|
+ User user = new User();
|
|
|
+ user.setPassword("123456");
|
|
|
+ user.setAccount(supplier.getCode());
|
|
|
+ user.setName(supplier.getName());
|
|
|
+ user.setRealName(supplier.getName());
|
|
|
+ iUserClient.saveUser(user);
|
|
|
+ supplier.setBingdUserId(String.valueOf(user.getId()));
|
|
|
+ save(supplier);
|
|
|
+ //保存文件
|
|
|
+ List<StockAttachment> attr = supplier.getAttr();
|
|
|
+ if(CollectionUtil.isNotEmpty(attr)){
|
|
|
+ for(StockAttachment s:attr){
|
|
|
+ s.setBusiId(supplier.getId());
|
|
|
+ s.setBusiType(AttachmentTypeEnum.TYPE_TWO.getKey());
|
|
|
+ s.setCreatedTime(new Date());
|
|
|
+ }
|
|
|
+ stockAttachmentService.saveBatch(attr);
|
|
|
+ }
|
|
|
+ //保存联系人
|
|
|
+ List<SupplierContacts> contactsList = supplier.getContactsList();
|
|
|
+ if(CollectionUtil.isNotEmpty(contactsList)){
|
|
|
+ contactsList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierContactsService.saveBatch(contactsList);
|
|
|
+ }
|
|
|
+ //保存账户信息
|
|
|
+ List<SupplierBank> bankList = supplier.getBankList();
|
|
|
+ if(CollectionUtil.isNotEmpty(bankList)){
|
|
|
+ bankList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierBankService.saveBatch(bankList);
|
|
|
+ }
|
|
|
+ //保存维护记录
|
|
|
+ List<SupplierKeep> keepList = supplier.getKeepList();
|
|
|
+ if(CollectionUtil.isNotEmpty(keepList)){
|
|
|
+ keepList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierKeepService.saveBatch(keepList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @param supplier
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void editSupplier(Supplier supplier) {
|
|
|
+ supplier.setUpdate();
|
|
|
+ updateById(supplier);
|
|
|
+ //清空操作重新赋值
|
|
|
+ //保存文件
|
|
|
+ List<StockAttachment> attr = supplier.getAttr();
|
|
|
+ if(CollectionUtil.isNotEmpty(attr)){
|
|
|
+ stockAttachmentService.remove(Wrappers.<StockAttachment>query().lambda().eq(StockAttachment::getBusiId,supplier.getId()));
|
|
|
+ for(StockAttachment s:attr){
|
|
|
+ s.setBusiId(supplier.getId());
|
|
|
+ s.setBusiType(AttachmentTypeEnum.TYPE_TWO.getKey());
|
|
|
+ s.setCreatedTime(new Date());
|
|
|
+ }
|
|
|
+ stockAttachmentService.saveBatch(attr);
|
|
|
+ }
|
|
|
+ //保存联系人
|
|
|
+ List<SupplierContacts> contactsList = supplier.getContactsList();
|
|
|
+ if(CollectionUtil.isNotEmpty(contactsList)){
|
|
|
+ supplierContactsService.remove(Wrappers.<SupplierContacts>query().lambda().eq(SupplierContacts::getSupplierId,supplier.getId()));
|
|
|
+ contactsList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierContactsService.saveBatch(contactsList);
|
|
|
+ }
|
|
|
+ //保存账户信息
|
|
|
+ List<SupplierBank> bankList = supplier.getBankList();
|
|
|
+ if(CollectionUtil.isNotEmpty(bankList)){
|
|
|
+ supplierBankService.remove(Wrappers.<SupplierBank>query().lambda().eq(SupplierBank::getSupplierId,supplier.getId()));
|
|
|
+ bankList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierBankService.saveBatch(bankList);
|
|
|
+ }
|
|
|
+ //保存维护记录
|
|
|
+ List<SupplierKeep> keepList = supplier.getKeepList();
|
|
|
+ if(CollectionUtil.isNotEmpty(keepList)){
|
|
|
+ supplierKeepService.remove(Wrappers.<SupplierKeep>query().lambda().eq(SupplierKeep::getSupplierId,supplier.getId()));
|
|
|
+ keepList.forEach((entity) ->{entity.setCreate();entity.setSupplierId(supplier.getId());});
|
|
|
+ supplierKeepService.saveBatch(keepList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delSupplier(String id) {
|
|
|
+ removeById(id);
|
|
|
+ stockAttachmentService.remove(Wrappers.<StockAttachment>query().lambda().eq(StockAttachment::getBusiId,id));
|
|
|
+ supplierContactsService.remove(Wrappers.<SupplierContacts>query().lambda().eq(SupplierContacts::getSupplierId,id));
|
|
|
+ supplierBankService.remove(Wrappers.<SupplierBank>query().lambda().eq(SupplierBank::getSupplierId,id));
|
|
|
+ supplierKeepService.remove(Wrappers.<SupplierKeep>query().lambda().eq(SupplierKeep::getSupplierId,id));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @param condition
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Supplier> getList(Map<String, Object> condition){
|
|
|
+ return baseMapper.getList(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表条数
|
|
|
+ * @param condition
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer getListCount(Map<String, Object> condition) {
|
|
|
+ return baseMapper.getListCount(condition);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计物料分类
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Supplier> statisticsClassify() {
|
|
|
+ return baseMapper.getGroupByCategory();
|
|
|
+ }
|
|
|
|
|
|
}
|