Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.sls.bo.tasksales;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- 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.QueryBuilder;
- import org.jleaf.erp.sls.dao.SalesmanVisitPlanDao;
- //import org.jleaf.core.dao.QueryBuilder;
- 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;
- /**
- * Get Customer Visit Plan By Salesman And Date
- * @author Danielli Prasetyo Pangestu,May 5 2020
- * @version 1.0.0
- */
- @Service
- @InfoIn(value={
- @Info(name = "userLoginId", description = "User Login Id",type = Long.class),
- @Info(name = "tenantLoginId", description = "Tenant Login Id", type = Long.class),
- @Info(name = "roleLoginId", description = "Role Login Id", type = Long.class),
- @Info(name = "datetime", description = "Date Time", type = String.class),
- @Info(name = "salesmanId", description = "Salesman Id", type = Long.class),
- @Info(name = "date", description = "Date", type = String.class),
- })
- @InfoOut(value={
- @Info(name = "customerList", description = "List of customerList(visitId, customerId, customerCode, customerName, customerAddress,longitude, latitude, checkInTimeLocal, checkInTimeServer, checkOutTimeLocal, checkOutTimeServer, strategy, remark, statusVisit)", type = List.class)
- })
- @ErrorList(errorKeys={})
- public class GetCustomerVisitPlanBySalesmanAndDate extends AbstractBusinessFunction implements BusinessFunction{
- private static final Logger log = LoggerFactory.getLogger(GetCustomerVisitPlanBySalesmanAndDate.class);
- @Autowired
- SalesmanVisitPlanDao salesmanVisitPlanDao;
- @Override
- public String getDescription() {
- return "melihat daftar toko dalam periode terpilih yang harus di kunjungi";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- //validasi
- ValidationUtil.valBlankOrNull(inputDto, "salesmanId");
- ValidationUtil.valBlankOrNull(inputDto, "date");
- //define input
- Long salesmanId = inputDto.getLong("salesmanId");
- log.info("SALESMAN ID = " + salesmanId );
- String date = inputDto.getString("date");
- log.info("DATE = " + date );
- Long tenantId = inputDto.getLong("tenantLoginId");
- log.info("SALESMAN ID = " + tenantId );
- //set builder
- QueryBuilder builder = new QueryBuilder();
- builder.add(" SELECT A.salesman_visit_plan_id, A.tenant_id, A.customer_id, ")
- .add(" A.visit_date, A.visit_strategy, A.status_visit, ")
- .add(" COALESCE(B.check_in_time_local,0) AS check_in_time_local, COALESCE(B.check_in_time_server,0) AS check_in_time_server, COALESCE(B.check_out_time_local,0) AS check_out_time_local, ")
- .add(" COALESCE(B.check_out_time_server,0) AS check_out_time_server, COALESCE(B.check_out_remark,:null ) AS remark, C.partner_code, C.partner_name, ")
- .add(" D.address_desc, D.address1, D.address2, D.address3, D.zip_code, D.longitude ,D.latitude ")
- .add(" FROM sl_salesman_visit_plan A ")
- .add(" LEFT OUTER JOIN sl_salesman_visit_realization B ON A.salesman_visit_plan_id = B.salesman_visit_plan_id ")
- .add(" INNER JOIN m_partner C ON A.customer_id = C.partner_id ")
- .add(" INNER JOIN m_partner_address D ON C.partner_id = D.partner_id ")
- .add(" WHERE A.salesman_id = :salesmanId AND A.visit_date = :date AND D.flg_default = :flagAddress AND A.tenant_id = :tenantId ");
- log.info("QUERY SQL : " + builder.toString());
- //set query in dao
- Query query = salesmanVisitPlanDao.createNativeQuery(builder.toString());
- //set parameter
- query.setParameter("null", GeneralConstants.EMPTY_VALUE);
- query.setParameter("salesmanId", salesmanId);
- query.setParameter("date", date);
- query.setParameter("flagAddress", GeneralConstants.YES);
- query.setParameter("tenantId", tenantId);
- //define output
- List<Object[]> result = query.getResultList();
- List<Dto> customerList = DtoUtil.createDtoListFromArray(result, "visitId", "tenantId", "customerId",
- "visitDate", "strategy", "statusVisit",
- "checkInTimeLocal", "checkInTimeServer", "checkOutTimeLocal",
- "checkOutTimeServer", "remark", "customerCode","customerName",
- "customerAddress", "customerAddress1", "customerAddress2", "customerAddress3",
- "zipCode", "longitude", "latitiude"
- );
- Dto outputDto = new Dto().put("customerList", customerList);
- log.info("OUTPUT : " + outputDto);
- return outputDto;
- }
- }
Add Comment
Please, Sign In to add comment