Exemplo n.º 1
0
Arquivo: take.py Projeto: onetera/sp
    def delete(self, id="json"):
        # 필수 입력 인자
        client_request_key = request.params.keys()

        # 태이크 고유 번호
        if "takeNo" not in client_request_key:
            response.status_int = 403
            return "Required variable Not Exists - takeNo"

        takeNo = request.params["takeNo"]

        # Take Attr Delete
        take_attr_sql = "delete from Take_Attr where ParentIDX = %d" % int(takeNo)
        Session.execute(take_attr_sql)

        Session.commit()

        # Take Delete
        take_sql = "delete from Take where IDX = %d" % int(takeNo)
        Session.execute(take_sql)

        Session.commit()

        if "json" == id:
            return '{"success": true}'
        else:
            return "<success>true</success>"
Exemplo n.º 2
0
Arquivo: take.py Projeto: onetera/sp
    def modify(self, id="json"):
        # 필수 입력 인자
        client_request_key = request.params.keys()

        # 태이크 고유 번호
        if "takeNo" not in client_request_key:
            response.status_int = 403
            return "Required variable Not Exists - takeNo"

        takeNo = request.params["takeNo"]

        # 기존에 존재한 Take 정보 가져오기
        take_info = (
            Session.query(
                "takeName", "takeStatus", "takeType", "takeContent", "takeWorktime", "takeIndication", "takePreview"
            )
            .from_statement(
                """
			select
				Take.Name as takeName,
				StatCode as takeStatus,
				TypeCode as takeType,
				Content as takeContent,
				attr1.`Value` AS takeWorktime,
				attr2.`Value` AS takeIndication,
				Preview as takePreview
			from Take
			LEFT OUTER JOIN `Take_Attr` AS attr1  ON attr1.`ParentIDX` = `Take`.`IDX` AND attr1.`MAttrID` = 'Worktime'
			LEFT OUTER JOIN `Take_Attr` AS attr2  ON attr2.`ParentIDX` = `Take`.`IDX` AND attr2.`MAttrID` = 'Indication'
			where IDX = :takeNo
		"""
            )
            .params(takeNo=takeNo)
            .first()
        )

        # 태이크명
        takeName = None
        if "takeName" in client_request_key:
            takeName = request.params["takeName"]

            # 태이크 미리보기(MOV, Directory)
        takePreview = None
        if "takePreview" in client_request_key:
            takePreview = request.params["takePreview"]

            # 태이크 상태
        takeStatus = None
        if "takeStatus" in client_request_key:
            takeStatus = request.params["takeStatus"]

            exiStatus = ExistsCode("Take_Stat", takeStatus)
            if not exiStatus:
                response.status_int = 403
                return "An invalid status code."

                # 태이크 타입
        takeType = None
        if "takeType" in client_request_key:
            takeType = request.params["takeType"]

            exiType = ExistsCode("Take_Type", takeType)
            if not exiType:
                response.status_int = 403
                return "An invalid status code."

                # 일한 시간
        takeWorktime = None
        if "takeWorktime" in client_request_key:
            takeWorktime = request.params["takeWorktime"]

            # 지시사항
        takeIndication = ""
        if "takeIndication" in client_request_key:
            takeIndication = request.params["takeIndication"]

            # 태이크 상세내용
        takeContent = ""
        if "takeContent" in client_request_key:
            takeContent = request.params["takeContent"]

        take_sql = "update Take set "
        take_sql_values = []
        if None != takeName and len(takeName) > 0:
            take_sql_values.append("takeName = '" + takeName + "'")

        if None != takePreview and len(takePreview) > 0:
            take_sql_values.append("takePreview = '" + takePreview + "'")

        if None != takeStatus and len(takeStatus) > 0:
            take_sql_values.append("takeStatus = '" + takeStatus + "'")

        if None != takeType and len(takeType) > 0:
            take_sql_values.append("takeType = '" + takeType + "'")

        if None != takeContent and len(takeContent) > 0:
            take_sql_values.append("takeContent = '" + takeContent + "'")

        modifyDate = time.strftime("%Y-%m-%d %H:%M:%S")

        take_sql_values.append("ModifyDate = '" + modifyDate + "'")

        take_sql += ", ".join(take_sql_values)
        take_sql += " where IDX = %d" % int(takeNo)

        Session.execute(take_sql)

        if None != takeWorktime and len(takeWorktime) > 0:
            take_attr_sql = (
                "update Take_Attr set Value='"
                + takeWorktime
                + "' where ParentIDX=%(ParentIDX)d and MAttrIDX=24" % dict(ParentIDX=takeNo)
            )
            Session.execute(take_attr_sql)

        if None != takeIndication and len(takeIndication) > 0:
            take_attr_sql = (
                "update Take_Attr set Value='"
                + takeIndication
                + "' where ParentIDX=%(ParentIDX)d and MAttrIDX=25" % dict(ParentIDX=takeNo)
            )
            Session.execute(take_attr_sql)

        Session.commit()

        if "json" == id:
            return json.dumps({"takeNo": takeNo, "takeModifyDate": modifyDate})
        else:
            to_xml = "<records><takeNo>" + takeNo
            to_xml += "</takeNo><takeModifyDate>"
            to_xml += modifyDate + "</takeModifyDate></records>"

            return to_xml
