CMS增加号码别名
This commit is contained in:
parent
426bfc3b62
commit
01057d6ce6
@ -0,0 +1,35 @@
|
||||
package com.pudonghot.yo.cms.controller;
|
||||
|
||||
import com.wacai.tigon.form.FormList;
|
||||
import com.pudonghot.yo.model.domain.PhoneAlias;
|
||||
import com.wacai.tigon.web.annotation.FilterCol;
|
||||
import com.wacai.tigon.web.annotation.ListApi;
|
||||
import com.wacai.tigon.web.annotation.OrderCol;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.wacai.tigon.web.controller.BaseCrudController;
|
||||
import com.pudonghot.yo.cms.form.update.FormUpdatePhoneAlias;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneAlias;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@ListApi(searchCols = {
|
||||
PhoneAlias.NOTE
|
||||
},
|
||||
orderCols = {
|
||||
@OrderCol(PhoneAlias.CREATED_TIME)
|
||||
},
|
||||
filterCols = {
|
||||
@FilterCol(param = PhoneAlias.CREATED_BY, type = String.class),
|
||||
})
|
||||
@Controller
|
||||
@RequestMapping("/cms/api/phone-alias")
|
||||
public class PhoneAliasController
|
||||
extends BaseCrudController<Integer,
|
||||
PhoneAlias,
|
||||
FormList,
|
||||
FormCreatePhoneAlias,
|
||||
FormUpdatePhoneAlias> {
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.pudonghot.yo.cms.form.create;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import com.wacai.tigon.format.annotation.Trim;
|
||||
import com.pudonghot.yo.cms.form.BaseCreateForm;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class FormCreatePhoneAlias extends BaseCreateForm {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Trim
|
||||
@NotBlank
|
||||
private String phone;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.pudonghot.yo.cms.form.update;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import com.pudonghot.yo.cms.form.BaseUpdateForm;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class FormUpdatePhoneAlias extends BaseUpdateForm {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.pudonghot.yo.cms.service;
|
||||
|
||||
import com.pudonghot.yo.model.domain.PhoneAlias;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneAlias;
|
||||
import com.pudonghot.yo.cms.form.update.FormUpdatePhoneAlias;
|
||||
import com.wacai.tigon.service.BaseCrudByFormService;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
public interface PhoneAliasService
|
||||
extends BaseCrudByFormService<Integer,
|
||||
PhoneAlias,
|
||||
FormCreatePhoneAlias,
|
||||
FormUpdatePhoneAlias> {
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package com.pudonghot.yo.cms.service.impl;
|
||||
|
||||
import lombok.val;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.springframework.util.Assert;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.pudonghot.yo.model.domain.PhoneAlias;
|
||||
import com.pudonghot.yo.mapper.PhoneAliasMapper;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import com.pudonghot.yo.mapper.CallDetailRecordMapper;
|
||||
import com.pudonghot.yo.cms.service.PhoneAliasService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneAlias;
|
||||
import com.pudonghot.yo.cms.form.update.FormUpdatePhoneAlias;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.wacai.tigon.service.support.BaseCrudByFormServiceSupport;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PhoneAliasServiceImpl
|
||||
extends BaseCrudByFormServiceSupport<Integer,
|
||||
PhoneAlias,
|
||||
FormCreatePhoneAlias,
|
||||
FormUpdatePhoneAlias,
|
||||
PhoneAliasMapper>
|
||||
implements PhoneAliasService {
|
||||
|
||||
@Value("${yo.cms.phone-alias.length:6}")
|
||||
private int aliasLength;
|
||||
@Autowired
|
||||
private CallDetailRecordMapper callDetailRecordMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void validate(final FormCreatePhoneAlias form) {
|
||||
val phone = form.getPhone();
|
||||
if (StringUtils.isNumeric(phone)) {
|
||||
Assert.state(!mapper.exists(new Search(
|
||||
PhoneAlias.TENANT_ID, form.getTenantId())
|
||||
.eq(PhoneAlias.PHONE, phone)), () -> "号码[" + phone + "]已存在");
|
||||
return;
|
||||
}
|
||||
|
||||
val phoneFound = callDetailRecordMapper.findPhoneByConnId(phone);
|
||||
Assert.state(StringUtils.isNotBlank(phoneFound),
|
||||
() -> "No phone of ConnID [" + phone + "] found");
|
||||
form.setPhone(phoneFound);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void beforeCreate(final FormCreatePhoneAlias form, final PhoneAlias model) {
|
||||
String alias = RandomStringUtils.randomNumeric(aliasLength);
|
||||
val tenantId = form.getTenantId();
|
||||
while (mapper.exists(new Search(PhoneAlias.TENANT_ID, tenantId)
|
||||
.eq(PhoneAlias.ALIAS, alias))) {
|
||||
log.debug("Phone alias [{}] exists.", alias);
|
||||
alias = RandomStringUtils.randomNumeric(aliasLength);
|
||||
}
|
||||
model.setAlias(alias);
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@ import com.pudonghot.yo.cms.form.BaseUpdateForm;
|
||||
import com.pudonghot.yo.cms.form.BaseCreateForm;
|
||||
import com.pudonghot.yo.cms.service.PhoneListService;
|
||||
import com.pudonghot.yo.mapper.CallDetailRecordMapper;
|
||||
import com.pudonghot.yo.model.domain.CallDetailRecord;
|
||||
import com.pudonghot.yo.cms.form.FormCreateUploadPhoneList;
|
||||
import com.pudonghot.yo.cms.form.create.FormCreatePhoneList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -66,19 +65,13 @@ public class PhoneListServiceImpl<M extends PhoneList,
|
||||
return new ViewModel<>(null);
|
||||
}
|
||||
|
||||
String findByConnId(final String connId) {
|
||||
val callDetailRecord = callDetailRecordMapper.find(
|
||||
new Search(CallDetailRecord.CONN_ID, connId).limit(1));
|
||||
return callDetailRecord != null ? callDetailRecord.getCalledNumber() : null;
|
||||
}
|
||||
|
||||
List<M> validateNumber(final FormCreatePhoneList form) {
|
||||
val phones = form.getPhone().split("[^\\w]+");
|
||||
val phoneListList = new ArrayList<M>(phones.length);
|
||||
|
||||
for (val phone : phones) {
|
||||
if (!StringUtils.isNumeric(phone)) {
|
||||
val phone2 = findByConnId(phone);
|
||||
val phone2 = callDetailRecordMapper.findPhoneByConnId(phone);
|
||||
Assert.state(StringUtils.isNotBlank(phone2),
|
||||
() -> "通话ID[" + phone + "]未找到拨打记录");
|
||||
phoneListList.add(createModel(form, phone2));
|
||||
@ -122,7 +115,7 @@ public class PhoneListServiceImpl<M extends PhoneList,
|
||||
for (val phone : phones) {
|
||||
String phoneClean;
|
||||
if (!StringUtils.isNumeric(phone)) {
|
||||
val phone2 = findByConnId(phone);
|
||||
val phone2 = callDetailRecordMapper.findPhoneByConnId(phone);
|
||||
if (StringUtils.isNotBlank(phone2)) {
|
||||
phoneClean = phone2;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ spring:
|
||||
max-file-size: 256MB
|
||||
max-request-size: 256MB
|
||||
redis:
|
||||
host: localhost
|
||||
host: 192.168.3.5
|
||||
port: 6379
|
||||
password: 123456
|
||||
|
||||
@ -26,12 +26,12 @@ site:
|
||||
# Datasource
|
||||
yo:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://192.168.3.5/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
username: yoqw
|
||||
password: yoqw_query!
|
||||
freeswitch:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost/fs_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://192.168.3.5/fs_dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
username: freeswitch
|
||||
password: RR!h5IpirsnJ
|
||||
cms:
|
||||
@ -51,11 +51,10 @@ tigon:
|
||||
shiro:
|
||||
cas:
|
||||
server:
|
||||
addr: https://cas.pudong-hot.com
|
||||
addr: https://cas-daily.pudonghot.com
|
||||
client:
|
||||
addr: http://localhost:4200
|
||||
filter-chain: >
|
||||
${site.context-path}/auth/login=anon
|
||||
/=anon
|
||||
/index.html=anon
|
||||
/assets/**=anon
|
||||
@ -64,7 +63,7 @@ tigon:
|
||||
## Dubbo Registry
|
||||
dubbo:
|
||||
registry:
|
||||
address: zookeeper://localhost:2181
|
||||
address: zookeeper://192.168.3.5:2181
|
||||
file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache
|
||||
consumer:
|
||||
check: false
|
||||
|
@ -1,65 +0,0 @@
|
||||
# Server
|
||||
server.port=8080
|
||||
spring.application.name=tigon-codegen
|
||||
spring.jackson.time-zone=GMT+8
|
||||
spring.jackson.serialization.write-dates-as-timestamps=true
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.servlet.multipart.max-file-size=256MB
|
||||
spring.servlet.multipart.max-request-size=256MB
|
||||
|
||||
# Data source
|
||||
tigon.codegen.datasource.url=jdbc:mysql://localhost/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
tigon.codegen.datasource.username=yoqw
|
||||
tigon.codegen.datasource.password=yoqw_query!
|
||||
|
||||
# Code gen
|
||||
tigon.codegen.base-package=com.pudonghot.yo
|
||||
tigon.codegen.default-gen-items=model,form,mapper,service,service-impl,controller
|
||||
tigon.codegen.mapper.cache-enabled=false
|
||||
|
||||
# Model
|
||||
tigon.codegen.table-prefix=br
|
||||
tigon.codegen.model.project-dir=lib/model
|
||||
tigon.codegen.model.base-package=com.pudonghot.yo.model.domain
|
||||
tigon.codegen.model.base-class.name=BaseDomain
|
||||
tigon.codegen.model.base-class.fields=id,active,createdTime,updatedTime,createdBy,updatedBy,note
|
||||
tigon.codegen.model.base-class.full-name=com.pudonghot.yo.model.domain.BaseDomain
|
||||
tigon.codegen.model.base-class.import-required=false
|
||||
|
||||
# Form Create
|
||||
tigon.codegen.form-create.project-dir=cms
|
||||
tigon.codegen.form-create.base-package=com.pudonghot.yo.cms.form.create
|
||||
tigon.codegen.form-create.base-class.name=BaseCreateForm
|
||||
tigon.codegen.form-create.base-class.full-name=com.pudonghot.yo.cms.form.BaseCreateForm
|
||||
tigon.codegen.form-create.base-class.import-required=true
|
||||
|
||||
# Form Update
|
||||
tigon.codegen.form-update.project-dir=cms
|
||||
tigon.codegen.form-update.base-package=com.pudonghot.yo.cms.form.update
|
||||
tigon.codegen.form-update.base-class.name=BaseUpdateForm
|
||||
tigon.codegen.form-update.base-class.full-name=com.pudonghot.yo.cms.form.BaseUpdateForm
|
||||
tigon.codegen.form-update.base-class.import-required=true
|
||||
|
||||
# Mapper
|
||||
tigon.codegen.mapper.project-dir=lib/mapper
|
||||
tigon.codegen.mapper.base-package=com.pudonghot.yo.mapper
|
||||
|
||||
# Service
|
||||
tigon.codegen.service.project-dir=cms
|
||||
tigon.codegen.service.base-package=com.pudonghot.yo.cms.service
|
||||
|
||||
# Service Impl
|
||||
tigon.codegen.service-impl.project-dir=cms
|
||||
tigon.codegen.service-impl.base-package=com.pudonghot.yo.cms.service.impl
|
||||
|
||||
# Controller
|
||||
tigon.codegen.controller.project-dir=cms
|
||||
tigon.codegen.controller.base-package=com.pudonghot.yo.cms.controller
|
||||
|
||||
# Controller
|
||||
tigon.codegen.view.project-dir=web/cms
|
||||
# tigon.codegen.view.base-package=com.pudonghot.yo.cms.controller
|
||||
|
||||
# File Doc
|
||||
tigon.codegen.file-doc.gen=true
|
||||
tigon.codegen.file-doc.author=Donghuang
|
@ -29,6 +29,6 @@ WORK_DIR=$(pwd)
|
||||
echo "Work dir [$WORK_DIR]"
|
||||
|
||||
mvn -T 4C -am -DskipTests -pl lib/tigon/codegen spring-boot:run \
|
||||
-Dspring-boot.run.arguments="--tigon.codegen.work-dir=$WORK_DIR --spring.config.location=$WORK_DIR/codegen.properties --server.port=8088"
|
||||
-Dspring-boot.run.arguments="--tigon.codegen.work-dir=$WORK_DIR --spring.config.location=$WORK_DIR/codegen.yml --server.port=8088"
|
||||
popd
|
||||
|
||||
|
65
codegen.yml
Normal file
65
codegen.yml
Normal file
@ -0,0 +1,65 @@
|
||||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
application:
|
||||
name: tigon-codegen
|
||||
jackson:
|
||||
serialization:
|
||||
fail-on-empty-beans: false
|
||||
write-dates-as-timestamps: true
|
||||
time-zone: GMT+8
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 256MB
|
||||
max-request-size: 256MB
|
||||
tigon:
|
||||
codegen:
|
||||
base-package: com.pudonghot.yo
|
||||
controller:
|
||||
base-package: com.pudonghot.yo.cms.controller
|
||||
project-dir: cms
|
||||
datasource:
|
||||
password: yoqw_query!
|
||||
url: jdbc:mysql://192.168.3.5/yoqw?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||
username: yoqw
|
||||
default-gen-items: model,form,mapper,service,service-impl,controller
|
||||
file-doc:
|
||||
author: Donghuang
|
||||
gen: true
|
||||
form-create:
|
||||
base-class:
|
||||
fields: tenantId,tenantCode
|
||||
full-name: com.pudonghot.yo.cms.form.BaseCreateForm
|
||||
import-required: true
|
||||
name: BaseCreateForm
|
||||
base-package: com.pudonghot.yo.cms.form.create
|
||||
project-dir: cms
|
||||
form-update:
|
||||
base-class:
|
||||
fields: tenantId,tenantCode
|
||||
full-name: com.pudonghot.yo.cms.form.BaseUpdateForm
|
||||
import-required: true
|
||||
name: BaseUpdateForm
|
||||
base-package: com.pudonghot.yo.cms.form.update
|
||||
project-dir: cms
|
||||
mapper:
|
||||
base-package: com.pudonghot.yo.mapper
|
||||
cache-enabled: false
|
||||
project-dir: lib/mapper
|
||||
model:
|
||||
base-class:
|
||||
fields: id,active,createdTime,updatedTime,createdBy,updatedBy,note
|
||||
full-name: com.pudonghot.yo.model.domain.BaseDomain
|
||||
import-required: false
|
||||
name: BaseDomain
|
||||
base-package: com.pudonghot.yo.model.domain
|
||||
project-dir: lib/model
|
||||
service:
|
||||
base-package: com.pudonghot.yo.cms.service
|
||||
project-dir: cms
|
||||
service-impl:
|
||||
base-package: com.pudonghot.yo.cms.service.impl
|
||||
project-dir: cms
|
||||
table-prefix: br
|
||||
view:
|
||||
project-dir: web/cms
|
@ -1,7 +1,10 @@
|
||||
package com.pudonghot.yo.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.val;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.pudonghot.yo.model.domain.CallDetailRecord;
|
||||
import com.pudonghot.yo.model.dbobject.CallDetailReport;
|
||||
@ -31,4 +34,15 @@ public interface CallDetailRecordMapper extends BaseMapper<Integer, CallDetailRe
|
||||
*/
|
||||
List<CallDetailReport> accountReport(
|
||||
@Param("arg") ReqCallDetailRecordAccountReport arg);
|
||||
|
||||
/**
|
||||
* find by conn id
|
||||
*
|
||||
* @param connId conn id
|
||||
* @return cdr
|
||||
*/
|
||||
default String findPhoneByConnId(final String connId) {
|
||||
return findCol(CallDetailRecord.CALLED_NUMBER,
|
||||
new Search(CallDetailRecord.CONN_ID, connId).limit(1));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.pudonghot.yo.mapper;
|
||||
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import com.pudonghot.yo.model.domain.PhoneAlias;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
public interface PhoneAliasMapper extends BaseMapper<Integer, PhoneAlias> {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE mapper PUBLIC
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pudonghot.yo.mapper.PhoneAliasMapper">
|
||||
</mapper>
|
@ -0,0 +1,24 @@
|
||||
package com.pudonghot.yo.mapper;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||
public class PhoneAliasMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
@Autowired
|
||||
private PhoneAliasMapper mapper;
|
||||
@Test
|
||||
public void mapperTest() {
|
||||
mapper.list(new Search().limit(8));
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.pudonghot.yo.model.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.mybatis.NotUpdate;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
/**
|
||||
* @author Donghuang
|
||||
* @date Feb 27, 2021 00:39:15
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Table("br_phone_alias")
|
||||
@FieldNameConstants(prefix = "")
|
||||
public class PhoneAlias extends TenantDomain {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotUpdate
|
||||
private String phone;
|
||||
@NotUpdate
|
||||
private String alias;
|
||||
}
|
@ -14,11 +14,7 @@ import lombok.experimental.FieldNameConstants;
|
||||
@Setter
|
||||
@Table("br_sequence")
|
||||
@FieldNameConstants(prefix = "")
|
||||
public class Sequence extends BaseDomain {
|
||||
@NotUpdate
|
||||
private Integer tenantId;
|
||||
@NotUpdate
|
||||
private String tenantCode;
|
||||
public class Sequence extends TenantDomain {
|
||||
@NotUpdate
|
||||
private String name;
|
||||
@NotUpdate
|
||||
|
@ -31,8 +31,8 @@ public class ConfigProperties implements InitializingBean {
|
||||
private String basePackage;
|
||||
private String tablePrefix;
|
||||
private ItemModel model = new ItemModel();
|
||||
private Item formCreate = new Item();
|
||||
private Item formUpdate = new Item();
|
||||
private ItemModel formCreate = new ItemModel();
|
||||
private ItemModel formUpdate = new ItemModel();
|
||||
private ItemMapper mapper = new ItemMapper();
|
||||
private Item service = new Item();
|
||||
private Item serviceImpl = new Item();
|
||||
|
@ -3,14 +3,12 @@ package com.wacai.tigon.codegen.service.support;
|
||||
import lombok.val;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import com.wacai.tigon.form.FC0;
|
||||
import com.wacai.tigon.form.FU0;
|
||||
import com.wacai.tigon.json.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.stream.Collectors;
|
||||
import com.wacai.tigon.form.FormList;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
@ -119,7 +117,7 @@ public class CodeGenServiceSupport implements CodeGenService, InitializingBean {
|
||||
|
||||
final String baseModelName;
|
||||
final String baseModelFullName;
|
||||
final Collection<String> baseCols;
|
||||
final Collection<String> modelBaseFields;
|
||||
|
||||
// custom super class
|
||||
val modelBaseClass = configProps.getModel().getBaseClass();
|
||||
@ -132,15 +130,13 @@ public class CodeGenServiceSupport implements CodeGenService, InitializingBean {
|
||||
baseModelFullName = modelBaseClass.isImportRequired() ?
|
||||
modelSuperClassImportName : null;
|
||||
|
||||
baseCols = configProps.getModel().getBaseClass().getFields()
|
||||
.stream().map(WordUtils::convertCamelCase)
|
||||
.collect(Collectors.toSet());
|
||||
modelBaseFields = configProps.getModel().getBaseClass().getFields();
|
||||
}
|
||||
else {
|
||||
log.info("No base model specified.");
|
||||
baseModelName = null;
|
||||
baseModelFullName = null;
|
||||
baseCols = Collections.emptyList();
|
||||
modelBaseFields = Collections.emptyList();
|
||||
}
|
||||
|
||||
fmDataModel.put("baseModelFullName", baseModelFullName);
|
||||
@ -157,10 +153,10 @@ public class CodeGenServiceSupport implements CodeGenService, InitializingBean {
|
||||
val col = colIt.next();
|
||||
// col name
|
||||
val colName = ((String) col.get("col")).toLowerCase();
|
||||
log.info("Process model col [{}].", colName);
|
||||
if (!baseCols.contains(colName)) {
|
||||
// prop name
|
||||
val propName = (String) col.get("name");
|
||||
// prop name
|
||||
val propName = (String) col.get("name");
|
||||
log.info("Process model col [{}] field.", colName, propName);
|
||||
if (!modelBaseFields.contains(propName)) {
|
||||
// for setName
|
||||
col.put("Name", StringUtils.capitalize(propName));
|
||||
if ((Boolean) col.get("notNull")) {
|
||||
@ -186,6 +182,10 @@ public class CodeGenServiceSupport implements CodeGenService, InitializingBean {
|
||||
|
||||
fmDataModel.put("idType", idType);
|
||||
fmDataModel.put("cols", colsWithoutBase);
|
||||
fmDataModel.put("fcProps", newPropsWithoutBase(colsWithoutBase,
|
||||
configProps.getFormCreate().getBaseClass().getFields()));
|
||||
fmDataModel.put("fuProps", newPropsWithoutBase(colsWithoutBase,
|
||||
configProps.getFormUpdate().getBaseClass().getFields()));
|
||||
fmDataModel.put("imports", imports);
|
||||
|
||||
fmDataModel.put("ModelName", model);
|
||||
@ -338,6 +338,16 @@ public class CodeGenServiceSupport implements CodeGenService, InitializingBean {
|
||||
genConfig = json.parse(
|
||||
IOUtils.toString(ins, StandardCharsets.UTF_8), GenConfig.class);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> newPropsWithoutBase(final List<Map<String, Object>> baseProps, final Collection<String> baseFields) {
|
||||
val props = new ArrayList<>(baseProps);
|
||||
val it = props.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (baseFields.contains(it.next().get("name"))) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
package ${controllerPkg};
|
||||
|
||||
<#list cols as prop>
|
||||
<#if prop.javaType == 'Date'>
|
||||
import java.util.Date;
|
||||
@ -14,6 +15,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import ${ctrlrTestToolFullName};
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,4 +1,5 @@
|
||||
package ${controllerPkg};
|
||||
|
||||
import ${modelPkg}.${ModelName};
|
||||
import ${formListFullName};
|
||||
import ${formCreatePkg}.FormCreate${ModelName};
|
||||
@ -6,6 +7,7 @@ import ${formUpdatePkg}.FormUpdate${ModelName};
|
||||
import ${baseControllerFullName};
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ${formCreatePkg};
|
||||
<#import "/codegen/commons.ftl" as CodeGen>
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
<#if baseFormCreateFullName?has_content>
|
||||
@ -8,6 +9,7 @@ import ${baseFormCreateFullName};
|
||||
<#list imports as p>
|
||||
import ${p};
|
||||
</#list>
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
@ -15,7 +17,8 @@ ${objDoc}
|
||||
@Setter
|
||||
public class FormCreate${ModelName} extends ${baseFormCreateName} {
|
||||
private static final long serialVersionUID = 1L;
|
||||
<#list cols as prop>
|
||||
|
||||
<#list fcProps as prop>
|
||||
private ${prop.javaType} ${prop.name};
|
||||
</#list>
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package ${formUpdatePkg};
|
||||
<#import "/codegen/commons.ftl" as CodeGen>
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
<#if baseFormUpdateFullName?has_content>
|
||||
@ -8,6 +9,7 @@ import ${baseFormUpdateFullName};
|
||||
<#list imports as p>
|
||||
import ${p};
|
||||
</#list>
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
@ -15,7 +17,8 @@ ${objDoc}
|
||||
@Setter
|
||||
public class FormUpdate${ModelName} extends ${baseFormUpdateName} {
|
||||
private static final long serialVersionUID = 1L;
|
||||
<#list cols as prop>
|
||||
|
||||
<#list fuProps as prop>
|
||||
private ${prop.javaType} ${prop.name};
|
||||
</#list>
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
package ${mapperPkg};
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import ${searchFullName};
|
||||
@ -6,6 +7,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ${mapperPkg};
|
||||
|
||||
import ${baseMapperFullName};
|
||||
import ${modelPkg}.${ModelName};
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,4 +1,5 @@
|
||||
package ${modelPkg};
|
||||
|
||||
<#import "/codegen/commons.ftl" as CodeGen>
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -10,6 +11,7 @@ import ${baseModelFullName};
|
||||
<#list imports as p>
|
||||
import ${p};
|
||||
</#list>
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
@ -19,6 +21,7 @@ ${objDoc}
|
||||
@FieldNameConstants(prefix = "")
|
||||
public class ${ModelName} <#if baseModelName?has_content>extends ${baseModelName} </#if>{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#--
|
||||
// Column Names
|
||||
<#list cols as prop>
|
||||
|
@ -1,4 +1,5 @@
|
||||
package ${serviceImplPkg};
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${modelPkg}.${ModelName};
|
||||
import ${mapperPkg}.${ModelName}Mapper;
|
||||
@ -6,6 +7,7 @@ import ${servicePkg}.${ModelName}Service;
|
||||
import ${formCreatePkg}.FormCreate${ModelName};
|
||||
import ${formUpdatePkg}.FormUpdate${ModelName};
|
||||
import ${baseServiceSupportFullName};
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,8 +1,10 @@
|
||||
package ${servicePkg};
|
||||
|
||||
import ${modelPkg}.${ModelName};
|
||||
import ${formCreatePkg}.FormCreate${ModelName};
|
||||
import ${formUpdatePkg}.FormUpdate${ModelName};
|
||||
import ${baseServiceFullName};
|
||||
|
||||
<#if objDoc?has_content>
|
||||
${objDoc}
|
||||
</#if>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import BaseRoute from '../base';
|
||||
|
||||
export default BaseRoute.extend({
|
||||
perm: 'PERM_VIEW_${permName}_CREATE',
|
||||
breadcrumbs: [{route: '${minusJoinedModelName}.list', text: '${nameCn}列表'}, {text: '创建${nameCn}'}],
|
||||
|
@ -1,4 +1,5 @@
|
||||
import BaseEditRoute from '../base-edit';
|
||||
|
||||
export default BaseEditRoute.extend({
|
||||
perm: 'PERM_VIEW_${permName}_EDIT',
|
||||
afterModel(model) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import BaseListRoute from '../base-list';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
perm: 'PERM_VIEW_${permName}_LIST',
|
||||
breadcrumbs: [{text: '${nameCn}列表'}]
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Service from '../service';
|
||||
|
||||
export default Service.extend({
|
||||
modelName: '${ModelName}',
|
||||
// constraints: { }
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.wacai.tigon.service.support;
|
||||
|
||||
import lombok.val;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.Assert;
|
||||
import com.wacai.tigon.model.ViewModel;
|
||||
@ -29,7 +30,7 @@ public class BaseCrudByFormServiceSupport
|
||||
public ViewModel<Model> create(final FormForCreate form) {
|
||||
log.debug("Create form [{}].", form);
|
||||
validate(form);
|
||||
final Model model = form.copy(modelType);
|
||||
val model = form.copy(modelType);
|
||||
beforeCreate(form, model);
|
||||
return create(model);
|
||||
}
|
||||
@ -41,7 +42,7 @@ public class BaseCrudByFormServiceSupport
|
||||
public ViewModel<Model> update(final FormForUpdate form) {
|
||||
log.debug("Update form [{}].", form);
|
||||
validate(form);
|
||||
final Model model = findValid(form.getId());
|
||||
val model = findValid(form.getId());
|
||||
form.copy(model);
|
||||
beforeUpdate(form, model);
|
||||
return update(model);
|
||||
@ -56,7 +57,7 @@ public class BaseCrudByFormServiceSupport
|
||||
* @return valid model or throw exception
|
||||
*/
|
||||
protected Model findValid(final PrimaryKey id) {
|
||||
final Model model = find(id);
|
||||
val model = find(id);
|
||||
Assert.state(model != null, "No model [" + id + "] found");
|
||||
return model;
|
||||
}
|
||||
|
@ -127,6 +127,12 @@ export default (function() {
|
||||
route: 'phone-greylist.list',
|
||||
icon: 'fa fa-list-alt',
|
||||
text: '电话呼叫灰名单'
|
||||
},
|
||||
{
|
||||
perm: 'PERM_VIEW_PHONE_ALIAS_LIST',
|
||||
route: 'phone-alias.list',
|
||||
icon: 'fa fa-exchange',
|
||||
text: '号码别名'
|
||||
}
|
||||
]
|
||||
}, {
|
||||
|
@ -150,6 +150,10 @@ Router.map(function() {
|
||||
this.route('create');
|
||||
this.route('edit', {path: '/:id/edit'});
|
||||
});
|
||||
this.route('phone-alias', function() {
|
||||
this.route('list');
|
||||
this.route('create');
|
||||
});
|
||||
});
|
||||
|
||||
export default Router;
|
||||
|
11
web/cms/app/routes/phone-alias/create.js
Normal file
11
web/cms/app/routes/phone-alias/create.js
Normal file
@ -0,0 +1,11 @@
|
||||
import BaseRoute from '../base';
|
||||
|
||||
export default BaseRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_ALIAS_CREATE',
|
||||
breadcrumbs: [{route: 'phone-alias.list', text: '号码别名列表'}, {text: '创建号码别名'}],
|
||||
model(params) {
|
||||
return {
|
||||
active: true
|
||||
};
|
||||
}
|
||||
});
|
10
web/cms/app/routes/phone-alias/edit.js
Normal file
10
web/cms/app/routes/phone-alias/edit.js
Normal file
@ -0,0 +1,10 @@
|
||||
import BaseEditRoute from '../base-edit';
|
||||
|
||||
export default BaseEditRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_ALIAS_EDIT',
|
||||
afterModel(model) {
|
||||
this.set('breadcrumbs',
|
||||
[{route: 'phone-alias.list', text: '号码别名列表'},
|
||||
{text: '编辑号码别名[' + model.id + ']'}]);
|
||||
}
|
||||
});
|
6
web/cms/app/routes/phone-alias/list.js
Normal file
6
web/cms/app/routes/phone-alias/list.js
Normal file
@ -0,0 +1,6 @@
|
||||
import BaseListRoute from '../base-list';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
perm: 'PERM_VIEW_PHONE_ALIAS_LIST',
|
||||
breadcrumbs: [{text: '号码别名列表'}]
|
||||
});
|
14
web/cms/app/services/phone-alias/service.js
Normal file
14
web/cms/app/services/phone-alias/service.js
Normal file
@ -0,0 +1,14 @@
|
||||
import Service from '../service';
|
||||
|
||||
export default Service.extend({
|
||||
modelName: 'PhoneAlias',
|
||||
constraints: {
|
||||
phone: {
|
||||
presence: true,
|
||||
length: {
|
||||
minimum: 4,
|
||||
maximum: 36
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
8
web/cms/app/templates/phone-alias/create.hbs
Normal file
8
web/cms/app/templates/phone-alias/create.hbs
Normal file
@ -0,0 +1,8 @@
|
||||
{{#form-content}}
|
||||
<hr />
|
||||
{{form-input name='phone' label='号码'}}
|
||||
{{form-input name='note' label='备注'}}
|
||||
<hr />
|
||||
{{form-footer-buttons type='create'}}
|
||||
{{/form-content}}
|
||||
{{outlet}}
|
9
web/cms/app/templates/phone-alias/edit.hbs
Normal file
9
web/cms/app/templates/phone-alias/edit.hbs
Normal file
@ -0,0 +1,9 @@
|
||||
{{#form-content}}
|
||||
{{form-input type='hidden' name='id'}}
|
||||
{{form-input name='name' label='名称'}}
|
||||
{{form-input-enabled}}
|
||||
{{form-input name='note' label='备注'}}
|
||||
<hr />
|
||||
{{form-footer-buttons type='update'}}
|
||||
{{/form-content}}
|
||||
{{outlet}}
|
90
web/cms/app/templates/phone-alias/list.hbs
Normal file
90
web/cms/app/templates/phone-alias/list.hbs
Normal file
@ -0,0 +1,90 @@
|
||||
<div class="widget-box transparent" style="padding-top: 2px; border: 1px solid #ddd;">
|
||||
{{#grid-header}}
|
||||
{{#has-perm 'PERM_VIEW_PHONE_ALIAS_CREATE'}}
|
||||
<li>
|
||||
{{#link-to 'phone-alias.create'}}
|
||||
<i class="ace-icon fa fa-plus-circle bigger-110 green"></i>
|
||||
新建号码别名
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{/has-perm}}
|
||||
{{/grid-header}}
|
||||
<div class="widget-body">
|
||||
<!-- #section:custom/scrollbar -->
|
||||
<div class="widget-main no-padding">
|
||||
<table class="table table-striped table-bordered table-hover dataTable">
|
||||
<thead class="thin-border-bottom">
|
||||
<tr>
|
||||
<th>
|
||||
别名
|
||||
</th>
|
||||
<th>
|
||||
号码
|
||||
</th>
|
||||
<th>
|
||||
创建人
|
||||
</th>
|
||||
{{#sortable-th name='createdTime'}}
|
||||
创建时间
|
||||
{{/sortable-th}}
|
||||
<th>
|
||||
<i class="ace-icon fa fa-sticky-note-o bigger-110"></i>
|
||||
备注
|
||||
</th>
|
||||
<th>
|
||||
<i class="ace-icon fa fa-exchange bigger-110 hidden-480"></i>
|
||||
{{th-filter name='active'
|
||||
text='状态'
|
||||
dialog-title='状态'
|
||||
options=(array (hash value=true text='启用')
|
||||
(hash value=false text='禁用'))
|
||||
}}
|
||||
</th>
|
||||
<th>
|
||||
<i class="ace-icon fa fa-cogs bigger-110 hidden-480"></i>
|
||||
管理
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each model.data as |it|}}
|
||||
<tr>
|
||||
<td>
|
||||
{{it.alias}}
|
||||
</td>
|
||||
<td>
|
||||
{{it.phone}}
|
||||
</td>
|
||||
<td>
|
||||
{{it.createdBy}}
|
||||
</td>
|
||||
<td>
|
||||
{{moment-format it.createdTime 'YYYY-MM-DD HH:mm:ss'}}
|
||||
</td>
|
||||
<td>
|
||||
{{editable-cell model=it field='note'}}
|
||||
</td>
|
||||
<td>
|
||||
{{status-cell model=it}}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
{{#has-perm 'PERM_VIEW_PHONE_ALIAS_EDIT'}}
|
||||
{{status-toggle-button model=it}}
|
||||
{{/has-perm}}
|
||||
{{#has-perm 'PERM_VIEW_PHONE_ALIAS_DELETE'}}
|
||||
{{#unless it.active}}
|
||||
{{delete-button model=it}}
|
||||
{{/unless}}
|
||||
{{/has-perm}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{pagination-bar}}
|
||||
</div>
|
||||
</div>
|
||||
{{outlet}}
|
Loading…
x
Reference in New Issue
Block a user