Browse Source

客户相关代码

Signed-off-by: fengb <fengbin1989@aliyun.com>
cangku
fengb 3 years ago
parent
commit
fa8318c219
  1. 43
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java
  2. 156
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Customer.java
  3. 210
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/CustomerExample.java
  4. 65
      hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml

43
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java

@ -35,16 +35,19 @@ public class CustomerController {
@ApiOperation(value = "新增客户")
public Result save(Customer customer) {
String encryptPass = new BCryptPasswordEncoder().encode(customer.getPassword());
customer.setPassword(encryptPass);
boolean result = customerService.save(customer);
String encryptPass = new BCryptPasswordEncoder().encode("123456");//默认密码
User user = new User();
user.setUsername(customer.getName());
user.setUsername(customer.getUserName());
user.setNickname(customer.getName());
user.setSex(customer.getSex());
user.setAddress(customer.getAddress());
user.setType(2);//客户
user.setMobile(customer.getPhone());
user.setPassword(encryptPass);
userService.save(user);
User saveUser = userService.save(user);
customer.setUserId(saveUser.getId());
boolean result = customerService.save(customer);
if(result) {
return ResultUtil.success("添加成功");
} else {
@ -52,17 +55,25 @@ public class CustomerController {
}
}
// @RequestMapping(value = "/edit", method = RequestMethod.POST)
// @ApiOperation(value = "根据客户id修改客户")
// public Result edit(Customer customer) {
//
// boolean result = customerService.updateById(customer);
// if(result) {
// return ResultUtil.success("修改成功");
// } else {
// return ResultUtil.error("修改失败");
// }
// }
@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ApiOperation(value = "根据客户id修改客户")
public Result edit(Customer customer) {
Customer originCustomer = customerService.getById(customer.getId());
User user = userService.get(originCustomer.getUserId());
user.setNickname(customer.getName());
user.setSex(customer.getSex());
user.setMobile(customer.getPhone());
user.setAddress(customer.getAddress());
userService.update(user);
boolean result = customerService.updateById(customer);
if(result) {
return ResultUtil.success("修改成功");
} else {
return ResultUtil.error("修改失败");
}
}
@RequestMapping(value = "/delById", method = RequestMethod.POST)
@ApiOperation(value = "根据id删除客户")

156
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Customer.java

@ -1,16 +1,23 @@
package cc.hiver.mall.entity;
import cc.hiver.core.common.utils.SnowFlakeUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@ApiModel(value = "客户表")
@TableName(value = "t_customer", autoResultMap = true)
public class Customer implements Serializable {
private String id;
private static final long serialVersionUID = 1L;
private String id = SnowFlakeUtil.nextId().toString();
private String createBy;
@ -25,15 +32,15 @@ public class Customer implements Serializable {
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "手机号")
private String phone;
@ApiModelProperty(value = "地址")
private String address;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "省")
private String province;
@ -46,142 +53,11 @@ public class Customer implements Serializable {
@ApiModelProperty(value = "商品id")
private String shopId;
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreateBy() {
return createBy;
}
@ApiModelProperty(value = "用户id")
private String userId;
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
@TableField(exist = false)
@ApiModelProperty(value = "登录账号")
private String userName;
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getDelFlag() {
return delFlag;
}
public void setDelFlag(Integer delFlag) {
this.delFlag = delFlag;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", createBy=").append(createBy);
sb.append(", createTime=").append(createTime);
sb.append(", delFlag=").append(delFlag);
sb.append(", updateBy=").append(updateBy);
sb.append(", updateTime=").append(updateTime);
sb.append(", name=").append(name);
sb.append(", phone=").append(phone);
sb.append(", address=").append(address);
sb.append(", password=").append(password);
sb.append(", province=").append(province);
sb.append(", city=").append(city);
sb.append(", area=").append(area);
sb.append(", shopId=").append(shopId);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

210
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/CustomerExample.java

@ -565,6 +565,76 @@ public class CustomerExample {
return (Criteria) this;
}
public Criteria andSexIsNull() {
addCriterion("sex is null");
return (Criteria) this;
}
public Criteria andSexIsNotNull() {
addCriterion("sex is not null");
return (Criteria) this;
}
public Criteria andSexEqualTo(String value) {
addCriterion("sex =", value, "sex");
return (Criteria) this;
}
public Criteria andSexNotEqualTo(String value) {
addCriterion("sex <>", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThan(String value) {
addCriterion("sex >", value, "sex");
return (Criteria) this;
}
public Criteria andSexGreaterThanOrEqualTo(String value) {
addCriterion("sex >=", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThan(String value) {
addCriterion("sex <", value, "sex");
return (Criteria) this;
}
public Criteria andSexLessThanOrEqualTo(String value) {
addCriterion("sex <=", value, "sex");
return (Criteria) this;
}
public Criteria andSexLike(String value) {
addCriterion("sex like", value, "sex");
return (Criteria) this;
}
public Criteria andSexNotLike(String value) {
addCriterion("sex not like", value, "sex");
return (Criteria) this;
}
public Criteria andSexIn(List<String> values) {
addCriterion("sex in", values, "sex");
return (Criteria) this;
}
public Criteria andSexNotIn(List<String> values) {
addCriterion("sex not in", values, "sex");
return (Criteria) this;
}
public Criteria andSexBetween(String value1, String value2) {
addCriterion("sex between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andSexNotBetween(String value1, String value2) {
addCriterion("sex not between", value1, value2, "sex");
return (Criteria) this;
}
public Criteria andPhoneIsNull() {
addCriterion("phone is null");
return (Criteria) this;
@ -705,76 +775,6 @@ public class CustomerExample {
return (Criteria) this;
}
public Criteria andPasswordIsNull() {
addCriterion("password is null");
return (Criteria) this;
}
public Criteria andPasswordIsNotNull() {
addCriterion("password is not null");
return (Criteria) this;
}
public Criteria andPasswordEqualTo(String value) {
addCriterion("password =", value, "password");
return (Criteria) this;
}
public Criteria andPasswordNotEqualTo(String value) {
addCriterion("password <>", value, "password");
return (Criteria) this;
}
public Criteria andPasswordGreaterThan(String value) {
addCriterion("password >", value, "password");
return (Criteria) this;
}
public Criteria andPasswordGreaterThanOrEqualTo(String value) {
addCriterion("password >=", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLessThan(String value) {
addCriterion("password <", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLessThanOrEqualTo(String value) {
addCriterion("password <=", value, "password");
return (Criteria) this;
}
public Criteria andPasswordLike(String value) {
addCriterion("password like", value, "password");
return (Criteria) this;
}
public Criteria andPasswordNotLike(String value) {
addCriterion("password not like", value, "password");
return (Criteria) this;
}
public Criteria andPasswordIn(List<String> values) {
addCriterion("password in", values, "password");
return (Criteria) this;
}
public Criteria andPasswordNotIn(List<String> values) {
addCriterion("password not in", values, "password");
return (Criteria) this;
}
public Criteria andPasswordBetween(String value1, String value2) {
addCriterion("password between", value1, value2, "password");
return (Criteria) this;
}
public Criteria andPasswordNotBetween(String value1, String value2) {
addCriterion("password not between", value1, value2, "password");
return (Criteria) this;
}
public Criteria andProvinceIsNull() {
addCriterion("province is null");
return (Criteria) this;
@ -1054,6 +1054,76 @@ public class CustomerExample {
addCriterion("shop_id not between", value1, value2, "shopId");
return (Criteria) this;
}
public Criteria andUserIdIsNull() {
addCriterion("user_id is null");
return (Criteria) this;
}
public Criteria andUserIdIsNotNull() {
addCriterion("user_id is not null");
return (Criteria) this;
}
public Criteria andUserIdEqualTo(String value) {
addCriterion("user_id =", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdNotEqualTo(String value) {
addCriterion("user_id <>", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdGreaterThan(String value) {
addCriterion("user_id >", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdGreaterThanOrEqualTo(String value) {
addCriterion("user_id >=", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdLessThan(String value) {
addCriterion("user_id <", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdLessThanOrEqualTo(String value) {
addCriterion("user_id <=", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdLike(String value) {
addCriterion("user_id like", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdNotLike(String value) {
addCriterion("user_id not like", value, "userId");
return (Criteria) this;
}
public Criteria andUserIdIn(List<String> values) {
addCriterion("user_id in", values, "userId");
return (Criteria) this;
}
public Criteria andUserIdNotIn(List<String> values) {
addCriterion("user_id not in", values, "userId");
return (Criteria) this;
}
public Criteria andUserIdBetween(String value1, String value2) {
addCriterion("user_id between", value1, value2, "userId");
return (Criteria) this;
}
public Criteria andUserIdNotBetween(String value1, String value2) {
addCriterion("user_id not between", value1, value2, "userId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

65
hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml

@ -9,13 +9,14 @@
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="sex" jdbcType="VARCHAR" property="sex" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="address" jdbcType="VARCHAR" property="address" />
<result column="password" jdbcType="VARCHAR" property="password" />
<result column="province" jdbcType="VARCHAR" property="province" />
<result column="city" jdbcType="VARCHAR" property="city" />
<result column="area" jdbcType="VARCHAR" property="area" />
<result column="shop_id" jdbcType="VARCHAR" property="shopId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -76,8 +77,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, create_by, create_time, del_flag, update_by, update_time, name, phone, address,
password, province, city, area, shop_id
id, create_by, create_time, del_flag, update_by, update_time, name, sex, phone, address,
province, city, area, shop_id, user_id
</sql>
<select id="selectByExample" parameterType="cc.hiver.mall.entity.CustomerExample" resultMap="BaseResultMap">
select
@ -112,14 +113,14 @@
<insert id="insert" parameterType="cc.hiver.mall.entity.Customer">
insert into t_customer (id, create_by, create_time,
del_flag, update_by, update_time,
name, phone, address,
password, province, city,
area, shop_id)
name, sex, phone, address,
province, city, area,
shop_id, user_id)
values (#{id,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=INTEGER}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
#{password,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR},
#{area,jdbcType=VARCHAR}, #{shopId,jdbcType=VARCHAR})
#{name,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
#{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{area,jdbcType=VARCHAR},
#{shopId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="cc.hiver.mall.entity.Customer">
insert into t_customer
@ -145,15 +146,15 @@
<if test="name != null">
name,
</if>
<if test="sex != null">
sex,
</if>
<if test="phone != null">
phone,
</if>
<if test="address != null">
address,
</if>
<if test="password != null">
password,
</if>
<if test="province != null">
province,
</if>
@ -166,6 +167,9 @@
<if test="shopId != null">
shop_id,
</if>
<if test="userId != null">
user_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -189,15 +193,15 @@
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="sex != null">
#{sex,jdbcType=VARCHAR},
</if>
<if test="phone != null">
#{phone,jdbcType=VARCHAR},
</if>
<if test="address != null">
#{address,jdbcType=VARCHAR},
</if>
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
<if test="province != null">
#{province,jdbcType=VARCHAR},
</if>
@ -210,6 +214,9 @@
<if test="shopId != null">
#{shopId,jdbcType=VARCHAR},
</if>
<if test="userId != null">
#{userId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="cc.hiver.mall.entity.CustomerExample" resultType="java.lang.Long">
@ -242,15 +249,15 @@
<if test="record.name != null">
name = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.sex != null">
sex = #{record.sex,jdbcType=VARCHAR},
</if>
<if test="record.phone != null">
phone = #{record.phone,jdbcType=VARCHAR},
</if>
<if test="record.address != null">
address = #{record.address,jdbcType=VARCHAR},
</if>
<if test="record.password != null">
password = #{record.password,jdbcType=VARCHAR},
</if>
<if test="record.province != null">
province = #{record.province,jdbcType=VARCHAR},
</if>
@ -263,6 +270,9 @@
<if test="record.shopId != null">
shop_id = #{record.shopId,jdbcType=VARCHAR},
</if>
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -277,13 +287,14 @@
update_by = #{record.updateBy,jdbcType=VARCHAR},
update_time = #{record.updateTime,jdbcType=TIMESTAMP},
name = #{record.name,jdbcType=VARCHAR},
sex = #{record.sex,jdbcType=VARCHAR},
phone = #{record.phone,jdbcType=VARCHAR},
address = #{record.address,jdbcType=VARCHAR},
password = #{record.password,jdbcType=VARCHAR},
province = #{record.province,jdbcType=VARCHAR},
city = #{record.city,jdbcType=VARCHAR},
area = #{record.area,jdbcType=VARCHAR},
shop_id = #{record.shopId,jdbcType=VARCHAR}
shop_id = #{record.shopId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -309,15 +320,15 @@
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="sex != null">
sex = #{sex,jdbcType=VARCHAR},
</if>
<if test="phone != null">
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="address != null">
address = #{address,jdbcType=VARCHAR},
</if>
<if test="password != null">
password = #{password,jdbcType=VARCHAR},
</if>
<if test="province != null">
province = #{province,jdbcType=VARCHAR},
</if>
@ -330,6 +341,9 @@
<if test="shopId != null">
shop_id = #{shopId,jdbcType=VARCHAR},
</if>
<if test="userId != null">
user_id = #{userId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -341,13 +355,14 @@
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
name = #{name,jdbcType=VARCHAR},
sex = #{sex,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
address = #{address,jdbcType=VARCHAR},
password = #{password,jdbcType=VARCHAR},
province = #{province,jdbcType=VARCHAR},
city = #{city,jdbcType=VARCHAR},
area = #{area,jdbcType=VARCHAR},
shop_id = #{shopId,jdbcType=VARCHAR}
shop_id = #{shopId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
Loading…
Cancel
Save