| | |
| | | ----------------------------------------------------------------------------------------------------- å
æ°æ®æµè¯è¡¨ * |
| | | -- drop table if exists md.md_zxcg; |
| | | create table md.md_zxcg( |
| | | id serial primary key, |
| | | gid serial primary key, |
| | | zh varchar(50), |
| | | zj float8, |
| | | lc float8, |
| | | x float8, |
| | | y float8, |
| | | z float8, |
| | | pid integer, |
| | | create_user integer, |
| | | create_time timestamp(6) without time zone default now(), |
| | | update_user integer, |
| | |
| | | |
| | | -- drop table if exists md.md_gdcg; |
| | | create table md.md_gdcg( |
| | | id serial primary key, |
| | | gid serial primary key, |
| | | bh varchar(100), |
| | | gxdh varchar(100), |
| | | ljdh varchar(100), |
| | |
| | | gkpl varchar(100), |
| | | dldy varchar(100), |
| | | bz varchar(100), |
| | | pid integer, |
| | | create_user integer, |
| | | create_time timestamp(6) without time zone default now(), |
| | | update_user integer, |
| | |
| | | import com.baomidou.mybatisplus.core.MybatisConfiguration; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
| | | import com.lf.server.extend.CustomizedSqlInjector; |
| | | import org.apache.ibatis.type.JdbcType; |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.context.annotation.Bean; |
| | |
| | | } |
| | | }; |
| | | } |
| | | |
| | | @Bean |
| | | public CustomizedSqlInjector customizedSqlInjector() { |
| | | return new CustomizedSqlInjector(); |
| | | } |
| | | } |
| | |
| | | package com.lf.server.entity.md; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.lf.server.annotation.ExcelHead; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | |
| | | import java.io.Serializable; |
| | | import java.sql.Timestamp; |
| | | |
| | | /** |
| | | * ç®¡éææè¡¨ |
| | |
| | | @AllArgsConstructor |
| | | @TableName("md.md_gdcg") |
| | | @ExcelHead(headRows = 3,excludeSheets = "å°é¢,ç®å½") |
| | | public class MdGdcgEntity { |
| | | public class MdGdcgEntity implements Serializable { |
| | | private static final long serialVersionUID = -221347663194025408L; |
| | | |
| | | @TableId(type = IdType.AUTO) |
| | | private Integer gid; |
| | | |
| | | @ExcelProperty(index = 0) |
| | | private String bh; |
| | | |
| | |
| | | |
| | | @ExcelProperty(index = 17) |
| | | private String bz; |
| | | |
| | | private Integer createUser; |
| | | |
| | | private Timestamp createTime; |
| | | |
| | | private Integer updateUser; |
| | | |
| | | private Timestamp updateTime; |
| | | |
| | | public String getBh() { |
| | | return bh; |
| | |
| | | public void setBz(String bz) { |
| | | this.bz = bz; |
| | | } |
| | | |
| | | public Integer getGid() { |
| | | return gid; |
| | | } |
| | | |
| | | public void setGid(Integer gid) { |
| | | this.gid = gid; |
| | | } |
| | | |
| | | public Integer getCreateUser() { |
| | | return createUser; |
| | | } |
| | | |
| | | public void setCreateUser(Integer createUser) { |
| | | this.createUser = createUser; |
| | | } |
| | | |
| | | public Timestamp getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Timestamp createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public Integer getUpdateUser() { |
| | | return updateUser; |
| | | } |
| | | |
| | | public void setUpdateUser(Integer updateUser) { |
| | | this.updateUser = updateUser; |
| | | } |
| | | |
| | | public Timestamp getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Timestamp updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | } |
| | |
| | | @ExcelProperty(index = 5) |
| | | private Double z; |
| | | |
| | | private Integer pid; |
| | | |
| | | private Integer createUser; |
| | | |
| | | private Timestamp createTime; |
| | |
| | | private Integer updateUser; |
| | | |
| | | private Timestamp updateTime; |
| | | |
| | | public Integer getGid() { |
| | | return gid; |
| | | } |
| | | |
| | | public void setGid(Integer gid) { |
| | | this.gid = gid; |
| | | } |
| | | |
| | | public String getZh() { |
| | | return zh; |
| | |
| | | this.z = z; |
| | | } |
| | | |
| | | public Integer getPid() { |
| | | return pid; |
| | | public Integer getGid() { |
| | | return gid; |
| | | } |
| | | |
| | | public void setPid(Integer pid) { |
| | | this.pid = pid; |
| | | public void setGid(Integer gid) { |
| | | this.gid = gid; |
| | | } |
| | | |
| | | public Integer getCreateUser() { |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.extend; |
| | | |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * èªå®ä¹æ¹æ³SQL注å
¥å¨ |
| | | * @author WWW |
| | | */ |
| | | public class CustomizedSqlInjector extends DefaultSqlInjector { |
| | | /** |
| | | * 妿åªéå¢å æ¹æ³ï¼ä¿çmybatis plusèªå¸¦æ¹æ³ï¼ |
| | | * å¯ä»¥å
è·åsuper.getMethodList()ï¼åæ·»å add |
| | | */ |
| | | @Override |
| | | public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { |
| | | List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); |
| | | methodList.add(new InsertBatchMethod()); |
| | | methodList.add(new UpdateBatchMethod()); |
| | | |
| | | return methodList; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.extend; |
| | | |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | import org.apache.ibatis.executor.keygen.NoKeyGenerator; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlSource; |
| | | |
| | | /** |
| | | * æ¹éæå
¥æ¹æ³ |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class InsertBatchMethod extends AbstractMethod { |
| | | /** |
| | | * insert into user(id, name, age) values (1, "a", 17), (2, "b", 18); |
| | | * <script> |
| | | * insert into user(id, name, age) values |
| | | * <foreach collection="list" item="item" index="index" open="(" separator="),(" close=")"> |
| | | * #{item.id}, #{item.name}, #{item.age} |
| | | * </foreach> |
| | | * </script> |
| | | */ |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | final String sql = "<script>insert into %s %s values %s</script>"; |
| | | final String fieldSql = prepareFieldSql(tableInfo); |
| | | final String valueSql = prepareValuesSql(tableInfo); |
| | | final String sqlResult = String.format(sql, tableInfo.getTableName(), fieldSql, valueSql); |
| | | |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | |
| | | // 第ä¸ä¸ªåæ°å¿
é¡»åRootMapperçèªå®ä¹æ¹æ³åä¸è´ |
| | | return this.addInsertMappedStatement(mapperClass, modelClass, "insertBatch", sqlSource, new NoKeyGenerator(), null, null); |
| | | } |
| | | |
| | | private String prepareFieldSql(TableInfo tableInfo) { |
| | | StringBuilder fieldSql = new StringBuilder(); |
| | | fieldSql.append(tableInfo.getKeyColumn()).append(","); |
| | | tableInfo.getFieldList().forEach(x -> { |
| | | fieldSql.append(x.getColumn()).append(","); |
| | | }); |
| | | |
| | | fieldSql.delete(fieldSql.length() - 1, fieldSql.length()); |
| | | fieldSql.insert(0, "("); |
| | | fieldSql.append(")"); |
| | | |
| | | return fieldSql.toString(); |
| | | } |
| | | |
| | | private String prepareValuesSql(TableInfo tableInfo) { |
| | | final StringBuilder valueSql = new StringBuilder(); |
| | | valueSql.append("<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"(\" separator=\"),(\" close=\")\">"); |
| | | valueSql.append("#{item.").append(tableInfo.getKeyProperty()).append("},"); |
| | | tableInfo.getFieldList().forEach(x -> valueSql.append("#{item.").append(x.getProperty()).append("},")); |
| | | valueSql.delete(valueSql.length() - 1, valueSql.length()); |
| | | valueSql.append("</foreach>"); |
| | | |
| | | return valueSql.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.extend; |
| | | |
| | | import com.baomidou.mybatisplus.core.injector.AbstractMethod; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlSource; |
| | | |
| | | /** |
| | | * æ¹éæ´æ°æ¹æ³ |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class UpdateBatchMethod extends AbstractMethod { |
| | | /** |
| | | * update user set name = "a", age = 17 where id = 1; |
| | | * update user set name = "b", age = 18 where id = 2; |
| | | * <script> |
| | | * <foreach collection="list" item="item" separator=";"> |
| | | * update user |
| | | * <set> |
| | | * <if test="item.name != null and item.name != ''"> |
| | | * name = #{item.name,jdbcType=VARCHAR}, |
| | | * </if> |
| | | * <if test="item.age != null"> |
| | | * age = #{item.age,jdbcType=INTEGER}, |
| | | * </if> |
| | | * </set> |
| | | * where id = #{item.id,jdbcType=INTEGER} |
| | | * </foreach> |
| | | * </script> |
| | | */ |
| | | @Override |
| | | public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) { |
| | | String sql = "<script>\n<foreach collection=\"list\" item=\"item\" separator=\";\">\nupdate %s %s where %s=#{%s} %s\n</foreach>\n</script>"; |
| | | String additional = tableInfo.isWithVersion() ? tableInfo.getVersionFieldInfo().getVersionOli("item", "item.") : "" + tableInfo.getLogicDeleteSql(true, true); |
| | | String setSql = sqlSet(tableInfo.isWithLogicDelete(), false, tableInfo, false, "item", "item."); |
| | | String sqlResult = String.format(sql, tableInfo.getTableName(), setSql, tableInfo.getKeyColumn(), "item." + tableInfo.getKeyProperty(), additional); |
| | | |
| | | SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass); |
| | | |
| | | // 第ä¸ä¸ªåæ°å¿
é¡»åRootMapperçèªå®ä¹æ¹æ³åä¸è´ |
| | | return this.addUpdateMappedStatement(mapperClass, modelClass, "updateBatch", sqlSource); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Select("select ${field} from ${tab} where ${field} like #{value} order by ${field} limit 10") |
| | | public List<String> selectFieldFuzzy(@Param("tab") String tab, @Param("field") String field, @Param("value") String value); |
| | | |
| | | /** |
| | | * èªå®ä¹æ¹éæå
¥ |
| | | * 妿è¦èªå¨å¡«å
ï¼@Param(xx) xxåæ°åå¿
é¡»æ¯ list/collection/array 3个çå
¶ä¸ä¹ä¸ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public int insertBatch(@Param("list") List<T> list); |
| | | |
| | | /** |
| | | * èªå®ä¹æ¹éæ´æ°ï¼æ¡ä»¶ä¸ºä¸»é® |
| | | * 妿è¦èªå¨å¡«å
ï¼@Param(xx) xxåæ°åå¿
é¡»æ¯ list/collection/array 3个çå
¶ä¸ä¹ä¸ |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public int updateBatch(@Param("list") List<T> list); |
| | | } |
| | |
| | | import com.lf.server.entity.ctrl.TabMapperEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.md.MdZxcgEntity; |
| | | import com.lf.server.helper.ClassHelper; |
| | | import com.lf.server.helper.ExcelHelper; |
| | | import com.lf.server.helper.FileHelper; |
| | |
| | | return 0; |
| | | } |
| | | |
| | | return 0; |
| | | // https://blog.csdn.net/LSL1618/article/details/109102424 |
| | | |
| | | int rows = 0; |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | | rows += baseMapper.insert(list.get(i)); |
| | | } |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |