Mybatis注解方式增刪改查

supplierMapper

package com.leading.supplierservice.domain.supplier.mapper;

import com.leading.supplierservice.domain.supplier.dto.SupplierDTO;

import com.leading.supplierservice.domain.supplier.dto.SupplierDetailDTO;

import com.leading.supplierservice.domain.supplier.dto.SupplierInfoDTO;

import com.leading.supplierservice.domain.supplier.dto.SupplierListDTO;

import com.leading.supplierservice.domain.supplier.model.Supplier;

import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SupplierMapper {

? ? final String SUPPLIER_COLUMN = " no , name , shortName , contacts , dockingWay , memo , creatorId , creatorName , createTime , updateTime ";

? ? final String SUPPLIER_COLUMN_PAGE_LIST = " id , no , name , shortName , contacts , dockingWay , memo? , creatorName? ";

? ? /**

? ? * 創建供應商

? ? *

? ? * @param supplier

? ? */

? ? @Insert({

? ? ? ? ? ? " insert? into Supplier ( ",

? ? ? ? ? ? SUPPLIER_COLUMN,

? ? ? ? ? ? " ) values ( ",

? ? ? ? ? ? " #{supplier.no} , #{supplier.name} , #{supplier.shortName} , #{supplier.contacts} , #{supplier.dockingWay} , #{supplier.memo} , #{supplier.creatorId} , #{supplier.creatorName} , now() , now()? ",

? ? ? ? ? ? " ) ",

? ? })

? ? @Options(useGeneratedKeys = true ,keyProperty="supplier.id", keyColumn="id")

? ? Long createSupplier(@Param("supplier") Supplier supplier);

? ? /**

? ? * 更新

? ? *

? ? * @param supplier

? ? */

? ? @Update({

? ? ? ? ? ? "<script>",

? ? ? ? ? ? " update Supplier ",

? ? ? ? ? ? "<set>",

? ? ? ? ? ? "<if test='supplier.name != null'>? name='${supplier.name}' , </if>",

? ? ? ? ? ? "<if test='supplier.shortName != null'>? shortName='${supplier.shortName}' , </if>",

? ? ? ? ? ? "<if test='supplier.contacts != null'>? contacts='${supplier.contacts}' , </if>",

? ? ? ? ? ? "<if test='supplier.dockingWay != null'>? dockingWay=${supplier.dockingWay} , </if>",

? ? ? ? ? ? "<if test='supplier.memo != null'>? memo='${supplier.memo}' , </if>",

? ? ? ? ? ? "updateTime = now()",

? ? ? ? ? ? "</set>",

? ? ? ? ? ? " where id = #{supplier.id} ",

? ? ? ? ? ? "</script>"

? ? })

? ? void updateSupplier(@Param("supplier") Supplier supplier);

? ? /**

? ? * 分頁查詢 - 數量

? ? *

? ? * @param name

? ? * @param contacts

? ? * @return

? ? */

? ? @Select({

? ? ? ? ? ? "<script>",

? ? ? ? ? ? " select count(id) from Supplier? ",

? ? ? ? ? ? "<where>",

? ? ? ? ? ? "<if test=\"name != null and name !='' \"> and name='${name}'? </if>",

? ? ? ? ? ? "<if test=\"contacts != null and contacts!='' \"> and contacts='${contacts}'? </if>",

? ? ? ? ? ? "</where>",

? ? ? ? ? ? "</script>"

? ? })

? ? Integer CountFindSupplierList(@Param("name") String name, @Param("contacts") String contacts);

? ? /**

? ? * 分頁查詢 - 數據

? ? *

? ? * @param name

? ? * @param contacts

? ? * @return

? ? */

? ? @Select({

? ? ? ? ? ? "<script>",

? ? ? ? ? ? " select " + SUPPLIER_COLUMN_PAGE_LIST + " from Supplier? ",

? ? ? ? ? ? "<where>",

? ? ? ? ? ? "<if test=\"name != null and name !='' \"> and name='${name}'? </if>",

? ? ? ? ? ? "<if test=\"contacts != null and contacts!='' \"> and contacts='${contacts}'? </if>",

? ? ? ? ? ? "</where>",

? ? ? ? ? ? "order by updateTime desc ",

? ? ? ? ? ? "limit ${offset},${pageSize}",

? ? ? ? ? ? "</script>"

? ? })

? ? List<SupplierListDTO> findSupplierList(@Param("name") String name, @Param("contacts") String contacts, @Param("offset") Integer offset,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Param("pageSize") Integer pageSize);

? ? /**

? ? * 獲取詳情

? ? *

? ? * @param id

? ? * @return

? ? */

? ? @Select({

? ? ? ? ? ? "<script>",

? ? ? ? ? ? " select * from Supplier where id=#{id}? ",

? ? ? ? ? ? "</script>"

? ? })

? ? Supplier getSupplierDetail(@Param("id") Long id);

}

suplierOperationLogMapper

package com.leading.supplierservice.domain.supplier.mapper;

import com.leading.common.model.ErpUserInfo;

import com.leading.supplierservice.domain.supplier.dto.SupplierOperationLogDTO;

import com.leading.supplierservice.domain.supplier.model.SupplierOperationLog;

import org.apache.ibatis.annotations.Insert;

import org.apache.ibatis.annotations.Param;

import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SupplierOperationLogMapper {

? ? final String SUPPLIER_OPERATION_LOG_COLUMN = " supplierId , operation , description , operatorId , operatorInfo , operationTime? ";

? ? /**

? ? * 創建日志

? ? *

? ? * @param supplierOperationLog

? ? */

? ? @Insert({

? ? ? ? ? ? " insert? into SupplierOperationLog ( ",

? ? ? ? ? ? SUPPLIER_OPERATION_LOG_COLUMN,

? ? ? ? ? ? " ) values ( ",

? ? ? ? ? ? " #{supplierOperationLog.supplierId} , #{supplierOperationLog.operation} , #{supplierOperationLog.description} , #{supplierOperationLog.operatorId} ,#{userInfo,typeHandler=com.leading.common.mybatis.handler.JsonTypeHandler} , now()? ",

? ? ? ? ? ? " ) ",

? ? })

? ? void createSupplierOperationLog(@Param("supplierOperationLog") SupplierOperationLog supplierOperationLog , @Param("userInfo")ErpUserInfo erpUserInfo);

? ? /**

? ? * 查詢 - 根據供應商編號

? ? *

? ? * @param supplierId

? ? */

? ? @Select({

? ? ? ? ? ? "<script>",

? ? ? ? ? ? " select * from SupplierOperationLog? ",

? ? ? ? ? ? "<where>",

? ? ? ? ? ? "<if test='supplierId != null'> and supplierId=#{supplierId}? </if>",

? ? ? ? ? ? "</where>",

? ? ? ? ? ? "</script>",

? ? })

? ? List<SupplierOperationLogDTO> findSupplierOperationLog(@Param("supplierId") Long supplierId);

}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容