From a4d9abbf63c5b7e755cd248388c88642b98c8756 Mon Sep 17 00:00:00 2001 From: siontion Date: Wed, 10 Jan 2024 10:39:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=9B=E5=BA=94=E5=95=86=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 供应商新建编码修改 --- .../service/supplier/SupplierServiceImpl.java | 155 +++++++++--------- 1 file changed, 81 insertions(+), 74 deletions(-) diff --git a/mes-module-heli/mes-module-heli-biz/src/main/java/com/chanko/yunxi/mes/module/heli/service/supplier/SupplierServiceImpl.java b/mes-module-heli/mes-module-heli-biz/src/main/java/com/chanko/yunxi/mes/module/heli/service/supplier/SupplierServiceImpl.java index 2bcc994a..71aea451 100644 --- a/mes-module-heli/mes-module-heli-biz/src/main/java/com/chanko/yunxi/mes/module/heli/service/supplier/SupplierServiceImpl.java +++ b/mes-module-heli/mes-module-heli-biz/src/main/java/com/chanko/yunxi/mes/module/heli/service/supplier/SupplierServiceImpl.java @@ -1,74 +1,81 @@ -package com.chanko.yunxi.mes.module.heli.service.supplier; - -import org.springframework.stereotype.Service; -import javax.annotation.Resource; -import org.springframework.validation.annotation.Validated; -import org.springframework.transaction.annotation.Transactional; - -import java.util.*; -import com.chanko.yunxi.mes.module.heli.controller.admin.supplier.vo.*; -import com.chanko.yunxi.mes.module.heli.dal.dataobject.supplier.SupplierDO; -import com.chanko.yunxi.mes.framework.common.pojo.PageResult; -import com.chanko.yunxi.mes.framework.common.pojo.PageParam; -import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils; - -import com.chanko.yunxi.mes.module.heli.dal.mysql.supplier.SupplierMapper; - -import static com.chanko.yunxi.mes.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*; - -/** - * 供应商 Service 实现类 - * - * @author 管理员 - */ -@Service -@Validated -public class SupplierServiceImpl implements SupplierService { - - @Resource - private SupplierMapper supplierMapper; - - @Override - public Long createSupplier(SupplierSaveReqVO createReqVO) { - // 插入 - SupplierDO supplier = BeanUtils.toBean(createReqVO, SupplierDO.class); - supplierMapper.insert(supplier); - // 返回 - return supplier.getId(); - } - - @Override - public void updateSupplier(SupplierSaveReqVO updateReqVO) { - // 校验存在 - validateSupplierExists(updateReqVO.getId()); - // 更新 - SupplierDO updateObj = BeanUtils.toBean(updateReqVO, SupplierDO.class); - supplierMapper.updateById(updateObj); - } - - @Override - public void deleteSupplier(Long id) { - // 校验存在 - validateSupplierExists(id); - // 删除 - supplierMapper.deleteById(id); - } - - private void validateSupplierExists(Long id) { - if (supplierMapper.selectById(id) == null) { - throw exception(SUPPLIER_NOT_EXISTS); - } - } - - @Override - public SupplierDO getSupplier(Long id) { - return supplierMapper.selectById(id); - } - - @Override - public PageResult getSupplierPage(SupplierPageReqVO pageReqVO) { - return supplierMapper.selectPage(pageReqVO); - } - -} \ No newline at end of file +package com.chanko.yunxi.mes.module.heli.service.supplier; + +import cn.hutool.core.lang.UUID; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import com.chanko.yunxi.mes.module.heli.controller.admin.supplier.vo.*; +import com.chanko.yunxi.mes.module.heli.dal.dataobject.supplier.SupplierDO; +import com.chanko.yunxi.mes.framework.common.pojo.PageResult; +import com.chanko.yunxi.mes.framework.common.pojo.PageParam; +import com.chanko.yunxi.mes.framework.common.util.object.BeanUtils; + +import com.chanko.yunxi.mes.module.heli.dal.mysql.supplier.SupplierMapper; + +import static com.chanko.yunxi.mes.framework.common.exception.util.ServiceExceptionUtil.exception; +import static com.chanko.yunxi.mes.module.heli.enums.CodeEnum.CUSTOMER; +import static com.chanko.yunxi.mes.module.heli.enums.CodeEnum.SUPPLIER; +import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*; + +/** + * 供应商 Service 实现类 + * + * @author 管理员 + */ +@Service +@Validated +public class SupplierServiceImpl implements SupplierService { + + @Resource + private SupplierMapper supplierMapper; + + @Override + public Long createSupplier(SupplierSaveReqVO createReqVO) { + // 插入 + SupplierDO supplier = BeanUtils.toBean(createReqVO, SupplierDO.class); + supplier.setCode(UUID.fastUUID().toString(true)); + supplierMapper.insert(supplier); + + supplier.setCode(SUPPLIER.getCode(supplier.getId().toString())); + supplierMapper.updateById(supplier); + // 返回 + return supplier.getId(); + } + + @Override + public void updateSupplier(SupplierSaveReqVO updateReqVO) { + // 校验存在 + validateSupplierExists(updateReqVO.getId()); + // 更新 + SupplierDO updateObj = BeanUtils.toBean(updateReqVO, SupplierDO.class); + supplierMapper.updateById(updateObj); + } + + @Override + public void deleteSupplier(Long id) { + // 校验存在 + validateSupplierExists(id); + // 删除 + supplierMapper.deleteById(id); + } + + private void validateSupplierExists(Long id) { + if (supplierMapper.selectById(id) == null) { + throw exception(SUPPLIER_NOT_EXISTS); + } + } + + @Override + public SupplierDO getSupplier(Long id) { + return supplierMapper.selectById(id); + } + + @Override + public PageResult getSupplierPage(SupplierPageReqVO pageReqVO) { + return supplierMapper.selectPage(pageReqVO); + } + +}