添加客户注册

dev
lisai17@sina.com 2020-08-12 16:59:27 +08:00
parent f856607eaa
commit e133f507f2
10 changed files with 228 additions and 52 deletions

View File

@ -0,0 +1,74 @@
package com.cowr.common.enums;
import java.util.ArrayList;
import java.util.List;
/**
100
101
102
201
202
300
400
500 退
501 退
502
*/
public enum RoleEnum {
DEVOPS(99),
SUPERADMIN(100),
SUPERCTRL(101),
SUPERSTEVEDORE(102),
TRANCOADMIN(201),
TRANCODRIVER(202),
CUSTOMER(300),
PRESIDENT(500),
TREASURER(501),
PRESIDENTVIEW(502)
;
private Integer roleid;
public Integer getRoleid() {
return roleid;
}
public void setRoleid(Integer roleid) {
this.roleid = roleid;
}
RoleEnum(Integer roleid){
this.roleid = roleid;
}
/**
* roleid
* @param roleid
* @return
*/
public static boolean hasRoleId(int roleid){
for(RoleEnum roleEnum : RoleEnum.values()){
if(roleEnum.roleid == roleid){
return true;
}
}
return false;
}
public static List<Integer> getRoleIdArr(){
List<Integer> list = new ArrayList<>();
for(RoleEnum roleEnum : RoleEnum.values()){
list.add(roleEnum.getRoleid());
}
return list;
}
}

View File

