| @@ -0,0 +1,71 @@ | |||||
| package com.simple.controller; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.util.Assert; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxChannel; | |||||
| import com.simple.service.WxChannelService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| @RestController | |||||
| @RequestMapping("wxChannel") | |||||
| public class WxChannelController extends BaseController | |||||
| { | |||||
| @Autowired | |||||
| private WxChannelService wxChannelService; | |||||
| private Logger logger = Logger.getLogger(WxChannelController.class); | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| public ResultData list(@ModelAttribute WxChannel wxChannel,Integer pageNum, Integer pageSize) { | |||||
| if (null == wxChannel) wxChannel = new WxChannel(); | |||||
| final PageInfo<WxChannel> page = wxChannelService.listAsPage(wxChannel, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxChannel wxChannel) { | |||||
| //Assert.notNull(wxChannel.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxChannelService.saveOrUpdate(wxChannel); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxChannel wxChannel) { | |||||
| wxChannelService.saveOrUpdate(wxChannel); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxChannelService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxChannelService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -19,10 +19,10 @@ import io.swagger.annotations.ApiOperation; | |||||
| @RequestMapping("wxCoupon") | @RequestMapping("wxCoupon") | ||||
| public class WxCouponController extends BaseController | public class WxCouponController extends BaseController | ||||
| { | { | ||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @@ -0,0 +1,141 @@ | |||||
| package com.simple.domain.po; | |||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.util.List; | |||||
| import javax.persistence.Id; | |||||
| import java.io.Serializable; | |||||
| @Table(name = "wx_channel") | |||||
| public class WxChannel implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @Transient | |||||
| protected List<String> 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<String> getIds() { | |||||
| return ids; | |||||
| } | |||||
| public void setIds(List<String> ids) { | |||||
| this.ids = ids; | |||||
| } | |||||
| /***/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="tenantId") | |||||
| private Long tenantId; | |||||
| /*渠道ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="渠道ID",name="channelId") | |||||
| private Integer channelId; | |||||
| /*渠道名**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="渠道名",name="title") | |||||
| private String title; | |||||
| /*图片url**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="图片url",name="img") | |||||
| private String img; | |||||
| public Long getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(Long _tenantId) { | |||||
| tenantId = _tenantId; | |||||
| } | |||||
| public Integer getChannelId() { | |||||
| return channelId; | |||||
| } | |||||
| public void setChannelId(Integer _channelId) { | |||||
| channelId = _channelId; | |||||
| } | |||||
| public String getTitle() { | |||||
| return title; | |||||
| } | |||||
| public void setTitle(String _title) { | |||||
| title = _title; | |||||
| } | |||||
| public String getImg() { | |||||
| return img; | |||||
| } | |||||
| public void setImg(String _img) { | |||||
| img = _img; | |||||
| } | |||||
| public static enum Field | |||||
| { | |||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||||
| ,ChannelId_ASC("`channelId` ASC"),ChannelId_DESC("`channelId` DESC") | |||||
| ,Title_ASC("`title` ASC"),Title_DESC("`title` DESC") | |||||
| ,Img_ASC("`img` ASC"),Img_DESC("`img` 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(WxChannel.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()); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(String sortColumns) | |||||
| { | |||||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||||
| return; | |||||
| } | |||||
| if (sortColumns.contains(",")) { | |||||
| String[] cols = sortColumns.split(","); | |||||
| java.util.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)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.simple.mapper; | |||||
| import java.util.*; | |||||
| import com.simple.common.CommonMapper; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import com.simple.domain.po.WxChannel; | |||||
| public interface WxChannelMapper extends CommonMapper<WxChannel, String> { | |||||
| List<WxChannel> findList(WxChannel wxChannel); | |||||
| } | |||||
| @@ -0,0 +1,48 @@ | |||||
| package com.simple.service; | |||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.simple.domain.po.WxChannel; | |||||
| public interface WxChannelService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param offset | |||||
| * @param limit | |||||
| * @return | |||||
| */ | |||||
| PageInfo<WxChannel> listAsPage(WxChannel record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| WxChannel getById(Long id); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| void saveOrUpdate(WxChannel record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| } | |||||
| @@ -0,0 +1,54 @@ | |||||
| package com.simple.service.impl; | |||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.simple.domain.po.WxChannel; | |||||
| import com.simple.mapper.WxChannelMapper; | |||||
| import com.simple.service.WxChannelService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.simple.common.IdWorker; | |||||
| @Service | |||||
| public class WxChannelServiceImpl implements WxChannelService { | |||||
| @Autowired | |||||
| WxChannelMapper wxChannelMapper; | |||||
| @Override | |||||
| public PageInfo<WxChannel> listAsPage(WxChannel record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxChannelMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public WxChannel getById(Long id) { | |||||
| return wxChannelMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public void saveOrUpdate(WxChannel record) { | |||||
| if (record.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| wxChannelMapper.insertSelective(record); | |||||
| } else { | |||||
| wxChannelMapper.updateByPrimaryKeySelective(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| wxChannelMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| } | |||||
| @@ -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.simple.mapper.WxChannelMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxChannel"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="BIGINT" property="tenantId" /> | |||||
| <result column="channel_id" jdbcType="INTEGER" property="channelId" /> | |||||
| <result column="title" jdbcType="VARCHAR" property="title" /> | |||||
| <result column="img" jdbcType="VARCHAR" property="img" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`channel_id`,`title`,`img` | |||||
| </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 != channelId "> | |||||
| and `channel_id` = #{channelId} | |||||
| </if> | |||||
| <if test=" null != title "> | |||||
| and `title` like concat('%', #{title},'%') | |||||
| </if> | |||||
| <if test=" null != img "> | |||||
| and `img` like concat('%', #{img},'%') | |||||
| </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.simple.domain.po.WxChannel" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_channel | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| </mapper> | |||||