@@ -4,9 +4,7 @@ import com.qmrz.exception.ABException; | |||
import com.qmrz.service.TableService; | |||
import com.qmrz.utils.CGHelper; | |||
import com.qmrz.utils.Fn; | |||
import com.qmrz.utils.MapUtil; | |||
import com.qmrz.utils.SpringContextUtil; | |||
import org.apache.commons.lang.StringUtils; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
@@ -16,11 +14,11 @@ import java.util.stream.Collectors; | |||
/** | |||
* Mapper生成 | |||
*/ | |||
public class MapperGenerator { | |||
public class MapperFPGenerator { | |||
private TableService tableService; | |||
private String dbName; | |||
public MapperGenerator(String dbName) { | |||
public MapperFPGenerator(String dbName) { | |||
tableService = SpringContextUtil.getBean(TableService.class); | |||
this.dbName = dbName; | |||
} | |||
@@ -31,7 +29,7 @@ public class MapperGenerator { | |||
Map<String, List<Map>> result = columnList.stream().collect(Collectors.groupingBy(map -> Fn.toString(map.get("table_name")), Collectors.toList())); | |||
CGHelper cgHelper = new CGHelper("mapper2.ftl", dbName);//无同步代码版本 | |||
CGHelper cgHelper = new CGHelper("mapper_fp.ftl", dbName);//无同步代码版本 | |||
// CGHelper cgHelper = new CGHelper("mapper_sync.ftl", dbName);//有同步代码版本 | |||
tableList.forEach(item -> { | |||
@@ -76,7 +74,7 @@ public class MapperGenerator { | |||
item.put("table_name2", table_name2);//首字母大写 | |||
item.put("orderBy", orderBy); | |||
item.put("primaryKeyName", primaryKeyName.toString()); | |||
cgHelper.generator("mapper2", table_name2 + "Mapper.xml", item); | |||
cgHelper.generator("mapper_fp", table_name2 + "Mapper.xml", item); | |||
}); | |||
} | |||
} |
@@ -14,11 +14,11 @@ import java.util.stream.Collectors; | |||
/** | |||
* Mapper生成 | |||
*/ | |||
public class MapperFPGenerator { | |||
public class MapperFPRGenerator { | |||
private TableService tableService; | |||
private String dbName; | |||
public MapperFPGenerator(String dbName) { | |||
public MapperFPRGenerator(String dbName) { | |||
tableService = SpringContextUtil.getBean(TableService.class); | |||
this.dbName = dbName; | |||
} | |||
@@ -29,7 +29,7 @@ public class MapperFPGenerator { | |||
Map<String, List<Map>> result = columnList.stream().collect(Collectors.groupingBy(map -> Fn.toString(map.get("table_name")), Collectors.toList())); | |||
CGHelper cgHelper = new CGHelper("mapper_fp.ftl", dbName);//无同步代码版本 | |||
CGHelper cgHelper = new CGHelper("mapper_fpr.ftl", dbName);//无同步代码版本 | |||
// CGHelper cgHelper = new CGHelper("mapper_sync.ftl", dbName);//有同步代码版本 | |||
tableList.forEach(item -> { | |||
@@ -74,7 +74,7 @@ public class MapperFPGenerator { | |||
item.put("table_name2", table_name2);//首字母大写 | |||
item.put("orderBy", orderBy); | |||
item.put("primaryKeyName", primaryKeyName.toString()); | |||
cgHelper.generator("mapper_fp", table_name2 + "Mapper.xml", item); | |||
cgHelper.generator("mapper_fpr", table_name2 + "Mapper.xml", item); | |||
}); | |||
} | |||
} |
@@ -43,7 +43,7 @@ public class MapperGenerator { | |||
List<String> orderByList = new ArrayList<>(); | |||
tmpColumnList.stream().filter(i -> { | |||
String tmpColumnName = Fn.toString(i.get("column_name")); | |||
if ("createdatetime".equals(tmpColumnName)) { | |||
if ("createtime".equals(tmpColumnName)) { | |||
orderByList.add("t."+tmpColumnName + " desc"); | |||
return true; | |||
} | |||
@@ -8,6 +8,223 @@ ${table_name}(${table_comment}) | |||
--> | |||
<mapper namespace="com.qmrz.domain.mapper.${table_name2}Mapper"> | |||
<select id="getList" resultType="java.util.LinkedHashMap"> | |||
select <#list columnList as item>t.${item.column_name}<#if item_has_next>,</#if></#list> | |||
,zp2.name gldwname,zp3.name gldw2name,za.name xzqhname | |||
,IFNULL(th.status,0) status | |||
<!-- 已分派 --> | |||
<if test='where_status=="1"'> | |||
,th.fppoliceid,fpP1.fullname fppolicename | |||
,th.jspoliceid,jsP1.fullname jspolicename | |||
,th.fptime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
</if> | |||
<!-- 2撤回 3退回 --> | |||
<if test='where_status.contains("2") || where_status.contains("3")'> | |||
,th.currpoliceid chthpoliceid,p.fullname chthpolicename | |||
,th.operationtime chthtime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.remarks | |||
</if> | |||
<!-- 已反馈 --> | |||
<if test='where_status=="4"'> | |||
,th.currpoliceid fkpoliceid,p.fullname fkpolicename | |||
,th.operationtime fktime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.memo,th.remarks, th.gldw fkgldw, fkzp2.name fkgldwname | |||
</if> | |||
<!-- 无需处理 --> | |||
<if test='where_status=="5"'> | |||
,th.currpoliceid wxclpoliceid,p.fullname wxclpolicename | |||
,th.operationtime wxcltime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.remarks | |||
</if> | |||
from ${table_name} t | |||
left join zonepubinfo zp2 on zp2.pubcode = t.gldw <!-- 第4级 管辖单位(派出所代码) --> | |||
left join zonepubinfo zp3 on zp3.pubcode = t.gldw2 <!-- 第5级 管辖单位(警务区代码) --> | |||
left join zoneadmin za on za.id = t.xzqh <!-- 行政区划 --> | |||
left join ${table_name}relation th on t.${primaryKeyName}=th.lnid | |||
left join police p on p.id=th.currpoliceid <!-- 最近一次操作时的人员ID(分派时为接收人) --> | |||
<!-- 已分派 --> | |||
<if test='where_status=="1"'> | |||
left join police fpP1 on fpP1.id=th.fppoliceid | |||
left join police jsP1 on jsP1.id=th.jspoliceid | |||
</if> | |||
<!-- 已反馈 --> | |||
<if test='where_status=="4"'> | |||
left join zonepubinfo fkzp2 on fkzp2.pubcode = th.gldw and th.memo=4 | |||
</if> | |||
<where> | |||
<include refid="common_where" /> | |||
<!--类型区别 最新: 0 未分派 1已分派 2 撤回 3 退回 4 已反馈 5无需处理--> | |||
<choose> | |||
<when test='where_status=="0"'> | |||
<!-- and th.status is null --> | |||
and ifnull(th.status,0) = 0 | |||
</when> | |||
<otherwise> | |||
and th.status in ( ${'$'}{where_status} ) | |||
</otherwise> | |||
</choose> | |||
<!--app模糊搜索 --> | |||
<if test="_parameter.containsKey('like_appkeyword')"> | |||
<!-- TODO 需处理 | |||
and CONCAT(t.ownername,'|',t.ownerphone,'|',t.houseaddr) like concat('%', ${'#'}{like_appkeyword} ,'%') | |||
--> | |||
</if> | |||
<!--查询当日 或 历史--> | |||
<if test="_parameter.containsKey('where_historytype')"> | |||
<!--当日--> | |||
<if test=" where_historytype == 1 "> | |||
and DATEDIFF(th.operationtime,now())=0 | |||
</if> | |||
<!--历史--> | |||
<if test=" where_historytype == 2 "> | |||
<![CDATA[ and DATEDIFF(th.operationtime,now())<0 ]]> | |||
</if> | |||
</if> | |||
<!--分派时间查询--> | |||
<if test="_parameter.containsKey('where_fpbegintime')"> | |||
<![CDATA[ and th.operationtime >= ${'#'}{where_fpbegintime} ]]> | |||
</if> | |||
<if test="_parameter.containsKey('where_fpendtime')"> | |||
<![CDATA[ and th.operationtime < ${'#'}{where_fpendtime} ]]> | |||
</if> | |||
<!--撤回退回时间查询--> | |||
<if test="_parameter.containsKey('where_chthbegintime')"> | |||
<![CDATA[ and th.operationtime >= ${'#'}{where_chthbegintime} ]]> | |||
</if> | |||
<if test="_parameter.containsKey('where_chthendtime')"> | |||
<![CDATA[ and th.operationtime < ${'#'}{where_chthendtime} ]]> | |||
</if> | |||
<!--反馈时间查询--> | |||
<if test="_parameter.containsKey('where_fkbegintime')"> | |||
<![CDATA[ and th.operationtime >= ${'#'}{where_fkbegintime} ]]> | |||
</if> | |||
<if test="_parameter.containsKey('where_fkendtime')"> | |||
<![CDATA[ and th.operationtime < ${'#'}{where_fkendtime} ]]> | |||
</if> | |||
<!--无需处理时间查询--> | |||
<if test="_parameter.containsKey('where_wxclbegintime')"> | |||
<![CDATA[ and th.operationtime >= ${'#'}{where_wxclbegintime} ]]> | |||
</if> | |||
<if test="_parameter.containsKey('where_wxclendtime')"> | |||
<![CDATA[ and th.operationtime < ${'#'}{where_wxclendtime} ]]> | |||
</if> | |||
<!--接受人 status=1 已分派 | 撤回人退回人 status in (2,3)撤回退回 | 反馈人 status=4 已反馈 5无需处理--> | |||
<if test='where_status=="1"'> | |||
<if test="_parameter.containsKey('like_fppolicename')"> | |||
and fpP1.fullname like concat('%',${'#'}{like_fppolicename},'%') | |||
</if> | |||
</if> | |||
<choose> | |||
<!-- 接收人 --> | |||
<when test="_parameter.containsKey('like_jspolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_jspolicename},'%') | |||
</when> | |||
<!-- 撤回人 --> | |||
<when test="_parameter.containsKey('like_chpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_chpolicename},'%') | |||
</when> | |||
<!-- 退回人 --> | |||
<when test="_parameter.containsKey('like_thpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_thpolicename},'%') | |||
</when> | |||
<!-- 撤回/退回人 --> | |||
<when test="_parameter.containsKey('like_chthpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_chthpolicename},'%') | |||
</when> | |||
<!-- 反馈人 --> | |||
<when test="_parameter.containsKey('like_fkpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_fkpolicename},'%') | |||
</when> | |||
<!-- 无需处理人 --> | |||
<when test="_parameter.containsKey('like_wxclpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_wxclpolicename},'%') | |||
</when> | |||
</choose> | |||
<if test="_parameter.containsKey('where_fppoliceid')"> | |||
and th.fppoliceid = ${'#'}{where_fppoliceid} | |||
</if> | |||
<choose> | |||
<when test="_parameter.containsKey('where_jspoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_jspoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_chpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_chpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_thpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_thpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_chthpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_chthpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_fkpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_fkpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_wxclpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_wxclpoliceid} | |||
</when> | |||
</choose> | |||
<!--反馈结果--> | |||
<if test="_parameter.containsKey('where_memo')"> | |||
and th.memo = ${'#'}{where_memo} | |||
</if> | |||
<!--过滤出选中--> | |||
<if test="_parameter.containsKey('where_idlist')"> | |||
and t.${primaryKeyName} in ( | |||
<foreach item="item" index="index" collection="where_idlist" separator="," > | |||
${'#'}{item} | |||
</foreach> | |||
) | |||
</if> | |||
<!-- 系统数据权限条件 登入信息过滤 不能加前缀 where_ --> | |||
<if test="_parameter.containsKey('policeid')"> | |||
and th.currpoliceid= ${'#'}{policeid} | |||
</if> | |||
<if test="_parameter.containsKey('gldw2List')"> | |||
and t.gldw2 in ( | |||
<foreach item="item" index="index" collection="gldw2List" separator=","> | |||
${'#'}{item} | |||
</foreach> | |||
) | |||
</if> | |||
</where> | |||
<if test='where_status == "0"'> | |||
${orderBy} | |||
</if> | |||
<if test='where_status != "0"'> | |||
order by th.operationtime desc , t.${primaryKeyName} desc | |||
</if> | |||
</select> | |||
<!-- ========================= 分隔线以下为生成的通用代码 ========================= --> | |||
<!-- | |||
@@ -8,196 +8,18 @@ ${table_name}(${table_comment}) | |||
--> | |||
<mapper namespace="com.qmrz.domain.mapper.${table_name2}Mapper"> | |||
<select id="getList" resultType="java.util.LinkedHashMap"> | |||
select <#list columnList as item>t.${item.column_name}<#if item_has_next>,</#if></#list> | |||
,zp2.name gldwname,zp3.name gldw2name,za.name xzqhname | |||
,IFNULL(th.status,0) status | |||
<!-- 已分派 --> | |||
<if test='where_status=="1"'> | |||
,th.fppoliceid,fpP1.fullname fppolicename | |||
,th.jspoliceid,jsP1.fullname jspolicename | |||
,th.fptime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
</if> | |||
<!-- 2撤回 3退回 --> | |||
<if test='where_status.contains("2") || where_status.contains("3")'> | |||
,th.currpoliceid chthpoliceid,p.fullname chthpolicename | |||
,th.operationtime chthtime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.remarks | |||
</if> | |||
<!-- 已反馈 --> | |||
<if test='where_status=="4"'> | |||
,th.currpoliceid fkpoliceid,p.fullname fkpolicename | |||
,th.operationtime fktime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.memo,th.remarks, th.gldw fkgldw, fkzp2.name fkgldwname | |||
</if> | |||
<!-- 无需处理 --> | |||
<if test='where_status=="5"'> | |||
,th.currpoliceid wxclpoliceid,p.fullname wxclpolicename | |||
,th.operationtime wxcltime | |||
,if(th.chpoliceid,1,0) chstatus, if(th.thpoliceid,1,0) thstatus | |||
,th.remarks | |||
</if> | |||
<!-- 主要用于反馈、退回、撤回操作时,前提数据状态是已分派状态 --> | |||
<select id="selectListForIdList" resultType="java.util.HashMap" parameterType="java.util.Map"> | |||
select t.lnid ,t.status ,t.currpoliceid, p.roletype | |||
from ${table_name} t | |||
left join zonepubinfo zp2 on zp2.pubcode = t.gldw <!-- 第4级 管辖单位(派出所代码) --> | |||
left join zonepubinfo zp3 on zp3.pubcode = t.gldw2 <!-- 第5级 管辖单位(警务区代码) --> | |||
left join zoneadmin za on za.id = t.xzqh <!-- 行政区划 --> | |||
left join ${table_name}relation th on t.${primaryKeyName}=th.lnid | |||
left join police p on p.id=th.currpoliceid <!-- 最近一次操作时的人员ID(分派时为接收人) --> | |||
<!-- 已分派 --> | |||
<if test='where_status=="1"'> | |||
left join police fpP1 on fpP1.id=th.fppoliceid | |||
left join police jsP1 on jsP1.id=th.jspoliceid | |||
</if> | |||
<!-- 已反馈 --> | |||
<if test='where_status=="4"'> | |||
left join zonepubinfo fkzp2 on fkzp2.pubcode = th.gldw and th.memo=4 | |||
</if> | |||
left join police p on p.id=t.currpoliceid | |||
<where> | |||
<include refid="common_where" /> | |||
<!--类型区别 最新: 0 未分派 1已分派 2 撤回 3 退回 4 已反馈 5无需处理--> | |||
<choose> | |||
<when test='where_status=="0"'> | |||
<!-- and th.status is null --> | |||
and ifnull(th.status,0) = 0 | |||
</when> | |||
<otherwise> | |||
and th.status in ( ${'$'}{where_status} ) | |||
</otherwise> | |||
</choose> | |||
<!--app模糊搜索 --> | |||
<if test="_parameter.containsKey('like_appkeyword')"> | |||
<!-- TODO 需处理 | |||
and CONCAT(t.ownername,'|',t.ownerphone,'|',t.houseaddr) like concat('%', ${'#'}{like_appkeyword} ,'%') | |||
--> | |||
</if> | |||
<!--查询当日 或 历史--> | |||
<if test="_parameter.containsKey('where_historytype')"> | |||
<!--当日--> | |||
<if test=" where_historytype == 1 "> | |||
and DATEDIFF(th.operationtime,now())=0 | |||
</if> | |||
<!--历史--> | |||
<if test=" where_historytype == 2 "> | |||
<![CDATA[ and DATEDIFF(th.operationtime,now())<0 ]]> | |||
</if> | |||
</if> | |||
<!--反馈时间查询--> | |||
<if test="_parameter.containsKey('where_fkbegintime')"> | |||
<![CDATA[ and th.operationtime >= ${'#'}{where_fkbegintime} ]]> | |||
</if> | |||
<if test="_parameter.containsKey('where_fkendtime')"> | |||
<![CDATA[ and th.operationtime < ${'#'}{where_fkendtime} ]]> | |||
</if> | |||
<!--接受人 status=1 已分派 | 撤回人退回人 status in (2,3)撤回退回 | 反馈人 status=4 已反馈 5无需处理--> | |||
<if test='where_status=="1"'> | |||
<if test="_parameter.containsKey('like_fppolicename')"> | |||
and fpP1.fullname like concat('%',${'#'}{like_fppolicename},'%') | |||
</if> | |||
</if> | |||
<choose> | |||
<!-- 接收人 --> | |||
<when test="_parameter.containsKey('like_jspolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_jspolicename},'%') | |||
</when> | |||
<!-- 撤回人 --> | |||
<when test="_parameter.containsKey('like_chpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_chpolicename},'%') | |||
</when> | |||
<!-- 退回人 --> | |||
<when test="_parameter.containsKey('like_thpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_thpolicename},'%') | |||
</when> | |||
<!-- 撤回/退回人 --> | |||
<when test="_parameter.containsKey('like_chthpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_chthpolicename},'%') | |||
</when> | |||
<!-- 反馈人 --> | |||
<when test="_parameter.containsKey('like_fkpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_fkpolicename},'%') | |||
</when> | |||
<!-- 无需处理人 --> | |||
<when test="_parameter.containsKey('like_wxclpolicename')"> | |||
and p.fullname like concat('%',${'#'}{like_wxclpolicename},'%') | |||
</when> | |||
</choose> | |||
<if test="_parameter.containsKey('where_fppoliceid')"> | |||
and th.fppoliceid = ${'#'}{where_fppoliceid} | |||
</if> | |||
<choose> | |||
<when test="_parameter.containsKey('where_jspoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_jspoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_chpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_chpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_thpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_thpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_chthpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_chthpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_fkpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_fkpoliceid} | |||
</when> | |||
<when test="_parameter.containsKey('where_wxclpoliceid')"> | |||
and th.currpoliceid = ${'#'}{where_wxclpoliceid} | |||
</when> | |||
</choose> | |||
<!--反馈结果--> | |||
<if test="_parameter.containsKey('where_memo')"> | |||
and th.memo = ${'#'}{where_memo} | |||
</if> | |||
<!--过滤出选中--> | |||
<if test="_parameter.containsKey('where_idlist')"> | |||
and t.${primaryKeyName} in ( | |||
<foreach item="item" index="index" collection="where_idlist" separator="," > | |||
${'#'}{item} | |||
</foreach> | |||
) | |||
</if> | |||
<!-- 系统数据权限条件 登入信息过滤 不能加前缀 where_ --> | |||
<if test="_parameter.containsKey('policeid')"> | |||
and th.currpoliceid= ${'#'}{policeid} | |||
</if> | |||
<if test="_parameter.containsKey('gldw2List')"> | |||
and t.gldw2 in ( | |||
<foreach item="item" index="index" collection="gldw2List" separator=","> | |||
${'#'}{item} | |||
</foreach> | |||
) | |||
</if> | |||
and t.lnid in ( | |||
<foreach item="item" index="index" collection="where_idlist" separator="," > | |||
${'#'}{item} | |||
</foreach> | |||
) | |||
</where> | |||
<if test='where_status == "0"'> | |||
${orderBy} | |||
</if> | |||
<if test='where_status != "0"'> | |||
order by th.operationtime desc , t.${primaryKeyName} desc | |||
</if> | |||
</select> | |||
<!-- ========================= 分隔线以下为生成的通用代码 ========================= --> | |||
@@ -11,8 +11,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |||
@SpringBootTest(classes = CodeGenerator.class) | |||
public class TestCodeGenerator { | |||
// private String dbname="ga-dp-dev"; | |||
//private String dbname="qmrz"; | |||
private String dbname="ga-lock-dev"; | |||
private String dbname="qmrz"; | |||
// private String dbname="ga-lock-dev"; | |||
// private String dbname="psbd-dev"; | |||
// private String dbname="ga-hotelmanage-dev"; | |||
/** | |||
@@ -23,6 +23,8 @@ public class TestCodeGenerator { | |||
readme(); | |||
mapper(); | |||
mapperSync(); | |||
mapperFP(); | |||
mapperFPR(); | |||
javaSync(); | |||
// service(); | |||
service2(); | |||
@@ -64,6 +66,18 @@ public class TestCodeGenerator { | |||
generator.generator(); | |||
} | |||
@Test | |||
public void mapperFP() { | |||
MapperFPGenerator generator = new MapperFPGenerator(dbname); | |||
generator.generator(); | |||
} | |||
@Test | |||
public void mapperFPR() { | |||
MapperFPRGenerator generator = new MapperFPRGenerator(dbname); | |||
generator.generator(); | |||
} | |||
@Test | |||
public void javaSync() { | |||
JavaSyncGenerator generator = new JavaSyncGenerator(dbname); | |||