Esempio n. 1
0
    def update_db(self):
        """更新数据库"""
        _Sql = Sql()

        if self.is_receipt:
            # d = {
            #     # "QpSeqNo": self.cusCiqNo,
            #     "QpNotes": self.note,
            #     "QpEntryId": self.entryId,
            #     "ProcessTime": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
            #     "DecState": "CR_" + self.channel,
            #
            # }
            # if d["QpEntryId"] is None:
            #     d.pop("DecDate")
            # _Sql.update("DecMsg", where={"QpSeqNo": self.cusCiqNo}, **d)
            # # logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))
            #
            # # 插入DecReceipt信息
            # ret = _Sql.select("DecMsg", "DecId,ClientSeqNo", where={"QpSeqNo": self.cusCiqNo})
            # if not ret:
            #     logger.warn(
            #         "插入数据到DecReceipt表时,根据统一编号在DecMsg搜索DecId,ClientSeqNo,未搜到,严重逻辑错误," +
            #         "说明申报成功后应该将QpSeqNo更新到DecMsg,但此步未做,本DecReceipt信息:{}, 'QpSeqNo': {}".format(d, self.cusCiqNo))
            #     return False
            #
            # DecId, ClientSeqNo = ret[0]
            # d = {
            #     "DecId": DecId,
            #     "SeqNo": self.cusCiqNo,
            #     "ClientSeqNo": ClientSeqNo,
            #     "NoticeDate": self.noticeDate,
            #     "DecState": "CR_" + self.channel,
            #     "Note": self.note,
            #     "DecDate": self.dDate,  # 申报日期
            #     "IEDate": self.dDate,  # 进出口日期
            # }
            # if self.dDate:
            #     pass
            # else:
            #     d.pop("DecDate")
            #     d.pop("IEDate")
            #
            # _Sql.insert("DecReceipt", **d)
            # logger.info("单一窗口:报关单海关回执写入数据库DecReceipt成功:{}".format(d))

            return True

        else:
            d = {
                "QpSeqNo": self.SeqNo,
                "QpNotes": self.ErrorMessage,
                "DecState": "TS_O&K",
            }
            if self.file_name.startswith('Failed'):
                d.pop('QpSeqNo')
            if d['QpNotes'] and len(d['QpNotes']) > 200:
                d['QpNotes'] = d['QpNotes'][:200]
            try:

                _Sql.update("NRelation", where={"ClientSeqNo": getattr(self, "ClientSeqNo")}, **d)
                logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))
            except Exception as e:
                logger.warning('更新回执失败,错误信息:{}'.format(e))
                return False

            return True
Esempio n. 2
0
    def update_db(self):
        """更新数据库"""
        _Sql = Sql()
        if self.is_receipt:
            d = {
                # "QpSeqNo": self.cusCiqNo,
                "QpNotes": self.note,
                "QpEntryId": self.entryId,
                "ProcessTime":
                datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
                "DecState": "CR_" + self.channel if self.channel else None,
            }
            import copy
            _d = copy.deepcopy(d)
            for k in _d:
                if _d[k] is None:
                    d.pop(k)
            _Sql.update("NRelation", where={"QpSeqNo": self.cusCiqNo}, **d)
            return True
        elif self.is_other:
            Nids = _Sql.select('NRelation',
                               'id',
                               where={"QpSeqNo": getattr(self, "n_SeqNo")})
            if Nids:
                for nid in Nids:
                    DecIds = _Sql.select('Relation',
                                         'DecId',
                                         'PId',
                                         where={"NId": nid})
                    for decid, PId in DecIds:
                        _Sql.insert('DecLicenseDoc',
                                    DecId=decid,
                                    DocuCode='a',
                                    CertCode=self.n_QpEntryId)
                        _Sql.update('DecHead',
                                    where={'DecId': decid},
                                    SeqNo=self.dec_SeqNo)
                        _Sql.update('DecMsg',
                                    where={'DecId': decid},
                                    QpSeqNo=self.dec_SeqNo)
                        _Sql.update('PassPortHead',
                                    where={'PId': PId},
                                    RltNo=self.n_QpEntryId)
                        passports = _Sql.select('PassPortHead',
                                                'BindTypecd',
                                                'RltTbTypecd',
                                                'id',
                                                where={'PId': PId})
                        for passport in passports:
                            if 2 == passport[0]:
                                _Sql.insert('PassPortAcmp',
                                            RltTbTypecd=passport[1],
                                            RltNo=self.n_QpEntryId,
                                            Acmp2Head=passport[2])
            else:
                logger.warning('更新回执失败,核注单统一编号{}未存在'.format(self.n_SeqNo))
                return False

            return True
        else:
            d = {
                "QpSeqNo": self.SeqNo,
                "QpNotes": self.ErrorMessage,
                "DecState": "TS_O&K",
            }
            if d['QpSeqNo'] is None:
                d.pop('QpSeqNo')
            if d['QpNotes'] and len(d['QpNotes']) > 200:
                d['QpNotes'] = d['QpNotes'][:200]

            try:
                if self.file_name.startswith(
                    ('Successed_PassPort', 'Failed_PassPort')):
                    Pid = _Sql.select(
                        'PRelation',
                        'id',
                        where={"ClientSeqNo": getattr(self, "ClientSeqNo")})
                    if Pid:
                        _Sql.update("PRelation",
                                    where={
                                        "ClientSeqNo":
                                        getattr(self, "ClientSeqNo")
                                    },
                                    **d)
                    else:
                        logger.warning("核放单更新回执失败, 自编号{}不存在".format(
                            self.ClientSeqNo))
                        return False
                else:
                    Nid = _Sql.select(
                        'NRelation',
                        'id',
                        where={"ClientSeqNo": getattr(self, "ClientSeqNo")})
                    if Nid:
                        _Sql.update("NRelation",
                                    where={
                                        "ClientSeqNo":
                                        getattr(self, "ClientSeqNo")
                                    },
                                    **d)
                        if self.SeqNo:
                            for NId in Nid:
                                _Sql.update("NemsInvtHeadType",
                                            where={"NId": NId},
                                            SeqNo=self.SeqNo)
                    else:
                        logger.warning("核注清单更新回执失败, 自编号{}不存在".format(
                            self.ClientSeqNo))
                        return False
                logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(
                    getattr(self, "ClientSeqNo"), d))
            except Exception as e:
                logger.warning('更新回执失败,错误信息:{}'.format(e))
                return False

            return True
Esempio n. 3
0
    def update_db(self):
        """更新数据库"""
        _Sql = Sql()

        if self.is_receipt:
            d = {
                # "QpSeqNo": self.cusCiqNo,
                "QpNotes": self.note,
                "QpEntryId": self.entryId,
                "ProcessTime": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
                "DecState": "CR_" + self.channel,
            }
            _Sql.update("DecMsg", where={"QpSeqNo": self.cusCiqNo}, **d)
            # logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))

            # 插入DecReceipt信息

            ret = _Sql.select("DecMsg", "DecId,ClientSeqNo", where={"QpSeqNo": self.cusCiqNo})
            if not ret:
                logger.warn(
                    "插入数据到DecReceipt表时,根据统一编号在DecMsg搜索DecId,ClientSeqNo,未搜到,严重逻辑错误,"+
                    "说明申报成功后应该将QpSeqNo更新到DecMsg,但此步未做,本DecReceipt信息:{}, 'QpSeqNo': {}".format(d, self.cusCiqNo))
                return False

            DecId,ClientSeqNo= ret[0]
            d = {
                "DecId": DecId,
                "SeqNo": self.cusCiqNo,
                "ClientSeqNo": ClientSeqNo,
                "NoticeDate": self.noticeDate,
                "DecState": "CR_" + self.channel,
                "Note": self.note,
                "DecDate": self.dDate,  # 申报日期
                "IEDate": self.dDate,   # 进出口日期
            }
            if self.dDate:
                pass
            else:
                d.pop("DecDate")
                d.pop("IEDate")

            _Sql.insert("DecReceipt", **d)
            logger.info("单一窗口:报关单海关回执写入数据库DecReceipt成功:{}".format(d))

            return True

        else:
            # if self.failInfo:
            #     d = {
            #         "QpNotes": self.failInfo,
            #         "ProcessTime": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
            #
            #     }
            #     _Sql.update("DecMsg", where={"ClientSeqNo": getattr(self, "ClientSeqNo")}, **d)
            #     logger.info("更新DecMsg,回执中包含错误信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))
            #     return True
            # elif self.retData:
            #     self.retData = json.loads(self.retData)
            #     responseMessage = self.retData.get("responseMessage")
            #     responseCode = self.retData.get("responseCode")
            #     cusCiqNo = self.retData.get("cusCiqNo")
            #     preEntryId = self.retData.get("preEntryId")
            #
            #     d = {
            #         "QpSeqNo": cusCiqNo,
            #         "QpNotes": responseMessage,
            #         "QpEntryId": preEntryId,
            #         "ProcessTime": datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
            #         "DecState": "TS_REQ",
            #     }
            #     _Sql.update("DecMsg", where={"ClientSeqNo": getattr(self, "ClientSeqNo")}, **d)
            #     logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))
            #     return True
            d = {
                "QpSeqNo": self.SeqNo,
                "QpNotes": self.ErrorMessage,
            }
            if d['QpSeqNo'] is None:
                d.pop('QpSeqNo')
            if d['QpNotes'] and len(d['QpNotes']) > 200:
                d['QpNotes'] = d['QpNotes'][:200]
            if "0" == self.failInfo:
                d['DecState'] = 'TS_O&K'
            else:
                d['DecState'] = 'TS_ERR'
            decid_tuple = _Sql.select("DecMsg", 'DecId', where={"ClientSeqNo": getattr(self, "ClientSeqNo")})
            try:
                if decid_tuple:
                    _Sql.update("DecMsg", where={"ClientSeqNo": getattr(self, "ClientSeqNo")}, **d)
                    logger.info("更新DecMsg信息,ClientSeqNo:{},msg:{}".format(getattr(self, "ClientSeqNo"), d))
                else:
                    logger.warning("更新回执失败, 自编号{}不存在".format(self.ClientSeqNo))
                    return False
            except Exception as e:
                logger.warning('更新回执失败,错误信息:{}'.format(e))
                return False

            return True