diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java index 36294aec..105afc75 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CustomerController.java +++ b/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删除客户") diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Customer.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Customer.java index f62a7a5e..8369ddd9 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/Customer.java +++ b/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(); - } } \ No newline at end of file diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/CustomerExample.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/CustomerExample.java index 4b7a8c8a..cbda7c04 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/entity/CustomerExample.java +++ b/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 values) { + addCriterion("sex in", values, "sex"); + return (Criteria) this; + } + + public Criteria andSexNotIn(List 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 values) { - addCriterion("password in", values, "password"); - return (Criteria) this; - } - - public Criteria andPasswordNotIn(List 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 values) { + addCriterion("user_id in", values, "userId"); + return (Criteria) this; + } + + public Criteria andUserIdNotIn(List 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 { diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml index 001cae5c..174e9cfb 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml @@ -9,13 +9,14 @@ + - + @@ -76,8 +77,8 @@ - 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 @@ -242,15 +249,15 @@ 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}, @@ -263,6 +270,9 @@ shop_id = #{record.shopId,jdbcType=VARCHAR}, + + user_id = #{record.userId,jdbcType=VARCHAR}, + @@ -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} @@ -309,15 +320,15 @@ name = #{name,jdbcType=VARCHAR}, + + sex = #{sex,jdbcType=VARCHAR}, + phone = #{phone,jdbcType=VARCHAR}, address = #{address,jdbcType=VARCHAR}, - - password = #{password,jdbcType=VARCHAR}, - province = #{province,jdbcType=VARCHAR}, @@ -330,6 +341,9 @@ shop_id = #{shopId,jdbcType=VARCHAR}, + + user_id = #{userId,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -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} \ No newline at end of file