com.jskj.assets.server.servcie.Sale.Sale_detailService.java Source code

Java tutorial

Introduction

Here is the source code for com.jskj.assets.server.servcie.Sale.Sale_detailService.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jskj.assets.server.servcie.Sale;

import com.jskj.assets.server.entity.Sale_detail_tb;
import com.jskj.assets.server.entity.Sale_detail_tbExample;
import com.jskj.assets.server.entity.child.Sale_detail_tbFindEntity;
import com.jskj.assets.server.mapper.Sale_detail_tbMapper;
import com.jskj.assets.server.mapper.SaletbMapper;
import com.jskj.assets.server.utils.Pager;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

/**
 *
 * @author 305027939
 */
@Service
public class Sale_detailService implements Sale_detailServiceIF {

    private static final Log log = LogFactory.getLog(Sale_detailService.class);
    @Resource
    private Sale_detail_tbMapper mapper;

    @Resource
    private SaletbMapper salemapper;

    @Override
    public Sale_detail_tb findSale_detail(Integer id) {
        Sale_detail_tbExample sale_detailExample = new Sale_detail_tbExample();
        sale_detailExample.createCriteria().andSaleIdEqualTo(id.toString());
        List<Sale_detail_tb> sale_details = mapper.selectByExample(sale_detailExample);
        for (Sale_detail_tb u : sale_details) {
            log.debug("found sale_detail:" + u.getSaleId());
        }
        return sale_details.get(0);
    }

    @Override
    public Sale_detail_tbFindEntity findAllSale_details(Pager page) {
        Sale_detail_tbExample exam = new Sale_detail_tbExample();
        Sale_detail_tbFindEntity findEntity = new Sale_detail_tbFindEntity();

        //count?limtStart/limitEnd
        int count = mapper.countByExample(exam);
        page.setCount(count);
        exam.setLimitStart(page.getStartDataIndex());
        exam.setLimitEnd(page.getPageSize());

        //?
        exam.setOrderByClause("sale_detail_id DESC");

        //?
        List<Sale_detail_tb> sale_details = mapper.selectByExample(exam);
        findEntity.setCount(count);
        findEntity.setSale_details(sale_details);
        for (Sale_detail_tb u : sale_details) {
            log.debug("found sale_detail:" + u.getSaleId());
        }
        return findEntity;
    }

    @Override
    public int saveSale_detail(Sale_detail_tb sale_detail) {
        log.debug("insert sale_detail:" + sale_detail.getSaleId());
        return mapper.insertSelective(sale_detail);
    }

    @Override
    public Sale_detail_tbFindEntity saveSale_detail(Sale_detail_tbFindEntity sale_detail) {
        log.debug("insert sale_detail:" + sale_detail.getSale().getSaleId());
        List<Sale_detail_tb> list = sale_detail.getSale_details();
        salemapper.insertSelective(sale_detail.getSale());

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            mapper.insertSelective((Sale_detail_tb) iterator.next());
        }
        return sale_detail;
    }

    @Override
    public int deleteSale_detail(Integer sale_detailId) {
        log.debug("delete sale_detail:" + sale_detailId);
        return mapper.deleteByPrimaryKey(sale_detailId);
    }

    @Override
    public int updateSale_detail(Sale_detail_tb sale_detail) {
        log.debug("update sale_detail:" + sale_detail.getSaleId());
        return mapper.updateByPrimaryKeySelective(sale_detail);
    }

}