parent
4580f76be4
commit
a4d9abbf63
@ -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<SupplierDO> getSupplierPage(SupplierPageReqVO pageReqVO) {
|
||||
return supplierMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
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<SupplierDO> getSupplierPage(SupplierPageReqVO pageReqVO) {
|
||||
return supplierMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue