| @@ -0,0 +1,75 @@ | |||||
| package com.iformall.controller.basic; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.WxMerchantScoreRules; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.service.*; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| /** | |||||
| * @author | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxMerchantScoreRules") | |||||
| public class WxMerchantScoreRulesController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxMerchantScoreRulesService wxMerchantScoreRulesService; | |||||
| @ApiOperation("获取商户积分规则") | |||||
| @GetMapping("getCreditRules") | |||||
| @SystemControllerLog(description = "商户-列表") | |||||
| public ResultData getCreditRules(Long merchantId) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantScoreRulesController::getRules"); | |||||
| if(merchantId == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| WxMerchantScoreRules scoreRules = wxMerchantScoreRulesService.getScoreRules(merchantId, EnumScoreRules.CREDIT.getCode()); | |||||
| if(scoreRules == null){ | |||||
| scoreRules = new WxMerchantScoreRules(); | |||||
| scoreRules.setOpen(EnumYesOrNo.NO.getCode()); | |||||
| scoreRules.setScale(WxMerchantScoreRules.DEFAULT_SCALE); | |||||
| } | |||||
| return new ResultData(scoreRules); | |||||
| } | |||||
| @ApiOperation("新增修改倍率设置") | |||||
| @PostMapping("addCreditRules") | |||||
| @SystemControllerLog(description = "商户-新增") | |||||
| public ResultData addCreditRules(@RequestBody WxMerchantScoreRules scoreRules) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantScoreRulesController::addCreditRules"); | |||||
| if(scoreRules.getMerchantId() == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"merchantId为空"); | |||||
| } | |||||
| scoreRules.updateTenantInfo(getTenantInfo()); | |||||
| WxMerchantScoreRules oldScoreRules = wxMerchantScoreRulesService.getScoreRules(scoreRules.getMerchantId(), EnumScoreRules.CREDIT.getCode()); | |||||
| if(oldScoreRules != null){ | |||||
| scoreRules.setId(oldScoreRules.getId()); | |||||
| } | |||||
| if(scoreRules.getScale() == null){ | |||||
| scoreRules.setScale(WxMerchantScoreRules.DEFAULT_SCALE); | |||||
| } | |||||
| if(scoreRules.getScale() < WxMerchantScoreRules.DEFAULT_SCALE){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"积分倍率不能小于1"); | |||||
| } | |||||
| wxMerchantScoreRulesService.saveOrUpdate(scoreRules); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,47 @@ | |||||
| package com.iformall.domain.po; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | |||||
| import com.baomidou.mybatisplus.annotation.TableName; | |||||
| import com.iformall.domain.po.base.BaseTenantEntity; | |||||
| import com.iformall.enums.EnumScoreType; | |||||
| import com.iformall.utils.Constant; | |||||
| import lombok.Data; | |||||
| import lombok.EqualsAndHashCode; | |||||
| import java.util.*; | |||||
| @TableName(value = "wx_merchant_score_rules") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class WxMerchantScoreRules extends BaseTenantEntity { | |||||
| @TableField(exist = false) | |||||
| public static final int DEFAULT_SCALE = 10; | |||||
| protected Long id; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="merchantId") | |||||
| private Long merchantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="规则",name="rules") | |||||
| private String rules; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||||
| private Date createDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||||
| private Date updateDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="EnumScoreRules 1成长值 2积分",name="type") | |||||
| private Integer type; | |||||
| @io.swagger.annotations.ApiModelProperty(value="是否打开",name="open") | |||||
| private Integer open; | |||||
| @io.swagger.annotations.ApiModelProperty(value="积分倍率",name="scale") | |||||
| private Integer scale; | |||||
| } | |||||
| @@ -103,7 +103,7 @@ public class WxScoreRules extends BaseTenantEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| @io.swagger.annotations.ApiModelProperty(value="1成长值 2积分",name="type") | |||||
| @io.swagger.annotations.ApiModelProperty(value="EnumScoreRules 1成长值 2积分",name="type") | |||||
| private Integer type; | private Integer type; | ||||
| @io.swagger.annotations.ApiModelProperty(value="清除前多少年积分",name="clearYear") | @io.swagger.annotations.ApiModelProperty(value="清除前多少年积分",name="clearYear") | ||||
| @@ -0,0 +1,18 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxMerchantScoreRules; | |||||
| import com.iformall.domain.po.WxScoreRules; | |||||
| import java.util.List; | |||||
| public interface WxMerchantScoreRulesMapper extends CommonMapper<WxMerchantScoreRules, String> { | |||||
| List<WxMerchantScoreRules> findList(WxMerchantScoreRules scoreRules); | |||||
| } | |||||
| @@ -0,0 +1,21 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.domain.po.WxMerchantScoreRules; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import java.util.List; | |||||
| public interface WxMerchantScoreRulesService { | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| void saveOrUpdate(WxMerchantScoreRules record); | |||||
| WxMerchantScoreRules getScoreRules(Long merchantId,Integer type); | |||||
| } | |||||
| @@ -0,0 +1,50 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.mapper.*; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.utils.Constant; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.*; | |||||
| @Service | |||||
| public class WxMerchantScoreRulesServiceImpl implements WxMerchantScoreRulesService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantScoreRulesMapper wxMerchantScoreRulesMapper; | |||||
| @Override | |||||
| public void saveOrUpdate(WxMerchantScoreRules record) { | |||||
| Date date = new Date(); | |||||
| record.setUpdateDate(date); | |||||
| if (record.getId() == null) { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| record.setCreateDate(date); | |||||
| wxMerchantScoreRulesMapper.insert(record); | |||||
| } else { | |||||
| wxMerchantScoreRulesMapper.updateById(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public WxMerchantScoreRules getScoreRules(Long merchantId, Integer type) { | |||||
| WxMerchantScoreRules scoreRules = new WxMerchantScoreRules(); | |||||
| scoreRules.setMerchantId(merchantId); | |||||
| scoreRules.setType(type); | |||||
| return wxMerchantScoreRulesMapper.selectOne(new QueryWrapper<>(scoreRules)); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,62 @@ | |||||
| <?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.WxMerchantScoreRulesMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMerchantScoreRules"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="merchant_id" jdbcType="VARCHAR" property="merchantId"/> | |||||
| <result column="rules" jdbcType="VARCHAR" property="rules"/> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/> | |||||
| <result column="type" jdbcType="INTEGER" property="type"/> | |||||
| <result column="open" jdbcType="INTEGER" property="open"/> | |||||
| <result column="scale" jdbcType="INTEGER" property="scale"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`merchant_id`,`rules`,`create_date`,`update_date`,`type`,`open`,`scale` | |||||
| </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 != type "> | |||||
| and `type` = #{type} | |||||
| </if> | |||||
| <if test=" null != open "> | |||||
| and `open` = #{open} | |||||
| </if> | |||||
| <if test=" null != scale "> | |||||
| and `scale` = #{scale} | |||||
| </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.WxMerchantScoreRules" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from wx_merchant_score_rules | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| </mapper> | |||||