@ -12,6 +12,7 @@ import java.util.regex.Pattern;
public class StrUtil {
public static final String regphone = "^1[3|4|5|7|8|9][\\d]{9}$"; // 放的比较宽
public static final String regphone_tel = "^((0\\d{2,3}-\\d{7,8})|(1[3584]\\d{9}))$"; // 座机或者手机
public static final String DEFAULT_PATH_SEPARATOR = ",";
/**

View File

@ -88,11 +88,11 @@ public abstract class BaseCustomer<M extends BaseCustomer<M>> extends BaseModel<
/**
* name: phone
* type: CHAR(11)
* type: VARCHAR(20)
* isNullable: YES
* isPrimaryKey: NO
* defaultValue:
* @param phone
* @param phone
*/
@JSONField(name="phone")
public void setPhone(String phone) {
@ -101,7 +101,7 @@ public abstract class BaseCustomer<M extends BaseCustomer<M>> extends BaseModel<
/**
* @return phone
* @return phone
*/
@JSONField(name="phone")
public String getPhone() {

View File

@ -133,7 +133,7 @@ public abstract class BaseCustomerReceiver<M extends BaseCustomerReceiver<M>> ex
/**
* name: lgtd
* type: DECIMAL(12,8)
* isNullable: NO
* isNullable: YES
* isPrimaryKey: NO
* defaultValue:
* @param lgtd
@ -155,7 +155,7 @@ public abstract class BaseCustomerReceiver<M extends BaseCustomerReceiver<M>> ex
/**
* name: lttd
* type: DECIMAL(12,8)
* isNullable: NO
* isNullable: YES
* isPrimaryKey: NO
* defaultValue:
* @param lttd
@ -180,7 +180,7 @@ public abstract class BaseCustomerReceiver<M extends BaseCustomerReceiver<M>> ex
* isNullable: YES
* isPrimaryKey: NO
* defaultValue:
* @param memo
* @param memo
*/
@JSONField(name="memo")
public void setMemo(java.lang.String memo) {
@ -189,7 +189,7 @@ public abstract class BaseCustomerReceiver<M extends BaseCustomerReceiver<M>> ex
/**
* @return memo
* @return memo
*/
@JSONField(name="memo")
public java.lang.String getMemo() {

View File

@ -4,6 +4,7 @@ import com.cowr.common.Const;
import com.cowr.common.base.BaseModel;
import com.cowr.common.base.BaseService;
import com.cowr.common.enums.Enums;
import com.cowr.common.enums.RoleEnum;
import com.cowr.common.enums.UserTypeEnum;
import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result;
@ -92,7 +93,7 @@ public class SysuserSyncService extends BaseService {
*/
public boolean isTreasurer(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(501);
return roleid.equals(RoleEnum.TREASURER.getRoleid());
}
/**
@ -104,12 +105,12 @@ public class SysuserSyncService extends BaseService {
*/
public boolean isPresident(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(500);
return roleid.equals(RoleEnum.PRESIDENT.getRoleid());
}
public boolean isPresidentView(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(502);
return roleid.equals(RoleEnum.PRESIDENTVIEW.getRoleid());
}
/**
@ -120,7 +121,7 @@ public class SysuserSyncService extends BaseService {
*/
public boolean isTrancoAdmin(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(201);
return roleid.equals(RoleEnum.TRANCOADMIN.getRoleid());
}
/**
@ -131,12 +132,12 @@ public class SysuserSyncService extends BaseService {
*/
public boolean isTrancoDriver(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(202);
return roleid.equals(RoleEnum.TRANCODRIVER.getRoleid());
}
public boolean isConfigAdmin(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(99);
return roleid.equals(RoleEnum.DEVOPS.getRoleid());
}
/**

View File

@ -1,16 +1,16 @@
# mysql
# GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.119' IDENTIFIED BY 'Local_1' WITH GRANT OPTION;
#jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
#user=ssjy_xsx
#password=Ssjy_xs_890
jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
user=ssjy_xsx
password=Ssjy_xs_890
jdbcUrl=jdbc:mysql://192.168.1.119:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
user=root
password=Local_1
#jdbcUrl=jdbc:mysql://192.168.1.119:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
#user=root
#password=Local_1
# redis
redis.basekey = ssjcgl_xsx_dev
redis.ip=192.168.1.119
redis.ip=r-wz9168ab2f2f7ec4pd.redis.rds.aliyuncs.com
redis.port=6379
redis.pwd=
redis.db=
redis.pwd=CoWR1111
redis.db=13

View File

@ -0,0 +1,31 @@
package com.cowr.service.ssjygl.system.sysuser;
import com.cowr.common.utils.StrUtil;
import com.cowr.common.validator.CrudParamValidator;
import com.cowr.common.view.Result;
import com.jfinal.core.Controller;
public class RegisterUserValidator extends CrudParamValidator {
@Override
protected void validate(Controller c) {
validateRegex("sysuser.phone", StrUtil.regphone, "sysuser.phone", "用户手机号格式错误");
validateString("sysuser.name", 1, 8, "sysuser.name", "用户姓名长度在1~8之间"); // 必填项字段长度必须大于0不能超过最大长度
validateString("sysuser.password", 6, 20, "sysuser.password", "用户密码长度在6~20之间"); // 必填项字段长度必须大于0不能超过最大长度
validateString("customer.texpayer_name", 1, 255, "customer.texpayer_name", "公司名称的长度在1~255之间");
validateString("customer.address", 1, 256, "customer.address", "公司地址的长度在1~255之间");
validateString("customer.phone", 1, 20, "customer.phone", "开票电话格式不正确");
validateString("customer.texpayer_num", 1, 20, "customer.texpayer_num", "纳税人识别号格式不正确");
validateString("customer.bank_name", 1, 128, "customer.bank_name", "开户银行名称格式不正确");
validateString("customer.bank_account", 1, 20, "customer.bank_account", "开户银行账号格式不正确");
validateString("customer.memo", 0, 256, "customer.memo", "备注长度在0~256之间");
validateString("receiver.name", 1, 128, "receiver.name", "收货人姓名在1~8之间");
validateRegex("receiver.phone", StrUtil.regphone, "receiver.phone", "收货人手机号格式不正确");
validateString("receiver.address", 1, 256, "receiver.address", "收获地址长度在1~256之间");
}
protected void handleError(Controller c) {
c.renderJson(Result.failed(getErrmsg()));
}
}

View File

@ -4,6 +4,8 @@ import com.cowr.common.Const;
import com.cowr.common.utils.StrUtil;
import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result;
import com.cowr.model.Customer;
import com.cowr.model.CustomerReceiver;
import com.cowr.model.Sysuser;
import com.cowr.service.ssjygl.main.AuthInterceptor;
import com.cowr.ssjygl.system.sysuser.SysuserPKValidator;
@ -15,7 +17,7 @@ import com.jfinal.core.Controller;
/**
* Generated by COWR Tue Jun 25 00:41:56 CST 2019
* TableName: sysuser
* Remarks:
* Remarks:
* PrimaryKey: id
*/
public class SysuserController extends Controller {
@ -27,7 +29,7 @@ public class SysuserController extends Controller {
* data = false
*/
@Before(SysuserPKValidator.class)
public void checkExistsByPk(){
public void checkExistsByPk() {
Sysuser model = getModel(Sysuser.class, "", true); // 忽略不在model中的字段
renderJson(SysuserSyncService.me.checkExistsByPk(model));
}
@ -36,7 +38,7 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserValidator.class)
public void save(){
public void save() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -52,7 +54,7 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserPKValidator.class)
public void del(){
public void del() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -68,7 +70,7 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserPKValidator.class)
public void restore(){
public void restore() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -84,7 +86,7 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserValidator.class)
public void edit(){
public void edit() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -99,9 +101,9 @@ public class SysuserController extends Controller {
/**
* sysuser
*/
public void find(){
PageParam pp = getBean(PageParam.class, "", true);
String name = get("name", "");
public void find() {
PageParam pp = getBean(PageParam.class, "", true);
String name = get("name", "");
String phone = get("phone", "");
Integer del = getInt("del", Const.LOGIC_DEL_VALID); // 默认显示未删除的
Integer type = getInt("type");
@ -113,13 +115,13 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserPKValidator.class)
public void findByPk(){
public void findByPk() {
Sysuser model = getModel(Sysuser.class, "", true); // 忽略不在model中的字段
renderJson(SysuserSyncService.me.findByPk(model));
}
@Clear(AuthInterceptor.class)
public void login(){
public void login() {
String name = get("name", "").trim();
String phone = get("phone", "").trim();
String password = get("password", "");
@ -130,13 +132,13 @@ public class SysuserController extends Controller {
/**
*
*/
public void checkPhone(){
public void checkPhone() {
String phone = get("phone", "");
// 先判断手机号是否符合格式要求,然后再判断数据库是否已经存在
if(!StrUtil.isPhone(phone)){
if (!StrUtil.isPhone(phone)) {
renderJson(Result.success(false));
}else{
} else {
renderJson(Result.success(SysuserSyncService.me.checkPhone(phone)));
}
}
@ -144,7 +146,7 @@ public class SysuserController extends Controller {
/**
*
*/
public void modpwd(){
public void modpwd() {
String token = get("token", "");
String oldpwd = get("oldpwd", "");
String newpwd = get("newpwd", "");
@ -156,7 +158,7 @@ public class SysuserController extends Controller {
* sysuser
*/
@Before(SysuserPKValidator.class)
public void resetpwd(){
public void resetpwd() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
if (tokenuser == null) {
@ -167,4 +169,18 @@ public class SysuserController extends Controller {
Sysuser model = getModel(Sysuser.class, "", true); // 忽略不在model中的字段
renderJson(SysuserSyncService.me.resetPassword(model, tokenuser));
}
/**
*
*/
@Clear(AuthInterceptor.class)
@Before(RegisterUserValidator.class)
public void register() {
// 两个密码前端验证,提交一个就可以了
Sysuser sysuser = getModel(Sysuser.class, "sysuser", true); // 忽略不在model中的字段
Customer customer = getModel(Customer.class, "customer", true);
CustomerReceiver receiver = getModel(CustomerReceiver.class, "receiver", true);
renderJson(SysuserSyncService.me.register(sysuser, customer, receiver));
}
}

View File

@ -2,8 +2,8 @@ package com.cowr.service.ssjygl.system.sysuser;
import com.cowr.common.Const;
import com.cowr.common.base.BaseModel;
import com.cowr.common.base.BaseService;
import com.cowr.common.enums.Enums;
import com.cowr.common.enums.RoleEnum;
import com.cowr.common.enums.UserTypeEnum;
import com.cowr.common.view.PageParam;
import com.cowr.common.view.Result;
@ -94,7 +94,7 @@ public class SysuserSyncService extends BaseSyncService {
*/
public boolean isTreasurer(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(501);
return roleid.equals(RoleEnum.TREASURER.getRoleid());
}
/**
@ -106,12 +106,12 @@ public class SysuserSyncService extends BaseSyncService {
*/
public boolean isPresident(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(500);
return roleid.equals(RoleEnum.PRESIDENT.getRoleid());
}
public boolean isPresidentView(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(502);
return roleid.equals(RoleEnum.PRESIDENTVIEW.getRoleid());
}
/**
@ -122,7 +122,7 @@ public class SysuserSyncService extends BaseSyncService {
*/
public boolean isTrancoAdmin(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(201);
return roleid.equals(RoleEnum.TRANCOADMIN.getRoleid());
}
/**
@ -133,12 +133,12 @@ public class SysuserSyncService extends BaseSyncService {
*/
public boolean isTrancoDriver(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(202);
return roleid.equals(RoleEnum.TRANCODRIVER.getRoleid());
}
public boolean isConfigAdmin(Integer roleid) {
if (roleid == null) return false;
return roleid.equals(99);
return roleid.equals(RoleEnum.DEVOPS.getRoleid());
}
/**
@ -235,13 +235,7 @@ public class SysuserSyncService extends BaseSyncService {
@Override
public boolean run() throws SQLException {
try {
boolean ret = model.save();
if (!ret) {
return false;
}
return SyncTaskService.me.save(new SyncTask().addSaveData(model))
return model.save() && SyncTaskService.me.save(new SyncTask().addSaveData(model))
&& ModifyLogService.me.save(model, null, Enums.DataOpType.SAVE.getId(), tokenuser);
}catch (Exception e){
log.error(e.getMessage(), e);
@ -623,4 +617,58 @@ public class SysuserSyncService extends BaseSyncService {
return Db.paginate(pp.getPage(), pp.getSize(), "select * ", sqlbuf.toString(), paraList.toArray());
}
public Result register(Sysuser sysuser, Customer customer, CustomerReceiver receiver){
if(sysuser.checkDuplicate("phone")){
return Result.failedstr("手机号 %s 已存在", sysuser.getPhone());
}
if(customer.checkDuplicate("name", "texpayer_name", "texpayer_num", "bank_account")){
return Result.failed("用户已存在");
}
sysuser.setType(UserTypeEnum.CUSTOMER.getTypeid());
sysuser.setPassword(getPwdMD5(sysuser.getPhone(), sysuser.getPassword()));
customer.setName(customer.getTexpayerName());
boolean ret = Db.tx(new IAtom() {
@Override
public boolean run() {
try{
boolean ret = customer.save();
if(!ret){
log.debug("客户信息保存失败");
return false;
}
sysuser.setEntityId(customer.getId());
sysuser.setRole(RoleEnum.CUSTOMER.getRoleid());
receiver.setCustomerId(customer.getId());
ret = sysuser.save() && receiver.save();
if(!ret){
log.debug("用户或者收获信息保存失败");
return false;
}
SyncTask synctask = new SyncTask();
synctask.addSaveData(sysuser);
synctask.addSaveData(customer);
synctask.addSaveData(receiver);
return SyncTaskService.me.save(synctask);
}catch (Exception e){
log.error(e.getMessage(), e);
}
return false;
}
});
return ret ? Result.success("注册成功") : Result.failed("注册失败");
}
}

View File

@ -3,6 +3,11 @@ jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx
user=ssjy_xsx
password=Ssjy_xs_890
# mysql
#jdbcUrl=jdbc:mysql://192.168.1.165:3306/ssjy_xsx_service_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true
#user=root
#password=Local_1
# redis
redis.basekey = ssjcgl_xsx_dev
redis.ip=r-wz9168ab2f2f7ec4pd.redis.rds.aliyuncs.com