Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.learntransaction.bo.salesordersimple;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.common.entity.OU;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.core.dao.CriteriaHelper;
- import org.jleaf.core.dao.QueryBuilder;
- import org.jleaf.erp.master.entity.Partner;
- import org.jleaf.learntransaction.LearnConstants;
- import org.jleaf.learntransaction.LearnExceptionConstants;
- import org.jleaf.learntransaction.dao.SalesOrderSimpleDao;
- import org.jleaf.learntransaction.entity.SalesOrderSimple;
- import org.jleaf.learntransaction.entity.SalesOrderSimpleItem;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- @Service
- @InfoIn(value={
- @Info(name="ouId", description="Ou id", type=Long.class, required=true),
- @Info(name="docNo", description="Sales order simple id", type=Long.class, required=true),
- @Info(name="startDate", description="Start date", type=String.class, required=true),
- @Info(name="endDate", description="End date", type=String.class, required=true),
- @Info(name="limit", description="Limit", type=Long.class, required=true),
- @Info(name="offset", description="Offset", type=Long.class, required=true)
- })
- @InfoOut(value={
- @Info(name="soSimpleList", description="list of sales order simple {id, ouName, docNo, docDate, "
- + "dueDate, remark, partnerName, partnerCp, discountPersentage, discountAmount}", type=List.class, required=true)
- })
- @ErrorList(errorKeys={
- LearnExceptionConstants.SALES_ORDER_SIMPLE_NOT_FOUND
- })
- public class GetApprovedSalesOrderSimpleListAdvance extends AbstractBusinessFunction implements BusinessFunction{
- private static final Logger log = LoggerFactory.getLogger(GetApprovedSalesOrderSimpleListAdvance.class);
- @Autowired
- SalesOrderSimpleDao salesOrderSimpleDao;
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return "GetApprovedSalesOrderSimpleListAdvance";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- // TODO Auto-generated method stub
- ValidationUtil.valDtoContainsKey(inputDto, "ouId");
- ValidationUtil.valDtoContainsKey(inputDto, "docNo");
- ValidationUtil.valDtoContainsKey(inputDto, "startDate");
- ValidationUtil.valDtoContainsKey(inputDto, "endDate");
- Long ouId = inputDto.getLong("ouId");
- String docNo = inputDto.getString("docNo");
- String startDate = inputDto.getString("startDate");
- String endDate = inputDto.getString("endDate");
- Long limit = inputDto.getLong("limit");
- Long offset= inputDto.getLong("offset");
- QueryBuilder builder = new QueryBuilder();
- builder.add("SELECT A.so_id, A.ou_id, A.doc_no, A.doc_date, A.due_date, A.remark, ");
- builder.add(" A.partner_id, A.partner_cp, B.discount_percentage, B.discount_amount ");
- builder.add(" FROM " + SalesOrderSimple.TABLE_NAME + " A ");
- builder.add(" LEFT JOIN "+ SalesOrderSimpleItem.TABLE_NAME + " B ON A.so_id=B.so_id ");
- builder.add(" WHERE A.doc_date BETWEEN :startDate AND :endDate");
- builder.addIfNotEquals(ouId, GeneralConstants.NULL_REF_VALUE_LONG, " AND A.ou_id=:ouId ");
- builder.add(" AND "+ CriteriaHelper.likeExpressionIgnoreCase(LearnConstants.STATUS_DOC_APPROVED," A.status_doc "));
- builder.addIfNotEmpty(docNo, " AND "+CriteriaHelper.likeExpressionIgnoreCase(docNo, " A.doc_no "));
- if(limit != null) builder.add(" LIMIT "+ limit);
- if(offset != null) builder.add(" OFFSET "+ offset);
- Query query = salesOrderSimpleDao.createNativeQuery(builder.toString());
- query.setParameter("startDate", startDate);
- query.setParameter("endDate", endDate);
- if(!GeneralConstants.NULL_REF_VALUE_LONG.equals(ouId)){
- query.setParameter("ouId", ouId);
- }
- log.debug("query[GASoSLA] : "+builder.toString());
- List<Object[]> resultList = query.getResultList();
- log.debug("list[GASoSLA] : "+resultList);
- if(resultList.size() == 0){
- throw new CoreException(LearnExceptionConstants.SALES_ORDER_SIMPLE_NOT_FOUND);
- }
- List<Dto> salesOrderSimpleList = DtoUtil.createDtoListFromArray(
- resultList,
- "id", "ouName", "docNo", "docDate", "dueDate", "remark", "partnerName", "partnerCp",
- "discountPercentage", "discountAmount"
- );
- Dto outputDto = new Dto();
- outputDto.put("salesOrderSimpleList[GASOSLA] : ", salesOrderSimpleList);
- return outputDto;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement