| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- package com.uas.eis.serviceImpl;
- import com.uas.eis.core.config.SpObserver;
- import com.uas.eis.dao.BaseDao;
- import com.uas.eis.entity.ErrorMessage;
- import com.uas.eis.exception.ApiSystemException;
- import com.uas.eis.sdk.entity.ApiResult;
- import com.uas.eis.sdk.resp.ApiResponse;
- import com.uas.eis.service.MESDataService;
- import com.uas.eis.utils.*;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.io.IOException;
- import java.sql.Timestamp;
- import java.util.*;
- @Service
- public class MESDataServiceImpl implements MESDataService {
- @Autowired
- private BaseDao baseDao;
- @Value("${spring.datasource.username}")
- private String username;
- @Override
- public List<Map<Object,Object>> snStepPass(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_STEPPASSED where sp_id=? and nvl(t_status,'W')='W' ",Integer.class,map.get("SP_ID"));
- remap.put("id",map.get("SP_ID"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_STEPPASSED"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- //baseDao.execute(SqlUtil.getInsertSqlbyGridStore(maps, "TEMP_STEPPASSED"));
- //baseDao.execute("update temp_steppassed set t_status='D',T_REMAKR='重复' where t_id in (select t_id from (select temp_steppassed.*,row_number()over(partition by sp_id order by t_id desc) cn from temp_steppassed where nvl(t_status,'W')='W' ) where cn>1)");
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public List<Map<Object,Object>> snInfo(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_SNINFO where SI_ID=? and nvl(t_status,'W')='W' ",Integer.class,map.get("SI_ID"));
- remap.put("id",map.get("SI_ID"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_SNINFO"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public List<Map<Object,Object>> makeSnRelation(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_MAKESNRELATION where ID=? and nvl(t_status,'W')='W' ",Integer.class,map.get("ID"));
- remap.put("id",map.get("ID"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_MAKESNRELATION"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public List<Map<Object,Object>> MAKEBAD(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_MAKEBAD where MB_CODE=? and nvl(t_status,'W')='W' ",Integer.class,map.get("MB_CODE"));
- remap.put("id",map.get("MB_CODE"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_MAKEBAD"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public List<Map<Object,Object>> makeBadReason(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_MAKEBADREASON where MBR_ID=? and nvl(t_status,'W')='W' ",Integer.class,map.get("MBR_ID"));
- remap.put("id",map.get("MBR_ID"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_MAKEBADREASON"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public List<Map<Object,Object>> packageDetail(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- List<Map<Object, Object>> maps = BaseUtil.parseGridStoreToMaps(data);
- SpObserver.putSp(AE_MASTER);
- List<Map<Object, Object>> relist = new ArrayList<>();
- for (Map<Object, Object> map : maps) {
- Map<Object, Object> remap = new HashMap<>();
- String remark = "";
- int cn = baseDao.getJdbcTemplate().queryForObject("select count(1) from TEMP_PACKAGEDETAIL where PD_ID=? and nvl(t_status,'W')='W' ",Integer.class,map.get("MBR_ID"));
- remap.put("id",map.get("PD_ID"));
- if(cn>0){
- map.put("T_STATUS","D");
- map.put("T_REMAKR","重复");
- remark = "重复";
- }else{
- map.put("T_STATUS","W");
- }
- map.put("T_KEY",accessKey);
- map.put("T_INDATE", Timestamp.valueOf(DateUtil.currentDateString(Constant.YMD_HMS)));
- try {
- baseDao.execute(SqlUtil.getInsertSqlByMap(map,"TEMP_PACKAGEDETAIL"));
- remap.put("result","OK");
- remap.put("remark",remark);
- }catch (Exception e){
- remap.put("result","NG");
- remap.put("remark",e.getMessage());
- e.printStackTrace();
- }
- relist.add(remap);
- }
- SpObserver.putSp(username);
- return relist;
- }
- @Override
- public ApiResult<List<Map<String,Object>>> getQRCode(String data) {
- Map<Object, Object> map = BaseUtil.parseFormStoreToMap(data);
- String veCode = StringUtil.nvl(map.get("veCode"), "");
- if ("".equals(veCode)){
- return ApiResponse.failRsp("10011","供应商代码不能为空!");
- }
- String prodCode = StringUtil.nvl(map.get("prodCode"), "");
- if ("".equals(prodCode)){
- return ApiResponse.failRsp("10012","物料代码不能为空!");
- }
- String machineCode = StringUtil.nvl(map.get("machineCode"), "");
- if ("".equals(machineCode)){
- return ApiResponse.failRsp("10013","机台号不能为空!");
- }
- String version = StringUtil.nvl(map.get("version"), "");
- if ("".equals(version)){
- return ApiResponse.failRsp("10014","版本号不能为空!");
- }
- String indate = StringUtil.nvl(map.get("indate"), "");
- if ("".equals(indate)){
- return ApiResponse.failRsp("10015","请确认获取条码的具体时间!");
- }
- if (baseDao.checkIf("ProdQRCode","qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)=0")) {
- List<Map<String, Object>> maps = baseDao.queryForList("select to_char(qr_date,'yyyy-MM-dd') qr_date, qr_prodcode, qr_vecode, qr_version, qr_machinecode, qr_qty, qr_serianum, qr_code from ProdQRCode where qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)=0");
- baseDao.execute("update ProdQRCode set qr_isobtained=-1 where qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)=0");
- return ApiResponse.successRsp("0", "Success", "", maps);
- }else
- return ApiResponse.failRsp("10015","获取失败,请检查参数!");
- }
- @Override
- public ApiResult<String> checkQRCode(String data) {
- Map<Object, Object> map = BaseUtil.parseFormStoreToMap(data);
- String veCode = StringUtil.nvl(map.get("veCode"), "");
- if ("".equals(veCode)){
- return ApiResponse.failRsp("10011","供应商代码不能为空!");
- }
- String prodCode = StringUtil.nvl(map.get("prodCode"), "");
- if ("".equals(prodCode)){
- return ApiResponse.failRsp("10012","物料代码不能为空!");
- }
- String machineCode = StringUtil.nvl(map.get("machineCode"), "");
- if ("".equals(machineCode)){
- return ApiResponse.failRsp("10013","机台号不能为空!");
- }
- String version = StringUtil.nvl(map.get("version"), "");
- if ("".equals(version)){
- return ApiResponse.failRsp("10014","版本号不能为空!");
- }
- String indate = StringUtil.nvl(map.get("indate"), "");
- if ("".equals(indate)){
- return ApiResponse.failRsp("10015","请确认获取条码的具体时间!");
- }
- String QRCode = StringUtil.nvl(map.get("QRCode"), "");
- if ("".equals(QRCode)){
- return ApiResponse.failRsp("10016","条码不能为空!");
- }
- if (baseDao.checkIf("ProdQRCode","qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0")){
- baseDao.execute("update ProdQRCode set qr_ldischeck=-1,qr_ldcheckres='OK',qr_ldcheckdate=sysdate where qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0");
- return ApiResponse.successRsp("0","Success","","OK");
- }else {
- baseDao.execute("update ProdQRCode set qr_ldischeck=-1,qr_ldcheckres='NG',qr_ldcheckdate=sysdate where qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0");
- return ApiResponse.successRsp("0", "Success", "", "NG");
- }
- }
- @Override
- public ApiResult<String> checkDCRQRCode(String accessKey, String requestId, String data) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- SpObserver.putSp(AE_MASTER);
- Map<Object, Object> map = BaseUtil.parseFormStoreToMap(data);
- String veCode = StringUtil.nvl(map.get("veCode"), "");
- if ("".equals(veCode)){
- return ApiResponse.failRsp("10011","供应商代码不能为空!");
- }
- String prodCode = StringUtil.nvl(map.get("prodCode"), "");
- if ("".equals(prodCode)){
- return ApiResponse.failRsp("10012","物料代码不能为空!");
- }
- String machineCode = StringUtil.nvl(map.get("machineCode"), "");
- if ("".equals(machineCode)){
- return ApiResponse.failRsp("10013","机台号不能为空!");
- }
- String version = StringUtil.nvl(map.get("version"), "");
- if ("".equals(version)){
- return ApiResponse.failRsp("10014","版本号不能为空!");
- }
- String indate = StringUtil.nvl(map.get("indate"), "");
- if ("".equals(indate)){
- return ApiResponse.failRsp("10015","请确认获取条码的具体时间!");
- }
- String QRCode = StringUtil.nvl(map.get("QRCode"), "");
- if ("".equals(QRCode)){
- return ApiResponse.failRsp("10016","条码不能为空!");
- }
- if (baseDao.checkIf("ProdQRCode","qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0")){
- baseDao.execute("update ProdQRCode set qr_dcrischeck=-1,qr_dcrcheckres='OK',qr_dcrcheckdate=sysdate where qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0");
- return ApiResponse.successRsp("0","Success",requestId,"OK");
- }else {
- baseDao.execute("update ProdQRCode set qr_dcrischeck=-1,qr_dcrcheckres='OK',qr_dcrcheckdate=sysdate where qr_code='"+QRCode+"' and qr_vecode='" + veCode + "' and qr_prodcode='" + prodCode + "' and qr_machinecode='" + machineCode + "' and qr_version='" + version + "' and to_char(qr_date,'yyyy-MM-dd')='"+indate+"' and nvl(qr_isobtained,0)<>0");
- return ApiResponse.successRsp("0", "Success", requestId, "NG");
- }
- }
- @Override
- @Transactional
- public int saveFilePath(String accessKey, String requestId,String path, int size, String filename) {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- SpObserver.putSp(AE_MASTER);
- int id = baseDao.getSeqId("filepath_seq");
- /**
- * 文件名含单引号无法下载*/
- filename=filename.replaceAll(",", ",");
- baseDao.execute("INSERT INTO filepath(fp_id,fp_path,fp_size,fp_man,fp_date,fp_name) values(" + id + ",'" + path + "'," + size
- + ",'" + accessKey+ "'," + DateUtil.parseDateToOracleString(Constant.YMD_HMS, new Date()) + ",'" + filename
- + "')");
- baseDao.execute("insert into DCRFILEDATA (DF_ID ,DF_DATE,DF_INMAN,DF_ATTACH,DF_FILENAME)" +
- " select DCRFILEDATA_seq.nextval,sysdate,?,?,? from dual ",accessKey,id,filename);
- return id;
- }
- @Override
- public ApiResult<String> uploadDCRFile(String accessKey, String requestId, MultipartFile file) throws IOException {
- try {
- String filename = file.getOriginalFilename();
- String path = saveFile(file);
- int id = saveFilePath(accessKey, requestId,path, (int) file.getSize(), filename);
- return ApiResponse.successRsp("0", "Success", requestId, "");
- }catch (Exception e) {
- e.printStackTrace();
- return ApiResponse.failRsp( "10011","上传失败"+(e.getMessage().length()>400 ? e.getMessage().substring(0,400):e.getMessage()));
- }
- }
- @Override
- public ApiResult<String> DCRLogExcel(String accessKey, String requestId, String data) {
- try {
- String AE_MASTER = checkAccessKey(accessKey, requestId);
- SpObserver.putSp(AE_MASTER);
- Map<Object, Object> store = BaseUtil.parseFormStoreToMap(data);
- store.put("dle_id",baseDao.getSeqId("dcrlogexcel_seq"));
- String formSql = SqlUtil.getInsertSqlByMap(store, "DCRLogExcel");
- baseDao.execute(formSql);
- return ApiResponse.successRsp("0", "Success", requestId, "传输成功!");
- }catch (Exception e) {
- e.printStackTrace();
- return ApiResponse.failRsp( "10020","传输失败"+(e.getMessage().length()>400 ? e.getMessage().substring(0,400):e.getMessage()));
- }
- }
- private String saveFile(MultipartFile file) throws IOException {
- String path = "/dcr";
- File filep = new File(path);
- String fileName = file.getOriginalFilename();
- if (!filep.isDirectory()) {
- filep.mkdir();
- }
- path = path+File.separator +fileName;
- FileUtils.copyInputStreamToFile(file.getInputStream(),new File(path));
- return path;
- }
- 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 (StringUtils.isEmpty(accessKey) || 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();
- }
- }
|