parent
10d76692fd
commit
ad2456479e
@ -1,74 +1,80 @@
|
||||
package com.chanko.yunxi.mes.module.heli.service.customer;
|
||||
|
||||
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.customer.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.customer.CustomerDO;
|
||||
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.customer.CustomerMapper;
|
||||
|
||||
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 CustomerServiceImpl implements CustomerService {
|
||||
|
||||
@Resource
|
||||
private CustomerMapper customerMapper;
|
||||
|
||||
@Override
|
||||
public Long createCustomer(CustomerSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CustomerDO customer = BeanUtils.toBean(createReqVO, CustomerDO.class);
|
||||
customerMapper.insert(customer);
|
||||
// 返回
|
||||
return customer.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomer(CustomerSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CustomerDO updateObj = BeanUtils.toBean(updateReqVO, CustomerDO.class);
|
||||
customerMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomer(Long id) {
|
||||
// 校验存在
|
||||
validateCustomerExists(id);
|
||||
// 删除
|
||||
customerMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateCustomerExists(Long id) {
|
||||
if (customerMapper.selectById(id) == null) {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerDO getCustomer(Long id) {
|
||||
return customerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CustomerDO> getCustomerPage(CustomerPageReqVO pageReqVO) {
|
||||
return customerMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
package com.chanko.yunxi.mes.module.heli.service.customer;
|
||||
|
||||
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.customer.vo.*;
|
||||
import com.chanko.yunxi.mes.module.heli.dal.dataobject.customer.CustomerDO;
|
||||
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.customer.CustomerMapper;
|
||||
|
||||
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.WORKSHOP;
|
||||
import static com.chanko.yunxi.mes.module.heli.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 客户新表 Service 实现类
|
||||
*
|
||||
* @author 管理员
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CustomerServiceImpl implements CustomerService {
|
||||
|
||||
@Resource
|
||||
private CustomerMapper customerMapper;
|
||||
|
||||
@Override
|
||||
public Long createCustomer(CustomerSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CustomerDO customer = BeanUtils.toBean(createReqVO, CustomerDO.class);
|
||||
customer.setCode(UUID.fastUUID().toString(true));
|
||||
customerMapper.insert(customer);
|
||||
customer.setCode(CUSTOMER.getCode(customer.getId().toString()));
|
||||
customerMapper.updateById(customer);
|
||||
// 返回
|
||||
return customer.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomer(CustomerSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCustomerExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CustomerDO updateObj = BeanUtils.toBean(updateReqVO, CustomerDO.class);
|
||||
customerMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCustomer(Long id) {
|
||||
// 校验存在
|
||||
validateCustomerExists(id);
|
||||
// 删除
|
||||
customerMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateCustomerExists(Long id) {
|
||||
if (customerMapper.selectById(id) == null) {
|
||||
throw exception(CUSTOMER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomerDO getCustomer(Long id) {
|
||||
return customerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CustomerDO> getCustomerPage(CustomerPageReqVO pageReqVO) {
|
||||
return customerMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue