|
|
@@ -1,200 +0,0 @@
|
|
|
-package com.uas.eis.task;
|
|
|
-
|
|
|
-import com.uas.eis.beans.result.CrmQueryResult;
|
|
|
-import com.uas.eis.dao.BaseDao;
|
|
|
-import com.uas.eis.dao.SqlRowList;
|
|
|
-import com.uas.eis.manager.CommonManager;
|
|
|
-import com.uas.eis.utils.Configuration;
|
|
|
-import com.uas.eis.utils.Constant;
|
|
|
-import com.uas.eis.utils.DateUtil;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-@Component
|
|
|
-@EnableAsync
|
|
|
-@EnableScheduling
|
|
|
-public class SampleApplyTask {
|
|
|
-
|
|
|
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BaseDao baseDao;
|
|
|
- @Autowired
|
|
|
- private CommonManager commonManager;
|
|
|
- @Resource(name = "configuration")
|
|
|
- private Configuration configuration;
|
|
|
-
|
|
|
-
|
|
|
- @Scheduled(cron = "0 0/15 * * * ?")
|
|
|
- public void syncSampleApply() {
|
|
|
- try {
|
|
|
- List<String> field_values = new ArrayList<>();
|
|
|
- SqlRowList rs = baseDao.queryForRowSet("select ml_syncTime from (select * from FXXKDockingErrorlog where nvl(ML_TYPE,' ')='样品申请主表下载' and ML_SYNCTIME is not null order by ml_date desc) where rownum=1");
|
|
|
- if(rs.next()){
|
|
|
- String ml_syncTime = rs.getGeneralString("ml_syncTime");
|
|
|
- field_values.add(ml_syncTime);
|
|
|
- //样品申请主表下载
|
|
|
- CrmQueryResult crmQueryResult = commonManager.queryCommon("create_time", field_values, "GT", "create_time", true, 50, "object_83m40__c", true);
|
|
|
- int errorCode = crmQueryResult.getErrorCode();
|
|
|
- if(errorCode == 0){
|
|
|
- Map<String, Object> data = crmQueryResult.getData();
|
|
|
- List<Map<String, Object>> dataList = (List<Map<String,Object>>) data.get("dataList");
|
|
|
- //m:成功条数 n:失败条数
|
|
|
- int m=0,n=0;
|
|
|
- if(dataList.size()>0){
|
|
|
- //最后(即最近)一次同步时间
|
|
|
- Long create_time_Last = Long.parseLong(new BigDecimal(dataList.get(dataList.size()-1).get("create_time").toString()).toPlainString());
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
- Object _id = dataList.get(i).get("_id");
|
|
|
- Object name = dataList.get(i).get("name");
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(Constant.YMD_HMS);
|
|
|
- try {
|
|
|
- String MAUser="";
|
|
|
- String username = configuration.getUsername();
|
|
|
- //根据申请抬头取得对应的子账套 若没有值则取资料中心
|
|
|
- Object field_h73i7__c = dataList.get(i).get("field_h73i7__c");
|
|
|
- if(field_h73i7__c!=null && !"".equals(field_h73i7__c.toString())){
|
|
|
- Object DISPLAYFIELD = baseDao.getFieldDataByCondition("comboData", "DISPLAYFIELD", "VALUEFIELD='" + field_h73i7__c + "' and APICODE='field_h73i7__c' and MODULEAPINAME='样品申请单'");
|
|
|
- if(DISPLAYFIELD!=null && !"".equals(DISPLAYFIELD.toString())){
|
|
|
- Object MA_USER = baseDao.getFieldDataByCondition("master", "MA_USER", "MA_FUNCTION='" + DISPLAYFIELD + "'");
|
|
|
- MAUser = (MA_USER == null || "".equals(MA_USER.toString()))?username:MA_USER.toString();
|
|
|
- }
|
|
|
- }
|
|
|
- if(baseDao.checkIf(MAUser+".ProdInOutApply", "pi_code='" + name + "'")){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'样品申请编号已存在','样品申请主表下载','"+name+"')");
|
|
|
- logger.info("异常信息:样品申请编号已存在");
|
|
|
- n++;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Object cu_code = baseDao.getFieldDataByCondition("customer", "max(cu_code) cu_code", "CU_FXXKID='" + dataList.get(i).get("field_l6W5b__c") + "' or cu_name='"+dataList.get(i).get("field_l6W5b__c__r")+"'");
|
|
|
- String cuCode =cu_code == null ? "" : cu_code.toString();
|
|
|
- //默认样品仓
|
|
|
- Object wh_description = baseDao.getFieldDataByCondition("Warehouse", "max(wh_description) wh_description", "wh_code='W02'");
|
|
|
- String pi_whname =wh_description == null ? "" : wh_description.toString();
|
|
|
-
|
|
|
- Object life_status = dataList.get(i).get("life_status");
|
|
|
- Object record_type = dataList.get(i).get("record_type");
|
|
|
-
|
|
|
- String lifeStatus = "normal".equals(life_status) ? "正常": (life_status==null? "" : life_status.toString());
|
|
|
- String recordType = "default__c".equals(record_type) ? "预设业务类型": (record_type==null? "" : record_type.toString());
|
|
|
- //负责人编号、名称
|
|
|
- Map<String,Object> owner__r =(Map<String,Object>) dataList.get(i).get("owner__r");
|
|
|
- Object owner_code = baseDao.getFieldDataByCondition(MAUser+".employee", "max(em_code) em_code", "em_name='" + owner__r.get("name") + "'");
|
|
|
- //创建人编号、名称
|
|
|
- Map<String,Object> created_by__r =(Map<String,Object>) dataList.get(i).get("created_by__r");
|
|
|
- Object created_by_code = baseDao.getFieldDataByCondition(MAUser+".employee", "max(em_code) em_code", "em_name='" + created_by__r.get("name") + "'");
|
|
|
- //最后更新人编号、名称
|
|
|
- Map<String,Object> last_modified_by__r =(Map<String,Object>) dataList.get(i).get("last_modified_by__r");
|
|
|
- Object last_modified_by_code = baseDao.getFieldDataByCondition(MAUser+".employee", "max(em_code) em_code", "em_name='" + last_modified_by__r.get("name") + "'");
|
|
|
- //申请日期
|
|
|
- Long field_lp4Q1__c = Long.parseLong(new BigDecimal(dataList.get(i).get("field_lp4Q1__c").toString()).toPlainString());
|
|
|
- Long create_time = Long.parseLong(new BigDecimal(dataList.get(i).get("create_time").toString()).toPlainString());
|
|
|
- Long last_modified_time = Long.parseLong(new BigDecimal(dataList.get(i).get("last_modified_time").toString()).toPlainString());
|
|
|
- //客户联系人:pi_purposename 电话:pi_expresscode
|
|
|
- int pi_id = baseDao.getSeqId(MAUser+".PRODINOUTAPPLY_SEQ");
|
|
|
- String sql="insert into "+MAUser+".ProdInOutApply(pi_id,pi_code,pi_class,pi_date,pi_status,pi_statuscode,pi_whcode,pi_whname,pi_cardcode,pi_title,pi_emcode,pi_emname,pi_recordman,pi_recorddate," +
|
|
|
- "pi_updateman,pi_updatedate,pi_purposename,pi_expresscode,pi_address,pi_email_user,pi_remark,pi_field_Il1e1,pi_record_type,pi_life_status,PI_FXXKID)" +
|
|
|
- "values("+pi_id+",'"+name+"','其它出库申请单',"+DateUtil.parseDateToOracleString(Constant.YMD_HMS,sdf.parse(sdf.format(field_lp4Q1__c)))+"," +
|
|
|
- "'已审核','AUDITED','W02','"+pi_whname+"','"+cuCode+"','"+dataList.get(i).get("field_l6W5b__c__r")+"','"+owner_code+"','"+owner__r.get("name")+"','"+ created_by__r.get("name")+"'," +
|
|
|
- DateUtil.parseDateToOracleString(Constant.YMD_HMS,sdf.parse(sdf.format(create_time)))+",'"+last_modified_by__r.get("name")+"',"+
|
|
|
- DateUtil.parseDateToOracleString(Constant.YMD_HMS,sdf.parse(sdf.format(last_modified_time)))+",'" +dataList.get(i).get("field_DzO73__c__r")+"',"+
|
|
|
- "'"+dataList.get(i).get("field_57196__c")+"','"+(dataList.get(i).get("field_Z2afs__c")==null?"":dataList.get(i).get("field_Z2afs__c"))+"','"+(dataList.get(i).get("field_1NKlv__c")==null?"":dataList.get(i).get("field_1NKlv__c"))+"'," +
|
|
|
- "'"+(dataList.get(i).get("field_lyGrw__c")==null?"":dataList.get(i).get("field_lyGrw__c"))+"','"+dataList.get(i).get("field_Il1e1__c")+"','"+recordType+"','"+lifeStatus+"','"+_id+"')";
|
|
|
- baseDao.execute(sql);
|
|
|
- //更新样品单中的核算部门
|
|
|
- baseDao.execute("update ProdInOutApply set (pi_departmentcode,pi_departmentname)=(select em_departmentcode,em_depart from employee where em_code=pi_emcode) where nvl(pi_emcode,' ')<>' ' and pi_id="+pi_id);
|
|
|
- //样品申请明细下载
|
|
|
- syncSampleApplyDetail(_id.toString(),pi_id,MAUser);
|
|
|
- m++;
|
|
|
- }catch (Exception e){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','样品申请主表下载','"+name+"')");
|
|
|
- logger.info("异常信息:"+e);
|
|
|
- n++;
|
|
|
- }
|
|
|
- }
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_syncTime) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'下载记录"+dataList.size()+"条,成功"+m+"条,失败"+n+"条','样品申请主表下载','"+create_time_Last+"')");
|
|
|
- }
|
|
|
- }else{
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','样品申请主表下载','')");
|
|
|
- logger.info("异常信息:"+crmQueryResult.getErrorMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','样品申请主表下载','')");
|
|
|
- logger.info("异常信息:"+e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void syncSampleApplyDetail(String SampleApply_id,int pi_id,String MAUser){
|
|
|
- List<String> field_values_Detail = new ArrayList<>();
|
|
|
- field_values_Detail.add(SampleApply_id);
|
|
|
- try {
|
|
|
- CrmQueryResult crmQueryResult = commonManager.queryCommon("field_8019j__c", field_values_Detail, "EQ", "create_time", true, 100, "object_Q55Nj__c", true);
|
|
|
- int errorCode = crmQueryResult.getErrorCode();
|
|
|
- if(errorCode == 0){
|
|
|
- Map<String, Object> data = crmQueryResult.getData();
|
|
|
- List<Map<String, Object>> dataList = (List<Map<String,Object>>) data.get("dataList");
|
|
|
- //默认样品仓
|
|
|
- Object wh_description = baseDao.getFieldDataByCondition("Warehouse", "max(wh_description) wh_description", "wh_code='W02'");
|
|
|
- String pi_whname =wh_description == null ? "" : wh_description.toString();
|
|
|
- //m:成功条数 n:失败条数
|
|
|
- int m=0,n=0;
|
|
|
- if(dataList.size()>0){
|
|
|
- //最后(即最近)一次同步时间
|
|
|
- Long create_time_Last = Long.parseLong(new BigDecimal(dataList.get(dataList.size()-1).get("create_time").toString()).toPlainString());
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
- Object _id = dataList.get(i).get("_id");
|
|
|
- Object name = dataList.get(i).get("name");
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(Constant.YMD_HMS);
|
|
|
- if(baseDao.checkIf(MAUser+".ProdIOApplyDetail", "pd_code='" + name + "' and pd_piid="+pi_id)){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'样品申请明细编号已存在','样品申请明细表下载','"+name+"')");
|
|
|
- logger.info("异常信息:样品申请明细编号已存在");
|
|
|
- n++;
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- //负责人编号、名称
|
|
|
- Map<String,Object> owner__r =(Map<String,Object>) dataList.get(i).get("owner__r");
|
|
|
- Object owner_code = baseDao.getFieldDataByCondition(MAUser+".employee", "max(em_code) em_code", "em_name='" + owner__r.get("name") + "'");
|
|
|
-
|
|
|
- String sql="insert into "+MAUser+".ProdIOApplyDetail(pd_id,pd_piid,pd_pdno,pd_code,pd_piclass,pd_whcode,pd_whname,pd_picode,pd_ownercode,pd_owner,pd_prodcode,pd_detail,pd_sepc,pd_brand,pd_outqty,YPonhand,PD_FXXKID)" +
|
|
|
- "values("+MAUser+".PRODIOAPPLYDETAIL_SEQ.nextval,"+pi_id+","+(i+1)+",'"+name+"','其它出库申请单','W02','"+pi_whname+"','"+dataList.get(i).get("field_8019j__c__r")+"'," +
|
|
|
- "'"+owner_code+"','"+owner__r.get("name")+"','"+ (dataList.get(i).get("field_2Lq6Y__c")==null?"":dataList.get(i).get("field_2Lq6Y__c")) +"','"+(dataList.get(i).get(" field_utezf__c__r")==null?"":dataList.get(i).get(" field_utezf__c__r"))+"'," +
|
|
|
- "'"+(dataList.get(i).get("field_21Suz__c")==null?"":dataList.get(i).get("field_21Suz__c"))+"','"+(dataList.get(i).get("field_y5dz2__c")==null?"":dataList.get(i).get("field_y5dz2__c"))+"','" +dataList.get(i).get("field_7uspZ__c")+"',"+
|
|
|
- "'"+dataList.get(i).get("field_lzxe2__c")+"','"+_id+"')";
|
|
|
- baseDao.execute(sql);
|
|
|
- m++;
|
|
|
- }catch (Exception e){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','样品申请明细表下载','"+name+"')");
|
|
|
- logger.info("异常信息:"+e);
|
|
|
- n++;
|
|
|
- }
|
|
|
- }
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_syncTime) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'下载记录"+dataList.size()+"条,成功"+m+"条,失败"+n+"条','样品申请明细表下载','"+create_time_Last+"')");
|
|
|
- }
|
|
|
- }else{
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','样品申请明细表下载','')");
|
|
|
- logger.info("异常信息:"+crmQueryResult.getErrorMessage());
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','样品申请明细表下载','')");
|
|
|
- logger.info("异常信息:"+e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-}
|