| @@ -1,7 +1,8 @@ | |||
| package com.iformall.domain.vo; | |||
| import javax.persistence.Id; | |||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |||
| import javax.persistence.Id; | |||
| public class WxMerchantVo { | |||
| private static final long serialVersionUID = 6687964942922444531L; | |||
| @@ -28,7 +29,12 @@ public class WxMerchantVo { | |||
| /**商户状态**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="商户状态1可用0停用",name="status") | |||
| private Integer merchantStatus; | |||
| /**商户业态**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="商户业态",name="businessId") | |||
| private Integer businessId; | |||
| /**商户业态**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="商户业态",name="parameter") | |||
| private String parameter; | |||
| /**地址**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="地址",name="addr") | |||
| @@ -85,13 +91,21 @@ public class WxMerchantVo { | |||
| addr = _addr; | |||
| } | |||
| public Integer getBusinessId() { | |||
| return businessId; | |||
| } | |||
| public String getMerChantImgUrl() { | |||
| public void setBusinessId(Integer businessId) { | |||
| this.businessId = businessId; | |||
| } | |||
| public String getMerchantImgUrl() { | |||
| return merchantImgUrl; | |||
| } | |||
| public void setMerChantImgUrl(String _imgUrl) { | |||
| public void setMerchantImgUrl(String _imgUrl) { | |||
| merchantImgUrl = _imgUrl; | |||
| } | |||
| public String getMerchantName() { | |||
| return merchantName; | |||
| } | |||
| @@ -111,6 +125,15 @@ public class WxMerchantVo { | |||
| this.merchantStatus = status; | |||
| } | |||
| public String getParameter() { | |||
| return parameter; | |||
| } | |||
| public void setParameter(String parameter) { | |||
| this.parameter = parameter; | |||
| } | |||
| public Integer getVipDiscountRate1() { | |||
| return vipDiscountRate1; | |||
| } | |||
| @@ -134,4 +157,6 @@ public class WxMerchantVo { | |||
| public void setVipDiscountRate3(Integer vipDiscountRate3) { | |||
| this.vipDiscountRate3 = vipDiscountRate3; | |||
| } | |||
| } | |||
| @@ -13,4 +13,5 @@ public interface WxCouponMerchantMapper extends CommonMapper<WxCouponMerchant, L | |||
| List<WxCouponMerchant> findList(WxCouponMerchant wxCouponMerchant); | |||
| List<WxMerchantVo> findMerchantVoList(Map paramMap); | |||
| List<WxMerchantVo> findMerchantNameList(Map paramMap); | |||
| List<WxMerchantVo> findMerchantBaseList(Map paramMap); | |||
| } | |||
| @@ -67,6 +67,18 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| return wxCouponMapper.findVoDetail(id); | |||
| } | |||
| private Long parseMerchantId(JSONObject merchantParam){ | |||
| return Long.valueOf(merchantParam.getString("id")); | |||
| } | |||
| private String parseParameter(JSONObject merchantParam){ | |||
| return merchantParam.getString("parameter"); | |||
| } | |||
| private Integer parseBusiness(JSONObject merchantParam){ | |||
| return Integer.valueOf(merchantParam.getString("businessId")); | |||
| } | |||
| @Override | |||
| @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public ResultData saveOrUpdate(WxCoupon record) { | |||
| @@ -93,34 +105,34 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| if (record.getId() == null) { | |||
| record.setId(idWorker.nextId()); | |||
| if (!record.getMerchantParams().isEmpty()) | |||
| { | |||
| List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); | |||
| List<WxCouponMerchant> couponMerchantList = new ArrayList<>(); | |||
| List<Integer> businessList= new ArrayList<>(); | |||
| merchantParamList.forEach(merchantParam -> { | |||
| WxCouponMerchant cm = new WxCouponMerchant(); | |||
| cm.setId(idWorker.nextId()); | |||
| cm.setMerchantId(merchantParam.getLong("id")); | |||
| cm.setParameter(merchantParam.getString("param")); | |||
| cm.setMerchantId(parseMerchantId(merchantParam)); | |||
| cm.setParameter(parseParameter(merchantParam)); | |||
| cm.setProductId(record.getId()); | |||
| cm.setCreateDate(new Date()); | |||
| cm.setUpdateDate(new Date()); | |||
| cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| couponMerchantList.add(cm); | |||
| businessList.add(merchantParam.getInteger("business")); | |||
| businessList.add(parseBusiness(merchantParam)); | |||
| wxCouponMerchantMapper.insertSelective(cm); | |||
| }); | |||
| if (businessList.stream().distinct().count() > 1) { | |||
| record.setBusiness(EnumBusiness.BUSINESS_NULL.getCode()); | |||
| } else { | |||
| record.setBusiness(businessList.get(0)); | |||
| } | |||
| wxCouponMerchantMapper.insertList(couponMerchantList); | |||
| } else{ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| record.setId(idWorker.nextId()); | |||
| record.setCreateDate(new Date()); | |||
| record.setUpdateDate(new Date()); | |||
| wxCouponMapper.insertSelective(record); | |||
| @@ -135,27 +147,27 @@ public class WxCouponServiceImpl implements WxCouponService { | |||
| List<Integer> businessList= new ArrayList<>(); | |||
| merchantParamList.stream().forEach(merchantParam -> { | |||
| WxCouponMerchant cm = new WxCouponMerchant(); | |||
| cm.setMerchantId(merchantParam.getLong("id")); | |||
| cm.setMerchantId(parseMerchantId(merchantParam)); | |||
| cm.setProductId(record.getId()); | |||
| WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(cm); | |||
| if (rcm != null) { | |||
| rcm.setMerchantId(merchantParam.getLong("id")); | |||
| rcm.setParameter(merchantParam.getString("param")); | |||
| rcm.setMerchantId(Long.valueOf(parseMerchantId(merchantParam))); | |||
| rcm.setParameter(parseParameter(merchantParam)); | |||
| rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| rcm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.updateByPrimaryKeySelective(rcm); | |||
| }else { | |||
| cm.setId(idWorker.nextId()); | |||
| cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||
| cm.setParameter(merchantParam.getString("param")); | |||
| cm.setParameter(parseParameter(merchantParam)); | |||
| cm.setCreateDate(new Date()); | |||
| cm.setUpdateDate(new Date()); | |||
| wxCouponMerchantMapper.insertSelective(cm); | |||
| } | |||
| businessList.add(merchantParam.getInteger("business")); | |||
| businessList.add(Integer.valueOf(parseBusiness(merchantParam))); | |||
| oldList.removeIf( | |||
| old->old.getProductId().equals(record.getId()) && | |||
| old.getMerchantId().equals(merchantParam.getLong("id"))); | |||
| old.getMerchantId().equals(Long.valueOf(parseMerchantId(merchantParam)))); | |||
| }); | |||
| oldList.stream().forEach(old->{ | |||
| @@ -131,7 +131,7 @@ | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantNameList" > | |||
| </collection> | |||
| </resultMap> | |||
| @@ -181,7 +181,7 @@ | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" > | |||
| </collection> | |||
| </resultMap> | |||
| @@ -80,8 +80,8 @@ | |||
| </if> | |||
| <if test=" null != validStartDate "> | |||
| and `valid_start_date` = #{validStartDate} | |||
| </if> | |||
| and `valid_start_date` = #{validStartDate} | |||
| </if> | |||
| <if test=" null != validEndDate "> | |||
| and `valid_end_date` = #{validEndDate} | |||
| @@ -175,8 +175,8 @@ | |||
| <collection column="{productId=id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" > | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantBaseList" > | |||
| </collection> | |||
| </resultMap> | |||
| @@ -64,9 +64,10 @@ | |||
| <sql id="allMerchantVoColumns"> | |||
| m.id, | |||
| m.img_url,m.name,m.link_phone,m.status, | |||
| m.img_url,m.name,m.link_phone,m.status,m.business_id, | |||
| s.addr,s.shop_number,s.baidu_poi, | |||
| mb.building_name,mf.floor_name | |||
| mb.building_name,mf.floor_name, | |||
| cm.parameter | |||
| </sql> | |||
| <resultMap id="MerchantVoResultMap" type="com.iformall.domain.vo.WxMerchantVo"> | |||
| @@ -75,6 +76,8 @@ | |||
| <result column="name" jdbcType="VARCHAR" property="merchantName"/> | |||
| <result column="link_phone" jdbcType="VARCHAR" property="merchantLinkPhone"/> | |||
| <result column="status" jdbcType="VARCHAR" property="merchantStatus"/> | |||
| <result column="business_id" jdbcType="INTEGER" property="businessId"/> | |||
| <result column="parameter" jdbcType="VARCHAR" property="parameter"/> | |||
| <result column="addr" jdbcType="VARCHAR" property="addr"/> | |||
| <result column="shop_number" jdbcType="VARCHAR" property="shopNumber"/> | |||
| @@ -95,11 +98,16 @@ | |||
| where cm.product_id = #{productId} | |||
| </select> | |||
| <sql id="allMerchantNameColumns"> | |||
| m.id,m.name,m.status | |||
| </sql> | |||
| <sql id="allMerchantBaseColumns"> | |||
| m.id, | |||
| m.img_url,m.name,m.link_phone,m.status,m.business_id, | |||
| cm.parameter | |||
| </sql> | |||
| <select id="findMerchantNameList" parameterType="java.util.Map" resultMap="MerchantVoResultMap"> | |||
| select | |||
| <include refid="allMerchantNameColumns"/> | |||
| @@ -108,4 +116,13 @@ | |||
| where cm.product_id = #{productId} | |||
| </select> | |||
| <select id="findMerchantBaseList" parameterType="java.util.Map" resultMap="MerchantVoResultMap"> | |||
| select | |||
| <include refid="allMerchantBaseColumns"/> | |||
| from wx_coupon_merchant cm | |||
| left join wx_merchant m on m.id = cm.merchant_id | |||
| where cm.product_id = #{productId} | |||
| </select> | |||
| </mapper> | |||
| @@ -315,7 +315,7 @@ | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantNameList" > | |||
| </collection> | |||
| </resultMap> | |||
| @@ -528,7 +528,7 @@ | |||
| <collection column="{productId=coupon_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" > | |||
| </collection> | |||
| </resultMap> | |||
| @@ -173,7 +173,7 @@ | |||
| <collection column="{productId=product_id}" property="merchantVoList" | |||
| ofType="com.iformall.domain.vo.WxMerchantVo" | |||
| javaType="java.util.ArrayList" | |||
| javaType="java.util.List" | |||
| select="com.iformall.mapper.WxCouponMerchantMapper.findMerchantVoList" > | |||
| </collection> | |||
| </resultMap> | |||