123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package com.qxgmat.service.inline;
- import com.github.pagehelper.Page;
- import com.nuliji.tools.AbstractService;
- import com.nuliji.tools.exception.ParameterException;
- import com.nuliji.tools.exception.SystemException;
- import com.nuliji.tools.mybatis.Example;
- import com.qxgmat.data.constants.enums.status.DirectionStatus;
- import com.qxgmat.data.dao.UserInvoiceMapper;
- import com.qxgmat.data.dao.entity.UserInvoice;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.Arrays;
- import java.util.Collection;
- import java.util.List;
- import java.util.stream.Collectors;
- @Service
- public class UserInvoiceService extends AbstractService {
- private static final Logger logger = LoggerFactory.getLogger(UserInvoice.class);
- @Resource
- private UserInvoiceMapper userInvoiceMapper;
- public UserInvoice getByOrder(Integer userId, Integer orderId){
- Example example = new Example(UserInvoice.class);
- if(userId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- );
- }
- if(orderId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("orderId", orderId)
- );
- }
- return one(userInvoiceMapper, example);
- }
- public List<UserInvoice> listByOrder(Integer userId, Collection orderIds){
- Example example = new Example(UserInvoice.class);
- if(userId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- );
- }
- if(orderIds != null){
- example.and(
- example.createCriteria()
- .andIn("orderId", orderIds)
- );
- }
- return select(userInvoiceMapper, example);
- }
- public Page<UserInvoice> listAdmin(int page, int size, Integer userId, Boolean isDownload, Boolean isFinish, String order, DirectionStatus direction){
- Example example = new Example(UserInvoice.class);
- if(userId != null){
- example.and(
- example.createCriteria()
- .andEqualTo("userId", userId)
- );
- }
- if(isDownload != null){
- example.and(
- example.createCriteria()
- .andEqualTo("isDownload", isDownload ? 1 : 0)
- );
- }
- if(isFinish != null){
- example.and(
- example.createCriteria()
- .andEqualTo("isFinish", isFinish ? 1 : 0)
- );
- }
- if(order == null || order.isEmpty()) order = "id";
- switch(direction){
- case ASC:
- example.orderBy(order).asc();
- break;
- case DESC:
- default:
- example.orderBy(order).desc();
- }
- return select(userInvoiceMapper, example, page, size);
- }
- public void finish(Integer[] ids){
- Example example = new Example(UserInvoice.class);
- example.and(
- example.createCriteria().andIn("id", Arrays.stream(ids).collect(Collectors.toList()))
- );
- update(userInvoiceMapper, example, UserInvoice.builder().isFinish(1).build());
- }
- public void download(Integer[] ids){
- Example example = new Example(UserInvoice.class);
- example.and(
- example.createCriteria().andIn("id", Arrays.stream(ids).collect(Collectors.toList()))
- );
- update(userInvoiceMapper, example, UserInvoice.builder().isDownload(1).build());
- }
- public UserInvoice add(UserInvoice invoice){
- int result = insert(userInvoiceMapper, invoice);
- invoice = one(userInvoiceMapper, invoice.getId());
- if(invoice == null){
- throw new SystemException("发票添加失败");
- }
- return invoice;
- }
- public UserInvoice edit(UserInvoice invoice){
- UserInvoice in = one(userInvoiceMapper, invoice.getId());
- if(in == null){
- throw new ParameterException("发票不存在");
- }
- int result = update(userInvoiceMapper, invoice);
- return invoice;
- }
- public boolean delete(Number id){
- UserInvoice in = one(userInvoiceMapper, id);
- if(in == null){
- throw new ParameterException("发票不存在");
- }
- int result = delete(userInvoiceMapper, id);
- return result > 0;
- }
- public UserInvoice get(Number id){
- UserInvoice in = one(userInvoiceMapper, id);
- if(in == null){
- throw new ParameterException("发票不存在");
- }
- return in;
- }
- public Page<UserInvoice> select(int page, int pageSize){
- return select(userInvoiceMapper, page, pageSize);
- }
- public Page<UserInvoice> select(Integer[] ids){
- return page(()->select(userInvoiceMapper, ids), 1, ids.length);
- }
- public List<UserInvoice> select(Collection ids){
- return select(userInvoiceMapper, ids);
- }
- }
|