| @@ -367,7 +367,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||||
| } | } | ||||
| basicInfo.undateFinalTenantId(ifParentUpdateTenantInfo()); | basicInfo.undateFinalTenantId(ifParentUpdateTenantInfo()); | ||||
| wxCUserBasicInfoService.exportData(ifParentUpdateTenantInfo(),basicInfo, request, response); | |||||
| wxCUserBasicInfoService.exportData(getTenantInfo(),basicInfo, request, response); | |||||
| } | } | ||||
| @RequestMapping("/exportTemplate") | @RequestMapping("/exportTemplate") | ||||
| @@ -1,12 +1,23 @@ | |||||
| CREATE DEFINER=`root`@`%` PROCEDURE `user_credit_clear`(IN `cutOffDate` VARCHAR(50),IN `finalTableIndex` VARCHAR(50)) | |||||
| CREATE PROCEDURE `user_credit_clear`(IN `cutOffDate` VARCHAR(50),IN `finalTableIndex` VARCHAR(50)) | |||||
| BEGIN | BEGIN | ||||
| DECLARE done INT DEFAULT 0; | DECLARE done INT DEFAULT 0; | ||||
| DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET done = -1; | DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET done = -1; | ||||
| select concat(finalTableIndex,'_',date_format(now(),'%Y%m%d%H%i')) into @tableSuffix; | select concat(finalTableIndex,'_',date_format(now(),'%Y%m%d%H%i')) into @tableSuffix; | ||||
| set @n = 100000; | |||||
| #START TRANSACTION; | #START TRANSACTION; | ||||
| set @backUpSqlb_0 = concat('create table wx_c_user_basic_info',finalTableIndex,@tableSuffix,' like wx_c_user_basic_info',finalTableIndex,';'); | |||||
| PREPARE back_up_sqlb_0 FROM @backUpSqlb_0; | |||||
| EXECUTE back_up_sqlb_0; | |||||
| DEALLOCATE PREPARE back_up_sqlb_0; | |||||
| set @backUpSqlb_1 = concat('insert into wx_c_user_basic_info',finalTableIndex,@tableSuffix,' select * from wx_c_user_basic_info',finalTableIndex,';'); | |||||
| PREPARE back_up_sqlb_1 FROM @backUpSqlb_1; | |||||
| EXECUTE back_up_sqlb_1; | |||||
| DEALLOCATE PREPARE back_up_sqlb_1; | |||||
| set @backUpSql1_0 = concat('CREATE TABLE `wx_credit_clear_md',@tableSuffix,'` (' | set @backUpSql1_0 = concat('CREATE TABLE `wx_credit_clear_md',@tableSuffix,'` (' | ||||
| ,'`id` bigint(20) NOT NULL,' | ,'`id` bigint(20) NOT NULL,' | ||||
| ,'`user_id` bigint(20) DEFAULT NULL,' | ,'`user_id` bigint(20) DEFAULT NULL,' | ||||
| @@ -20,24 +31,24 @@ BEGIN | |||||
| PREPARE back_up_sql1_0 FROM @backUpSql1_0; | PREPARE back_up_sql1_0 FROM @backUpSql1_0; | ||||
| EXECUTE back_up_sql1_0; | EXECUTE back_up_sql1_0; | ||||
| DEALLOCATE PREPARE back_up_sql1_0; | DEALLOCATE PREPARE back_up_sql1_0; | ||||
| INSERT into zz_process_log VALUES(NOW(),'user_credit_clear()','创建积分清零数据处理备份表',@backUpSql1_0); | INSERT into zz_process_log VALUES(NOW(),'user_credit_clear()','创建积分清零数据处理备份表',@backUpSql1_0); | ||||
| set @backUpSql1_1 = concat('insert into `wx_credit_clear_md',@tableSuffix,'`' | set @backUpSql1_1 = concat('insert into `wx_credit_clear_md',@tableSuffix,'`' | ||||
| ,'(`id`, `user_id`, `final_tenant_id`, `credit`, `sum_credit`, `credit_amount`, `cut_off_date`)' | ,'(`id`, `user_id`, `final_tenant_id`, `credit`, `sum_credit`, `credit_amount`, `cut_off_date`)' | ||||
| ,' select (select unix_timestamp(now()) + CEILING(RAND()*90000+10000)) id,wcubi.id user_id,wcubi.final_tenant_id,wcubi.credit,ifnull(wch.sum_credit,0) sum_credit,(ifnull(wch.sum_credit,0)-wcubi.credit) credit_amount,\'',cutOffDate,'\'' | |||||
| ,' select concat(date_format(now(),\'%Y%m\'),FLOOR(RAND()*1000000),(@n := @n + 1)) id,wcubi.id user_id,wcubi.final_tenant_id,wcubi.credit,ifnull(wch.sum_credit,0) sum_credit,(ifnull(wch.sum_credit,0)-wcubi.credit) credit_amount,\'',cutOffDate,'\'' | |||||
| ,' from wx_c_user_basic_info',finalTableIndex,' wcubi' | ,' from wx_c_user_basic_info',finalTableIndex,' wcubi' | ||||
| ,' left join (select c_user_id,sum(credit_num) sum_credit from wx_credit_history',finalTableIndex,' where credit_num > 0 and create_date >= \'',cutOffDate,'\' group by c_user_id) wch on wch.c_user_id = wcubi.id' | ,' left join (select c_user_id,sum(credit_num) sum_credit from wx_credit_history',finalTableIndex,' where credit_num > 0 and create_date >= \'',cutOffDate,'\' group by c_user_id) wch on wch.c_user_id = wcubi.id' | ||||
| ,' where wcubi.credit > ifnull(wch.sum_credit,0);'); | ,' where wcubi.credit > ifnull(wch.sum_credit,0);'); | ||||
| PREPARE back_up_sql1_1 FROM @backUpSql1_1; | PREPARE back_up_sql1_1 FROM @backUpSql1_1; | ||||
| EXECUTE back_up_sql1_1; | EXECUTE back_up_sql1_1; | ||||
| DEALLOCATE PREPARE back_up_sql1_1; | DEALLOCATE PREPARE back_up_sql1_1; | ||||
| INSERT into zz_process_log VALUES(NOW(),'user_credit_clear()','添加积分清零数据处理',@backUpSql1_1); | INSERT into zz_process_log VALUES(NOW(),'user_credit_clear()','添加积分清零数据处理',@backUpSql1_1); | ||||
| set @backUpSql1_2 = concat('insert into `wx_credit_history',finalTableIndex,'`' | set @backUpSql1_2 = concat('insert into `wx_credit_history',finalTableIndex,'`' | ||||
| ,'(`id`, `tenant_id`, `c_user_id`, `credit_amount`, `credit_num`, `credit_type`, `create_date`, `operator_type`, `operator_id`) ' | |||||
| ,'select id,final_tenant_id,user_id,sum_credit,credit_amount,14,now(),4,0' | |||||
| ,'(`id`, `tenant_id`, `c_user_id`, `credit_amount`, `credit_num`, `credit_type`, `create_date`, `operator_type`, `operator_id`, `change_purpose`) ' | |||||
| ,'select id,final_tenant_id,user_id,sum_credit,credit_amount,14,now(),4,0,\'积分清零计划\'' | |||||
| ,' from `wx_credit_clear_md',@tableSuffix,'`;'); | ,' from `wx_credit_clear_md',@tableSuffix,'`;'); | ||||
| PREPARE back_up_sql1_2 FROM @backUpSql1_2; | PREPARE back_up_sql1_2 FROM @backUpSql1_2; | ||||
| EXECUTE back_up_sql1_2; | EXECUTE back_up_sql1_2; | ||||
| @@ -1,8 +1,8 @@ | |||||
| INSERT INTO `wx_tags_type`(`id`, `name`, `group_id`, `group_name`, `flag`) VALUES (29, '子女', 2, '生活属性', 0); | INSERT INTO `wx_tags_type`(`id`, `name`, `group_id`, `group_name`, `flag`) VALUES (29, '子女', 2, '生活属性', 0); | ||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (166, '婴儿', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (167, '幼儿', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (168, '学龄前', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (169, '学龄初', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (170, '学龄中', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (171, '学龄晚', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (166, '婴儿(0-1岁)', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (167, '幼儿(1-3岁)', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (168, '学龄前(3-6岁)', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (169, '学龄初(6-12岁)', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (170, '学龄中(12-15岁)', 2, '生活属性', 29, '子女'); | |||||
| INSERT INTO `wx_tags`(`id`, `name`, `group_id`, `group_name`, `type_id`, `type_name`) VALUES (171, '学龄晚(15-18岁)', 2, '生活属性', 29, '子女'); | |||||
| @@ -1,12 +1,10 @@ | |||||
| package com.iformall.domain.po.base; | package com.iformall.domain.po.base; | ||||
| import com.baomidou.mybatisplus.annotation.TableField; | import com.baomidou.mybatisplus.annotation.TableField; | ||||
| import lombok.Data; | |||||
| import com.fasterxml.jackson.annotation.JsonIgnore; | |||||
| import lombok.EqualsAndHashCode; | import lombok.EqualsAndHashCode; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| /** | /** | ||||
| * @author Stormeye | * @author Stormeye | ||||
| * @date 2019/4/24 14:32 | * @date 2019/4/24 14:32 | ||||
| @@ -25,9 +23,14 @@ public class TenantEntity extends BaseEntity { | |||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| protected String finalTenantId; | protected String finalTenantId; | ||||
| @JsonIgnore | |||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| protected String shardTableSuffix; | protected String shardTableSuffix; | ||||
| @JsonIgnore | |||||
| @TableField(exist = false) | |||||
| protected String shardFinalTableSuffix; | |||||
| public void updateTenantInfo(TenantEntity info) { | public void updateTenantInfo(TenantEntity info) { | ||||
| setTenantId(info.getTenantId()); | setTenantId(info.getTenantId()); | ||||
| setParentTenantId(null); | setParentTenantId(null); | ||||
| @@ -54,11 +57,18 @@ public class TenantEntity extends BaseEntity { | |||||
| } | } | ||||
| public String getShardTableSuffix() { | public String getShardTableSuffix() { | ||||
| if(StringUtils.isNotBlank(tenantId)){ | |||||
| shardTableSuffix = "_" + Integer.parseInt(this.getTenantId())%100; | |||||
| if(StringUtils.isNotBlank(getTenantId())){ | |||||
| shardTableSuffix = "_" + Integer.parseInt(getTenantId())%100; | |||||
| } | } | ||||
| return shardTableSuffix; | return shardTableSuffix; | ||||
| } | } | ||||
| public String getShardFinalTableSuffix(){ | |||||
| if(StringUtils.isNotBlank(getFinalTenantId())){ | |||||
| shardFinalTableSuffix = "_" + Integer.parseInt(getFinalTenantId())%100; | |||||
| } | |||||
| return shardFinalTableSuffix; | |||||
| } | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| @@ -204,12 +204,12 @@ public enum EnumTag { | |||||
| ID_164(164L, EnumTagType.ID_28, "鞋尺码"), | ID_164(164L, EnumTagType.ID_28, "鞋尺码"), | ||||
| ID_165(165L, EnumTagType.ID_28, "鞋尺码"), | ID_165(165L, EnumTagType.ID_28, "鞋尺码"), | ||||
| ID_166(166L, EnumTagType.ID_29, "婴儿"), | |||||
| ID_167(167L, EnumTagType.ID_29, "幼儿"), | |||||
| ID_168(168L, EnumTagType.ID_29, "学龄前"), | |||||
| ID_169(169L, EnumTagType.ID_29, "学龄初"), | |||||
| ID_170(170L, EnumTagType.ID_29, "学龄中"), | |||||
| ID_171(171L, EnumTagType.ID_29, "学龄晚"), | |||||
| ID_166(166L, EnumTagType.ID_29, "婴儿(0-1岁)"), | |||||
| ID_167(167L, EnumTagType.ID_29, "幼儿(1-3岁)"), | |||||
| ID_168(168L, EnumTagType.ID_29, "学龄前(3-6岁)"), | |||||
| ID_169(169L, EnumTagType.ID_29, "学龄初(6-12岁)"), | |||||
| ID_170(170L, EnumTagType.ID_29, "学龄中(12-15岁)"), | |||||
| ID_171(171L, EnumTagType.ID_29, "学龄晚(15-18岁)"), | |||||
| ID_1000(1000L, EnumTagType.ID_50,"一天以内"), | ID_1000(1000L, EnumTagType.ID_50,"一天以内"), | ||||
| ID_1001(1001L, EnumTagType.ID_50,"一周以内"), | ID_1001(1001L, EnumTagType.ID_50,"一周以内"), | ||||
| @@ -1274,11 +1274,11 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService,IExc | |||||
| List<WxCUserBasicInfoVo> list = new ArrayList<WxCUserBasicInfoVo>(); | List<WxCUserBasicInfoVo> list = new ArrayList<WxCUserBasicInfoVo>(); | ||||
| basicInfo.setBegin((page-1)*10000); | basicInfo.setBegin((page-1)*10000); | ||||
| basicInfo.setLimit(10000); | basicInfo.setLimit(10000); | ||||
| if(StringUtils.isNotBlank(tenantInfo.getParentTenantId())){ | |||||
| //list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | |||||
| }else{ | |||||
| basicInfo.undateFinalTenantId(tenantInfo); | |||||
| } | |||||
| // if(StringUtils.isNotBlank(tenantInfo.getParentTenantId())){ | |||||
| // //list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | |||||
| // }else{ | |||||
| // basicInfo.undateFinalTenantId(tenantInfo); | |||||
| // } | |||||
| list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | list = wxCUserBasicInfoMapper.findVoList1(tenantInfo,basicInfo); | ||||
| if (null == list || list.size() <= 0 ) { | if (null == list || list.size() <= 0 ) { | ||||
| return null; | return null; | ||||
| @@ -822,8 +822,8 @@ | |||||
| <select id="findVoList1" resultMap="VoBaseResultMap"> | <select id="findVoList1" resultMap="VoBaseResultMap"> | ||||
| select | select | ||||
| <include refid="allVoColumns"/> | <include refid="allVoColumns"/> | ||||
| ,(select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit | |||||
| where credit.`tenant_id` = #{tenantInfo.tenantId} | |||||
| ,(select ifnull(sum(credit.credit_num),0) amount from wx_credit_history${tenantEntity.shardFinalTableSuffix} credit | |||||
| where credit.`tenant_id` = #{tenantInfo.finalTenantId} | |||||
| and credit.credit_num > 0 and credit.c_user_id = cu.id | and credit.credit_num > 0 and credit.c_user_id = cu.id | ||||
| <if test=" null != basicInfo.creditStartTime "> | <if test=" null != basicInfo.creditStartTime "> | ||||
| and credit.create_date >= #{basicInfo.creditStartTime} | and credit.create_date >= #{basicInfo.creditStartTime} | ||||
| @@ -831,8 +831,8 @@ | |||||
| <if test=" null != basicInfo.creditEndTime"> | <if test=" null != basicInfo.creditEndTime"> | ||||
| and credit.create_date < #{basicInfo.creditEndTime} | and credit.create_date < #{basicInfo.creditEndTime} | ||||
| </if>) as addCredit, | </if>) as addCredit, | ||||
| (select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit | |||||
| where credit.`tenant_id` = #{tenantInfo.tenantId} | |||||
| (select ifnull(sum(credit.credit_num),0) amount from wx_credit_history${tenantEntity.shardFinalTableSuffix} credit | |||||
| where credit.`tenant_id` = #{tenantInfo.finalTenantId} | |||||
| and credit.credit_num < 0 and credit.c_user_id = cu.id | and credit.credit_num < 0 and credit.c_user_id = cu.id | ||||
| <if test=" null != basicInfo.creditStartTime "> | <if test=" null != basicInfo.creditStartTime "> | ||||
| and credit.create_date >= #{basicInfo.creditStartTime} | and credit.create_date >= #{basicInfo.creditStartTime} | ||||