package com.steerinfo.dil.service.impl; import com.steerinfo.dil.mapper.RmsSupplierMapper; import com.steerinfo.dil.model.RmsSupplier; import com.steerinfo.dil.service.IRmsSupplierService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * RmsSupplier服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-10-22 06:18 * 类描述 * 修订历史: * 日期:2021-10-22 * 作者:HuJieHuan * 参考: * 描述:RmsSupplier服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "rmsSupplierService") public class RmsSupplierServiceImpl implements IRmsSupplierService { @Autowired private RmsSupplierMapper rmsSupplierMapper; /** * 操作供应商 * @param mapVal * @return */ @Override public int operationSupplier(Map mapVal) { // 得到金蝶主键供应商id Integer EASSupplierIdValue = (Integer) mapVal.get("EASSupplierId"); BigDecimal EASSupplierId = new BigDecimal(EASSupplierIdValue); // 得到供应商名称 String supplierName = (String) mapVal.get("supplierName"); // 得到供应商供应商简称 String supplierAbbreviation = (String) mapVal.get("supplierAbbreviation"); // 得到供应商代码 String supplierDutyParagraph = (String) mapVal.get("supplierDutyParagraph"); // 得到供应商地址 String supplierAddress = (String) mapVal.get("supplierAddress"); // 得到注册时间 Date supplierRegisterDate = (Date) mapVal.get("supplierRegisterDate"); // 得到委托代理人 String supplierContactsName = (String) mapVal.get("supplierAgent"); // 得到联系电话 String supplierContactNumber = (String) mapVal.get("supplierContactNumber"); // 得到数据数据状态 Integer dataStatus = (Integer) mapVal.get("dataStatus"); // 判断是否EASId已存在 Map map1 = new HashMap<>(); map1.put("easSupplierId",EASSupplierId); BigDecimal deleted = new BigDecimal(0); map1.put("deleted",deleted); List rmsSuppliers = rmsSupplierMapper.selectByParameters(map1); RmsSupplier rmsSupplier = new RmsSupplier(); rmsSupplier.setEasSupplierId(EASSupplierId); rmsSupplier.setSupplierName(supplierName); rmsSupplier.setSupplierAbbreviation(supplierAbbreviation); rmsSupplier.setSupplierDutyParagraph(supplierDutyParagraph); rmsSupplier.setSupplierAddress(supplierAddress); rmsSupplier.setSupplierRegisterDate(supplierRegisterDate); rmsSupplier.setSupplierContactsName(supplierContactsName); rmsSupplier.setSupplierContactNumber(supplierContactNumber); int result = 0; // 新增 if (rmsSuppliers.size() == 0) { BigDecimal supplierId = rmsSupplierMapper.getSupplierId(); rmsSupplier.setSupplierId(supplierId); rmsSupplier.setDeleted(new BigDecimal(0)); result = rmsSupplierMapper.insertSelective(rmsSupplier); } // 修改 if (rmsSuppliers.size() != 0 && dataStatus == 2) { RmsSupplier rmsSupplier1 = rmsSuppliers.get(0); rmsSupplier.setSupplierId(rmsSupplier1.getSupplierId()); result = rmsSupplierMapper.updateByPrimaryKeySelective(rmsSupplier); } // 逻辑删除 if (rmsSuppliers.size() != 0 && dataStatus == 3) { RmsSupplier rmsSupplier1 = rmsSuppliers.get(0); rmsSupplier.setSupplierId(rmsSupplier1.getSupplierId()); rmsSupplier.setDeleted(new BigDecimal(1)); result = rmsSupplierMapper.updateByPrimaryKeySelective(rmsSupplier); } return result; } /** * 查询供应商列表 * @param mapVal * @return */ @Override public List> getSupplierList(Map mapVal) { return rmsSupplierMapper.getSupplierList(mapVal); } /** * 添加供应商列表 * @param rmsSupplier * @return */ @Override public int insertSupplier(RmsSupplier rmsSupplier) { int i=0; // 判断用户输入的船名在数据库中是否存在 String supplierName=rmsSupplier.getSupplierName(); Map map = new HashMap<>(); map.put("supplierName",supplierName); List rmsSuppliers = rmsSupplierMapper.selectByParameters(map); if (rmsSuppliers.size() != 0 ) { RmsSupplier rmsSupplier1=rmsSuppliers.get(0); // 当供应商编号存在的时候,直接返回已经存在数据就行了 if (rmsSupplier1.getDeleted().equals(new BigDecimal(1))){ rmsSupplier.setInsertTime(new Date()); rmsSupplier.setInsertUsername("admin"); rmsSupplier.setDeleted(new BigDecimal(0)); rmsSupplier.setSupplierId(rmsSupplierMapper.getSupplierId()); i+=rmsSupplierMapper.insertSelective(rmsSupplier); } else{ i=-1; } } else { // 当供应商编号不存在的话,就直接加入 rmsSupplier.setInsertTime(new Date()); rmsSupplier.setInsertUsername("admin"); rmsSupplier.setDeleted(new BigDecimal(0)); rmsSupplier.setSupplierId(rmsSupplierMapper.getSupplierId()); i+=rmsSupplierMapper.insertSelective(rmsSupplier); } return i; } /** * 修改供应商信息 * @param rmsSupplier * @return */ @Override public int updateSupplier(RmsSupplier rmsSupplier) { rmsSupplier.setUpdateUsername("admin"); // 增加修改时间 rmsSupplier.setUpdateTime(new Date()); return rmsSupplierMapper.updateByPrimaryKeySelective(rmsSupplier); } /** * 根据id值删除供应商信息 * @param id * @return */ @Override public int deleteSupplier(BigDecimal id) { // 使用逻辑删除 RmsSupplier rmsSupplier=rmsSupplierMapper.selectByPrimaryKey(id); // 对于我们要删除的供应商,将他的deleted字段的值变为1 rmsSupplier.setDeleted(new BigDecimal(1)); return rmsSupplierMapper.updateByPrimaryKeySelective(rmsSupplier); } /** * 根据id值展示供应商信息 * @param id * @return */ @Override public List> getSupplierById(BigDecimal id) { return rmsSupplierMapper.selectSupplierById(id); } }