Exemplo n.º 3
0
Arquivo: take.py Projeto: onetera/sp
    def write(self, id="json"):
        # 필수 입력 인자
        client_request_key = request.params.keys()

        # 태스크 고유 번호
        if "taskNo" not in client_request_key:
            response.status_int = 403
            return "Required variable Not Exists - taskNo"

        taskNo = request.params["taskNo"]

        # 태이크명
        takeName = None
        if "takeName" not in client_request_key:
            response.status_int = 403
            return "Required variable Not Exists - takeName"

        takeName = request.params["takeName"]

        # 태이크 미리보기(MOV, Directory)
        takePreview = None
        if "takePreview" not in client_request_key:
            response.status_int = 403
            return "Required variable Not Exists - takePreview"

        takePreview = request.params["takePreview"]

        # 선택인자 검사

        # 태이크 상태
        takeStatus = "RDY"
        if "takeStatus" in client_request_key:
            takeStatus = request.params["takeStatus"]

            exiStatus = ExistsCode("Take_Stat", takeStatus)
            if not exiStatus:
                response.status_int = 403
                return "An invalid status code."

                # 태이크 타입
        takeType = "MDL"
        if "takeType" in client_request_key:
            takeType = request.params["takeType"]

            exiType = ExistsCode("Take_Type", takeType)
            if not exiType:
                response.status_int = 403
                return "An invalid status code."

                # 일한 시간
        takeWorktime = "0"
        if "takeWorktime" in client_request_key:
            takeWorktime = request.params["takeWorktime"]

            # 지시사항
        takeIndication = ""
        if "takeIndication" in client_request_key:
            takeIndication = request.params["takeIndication"]

            # 태이크 상세내용
        takeContent = ""
        if "takeContent" in client_request_key:
            takeContent = request.params["takeContent"]

            # Task의 정보를 가져온다.
        task_info = (
            Session.query("IDX", "Parent1", "Parent2", "Parent3", "Confirmer")
            .from_statement(
                " select IDX, Parent1, Parent2, Parent3, Parent4, Confirmer from " " Task where IDX = :taskNo"
            )
            .params(taskNo=taskNo)
            .first()
        )

        import uuid

        # Take 테이블의 최대 IDX 값을 가져온다
        take_max_idx = Session.query("max_no").from_statement("select max(IDX) as max_no from Take").first()

        take_sql = (
            "insert into Take (IDX, UUID, Name, Code, StatCode, "
            " TypeCode, Parent1, Parent2, Parent3, Parent4, Element, `Version`, "
            " Content, Preview, Confirmer, CreateDate, CreateBy, CreateBy2, "
            " ModifyDate, ModifyBy, ModifyBy2, SortNumber, IsPublish, IsStable, "
            " IsApproved) values (%(IDX)d, '%(UUID)s', '%(Name)s', '%(Name)s', '%(StatCode)s', "
            " '%(TypeCode)s', %(Parent1)d, %(Parent2)d, %(Parent3)d, %(Parent4)d, '%(Element)s', %(Version)d, "
            " '%(Content)s', '%(Preview)s', '%(Confirmer)s', timestamp('%(CreateDate)s'), '%(CreateBy)s', '%(CreateBy2)s', "
            " timestamp('%(ModifyDate)s'), '%(ModifyBy)s', '%(ModifyBy2)s', %(SortNumber)d, %(IsPublish)d, %(IsStable)d, %(IsApproved)d)"
        )

        CreateTime = time.strftime("%Y-%m-%d %H:%M:%S")

        take_sql = take_sql % dict(
            IDX=int(take_max_idx.max_no + 1),
            UUID=unicode(uuid.uuid1()),
            Name=unicode(takeName),
            StatCode=takeStatus,
            TypeCode=takeType,
            Parent1=task_info.Parent1,
            Parent2=task_info.Parent2,
            Parent3=task_info.Parent3,
            Parent4=task_info.IDX,
            Element="all",  # 임시고정
            Version=1,  # 임시고정
            Content=takeContent,
            Preview=takePreview,
            Confirmer=unicode(task_info.Confirmer),
            CreateDate=CreateTime,
            CreateBy="broker",
            CreateBy2="시스템".decode("utf-8"),
            ModifyDate=CreateTime,
            ModifyBy="broker",
            ModifyBy2="시스템".decode("utf-8"),
            SortNumber=500,
            IsPublish=0,
            IsStable=0,
            IsApproved=0,
        )

        Session.execute(take_sql)

        Session.commit()

        # Take_Attr Dict
        take_attr_value_dict = {
            0: {"MAttrIDX": 24, "MAttrID": "Worktime", "Name": "작업시간".decode("utf-8"), "Value": takeWorktime},
            1: {"MAttrIDX": 25, "MAttrID": "Indication", "Name": "지시사항".decode("utf-8"), "Value": takeIndication},
        }

        # Take_Attr 테이블의 최대 IDX 값을 가져온다
        for i in range(2):
            take_attr_max_idx = (
                Session.query("max_no").from_statement("select max(AttrIDX) as max_no from Take_Attr").first()
            )
            if None == take_attr_max_idx.max_no:
                take_attr_max_idx = 1
            else:
                take_attr_max_idx = take_attr_max_idx.max_no + 1

            take_attr_sql = (
                "insert into Take_Attr (AttrIDX, ParentIDX, MAttrIDX, MAttrID, Category, Name, Value) values "
            )
            take_attr_sql += (
                " (%(AttrIDX)d, %(ParentIDX)d, %(MAttrIDX)d, '%(MAttrID)s', '%(Category)s', '%(Name)s', '%(Value)s')"
            )

            take_extend_attr = take_attr_value_dict[i]

            take_attr_sql = take_attr_sql % dict(
                AttrIDX=take_attr_max_idx,
                ParentIDX=int(take_max_idx.max_no + 1),
                MAttrIDX=take_extend_attr["MAttrIDX"],
                MAttrID=take_extend_attr["MAttrID"],
                Category="Take",
                Name=take_extend_attr["Name"],
                Value=take_extend_attr["Value"],
            )

            Session.execute(take_attr_sql)
            Session.commit()

        if "json" == id:
            return json.dumps({"takeNo": int(take_max_idx.max_no + 1), "takeCreateDate": CreateTime})
        else:
            to_xml = "<records><takeNo>" + int(take_max_idx.max_no + 1)
            to_xml += "</takeNo><takeCreateDate>"
            to_xml += CreateTime + "</takeCreateDate></records>"

            return to_xml