|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.uas.eis.service.Impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.uas.eis.core.support.TokenProperties;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.entity.Make;
|
|
|
+import com.uas.eis.entity.MakeMaterial;
|
|
|
+import com.uas.eis.entity.Product;
|
|
|
+import com.uas.eis.service.ScheduleTaskService;
|
|
|
+import com.uas.eis.utils.MD5Util;
|
|
|
+import com.uas.eis.utils.PSHttpUtils;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author koul
|
|
|
+ * @email koul@usoftchina.com
|
|
|
+ * @date 2021-12-23 15:30
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ScheduleTaskServiceImpl implements ScheduleTaskService {
|
|
|
+ private static Map<String,String> tokenConfig = TokenProperties.getAllProperty();
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * STATUS(W等待执行,F执行失败,D已执行)
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void syncProducts() {
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select id from mes_product where status='W'");
|
|
|
+ while (rs.next()){
|
|
|
+ Product product = baseDao.getJdbcTemplate().queryForObject("select pr_kh_user,pr_code ,pr_detail ," +
|
|
|
+ "pr_spec ,nvl(pr_unit,'PCS') pr_unit,nvl(pr_cop,'BYT') pr_cop,nvl(pr_version,'0') " +
|
|
|
+ "pr_version,pr_serial,nvl(pr_validdays,'0') pr_validdays,pr_msdlevel ,pr_fhelpcode ," +
|
|
|
+ "pr_f_115 ,pr_f_116 ,pr_f_102,pr_kind,wh_mesc_user pr_whcode,wh_mesn_user pr_whname,flag," +
|
|
|
+ "pr_statuscode,pr_status from mes_product left join Warehouse on pr_whcode=wh_code where id=?",
|
|
|
+ new BeanPropertyRowMapper<Product>(Product.class),
|
|
|
+ rs.getInt("id"));
|
|
|
+ product.setMesUser(tokenConfig.get("mesUser"));
|
|
|
+ product.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
|
|
|
+ Map<String, Object> map = syncMES(JSON.toJSONString(product, SerializerFeature.WriteMapNullValue).replace("null", "\"\""), tokenConfig.get("syncProduct"));
|
|
|
+ if (map!=null){
|
|
|
+ int code = Integer.parseInt(StringUtil.nvl(map.get("code"), "-1"));
|
|
|
+ if (code==0){
|
|
|
+ baseDao.updateByCondition("mes_product","status='D'","status='W' and id="+rs.getInt("id"));
|
|
|
+ }else {
|
|
|
+ baseDao.updateByCondition("mes_product","status='F'","status='W' and id="+rs.getInt("id"));
|
|
|
+ baseDao.execute("insert into meserrorlog (mel_id,mel_url,mel_error,mel_indate,mel_djcode) values (MESERRORLOG_SEQ.NEXTVAL,'"+tokenConfig.get("syncProduct")+"','"+StringUtil.nvl(map.get("msg"),"")+"',sysdate,'"+product.getPr_code()+"')");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncMakeBases() {
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select id from mes_make where status='W'");
|
|
|
+ while (rs.next()){
|
|
|
+ Make make = baseDao.getJdbcTemplate().queryForObject("select id,ma_code,ma_prodcode,ma_qty,ma_custcode,pr_unit,pr_detail,pr_spec,ma_salecode,to_char(ma_planbegindate,'yyyy-MM-dd') ma_planbegindate,to_char(ma_planenddate,'yyyy-MM-dd') ma_planenddate,nvl(ma_cop,'BYT') ma_cop,'S' status,to_char(ma_date,'yyyy-MM-dd HH24:mi:ss') ma_date,ma_recorder,nvl(ma_version,0) ma_version,erpid,wc_id,pr_id,to_char(ma_modifydate,'yyyy-MM-dd HH24:mi:ss') ma_modifydate,ma_modifier,flag from mes_make left join product on ma_prodcode=pr_code left join workcenter on ma_wccode=wc_code where id=?",
|
|
|
+ new BeanPropertyRowMapper<Make>(Make.class),rs.getInt("id"));
|
|
|
+ make.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
|
|
|
+ make.setMesUser(tokenConfig.get("mesUser"));
|
|
|
+ Map<String, Object> map = syncMES(JSON.toJSONString(make, SerializerFeature.WriteMapNullValue).replace("null", "\"\""), tokenConfig.get("syncMakeBase"));
|
|
|
+ if (map!=null){
|
|
|
+ int code = Integer.parseInt(StringUtil.nvl(map.get("code"), "-1"));
|
|
|
+ if (code==0){
|
|
|
+ baseDao.updateByCondition("mes_make","status='D'","status='W' and id="+rs.getInt("id"));
|
|
|
+ }else {
|
|
|
+ baseDao.updateByCondition("mes_make","status='F'","status='W' and id="+rs.getInt("id"));
|
|
|
+ baseDao.execute("insert into meserrorlog (mel_id,mel_url,mel_error,mel_indate,mel_djcode) values (MESERRORLOG_SEQ.NEXTVAL,'"+tokenConfig.get("syncMakeBase")+"','"+StringUtil.nvl(map.get("msg"),"")+"',sysdate,'"+make.getMa_code()+"')");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncMakeBaseDetails() {
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select id,mm_code,mm_detno from mes_makematerial where status='W'");
|
|
|
+ while (rs.next()){
|
|
|
+ int count = baseDao.getCount("select count(1) from mes_make where status='D' and action<>'D' and ma_code='" + rs.getGeneralString("mm_code") + "'");
|
|
|
+ if (count>0) {
|
|
|
+ MakeMaterial makeMaterial = baseDao.getJdbcTemplate().queryForObject("select mm_code,erpid,mm_prodcode,pr_detail,pr_spec,pr_unit,mm_oneuseqty qty,mm_qty,mm_oneuseqty,case when mm_ifrep=-1 then 'alternative' else 'main' end type,bo_recorder,to_char(bo_date,'yyyy-MM-dd HH24:mi:ss') bo_date,nvl(bo_version,0) bo_version,nvl(bo_cop,'BYT') bo_cop,mm_repprodcode,mm_balance,ma_custcode,to_char(mc_indate,'yyyy-MM-dd HH24:mi:ss') mc_indate,mc_recorder,flag from mes_makematerial left join make on ma_id=mm_maid left join Product on mm_prodcode=pr_code left join bom on bo_id=mm_bomid left join MakeMaterialChangeDet on md_makecode=ma_code and md_mmdetno=mm_detno left join MakeMaterialChange on mc_id=md_mcid where id=? order by mm_detno", new BeanPropertyRowMapper<MakeMaterial>(MakeMaterial.class), rs.getInt("id"));
|
|
|
+ makeMaterial.setMesUser(tokenConfig.get("mesUser"));
|
|
|
+ makeMaterial.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
|
|
|
+ Map<String, Object> map = syncMES(JSON.toJSONString(makeMaterial, SerializerFeature.WriteMapNullValue).replace("null", "\"\""), tokenConfig.get("syncMakeBaseDetail"));
|
|
|
+ if (map != null) {
|
|
|
+ int code = Integer.parseInt(StringUtil.nvl(map.get("code"), "-1"));
|
|
|
+ if (code == 0) {
|
|
|
+ baseDao.updateByCondition("mes_makematerial", "status='D'", "status='W' and id=" + rs.getInt("id"));
|
|
|
+ } else {
|
|
|
+ baseDao.updateByCondition("mes_makematerial", "status='F'", "status='W' and id=" + rs.getInt("id"));
|
|
|
+ baseDao.execute("insert into meserrorlog (mel_id,mel_url,mel_error,mel_indate,mel_djcode,mel_djdetno) values(MESERRORLOG_SEQ.NEXTVAL,'" + tokenConfig.get("syncMakeBaseDetail") + "','" + StringUtil.nvl(map.get("msg"), "") + "',sysdate,'" + rs.getGeneralString("mm_code") + "',"+rs.getInt("mm_detno")+")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> syncMES(String params,String url){
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("code",-1);
|
|
|
+ System.err.println(params);
|
|
|
+ try {
|
|
|
+ String post = PSHttpUtils.sendPost(tokenConfig.get("mesHttp") + url, params);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(post);
|
|
|
+ int code = jsonObject.getIntValue("result");
|
|
|
+ if (code==0){
|
|
|
+ map.put("code",code);
|
|
|
+ map.put("msg","同步MES成功");
|
|
|
+ }else if(code==1){
|
|
|
+ map.put("code",code);
|
|
|
+ map.put("msg",jsonObject.getString("message"));
|
|
|
+ }else {
|
|
|
+ map.put("code",-1);
|
|
|
+ map.put("msg","接口调用异常,请联系MES处理!");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ map.put("msg","接口调用异常,请联系MES处理!");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|