Commit f52f5c49 by Simon Cheng

添加代码生成器及测试

parent 57490fa7
......@@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yd.api.customer.service.CustomerService;
import com.yd.api.customer.vo.CustomerFortuneRequestVO;
import com.yd.api.customer.vo.CustomerFortuneResponseVO;
import com.yd.api.customer.vo.CustomerQueryRequestVO;
import com.yd.api.customer.vo.CustomerQueryResponseVO;
import com.yd.api.customer.vo.CustomerVO;
......@@ -45,4 +47,17 @@ public class CustomerController {
result.setData(erpOrderQueryResponseVO);
return result;
}
/**
* 分页查询案例
* @param customerQueryRequestVO
* @return
*/
@RequestMapping("/selectByCustomerId")
public Object selectByCustomerId(@RequestBody CustomerFortuneRequestVO customerQueryRequestVO){
JsonResult result = new JsonResult();
CustomerFortuneResponseVO erpOrderQueryResponseVO = customerService.selectByCustomerId(customerQueryRequestVO);
result.addResult(erpOrderQueryResponseVO);
result.setData(erpOrderQueryResponseVO);
return result;
}
}
\ No newline at end of file
......@@ -2,14 +2,17 @@ package com.yd.api.customer.service;
import java.util.List;
import com.github.pagehelper.PageInfo;
import com.yd.api.customer.vo.CustomerFortuneRequestVO;
import com.yd.api.customer.vo.CustomerFortuneResponseVO;
import com.yd.api.customer.vo.CustomerQueryRequestVO;
import com.yd.api.customer.vo.CustomerQueryResponseVO;
import com.yd.api.customer.vo.CustomerVO;
import com.yd.dataccess.entity.customer.Customer;
public interface CustomerService {
List<CustomerVO> listAllCustomer();
CustomerQueryResponseVO findByPage(CustomerQueryRequestVO customerQueryRequestVO);
CustomerFortuneResponseVO selectByCustomerId(CustomerFortuneRequestVO customer);
}
......@@ -8,12 +8,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.yd.api.customer.vo.CustomerFortuneRequestVO;
import com.yd.api.customer.vo.CustomerFortuneResponseVO;
import com.yd.api.customer.vo.CustomerFortuneVO;
import com.yd.api.customer.vo.CustomerQueryRequestVO;
import com.yd.api.customer.vo.CustomerQueryResponseVO;
import com.yd.api.customer.vo.CustomerVO;
import com.yd.dataccess.entity.customer.Customer;
import com.yd.dataccess.entity.customer.CustomerFortune;
import com.yd.dataccess.mapper.customer.CustomerFortuneMapper;
import com.yd.dataccess.service.customer.CustomerDA;
import com.yd.util.page.PaginationInfo;
@Service("customerServiceImpl")
public class CustomerServiceImpl implements CustomerService{
......@@ -21,6 +25,9 @@ public class CustomerServiceImpl implements CustomerService{
@Autowired
private CustomerDA customerServiceDA;
@Autowired
private CustomerFortuneMapper customerFortuneMapper;
@Override
public List<CustomerVO> listAllCustomer() {
List<CustomerVO> listTo =new ArrayList<CustomerVO>();
......@@ -50,6 +57,23 @@ public class CustomerServiceImpl implements CustomerService{
customerQueryResponseVO.setCustomerPage(list);
return customerQueryResponseVO;
}
@Override
public CustomerFortuneResponseVO selectByCustomerId(CustomerFortuneRequestVO request) {
CustomerFortuneResponseVO customerQueryResponseVO = new CustomerFortuneResponseVO();
Long customerId = request.getCustomerId();
PageInfo<CustomerFortune> page = request.getPage();
PageInfo<CustomerFortune> list = customerServiceDA.selectByCustomerId(customerId, page.getPageNum(), page.getSize());
customerQueryResponseVO.setCustomerId(customerId);
customerQueryResponseVO.setCustomerPage(list);
return customerQueryResponseVO;
}
}
package com.yd.api.customer.vo;
import com.github.pagehelper.PageInfo;
import com.yd.dataccess.entity.customer.Customer;
import com.yd.dataccess.entity.customer.CustomerFortune;
public class CustomerFortuneRequestVO {
private Long customerId;//客户ID
private PageInfo<CustomerFortune> page;
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public PageInfo<CustomerFortune> getPage() {
return page;
}
public void setPage(PageInfo<CustomerFortune> page) {
this.page = page;
}
}
package com.yd.api.customer.vo;
import com.github.pagehelper.PageInfo;
import com.yd.api.result.CommonResult;
import com.yd.dataccess.entity.customer.Customer;
import com.yd.dataccess.entity.customer.CustomerFortune;
public class CustomerFortuneResponseVO {
private Long customerId;//客户ID
private PageInfo<CustomerFortune> customerPage;
private CommonResult commonResult;
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public PageInfo<CustomerFortune> getCustomerPage() {
return customerPage;
}
public void setCustomerPage(PageInfo<CustomerFortune> customerPage) {
this.customerPage = customerPage;
}
public CommonResult getCommonResult() {
return commonResult;
}
public void setCommonResult(CommonResult commonResult) {
this.commonResult = commonResult;
}
}
package com.yd.api.customer.vo;
import java.math.BigDecimal;
import java.util.Date;
public class CustomerFortuneVO {
private Long id;
private Long shareId;
private Long customerId;
private Long orderId;
private Date orderDate;
private BigDecimal orderPrice;
private BigDecimal referralRate;
private BigDecimal referralAmount;
private BigDecimal referralAmountAfterValueadded;
private Integer isTax;
private BigDecimal taxAmount;
private BigDecimal netAmount;
private Long campaignId;
private Date withdrawableDate;
private Long withdrawedId;
private Long fortunePayedId;
private Date createdAt;
private Long createdBy;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getShareId() {
return shareId;
}
public void setShareId(Long shareId) {
this.shareId = shareId;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public BigDecimal getOrderPrice() {
return orderPrice;
}
public void setOrderPrice(BigDecimal orderPrice) {
this.orderPrice = orderPrice;
}
public BigDecimal getReferralRate() {
return referralRate;
}
public void setReferralRate(BigDecimal referralRate) {
this.referralRate = referralRate;
}
public BigDecimal getReferralAmount() {
return referralAmount;
}
public void setReferralAmount(BigDecimal referralAmount) {
this.referralAmount = referralAmount;
}
public BigDecimal getReferralAmountAfterValueadded() {
return referralAmountAfterValueadded;
}
public void setReferralAmountAfterValueadded(BigDecimal referralAmountAfterValueadded) {
this.referralAmountAfterValueadded = referralAmountAfterValueadded;
}
public Integer getIsTax() {
return isTax;
}
public void setIsTax(Integer isTax) {
this.isTax = isTax;
}
public BigDecimal getTaxAmount() {
return taxAmount;
}
public void setTaxAmount(BigDecimal taxAmount) {
this.taxAmount = taxAmount;
}
public BigDecimal getNetAmount() {
return netAmount;
}
public void setNetAmount(BigDecimal netAmount) {
this.netAmount = netAmount;
}
public Long getCampaignId() {
return campaignId;
}
public void setCampaignId(Long campaignId) {
this.campaignId = campaignId;
}
public Date getWithdrawableDate() {
return withdrawableDate;
}
public void setWithdrawableDate(Date withdrawableDate) {
this.withdrawableDate = withdrawableDate;
}
public Long getWithdrawedId() {
return withdrawedId;
}
public void setWithdrawedId(Long withdrawedId) {
this.withdrawedId = withdrawedId;
}
public Long getFortunePayedId() {
return fortunePayedId;
}
public void setFortunePayedId(Long fortunePayedId) {
this.fortunePayedId = fortunePayedId;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
}
package com.yd.dataccess.entity.customer;
import java.math.BigDecimal;
import java.util.Date;
public class CustomerFortune {
private Long id;
private Long shareId;
private Long customerId;
private Long orderId;
private Date orderDate;
private BigDecimal orderPrice;
private BigDecimal referralRate;
private BigDecimal referralAmount;
private BigDecimal referralAmountAfterValueadded;
private Integer isTax;
private BigDecimal taxAmount;
private BigDecimal netAmount;
private Long campaignId;
private Date withdrawableDate;
private Long withdrawedId;
private Long fortunePayedId;
private Date createdAt;
private Long createdBy;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getShareId() {
return shareId;
}
public void setShareId(Long shareId) {
this.shareId = shareId;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public BigDecimal getOrderPrice() {
return orderPrice;
}
public void setOrderPrice(BigDecimal orderPrice) {
this.orderPrice = orderPrice;
}
public BigDecimal getReferralRate() {
return referralRate;
}
public void setReferralRate(BigDecimal referralRate) {
this.referralRate = referralRate;
}
public BigDecimal getReferralAmount() {
return referralAmount;
}
public void setReferralAmount(BigDecimal referralAmount) {
this.referralAmount = referralAmount;
}
public BigDecimal getReferralAmountAfterValueadded() {
return referralAmountAfterValueadded;
}
public void setReferralAmountAfterValueadded(BigDecimal referralAmountAfterValueadded) {
this.referralAmountAfterValueadded = referralAmountAfterValueadded;
}
public Integer getIsTax() {
return isTax;
}
public void setIsTax(Integer isTax) {
this.isTax = isTax;
}
public BigDecimal getTaxAmount() {
return taxAmount;
}
public void setTaxAmount(BigDecimal taxAmount) {
this.taxAmount = taxAmount;
}
public BigDecimal getNetAmount() {
return netAmount;
}
public void setNetAmount(BigDecimal netAmount) {
this.netAmount = netAmount;
}
public Long getCampaignId() {
return campaignId;
}
public void setCampaignId(Long campaignId) {
this.campaignId = campaignId;
}
public Date getWithdrawableDate() {
return withdrawableDate;
}
public void setWithdrawableDate(Date withdrawableDate) {
this.withdrawableDate = withdrawableDate;
}
public Long getWithdrawedId() {
return withdrawedId;
}
public void setWithdrawedId(Long withdrawedId) {
this.withdrawedId = withdrawedId;
}
public Long getFortunePayedId() {
return fortunePayedId;
}
public void setFortunePayedId(Long fortunePayedId) {
this.fortunePayedId = fortunePayedId;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Long getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Long createdBy) {
this.createdBy = createdBy;
}
}
\ No newline at end of file
package com.yd.dataccess.mapper.customer;
import com.github.pagehelper.Page;
import com.yd.dataccess.entity.customer.CustomerFortune;
public interface CustomerFortuneMapper {
int deleteByPrimaryKey(Long id);
int insert(CustomerFortune record);
int insertSelective(CustomerFortune record);
CustomerFortune selectByPrimaryKey(Long id);
int updateByPrimaryKeySelective(CustomerFortune record);
int updateByPrimaryKey(CustomerFortune record);
Page<CustomerFortune> selectByCustomerId(Long customerId);
}
\ No newline at end of file
......@@ -2,9 +2,9 @@ package com.yd.dataccess.service.customer;
import java.util.List;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.yd.dataccess.entity.customer.Customer;
import com.yd.dataccess.entity.customer.CustomerFortune;
/**
* @author Simon
......@@ -13,5 +13,8 @@ import com.yd.dataccess.entity.customer.Customer;
public interface CustomerDA {
List<Customer> listAllCustomers();
PageInfo<Customer> findByPage(int pageNo, int pageSize);
PageInfo<CustomerFortune> selectByCustomerId(Long customerId, int pageNo, int pageSize);
}
......@@ -7,6 +7,8 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yd.dataccess.entity.customer.Customer;
import com.yd.dataccess.entity.customer.CustomerFortune;
import com.yd.dataccess.mapper.customer.CustomerFortuneMapper;
import com.yd.dataccess.mapper.customer.CustomerMapper;
import com.yd.util.intercept.annotation.TargetDataSource;
import com.yd.util.intercept.commons.DataSourceKey;
......@@ -28,6 +30,9 @@ public class CustomerDAImpl implements CustomerDA {
@Resource
private CustomerMapper customerMapper;
@Resource
private CustomerFortuneMapper customerFortuneMapper;
@Override
@TargetDataSource(dataSourceKey = DataSourceKey.DB_MASTER)
public List<Customer> listAllCustomers() {
......@@ -53,6 +58,19 @@ public class CustomerDAImpl implements CustomerDA {
return pageInfo;
}
@Override
public PageInfo<CustomerFortune> selectByCustomerId(Long customerId, int pageNo, int pageSize) {
String orderBy = "created_at desc";
PageHelper.startPage(pageNo, pageSize, orderBy);
Page<CustomerFortune> destList = customerFortuneMapper.selectByCustomerId(customerId);
PageInfo<CustomerFortune> pageInfo = new PageInfo<>(destList);
return pageInfo;
}
}
......
......@@ -33,10 +33,10 @@ public class DynamicDataSourceAspect {
public void doBefore(JoinPoint joinPoint, TargetDataSource targetDataSource) {
DataSourceKey dataSourceKey = targetDataSource.dataSourceKey();
if (dataSourceKey == DataSourceKey.DB_MASTER) {
LOG.info(String.format("设置数据源为 %s", DataSourceKey.DB_MASTER));
LOG.info(String.format("默认数据源 %s", DataSourceKey.DB_MASTER));
DynamicDataSourceContextHolder.set(DataSourceKey.DB_MASTER);
} else if (dataSourceKey == DataSourceKey.DB_EGOLDEN) {
LOG.info(String.format("使用默认数据源 %s", DataSourceKey.DB_EGOLDEN));
LOG.info(String.format("设置数据源 %s", DataSourceKey.DB_EGOLDEN));
DynamicDataSourceContextHolder.set(DataSourceKey.DB_EGOLDEN);
}
}
......@@ -49,7 +49,7 @@ public class DynamicDataSourceAspect {
*/
@After("@annotation(targetDataSource)")
public void doAfter(JoinPoint joinPoint, TargetDataSource targetDataSource) {
LOG.info(String.format("当前数据源 %s 执行清理方法", targetDataSource.dataSourceKey()));
LOG.info(String.format("当前数据源 %s 执行清理方法", targetDataSource.dataSourceKey()));
DynamicDataSourceContextHolder.clear();
}
......
......@@ -7,7 +7,11 @@ public class DynamicRoutingDataSource extends AbstractRoutingDataSource {
private static final Logger LOG = Logger.getLogger(DynamicRoutingDataSource.class);
@Override
protected Object determineCurrentLookupKey() {
LOG.info("当前数据源:{}"+ DynamicDataSourceContextHolder.get());
if (DynamicDataSourceContextHolder.get()==null)
{
DynamicDataSourceContextHolder.set(DataSourceKey.DB_MASTER);
}
return DynamicDataSourceContextHolder.get();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment