Java tutorial
/* * 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.Stockpile; import com.jskj.assets.server.entity.Sale_detail_tb; import com.jskj.assets.server.entity.Sale_detail_tbExample; import com.jskj.assets.server.entity.SplitNexustb; import com.jskj.assets.server.entity.SplitNexustbExample; import com.jskj.assets.server.entity.Stockpiletb; import com.jskj.assets.server.entity.StockpiletbExample; import com.jskj.assets.server.entity.YiMiaotb; import com.jskj.assets.server.entity.YiMiaotbExample; import com.jskj.assets.server.entity.child.StockpiletbAll; import com.jskj.assets.server.entity.child.StockpiletbFindEntity; import com.jskj.assets.server.mapper.DanjuleixingtbMapper; import com.jskj.assets.server.mapper.Sale_detail_tbMapper; import com.jskj.assets.server.mapper.SplitNexustbMapper; import com.jskj.assets.server.mapper.StockpiletbMapper; import com.jskj.assets.server.mapper.YiMiaotbMapper; import com.jskj.assets.server.servcie.Yimiao.YiMiaoServiceIF; import com.jskj.assets.server.utils.Arith; import com.jskj.assets.server.utils.NbArray; import com.jskj.assets.server.utils.Pager; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import net.sf.cglib.beans.BeanCopier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Service; /** * * @author 305027939 */ @Service public class StockpileService implements StockpileServiceIF { public static BeanCopier copier = BeanCopier.create(Stockpiletb.class, StockpiletbAll.class, false); private static final Log log = LogFactory.getLog(StockpileService.class); @Resource private DanjuleixingtbMapper mapper; @Resource private StockpiletbMapper stockpilemapper; @Resource private YiMiaoServiceIF yimiaoservice; @Resource private YiMiaotbMapper yimiaomapper; @Resource private Sale_detail_tbMapper Sale_detail_tbMapper; @Resource private SplitNexustbMapper SplitNexustbMapper; @Override public int saveStockpile(Stockpiletb stockpile) { log.debug("insert kucunyimiao:" + yimiaomapper.selectByPrimaryKey(stockpile.getYimiaoId()).getYimiaoName()); return stockpilemapper.insert(stockpile); } @Override public StockpiletbAll findStockpiletbAll(Integer id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public Stockpiletb findStockpiletb(Integer id) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public StockpiletbFindEntity findALLStockpile(Pager page) { StockpiletbExample exam = new StockpiletbExample(); StockpiletbFindEntity findEntity = new StockpiletbFindEntity(); //count?limtStart/limitEnd int count = stockpilemapper.countByExample(exam); page.setCount(count); exam.setLimitStart(page.getStartDataIndex()); exam.setLimitEnd(page.getPageSize()); //? exam.setOrderByClause("stockpile_id DESC"); //? List<Stockpiletb> stockpiles = stockpilemapper.selectByExample(exam); List<StockpiletbAll> stockpilesAll = new ArrayList<StockpiletbAll>(); for (Stockpiletb stockpile : stockpiles) { StockpiletbAll stockpileAll = new StockpiletbAll(); copier.copy(stockpile, stockpileAll, null); log.debug("found stockpile:" + stockpile.getStockpileId()); if (stockpile.getYimiaoId() != null) { stockpileAll.setYimiao(yimiaomapper.selectByPrimaryKey(stockpile.getYimiaoId())); } stockpilesAll.add(stockpileAll); } findEntity.setCount(count); findEntity.setResult(stockpilesAll); return findEntity; } @Override public StockpiletbFindEntity findALLStockpile(Pager page, String conditionSql) { StockpiletbExample exam = new StockpiletbExample(); StockpiletbFindEntity findEntity = new StockpiletbFindEntity(); if (conditionSql != null && !conditionSql.trim().equals("")) { exam.createCriteria().addConditionSql(conditionSql); } //count?limtStart/limitEnd int count = stockpilemapper.countByExample(exam); page.setCount(count); exam.setLimitStart(page.getStartDataIndex()); exam.setLimitEnd(page.getPageSize()); //? exam.setOrderByClause("stockpile_id DESC"); //? List<Stockpiletb> stockpiles = stockpilemapper.selectByExample(exam); List<StockpiletbAll> stockpilesAll = new ArrayList<StockpiletbAll>(); for (Stockpiletb stockpile : stockpiles) { StockpiletbAll stockpileAll = new StockpiletbAll(); stockpile.setStockpileTotalprice( Arith.decimalPrice(Arith.mul(stockpile.getStockpileQuantity(), stockpile.getStockpilePrice()))); copier.copy(stockpile, stockpileAll, null); log.debug("found stockpile:" + stockpile.getStockpileId()); if (stockpile.getYimiaoId() != null) { stockpileAll.setYimiao(yimiaomapper.selectByPrimaryKey(stockpile.getYimiaoId())); } stockpilesAll.add(stockpileAll); } findEntity.setCount(count); findEntity.setResult(stockpilesAll); return findEntity; } @Override public int deleteStockpiletb(Integer stockpileId) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public int updateStockpiletb(Stockpiletb stockpile) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } @Override public StockpiletbFindEntity findyimiaokucun(Pager page, String conditionSql) { YiMiaotbExample yimiaoexam = new YiMiaotbExample(); yimiaoexam.createCriteria().addConditionSql(conditionSql); StockpiletbFindEntity findEntity = new StockpiletbFindEntity(); //count?limtStart/limitEnd int count = yimiaomapper.countByExample(yimiaoexam); page.setCount(count); //????????? // yimiaoexam.setLimitStart(page.getStartDataIndex()); // yimiaoexam.setLimitEnd(page.getPageSize()); //? yimiaoexam.setOrderByClause("yimiao_id DESC"); List<YiMiaotb> list = yimiaomapper.selectByExample(yimiaoexam); List<StockpiletbAll> kucun = new ArrayList<>(); for (YiMiaotb ym : list) { log.debug("KucunchaxunService,findYileiyimiaokc:" + ym.getYimiaoId()); StockpiletbAll yimiaokucunEntity = new StockpiletbAll(); StockpiletbExample exam = new StockpiletbExample(); exam.createCriteria().andYimiaoIdEqualTo(ym.getYimiaoId()); List<Stockpiletb> stockpilelist = stockpilemapper.selectByExample(exam); if (!stockpilelist.isEmpty()) { double kucunshuliang = 0d; double kucunjine = 0; for (int i = 0; i < stockpilelist.size(); i++) { kucunshuliang = Arith.decimal(kucunshuliang + stockpilelist.get(i).getStockpileQuantity(), 5); log.debug("KucunchaxunService,findYileiyimiaokc:kucunshuliang:" + kucunshuliang + ",kucunID:" + stockpilelist.get(i).getStockpileId()); //stockpilelist.get(0).setStockpileQuantity(kucunshuliang); if (ym.getYimiaoType().equals("") && ym.getYimiaoHuansuanlv() != null) { double danjia = Arith.decimalSinglePriceFromHuanSuanlv(ym.getYimiaoHuansuanlv(), stockpilelist.get(i).getStockpilePrice()); float fuzushuliang = Math.round(stockpilelist.get(i).getStockpileQuantity() * (Math.round(1 / ym.getYimiaoHuansuanlv()))); kucunjine = Arith.decimalPrice(Arith.add(kucunjine, Arith.mul(danjia, fuzushuliang))); } else { kucunjine = Arith.decimalPrice( Arith.add(kucunjine, Arith.mul(stockpilelist.get(i).getStockpileQuantity(), stockpilelist.get(i).getStockpilePrice()))); } //stockpilelist.get(0).setStockpileTotalprice(kucunjine); } copier.copy(stockpilelist.get(0), yimiaokucunEntity, null); yimiaokucunEntity.setStockpileTotalprice(kucunjine); yimiaokucunEntity.setStockpileQuantity(kucunshuliang); //0? if (kucunshuliang == 0) { --count; continue; } // yimiaokucunEntity.setStockpilePrice(0d); yimiaokucunEntity.setStockpilePrice(Arith.decimalPrice(Arith.div(kucunjine, kucunshuliang))); yimiaokucunEntity.setYimiao(ym); kucun.add(yimiaokucunEntity); } } findEntity.setCount(kucun.size()); findEntity.setResult(kucun); return findEntity; } /** * * @param page * @param conditionSql * @return ??? ?????ID?? */ @Override public StockpiletbFindEntity findsaleStockpile(Pager page, String conditionSql) { StockpiletbExample exam = new StockpiletbExample(); StockpiletbFindEntity findEntity = new StockpiletbFindEntity(); if (conditionSql != null && !conditionSql.trim().equals("")) { exam.createCriteria().addConditionSql(conditionSql); } //count?limtStart/limitEnd int count = stockpilemapper.countByExample(exam); page.setCount(count); exam.setLimitStart(page.getStartDataIndex()); exam.setLimitEnd(page.getPageSize()); //? exam.setOrderByClause("stockpile_id DESC"); //? List<Stockpiletb> stockpiles = stockpilemapper.selectByExample(exam); List<StockpiletbAll> stockpilesAll = new ArrayList<StockpiletbAll>(); List<Integer> saledate = new ArrayList();//???? int saleint = 0;//??? int jizhangdanju = 0;//?? for (Stockpiletb stockpile : stockpiles) { StockpiletbAll stockpileAll = new StockpiletbAll(); stockpile.setStockpileTotalprice( Arith.decimalPrice(Arith.mul(stockpile.getStockpileQuantity(), stockpile.getStockpilePrice()))); copier.copy(stockpile, stockpileAll, null); log.debug("found stockpile:" + stockpile.getStockpileId()); //????? YiMiaotb yimiao = yimiaomapper.selectByPrimaryKey(stockpile.getYimiaoId()); if (stockpile.getYimiaoId() != null) { stockpileAll.setYimiao(yimiao); } //??ID?? Double danjianshuliang = Arith.round(Arith.div(1, yimiao.getYimiaoHuansuanlv()), 0);//?? int shuliang = danjianshuliang.intValue(); Double kucunshuliang = Arith.round(Arith.mul(stockpile.getStockpileQuantity(), danjianshuliang), 0);//? int kcshuliang = kucunshuliang.intValue(); Sale_detail_tbExample saledetailExample = new Sale_detail_tbExample(); saledetailExample.createCriteria().andStockpileIdEqualTo(stockpile.getStockpileId()) .andStatusEqualTo(0); List<Sale_detail_tb> Sale_detaillist = Sale_detail_tbMapper.selectByExample(saledetailExample); for (Sale_detail_tb sale_detail : Sale_detaillist) { //???????? SplitNexustbExample splitExample = new SplitNexustbExample(); splitExample.createCriteria().andSaledanidLike("%" + sale_detail.getSaleId() + "%") .andYimiaoIdEqualTo(sale_detail.getYimiaoId()) .andStockpileIdEqualTo(stockpile.getStockpileId()); List<SplitNexustb> split = SplitNexustbMapper.selectByExample(splitExample); if (!split.isEmpty()) {//???? continue; } //? Double x = Arith.round(Arith.div(sale_detail.getQuantity(), yimiao.getYimiaoHuansuanlv()), 0); Double quantity = x % shuliang;//(?) if (quantity == 0) { continue; } saledate.add(quantity.intValue()); saleint += quantity.intValue();//??? jizhangdanju++;//?? } //?? if (saleint > shuliang) {//???? if (saleint < kcshuliang) {//????? //??? if (saledate.size() != 1) {//?????? saledate = NbArray.Nearest(saledate, danjianshuliang.intValue()); } int sale = 0; for (int sales : saledate) { sale += sales; } if (sale != danjianshuliang.intValue()) { if (kcshuliang >= danjianshuliang.intValue()) {//??? saledate.add(danjianshuliang.intValue() - sale); } else if (kcshuliang < danjianshuliang.intValue()) {//?? saledate.add(kcshuliang - sale);//?? } } stockpileAll.setSplit(saledate); } } else if (saleint <= danjianshuliang.intValue() && saleint > 0) {//????, saledate = NbArray.Nearest(saledate, danjianshuliang.intValue()); int shulian = (kcshuliang > danjianshuliang.intValue()) ? danjianshuliang.intValue() : kcshuliang; if ((shulian - saleint) > 0) saledate.add(shulian - saleint);//?? stockpileAll.setSplit(saledate); } stockpilesAll.add(stockpileAll); } findEntity.setCount(count); findEntity.setResult(stockpilesAll); return findEntity; } }