| @@ -0,0 +1,69 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxBrand; | |||||
| import com.iformall.service.WxBrandService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxBrand") | |||||
| public class WxBrandController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxBrandService wxBrandService; | |||||
| @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 WxBrand wxBrand, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::list"); | |||||
| if (null == wxBrand) { | |||||
| wxBrand = new WxBrand(); | |||||
| } | |||||
| final PageInfo<WxBrand> page = wxBrandService.listAsPage(wxBrand, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxBrand wxBrand) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::add"); | |||||
| wxBrand.setTenantId(getTenantId()); | |||||
| return wxBrandService.save(wxBrand); | |||||
| } | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxBrand wxBrand) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::update"); | |||||
| wxBrand.setTenantId(getTenantId()); | |||||
| return wxBrandService.update(wxBrand); | |||||
| } | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData delete(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::del"); | |||||
| wxBrandService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS, "查询成功", wxBrandService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,139 @@ | |||||
| package com.iformall.domain.po; | |||||
| import javax.persistence.Id; | |||||
| import javax.persistence.Table; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Table(name = "wx_brand") | |||||
| public class WxBrand 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; | |||||
| } | |||||
| @io.swagger.annotations.ApiModelProperty(value="tenantId",name="tenantId") | |||||
| private String tenantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="名称",name="name") | |||||
| private String name; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") | |||||
| private Date createtime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="修改时间",name="updatetime") | |||||
| private Date updatetime; | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String _name) { | |||||
| name = _name; | |||||
| } | |||||
| public Date getCreatetime() { | |||||
| return createtime; | |||||
| } | |||||
| public void setCreatetime(Date _createtime) { | |||||
| createtime = _createtime; | |||||
| } | |||||
| public Date getUpdatetime() { | |||||
| return updatetime; | |||||
| } | |||||
| public void setUpdatetime(Date _updatetime) { | |||||
| updatetime = _updatetime; | |||||
| } | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| } | |||||
| public static enum Field | |||||
| { | |||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||||
| ,Createtime_ASC("`createtime` ASC"),Createtime_DESC("`createtime` DESC") | |||||
| ,Updatetime_ASC("`updatetime` ASC"),Updatetime_DESC("`updatetime` 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(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(","); | |||||
| List<Field> fList = new 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,21 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxBrand; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public interface WxBrandMapper extends CommonMapper<WxBrand, String> { | |||||
| List<WxBrand> findList(WxBrand wxBrand); | |||||
| } | |||||
| @@ -0,0 +1,42 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxBrand; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public interface WxBrandService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param offset | |||||
| * @param limit | |||||
| * @return | |||||
| */ | |||||
| PageInfo<WxBrand> listAsPage(WxBrand record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| WxBrand getById(Long id); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| ResultData save(WxBrand wxBrand); | |||||
| ResultData update(WxBrand wxBrand); | |||||
| } | |||||
| @@ -0,0 +1,79 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxBrand; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxBrandMapper; | |||||
| import com.iformall.service.WxBrandService; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.Date; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Service | |||||
| public class WxBrandServiceImpl implements WxBrandService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxBrandMapper wxBrandMapper; | |||||
| @Override | |||||
| public PageInfo<WxBrand> listAsPage(WxBrand record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxBrandMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public WxBrand getById(Long id) { | |||||
| return wxBrandMapper.selectByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| wxBrandMapper.deleteByPrimaryKey(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData save(WxBrand wxBrand) { | |||||
| if(StringUtils.isEmpty(wxBrand.getName())){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"品牌名称不能为空"); | |||||
| } | |||||
| try { | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| wxBrand.setId(idWorker.nextId()); | |||||
| wxBrandMapper.insertSelective(wxBrand); | |||||
| return new ResultData(Result.SUCCESS, "操作成功"); | |||||
| } catch (Exception e) { | |||||
| logger.error("保存租赁合同信息失败,e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public ResultData update(WxBrand wxBrand) { | |||||
| if(StringUtils.isEmpty(wxBrand.getName())){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"品牌名称不能为空"); | |||||
| } | |||||
| try { | |||||
| wxBrand.setUpdatetime(new Date()); | |||||
| wxBrandMapper.updateByPrimaryKeySelective(wxBrand); | |||||
| return new ResultData(Result.SUCCESS, "操作成功"); | |||||
| } catch (Exception e) { | |||||
| logger.error("更新租赁合同信息失败,e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,42 @@ | |||||
| <?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.WxBrandMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxBrand"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||||
| <result column="createtime" jdbcType="TIMESTAMP" property="createtime" /> | |||||
| <result column="updatetime" jdbcType="TIMESTAMP" property="updatetime" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`name`,`createtime`,`updatetime`,`tenant_id` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> and `id` = #{id} </if> | |||||
| <if test=" null != name "> and `name` like concat('%',#{name},'%') </if> | |||||
| <if test=" null != createtime "> and `createtime` = #{createtime} </if> | |||||
| <if test=" null != updatetime "> and `updatetime` = #{updatetime} </if> | |||||
| <if test=" null != tenantId "> and `tenant_id` = #{tenantId} </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.WxBrand" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_brand | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| </mapper> | |||||