Browse Source

亿道次元EIS 增加查询生产进度接口

xiaost 1 year ago
parent
commit
2956f0334e

+ 19 - 1
src/main/java/com/uas/eis/controller/QueryController.java

@@ -1,14 +1,20 @@
 package com.uas.eis.controller;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import com.uas.eis.sdk.entity.ApiResult;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.uas.eis.service.QueryService;
 
+import javax.servlet.http.HttpServletRequest;
+
 @RestController
 public class QueryController {
 
@@ -26,5 +32,17 @@ public class QueryController {
 		Map<String, Object> map = new HashMap<String, Object>();
 		return queryService.doAction(code, param);
 	}
-	
+
+	/**
+	 * 获取生产进度接口
+	 * @param request
+	 * @param macode
+	 * @return
+	 */
+	@RequestMapping(value = "/api/mes/getMakeProcess" , method = RequestMethod.GET)
+	public ApiResult<List<Map<String,Object>>> getMakeProcess(HttpServletRequest request, String macode){
+		String accessKey = request.getHeader("AccessKey");
+		String requestId = request.getHeader("RequestId");
+		return queryService.getMakeProcess(accessKey,requestId,macode);
+	}
 }

+ 0 - 2
src/main/java/com/uas/eis/core/support/DataSourceInterceptor.java

@@ -15,8 +15,6 @@ import com.uas.eis.core.config.SpObserver;
 
 @Component
 public class DataSourceInterceptor implements HandlerInterceptor{
-	@Value("${spring.datasource.username}")
-	private String username;
 
 	private final DataSourceProperties dataSourceProperties;
      @Autowired

+ 6 - 0
src/main/java/com/uas/eis/dao/BaseDao.java

@@ -549,6 +549,12 @@ public class BaseDao{
 		return rs;
 	}
 
+	public SqlRowList queryForRowSet(String sql, Object... args) {
+		SqlRowList rs = new SqlRowList();
+		rs.setResultList(getJdbcTemplate().queryForList(sql, args));
+		return rs;
+	}
+
 	/**
 	 * @param tableName
 	 *            对应要查询的表

+ 6 - 0
src/main/java/com/uas/eis/service/QueryService.java

@@ -1,5 +1,10 @@
 package com.uas.eis.service;
 
+import com.uas.eis.sdk.entity.ApiResult;
+
+import java.util.List;
+import java.util.Map;
+
 public interface QueryService {
 
 	public abstract String login(String username, String password);
@@ -12,4 +17,5 @@ public interface QueryService {
 	
 	public Object doAction(String code, String param);
 
+	ApiResult<List<Map<String,Object>>> getMakeProcess(String accessKey, String requestId, String macode);
 }

+ 74 - 8
src/main/java/com/uas/eis/serviceImpl/QueryServiceImpl.java

@@ -9,9 +9,14 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.uas.eis.entity.ActionConfig;
-import com.uas.eis.entity.ErrorMsg;
+import com.uas.eis.core.config.SpObserver;
+import com.uas.eis.dao.SqlRowList;
+import com.uas.eis.entity.*;
+import com.uas.eis.exception.ApiSystemException;
 import com.uas.eis.exception.SystemException;
+import com.uas.eis.sdk.entity.ApiResult;
+import com.uas.eis.sdk.resp.ApiResponse;
+import com.uas.eis.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
@@ -20,9 +25,6 @@ import org.springframework.util.StringUtils;
 import com.alibaba.fastjson.JSON;
 import com.uas.eis.core.support.TokenHandler;
 import com.uas.eis.dao.BaseDao;
-import com.uas.eis.entity.QueryArgs;
-import com.uas.eis.entity.QueryConfig;
-import com.uas.eis.entity.QueryConfigDetail;
 import com.uas.eis.service.QueryService;
 import com.uas.eis.utils.BaseUtil;
 
@@ -254,7 +256,71 @@ public class QueryServiceImpl implements QueryService {
 	public Object doAction(String code, String param) {
 		return null;
 	}
-	
-	
-	
+
+	@Override
+	public ApiResult<List<Map<String,Object>>> getMakeProcess(String accessKey, String requestId, String macode) {
+		String AE_MASTER = checkAccessKey(accessKey, requestId);
+		SpObserver.putSp(AE_MASTER);
+		//如果有传工单则,查询指定工单的,
+		if(StringUtil.hasText(macode)){
+            SqlRowList rs = baseDao.queryForRowSet("select  nvl(SP_MAKECODE,mpd_makecode) v_makecode ,nvl(SP_WCCODE,wc_code) v_wccode,nvl(V_INQTY,0)V_INQTY, " +
+					"     nvl(mpd_inqty,0) v_planinqty,nvl(V_OKQTY,0)V_OKQTY,nvl(V_OUTQTY,0) V_OUTQTY,nvl(V_NGQTY,0) V_NGQTY, " +
+					"    case when nvl(v_outqty,0)>0 then round(nvl(v_ngqty,0)*100/nvl(v_outqty,0),2) else 0 end v_ngrate, " +
+					"            case when nvl(v_outqty,0)>0 then round(nvl(v_okqty,0)*100/nvl(v_outqty,0),2) else 0 end v_okrate " +
+					" from (select SP_WCCODE,SP_MAKECODE,sum(inqty) v_inqty ,sum(fokqty) v_okqty,sum(outqty) v_outqty,sum(snngqty) v_ngqty " +
+					"        from(select SP_MAKECODE,SP_WCCODE,sp_sncode,max(case when sp_ifturnin<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)inqty " +
+					"               ,max(case when NVL(sp_ifng,0)=0 and sp_ifturnout<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)fokqty " +
+					"               ,max(case when sp_ifturnout<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)outqty " +
+					"               ,max(case when NVL(sp_ifng,0)<>0 and sp_ifturnout<>0  and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)snngqty  " +
+					"               from steppassed where sp_makecode=? " +
+					"               group by SP_WCCODE,sp_sncode,SP_MAKECODE) group by SP_MAKECODE,SP_WCCODE)a " +
+					"          full join (select mpd_makecode,wc_code,sum(mpd_inqty) mpd_inqty from MakePlan left join MAKEPLANDETAIL on mpd_mpid=mp_id  " +
+					"             left join line on li_code=mpd_linecode left join workcenter on wc_code=li_wccode " +
+					"               where trunc(mpd_plandate)<=trunc(sysdate) and mpd_makecode =? " +
+					"               and mp_statuscode='AUDITED' and mp_kind='日计划' group by mpd_makecode,wc_code ) " +
+					"            on SP_WCCODE=wc_code and SP_MAKECODE=mpd_makecode",macode,macode);
+			if(rs.hasNext()){
+				return ApiResponse.successRsp("0",requestId,rs.getResultList());
+			}
+		}else{ //如果没有传工单号,则查询当天生产计划所有的工单
+			SqlRowList rs = baseDao.queryForRowSet("select nvl(SP_MAKECODE,mpd_makecode) v_makecode ,nvl(SP_WCCODE,wc_code) v_wccode,nvl(V_INQTY,0)V_INQTY, " +
+					"     nvl(mpd_inqty,0) v_planinqty,nvl(V_OKQTY,0)V_OKQTY,nvl(V_OUTQTY,0) V_OUTQTY,nvl(V_NGQTY,0) V_NGQTY, " +
+					"    case when nvl(v_outqty,0)>0 then round(nvl(v_ngqty,0)*100/nvl(v_outqty,0),2) else 0 end v_ngrate, " +
+					"            case when nvl(v_outqty,0)>0 then round(nvl(v_okqty,0)*100/nvl(v_outqty,0),2) else 0 end v_okrate " +
+					"      from (select SP_WCCODE,SP_MAKECODE,sum(inqty) v_inqty ,sum(fokqty) v_okqty,sum(outqty) v_outqty,sum(snngqty) v_ngqty " +
+					"        from(select SP_MAKECODE,SP_WCCODE,sp_sncode,max(case when sp_ifturnin<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)inqty " +
+					"               ,max(case when NVL(sp_ifng,0)=0 and sp_ifturnout<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)fokqty " +
+					"               ,max(case when sp_ifturnout<>0 and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end) outqty " +
+					"               ,max(case when NVL(sp_ifng,0)<>0 and sp_ifturnout<>0  and NVL(sp_ifrework,0)+NVL(sp_ifbackflow,0)=0 then 1 else 0 end)snngqty  " +
+					"               from steppassed where sp_makecode in (select distinct mpd_makecode from MakePlan left join MAKEPLANDETAIL on mpd_mpid=mp_id " +
+					"                   where trunc(mpd_plandate)=trunc(sysdate) and mp_statuscode='AUDITED' and mp_kind='日计划' ) " +
+					"               group by SP_WCCODE,sp_sncode,SP_MAKECODE) group by SP_MAKECODE,SP_WCCODE )a " +
+					"     full join (select  mpd_makecode,wc_code,sum(mpd_inqty) mpd_inqty from MakePlan left join MAKEPLANDETAIL on mpd_mpid=mp_id  " +
+					"                 left join line on li_code=mpd_linecode left join workcenter on wc_code=li_wccode " +
+					"                   where trunc(mpd_plandate)<=trunc(sysdate) and mpd_makecode in (select distinct mpd_makecode from MakePlan left join MAKEPLANDETAIL on mpd_mpid=mp_id " +
+					"                   where trunc(mpd_plandate)=trunc(sysdate) and mp_statuscode='AUDITED' and mp_kind='日计划' ) " +
+					"                   and mp_statuscode='AUDITED' and mp_kind='日计划' group by mpd_makecode,wc_code ) " +
+					"   on SP_WCCODE=wc_code and SP_MAKECODE=mpd_makecode");
+			if(rs.hasNext()){
+				return ApiResponse.successRsp("0",requestId,rs.getResultList());
+			}
+		}
+		return ApiResponse.successRsp("0",requestId,null);
+	}
+
+	private String checkAccessKey(String accessKey,String requestId){
+		Object accessSecret_O = baseDao.getFieldDataByCondition("APIEMPLOYEE", "AE_SECRET", "AE_KEY='"+accessKey+"'");
+		Object AE_MASTER = baseDao.getFieldDataByCondition("APIEMPLOYEE", "AE_MASTER", "AE_KEY='"+accessKey+"'");
+		String accessSecret = accessSecret_O == null ? "" : accessSecret_O.toString();
+		// 检查KEY是否合理
+		if (org.apache.commons.lang.StringUtils.isEmpty(accessKey) || org.apache.commons.lang.StringUtils.isEmpty(accessSecret) || AE_MASTER== null || "".equals(AE_MASTER.toString())) {
+			ApiResult apiResult = new ApiResult();
+			apiResult.setCode(ErrorMessage.ACCESSKEY_ILLEGAL.getCode());
+			apiResult.setMessage(ErrorMessage.ACCESSKEY_ILLEGAL.getMessage());
+			apiResult.setRequestId(requestId);
+			throw new ApiSystemException(apiResult);
+		}
+		return AE_MASTER.toString();
+	}
+
 }