| @@ -55,6 +55,9 @@ public class WxMerchantController extends BaseController { | |||
| @Autowired | |||
| private WxProfitPaymentReceiverService wxProfitPaymentReceiverService; | |||
| @Autowired | |||
| private WxMerchantRelationService wxMerchantRelationService; | |||
| @UserDataRuleAnnotation("merchant_list") | |||
| @ApiOperation("分页列表接口") | |||
| @@ -96,6 +99,44 @@ public class WxMerchantController extends BaseController { | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("区域商户和普通商户关系新增或更新") | |||
| @PostMapping("saveOrUpdate") | |||
| @SystemControllerLog(description = "区域商户和普通商户关系新增或更新") | |||
| public ResultData saveOrUpdate(@RequestBody WxMerchantRelation wxMerchantRelation) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::saveOrUpdate"); | |||
| if (null == wxMerchantRelation) wxMerchantRelation = new WxMerchantRelation(); | |||
| wxMerchantRelation.updateTenantInfo(getTenantInfo()); | |||
| return wxMerchantRelationService.saveOrUpdate(wxMerchantRelation.getRegionMerchantId(),wxMerchantRelation.getMerchantIds(),wxMerchantRelation.getType(),wxMerchantRelation.getTenantId()); | |||
| } | |||
| @ApiOperation("区域商户删除普通商户") | |||
| @GetMapping("/delByRegionId") | |||
| @ApiImplicitParam(name = "merchantId", value = "merchantId", dataType = "Long", paramType = "query", required = true) | |||
| @SystemControllerLog(description = "区域用户删除普通用户") | |||
| public ResultData delByRegionId(Long merchantId) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::delByRegionId"); | |||
| wxMerchantRelationService.deleteByMerchantId(merchantId); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @ApiOperation("区域商户和子商户列表") | |||
| @GetMapping("/relationList") | |||
| @ApiImplicitParam(name = "regionId", value = "regionId", dataType = "Long", paramType = "query", required = true) | |||
| @SystemControllerLog(description = "区域用户删除普通用户") | |||
| public ResultData relationList(Long regionId) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::relationList"); | |||
| List<WxMerchant> merchants = wxMerchantService.relationList(regionId); | |||
| return new ResultData(merchants); | |||
| } | |||
| @ApiOperation("子商户列表查询") | |||
| @GetMapping("/subMerchantList") | |||
| @SystemControllerLog(description = "子商户列表查询") | |||
| public ResultData subMerchantList() { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::subMerchantList"); | |||
| List<WxMerchant> merchants = wxMerchantService.subMerchantList(); | |||
| return new ResultData(merchants); | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @@ -0,0 +1,12 @@ | |||
| CREATE TABLE `wx_merchant_relation` | |||
| ( | |||
| `id` bigint(20) NOT NULL COMMENT '主键ID', | |||
| `tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', | |||
| `parent_tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID', | |||
| `region_merchant_id` bigint(20) NOT NULL COMMENT '区域商户id', | |||
| `merchant_id` bigint(20) NOT NULL COMMENT '普通商户id', | |||
| `is_del` smallint(1) DEFAULT '0' COMMENT '是否删除1是0否', | |||
| `create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | |||
| `update_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', | |||
| PRIMARY KEY (`id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='普通商户与区域商户关系表'; | |||
| @@ -0,0 +1,71 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| /** | |||
| * 普通商户与区域商户关系表 | |||
| * | |||
| * @author LRH | |||
| */ | |||
| @Data | |||
| @TableName("wx_merchant_relation") | |||
| @ToString(callSuper = true) | |||
| public class WxMerchantRelation extends TenantEntity { | |||
| /** | |||
| * 主键ID | |||
| */ | |||
| private Long id; | |||
| /** | |||
| * 租户ID | |||
| */ | |||
| private String tenantId; | |||
| /** | |||
| * 父租户ID | |||
| */ | |||
| private String parentTenantId; | |||
| /** | |||
| * 区域商户id | |||
| */ | |||
| private Long regionMerchantId; | |||
| /** | |||
| * 普通商户id | |||
| */ | |||
| private Long merchantId; | |||
| @TableField(exist = false) | |||
| private List<Long> merchantIds; | |||
| /** | |||
| * 是否删除1是0否 | |||
| */ | |||
| private Integer isDel; | |||
| /** | |||
| * 创建时间 | |||
| */ | |||
| private Date createDate; | |||
| /** | |||
| * 更新时间 | |||
| */ | |||
| private Date updateDate; | |||
| /** | |||
| * 新增还是修改 1-新增 2-修改 | |||
| */ | |||
| @TableField(exist = false) | |||
| private Integer type; | |||
| } | |||
| @@ -8,7 +8,9 @@ public enum EnumMerchantAdmin { | |||
| PUBLIC_COMMON(0, "普通商户"), | |||
| PUBLIC_ADMIN(1, "商管商户"), | |||
| PRIVATE_SYSTEM(2, "系统抽成商户"), | |||
| PRIVATE_SELL(3, "销售抽成商户"),; | |||
| PRIVATE_SELL(3, "销售抽成商户"), | |||
| REGIONAL(4, "区域商户"), | |||
| ; | |||
| public static EnumMerchantAdmin getEnum(Integer code) { | |||
| for (EnumMerchantAdmin value : values()) { | |||
| @@ -59,4 +59,7 @@ public interface WxMerchantMapper extends CommonMapper<WxMerchant, Long> { | |||
| int deleteByUpdate(Long id); | |||
| List<WxMerchant> getMerchantListByIds(@Param("relationIds") List<Long> relationIds); | |||
| List<WxMerchant> getSubMerchantListByIds(@Param("merchantIds") List<Long> merchantIds); | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxMerchantRelation; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import java.util.List; | |||
| public interface WxMerchantRelationMapper extends CommonMapper<WxMerchantRelation, Long> { | |||
| Integer selectByIds(@Param("ids") List<Long> ids); | |||
| void updateByReginId(@Param("regionId") Long regionId); | |||
| void insertBatch(List<WxMerchantRelation> list); | |||
| List<WxMerchantRelation> selectByReginId(@Param("regionId") Long regionId, @Param("ids") List<Long> ids); | |||
| void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds); | |||
| void deleteByMerchantId(@Param("merchantId") Long merchantId); | |||
| List<Long> getRelationByRegionId(@Param("regionId") Long regionId); | |||
| List<WxMerchantRelation> getInfByIds(@Param("ids") List<Long> ids); | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| package com.iformall.service; | |||
| import com.iformall.common.ResultData; | |||
| import java.util.List; | |||
| public interface WxMerchantRelationService { | |||
| ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, String tenantId); | |||
| void deleteByMerchantId(Long id); | |||
| List<Long> getRelationByRegionId(Long regionId); | |||
| } | |||
| @@ -3,19 +3,15 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.WxMerchantDto; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxMerchantCorp; | |||
| import com.iformall.domain.po.WxPark; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.domain.vo.WxMerchantSimpleVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeDetailVo; | |||
| import com.iformall.domain.vo.WxMerchantTradeVo; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -219,4 +215,9 @@ public interface WxMerchantService { | |||
| Map<Long, WxMerchant> findMerchantMap(WxMerchant merchantQ); | |||
| WxMerchant findParkMerchant(WxPark wxPark); | |||
| List<WxMerchant> relationList(Long regionId); | |||
| List<WxMerchant> subMerchantList(); | |||
| } | |||
| @@ -0,0 +1,97 @@ | |||
| package com.iformall.service.impl; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMerchantRelation; | |||
| import com.iformall.mapper.WxMerchantRelationMapper; | |||
| import com.iformall.service.WxMerchantRelationService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxMerchantRelationServiceImpl implements WxMerchantRelationService { | |||
| @Autowired | |||
| private WxMerchantRelationMapper wxMerchantRelationMapper; | |||
| @Autowired | |||
| private WxMerchantService wxMerchantService; | |||
| @Transactional(rollbackFor = {Exception.class}) | |||
| @Override | |||
| public ResultData saveOrUpdate(Long regionId, List<Long> ids, Integer type, String tenantId) { | |||
| if (regionId == null) { | |||
| return new ResultData(Result.ERROR, "区域商户id不能为空"); | |||
| } | |||
| //如果没选择普通商户,删除所有关系 | |||
| if (CollectionUtils.isEmpty(ids)) { | |||
| wxMerchantRelationMapper.updateByReginId(regionId); | |||
| return new ResultData(Result.SUCCESS, "编辑成功", null); | |||
| } | |||
| //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 | |||
| List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); | |||
| List<Long> list = new ArrayList<>(); | |||
| if (!CollectionUtils.isEmpty(infByIds)) { | |||
| list = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||
| //判断子商户是否已经被选了 | |||
| Integer integer = wxMerchantRelationMapper.selectByIds(list); | |||
| if (integer > 0) { | |||
| return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); | |||
| } | |||
| } | |||
| List<Long> finalList = list; | |||
| List<Long> collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); | |||
| //1-新增 2-修改 | |||
| if (type == 1) { | |||
| //选择就插入 | |||
| insertInfo(regionId, ids, tenantId); | |||
| return new ResultData(Result.SUCCESS, "新增成功", null); | |||
| } else if (type == 2) { | |||
| wxMerchantRelationMapper.updateByMerchantIds(list); | |||
| if (!CollectionUtils.isEmpty(collected)){ | |||
| insertInfo(regionId, collected, tenantId); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "编辑成功", null); | |||
| } | |||
| return null; | |||
| } | |||
| public void insertInfo(Long regionId, List<Long> ids, String tenantId) { | |||
| List<WxMerchantRelation> list = new ArrayList<>(); | |||
| for (Long id : ids) { | |||
| WxMerchantRelation relation = new WxMerchantRelation(); | |||
| relation.setId(IdWorker.get().nextId()); | |||
| relation.setMerchantId(id); | |||
| relation.setRegionMerchantId(regionId); | |||
| relation.setIsDel(0); | |||
| relation.setTenantId(tenantId); | |||
| list.add(relation); | |||
| } | |||
| wxMerchantRelationMapper.insertBatch(list); | |||
| } | |||
| @Override | |||
| public void deleteByMerchantId(Long merchantId) { | |||
| wxMerchantRelationMapper.deleteByMerchantId(merchantId); | |||
| } | |||
| @Override | |||
| public List<Long> getRelationByRegionId(Long regionId) { | |||
| return wxMerchantRelationMapper.getRelationByRegionId(regionId); | |||
| } | |||
| } | |||
| @@ -23,6 +23,7 @@ import com.iformall.utils.Constant; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.RedisCacheUtils; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -151,6 +152,9 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| @Autowired | |||
| WxBrandMapper wxBrandMapper; | |||
| @Autowired | |||
| WxMerchantRelationService wxMerchantRelationService; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| @@ -2055,4 +2059,26 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| return record; | |||
| } | |||
| /** | |||
| * 该区域商户下有哪些子商户 | |||
| */ | |||
| @Override | |||
| public List<WxMerchant> relationList(Long regionId) { | |||
| List<Long> relationIds = wxMerchantRelationService.getRelationByRegionId(regionId); | |||
| if (CollectionUtils.isEmpty(relationIds)){ | |||
| return null; | |||
| } | |||
| return wxMerchantMapper.getMerchantListByIds(relationIds); | |||
| } | |||
| /** | |||
| * 查询剩余子商户 | |||
| */ | |||
| @Override | |||
| public List<WxMerchant> subMerchantList() { | |||
| //查询已经被选择了的子商户 | |||
| List<Long> merchantIds = wxMerchantRelationService.getRelationByRegionId(null); | |||
| return wxMerchantMapper.getSubMerchantListByIds(merchantIds); | |||
| } | |||
| } | |||
| @@ -450,4 +450,28 @@ | |||
| where id = #{id} | |||
| </update> | |||
| <select id="getMerchantListByIds" resultType="com.iformall.domain.po.WxMerchant"> | |||
| select <include refid="allColumns"/> | |||
| from wx_merchant m | |||
| where m.is_del=0 and m.is_admin=4 | |||
| <if test="relationIds != null and relationIds.size > 0"> | |||
| and m.id in | |||
| <foreach collection="relationIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| <select id="getSubMerchantListByIds" resultType="com.iformall.domain.po.WxMerchant"> | |||
| select <include refid="allColumns"/> | |||
| from wx_merchant m | |||
| where m.is_del=0 and m.is_admin=4 | |||
| <if test="merchantIds != null and merchantIds.size > 0"> | |||
| and m.id NOT IN | |||
| <foreach collection="merchantIds" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| </select> | |||
| </mapper> | |||
| @@ -0,0 +1,93 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxMerchantRelationMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMerchantRelation"> | |||
| <result column="id" property="id"/> | |||
| <result column="tenant_id" property="tenantId"/> | |||
| <result column="parent_tenant_id" property="parentTenantId"/> | |||
| <result column="region_merchant_id" property="regionMerchantId"/> | |||
| <result column="merchant_id" property="merchantId"/> | |||
| <result column="is_del" property="isDel"/> | |||
| <result column="create_date" property="createDate"/> | |||
| <result column="update_date" property="updateDate"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`region_merchant_id`,`is_del`,`create_date`,`update_date` | |||
| </sql> | |||
| <select id="selectByIds" resultType="java.lang.Integer"> | |||
| select | |||
| count(1) | |||
| from wx_merchant_relation | |||
| where is_del = 0 and merchant_id not in | |||
| <foreach collection="ids" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </select> | |||
| <update id="updateByReginId"> | |||
| update wx_merchant_relation | |||
| set is_del = 1, update_date = now() | |||
| where region_merchant_id = #{regionId} | |||
| </update> | |||
| <insert id="insertBatch" parameterType="java.util.List"> | |||
| insert into wx_merchant_relation (id, tenant_id,merchant_id,region_merchant_id ) | |||
| values | |||
| <foreach collection="list" item="item" index="index" separator=","> | |||
| (#{item.id}, | |||
| #{item.tenantId}, | |||
| #{item.merchantId}, | |||
| #{item.regionMerchantId}) | |||
| </foreach> | |||
| </insert> | |||
| <select id="selectByReginId" resultType="com.iformall.domain.po.WxMerchantRelation"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_merchant_relation | |||
| where is_del = 0 and region_merchant_id = #{regionId} and merchant_id in | |||
| <foreach collection="ids" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </select> | |||
| <update id="updateByMerchantIds"> | |||
| update wx_merchant_relation | |||
| set is_del = 0, | |||
| update_date = now() | |||
| where merchant_id in | |||
| <foreach collection="merchantIds" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </update> | |||
| <update id="deleteByMerchantId"> | |||
| update wx_merchant_relation | |||
| set is_del = 1, update_date = now() | |||
| where merchant_id = #{merchantId} | |||
| </update> | |||
| <select id="getRelationByRegionId" resultType="java.lang.Long"> | |||
| select | |||
| merchant_id | |||
| from wx_merchant_relation | |||
| where is_del = 0 | |||
| <if test="regionId != null and regionId != ''"> | |||
| and region_merchant_id = #{regionId} | |||
| </if> | |||
| </select> | |||
| <select id="getInfByIds" resultType="com.iformall.domain.po.WxMerchantRelation"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_merchant_relation | |||
| where merchant_id in | |||
| <foreach collection="ids" index="index" item="id" open="(" separator="," close=")"> | |||
| #{id} | |||
| </foreach> | |||
| </select> | |||
| </mapper> | |||