| @@ -3,6 +3,7 @@ package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxLevelConfig; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.po.WxProfitSharingReceiver; | |||
| import com.iformall.service.WxMerchantService; | |||
| @@ -71,14 +72,7 @@ public class WxMerchantController extends BaseController { | |||
| public ResultData findById(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::findById"); | |||
| WxMerchant wxMerchant = wxMerchantService.getById(id); | |||
| if (wxMerchant != null) { | |||
| WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(wxMerchant); | |||
| if (receiver != null){ | |||
| wxMerchant.setAccountId(receiver.getReceiverAccount()); | |||
| wxMerchant.setAccountName(receiver.getTrueName()); | |||
| wxMerchant.setAccountTypeValue(receiver.getReceiverType()); | |||
| } | |||
| } | |||
| return new ResultData(wxMerchant); | |||
| } | |||
| @@ -139,5 +133,11 @@ public class WxMerchantController extends BaseController { | |||
| return wxMerchantService.updateMerchantTax(wxMerchant); | |||
| } | |||
| @ApiOperation("更新会员等级权益接口") | |||
| @PostMapping("updateMerchantLevel") | |||
| public ResultData updateMerchantLevel(@RequestBody WxMerchant wxMerchant) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantLevel"); | |||
| return wxMerchantService.updateMerchantLevel(wxMerchant); | |||
| } | |||
| } | |||
| @@ -0,0 +1,161 @@ | |||
| package com.iformall.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_level_merchant") | |||
| public class WxLevelMerchant implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /**租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| private String tenantId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="等级ID",name="productId") | |||
| private Long levelId; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") | |||
| private Long merchantId; | |||
| /*创建时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| private Date createDate; | |||
| /*折扣率**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="0-100折扣",name="discount") | |||
| private Integer discount; | |||
| public String getTenantId() { | |||
| return tenantId; | |||
| } | |||
| public void setTenantId(String tenantId) { | |||
| this.tenantId = tenantId; | |||
| } | |||
| public Long getMerchantId() { | |||
| return merchantId; | |||
| } | |||
| public void setMerchantId(Long merchantId) { | |||
| this.merchantId = merchantId; | |||
| } | |||
| public Date getCreateDate() { | |||
| return createDate; | |||
| } | |||
| public void setCreateDate(Date createDate) { | |||
| this.createDate = createDate; | |||
| } | |||
| public Long getLevelId() { | |||
| return levelId; | |||
| } | |||
| public void setLevelId(Long levelId) { | |||
| this.levelId = levelId; | |||
| } | |||
| public Integer getDiscount() { | |||
| return discount; | |||
| } | |||
| public void setDiscount(Integer discount) { | |||
| this.discount = discount; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,LevelId_ASC("`level_id` ASC"),LevelId_DESC("`product_id` DESC") | |||
| ,Discount_ASC("`discount` ASC"),Discount_DESC("`discount` DESC") | |||
| ,MerchantId_ASC("`merchant_id` ASC"),MerchantId_DESC("`merchant_id` DESC") | |||
| ,CreateDate_ASC("`create_date` ASC"),CreateDate_DESC("`create_date` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| } | |||
| public String getValue() { | |||
| return value; | |||
| } | |||
| public void setCol(String value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return this.getValue(); | |||
| } | |||
| } | |||
| public void setSortColumns(WxLevelMerchant.Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| } | |||
| for (int k = 0; k < fields.length; k++) { | |||
| if (fields[k] == null) { | |||
| return; | |||
| } | |||
| } | |||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||
| for (int k = 1; k < fields.length; k++) { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new java.util.ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||
| } else { | |||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||
| } | |||
| } | |||
| } | |||
| @@ -94,6 +94,8 @@ public class WxMerchant implements Serializable { | |||
| @Transient | |||
| private WxMerchantTax wxMerchantTax; | |||
| @Transient | |||
| private List<WxLevelConfig> levelConfigList; | |||
| /*租户ID**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||
| @@ -147,6 +149,13 @@ public class WxMerchant implements Serializable { | |||
| @io.swagger.annotations.ApiModelProperty(value = "类型", name = "type") | |||
| private Integer type; | |||
| public List<WxLevelConfig> getLevelConfigList() { | |||
| return levelConfigList; | |||
| } | |||
| public void setLevelConfigList(List<WxLevelConfig> levelConfigList) { | |||
| this.levelConfigList = levelConfigList; | |||
| } | |||
| public List<Map<String, Object>> getShoplist() { | |||
| return shoplist; | |||
| @@ -0,0 +1,11 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxLevelMerchant; | |||
| import java.util.List; | |||
| public interface WxLevelMerchantMapper extends CommonMapper<WxLevelMerchant, Long> { | |||
| List<WxLevelMerchant> findList(WxLevelMerchant wxLevelMerchant); | |||
| } | |||
| @@ -19,6 +19,9 @@ public interface WxLevelConfigService { | |||
| */ | |||
| PageInfo<WxLevelConfig> listAsPage(WxLevelConfig record, Integer pageIndex, Integer pageSize); | |||
| List<WxLevelConfig> listByMerchantId(Long merchantId, WxLevelConfig record); | |||
| void batchSaveByMerchantId(Long merchantId, List<WxLevelConfig> records); | |||
| /** | |||
| * getByTenantId | |||
| * @param tenantId | |||
| @@ -2,6 +2,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxLevelConfig; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| @@ -77,4 +78,5 @@ public interface WxMerchantService { | |||
| ResultData updateMerchantTax(WxMerchant wxMerchant); | |||
| ResultData updateMerchantLevel(WxMerchant wxMerchant); | |||
| } | |||
| @@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxLevelConfig; | |||
| import com.iformall.domain.po.WxLevelMerchant; | |||
| import com.iformall.mapper.WxLevelConfigMapper; | |||
| import com.iformall.mapper.WxLevelMerchantMapper; | |||
| import com.iformall.service.WxLevelConfigService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -22,6 +24,9 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||
| @Autowired | |||
| WxLevelConfigMapper wxLevelConfigMapper; | |||
| @Autowired | |||
| WxLevelMerchantMapper wxLevelMerchantapper; | |||
| @Override | |||
| public PageInfo<WxLevelConfig> listAsPage(WxLevelConfig record, Integer pageIndex, Integer pageSize) { | |||
| PageInfo<WxLevelConfig> page = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxLevelConfigMapper.findList(record)); | |||
| @@ -36,6 +41,45 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||
| return page; | |||
| } | |||
| public final static int DEFAULT_MERCHANT_DISCOUNT = 100; | |||
| @Override | |||
| public List<WxLevelConfig> listByMerchantId(Long merchantId, WxLevelConfig record) { | |||
| List<WxLevelConfig> list = wxLevelConfigMapper.findList(record); | |||
| list.stream().forEach(l->{ | |||
| WxLevelMerchant wxLevelMerchantParam = new WxLevelMerchant(); | |||
| wxLevelMerchantParam.setLevelId(l.getId()); | |||
| wxLevelMerchantParam.setMerchantId(merchantId); | |||
| WxLevelMerchant wxLevelMerchant = wxLevelMerchantapper.selectOne(wxLevelMerchantParam); | |||
| l.setCount(wxLevelMerchant != null? wxLevelMerchant.getDiscount().longValue():DEFAULT_MERCHANT_DISCOUNT); | |||
| }); | |||
| return list; | |||
| } | |||
| @Override | |||
| public void batchSaveByMerchantId(Long merchantId, List<WxLevelConfig> records) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| records.stream().forEach(l->{ | |||
| WxLevelMerchant wxLevelMerchantParam = new WxLevelMerchant(); | |||
| wxLevelMerchantParam.setLevelId(l.getId()); | |||
| wxLevelMerchantParam.setMerchantId(merchantId); | |||
| WxLevelMerchant wxLevelMerchant = wxLevelMerchantapper.selectOne(wxLevelMerchantParam); | |||
| if (wxLevelMerchant != null) { | |||
| wxLevelMerchant.setCreateDate(new Date()); | |||
| wxLevelMerchant.setDiscount(l.getCount().intValue()); | |||
| wxLevelMerchantapper.updateByPrimaryKeySelective(wxLevelMerchant); | |||
| }else { | |||
| wxLevelMerchantParam.setId(idWorker.nextId()); | |||
| wxLevelMerchantParam.setCreateDate(new Date()); | |||
| wxLevelMerchantParam.setDiscount(DEFAULT_MERCHANT_DISCOUNT); | |||
| wxLevelMerchantapper.insertSelective(wxLevelMerchant); | |||
| } | |||
| }); | |||
| } | |||
| @Override | |||
| public List<WxLevelConfig> findList(WxLevelConfig record){ | |||
| return wxLevelConfigMapper.findList(record); | |||
| @@ -85,12 +129,13 @@ public class WxLevelConfigServiceImpl implements WxLevelConfigService { | |||
| @Override | |||
| public void batchUpdateCapabilities(String tenantId, List<WxLevelConfig> records) { | |||
| records.stream() | |||
| .filter(l->l.getId() == null && l.getCount() != null) | |||
| .filter(l->l.getId() != null && l.getCount() != null) | |||
| .forEach(l->{ | |||
| l.setUpdateDate(new Date()); | |||
| JSONObject jo = new JSONObject(); | |||
| jo.put(CAPABILITY_SEND_CAR_COUPON,l.getCount()); | |||
| l.setCapability(jo.toJSONString()); | |||
| l.setUpdateDate(new Date()); | |||
| wxLevelConfigMapper.updateByPrimaryKeySelective(l); | |||
| }); | |||
| } | |||
| @@ -11,10 +11,7 @@ import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.service.WxProfitSharingReceiverService; | |||
| import com.iformall.service.WxRentContractService; | |||
| import com.iformall.service.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -79,6 +76,9 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| @Autowired | |||
| WxRentContractService wxRentContractService; | |||
| @Autowired | |||
| WxLevelConfigService wxLevelConfigService; | |||
| @Override | |||
| public PageInfo<WxMerchant> listAsPage(WxMerchant record, Integer pageIndex, Integer pageSize) { | |||
| @@ -176,6 +176,10 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| wxMerchant.setWxMerchantTax(new WxMerchantTax()); | |||
| } | |||
| WxLevelConfig wxLevelConfig = new WxLevelConfig(); | |||
| wxLevelConfig.setTenantId(wxMerchant.getTenantId()); | |||
| wxMerchant.setLevelConfigList(wxLevelConfigService.listByMerchantId(wxMerchant.getId(),wxLevelConfig)); | |||
| return wxMerchant; | |||
| } | |||
| @@ -511,4 +515,14 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData updateMerchantLevel(WxMerchant wxMerchant) { | |||
| try { | |||
| wxLevelConfigService.batchSaveByMerchantId(wxMerchant.getId(), wxMerchant.getLevelConfigList()); | |||
| } catch (Exception e) { | |||
| logger.error("db failed: 账号操作失败, e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "操作成功"); | |||
| } | |||
| } | |||
| @@ -8,12 +8,13 @@ | |||
| <result column="level" jdbcType="VARCHAR" property="level"/> | |||
| <result column="description" jdbcType="VARCHAR" property="description"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||
| <result column="discount_enable" jdbcType="SMALLINT" property="discountEnable"/> | |||
| <result column="capability" jdbcType="VARCHAR" property="capability"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`, `tenant_id`, `points`, `level`, `description`, `create_date`, `discount_enable`, `capability` | |||
| `id`, `tenant_id`, `points`, `level`, `description`, `create_date`, `update_date`, `discount_enable`, `capability` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -43,6 +44,10 @@ | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| <if test=" null != updateDate "> | |||
| and `update_date` = #{updateDate} | |||
| </if> | |||
| <if test=" null != discountEnable "> | |||
| and `discount_enable` = #{discountEnable} | |||
| </if> | |||
| @@ -0,0 +1,65 @@ | |||
| <?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.WxLevelMerchantMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxLevelMerchant"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | |||
| <result column="level_id" jdbcType="BIGINT" property="levelId" /> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||
| <result column="discount" jdbcType="INTEGER" property="discount" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`merchant_id`,`level_id`,`create_date`,`discount` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != merchantId "> | |||
| and `merchant_id` = #{merchantId} | |||
| </if> | |||
| <if test=" null != levelId "> | |||
| and `level_id` = #{levelId} | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| <if test=" null != discount "> | |||
| and `discount` = #{discount} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxLevelMerchant" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_level_merchant | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||