Add customer ID2
This commit is contained in:
parent
bf25b7489f
commit
5c843c837c
@ -1,8 +1,8 @@
|
||||
package com.pudonghot.ambition.crm.auth;
|
||||
|
||||
import lombok.val;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import me.chyxion.tigon.shiro.AuthCallback;
|
||||
import me.chyxion.tigon.shiro.model.AuthUser;
|
||||
@ -43,23 +43,23 @@ public class AuthCallbackSupport implements AuthCallback {
|
||||
public void onSuccessfulLogin(AuthenticationToken token,
|
||||
AuthenticationInfo info, Subject subject) {
|
||||
|
||||
WebSubject ws = (WebSubject) subject;
|
||||
Session session = ws.getSession(false);
|
||||
HttpServletRequest request = (HttpServletRequest) ws.getServletRequest();
|
||||
val ws = (WebSubject) subject;
|
||||
val session = ws.getSession(false);
|
||||
val request = (HttpServletRequest) ws.getServletRequest();
|
||||
|
||||
AuthUser<ViewModel<User>> authUser = new AuthUser<ViewModel<User>>();
|
||||
String ip = HttpServletRequestUtils.getClientIP(request);
|
||||
val authUser = new AuthUser<ViewModel<User>>();
|
||||
val ip = HttpServletRequestUtils.getClientIP(request);
|
||||
authUser.setAttr("ip", ip);
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
val userAgent = request.getHeader("User-Agent");
|
||||
authUser.setAttr("userAgent", userAgent);
|
||||
ViewModel<User> user = (ViewModel<User>) ((AuthInfo) info).getExtra();
|
||||
final String userId = user.getData().getId();
|
||||
val user = (ViewModel<User>) ((AuthInfo) info).getExtra();
|
||||
val userId = user.getData().getId();
|
||||
authUser.setUserId(userId);
|
||||
authUser.setUser(user);
|
||||
log.info("Save Auth User [{}] To Session [{}].", user, session.getId());
|
||||
authUser.save(session);
|
||||
|
||||
AuthLogFormForCreate alForm = new AuthLogFormForCreate();
|
||||
val alForm = new AuthLogFormForCreate();
|
||||
alForm.setUserId(userId);
|
||||
alForm.setIp(ip);
|
||||
alForm.setUserAgent(userAgent);
|
||||
@ -68,7 +68,6 @@ public class AuthCallbackSupport implements AuthCallback {
|
||||
authLogService.create(alForm);
|
||||
// HttpServletResponse response = (HttpServletResponse) ws.getServletResponse();
|
||||
log.info("User [{}] Logined.", userId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,14 +75,16 @@ public class AuthCallbackSupport implements AuthCallback {
|
||||
*/
|
||||
@Override
|
||||
public void onFailedLogin(AuthenticationToken token,
|
||||
AuthenticationException ae, Subject subject) {
|
||||
String loginId = (String) token.getPrincipal();
|
||||
String password = new String((char[]) token.getCredentials());
|
||||
AuthenticationException ae,
|
||||
Subject subject) {
|
||||
|
||||
val loginId = (String) token.getPrincipal();
|
||||
val password = new String((char[]) token.getCredentials());
|
||||
log.info("Login Id [{}] Password [{}] Login Failed.", loginId, password);
|
||||
|
||||
WebSubject ws = (WebSubject) subject;
|
||||
HttpServletRequest request = (HttpServletRequest) ws.getServletRequest();
|
||||
AuthFailedLogFormForCreate form = new AuthFailedLogFormForCreate();
|
||||
val ws = (WebSubject) subject;
|
||||
val request = (HttpServletRequest) ws.getServletRequest();
|
||||
val form = new AuthFailedLogFormForCreate();
|
||||
form.setLoginId(loginId);
|
||||
form.setPassword(password);
|
||||
form.setIp(HttpServletRequestUtils.getClientIP(request));
|
||||
@ -95,9 +96,9 @@ public class AuthCallbackSupport implements AuthCallback {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void beforeLogout(Subject subject) {
|
||||
final WebSubject ws = (WebSubject) subject;
|
||||
final Session session = ws.getSession(false);
|
||||
public void beforeLogout(final Subject subject) {
|
||||
val ws = (WebSubject) subject;
|
||||
val session = ws.getSession(false);
|
||||
if (session != null) {
|
||||
log.warn("Session [{}] Logout.", session);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.pudonghot.ambition.crm.auth;
|
||||
|
||||
import java.util.*;
|
||||
import lombok.val;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import me.chyxion.tigon.shiro.AuthRealm;
|
||||
@ -31,7 +32,7 @@ public class AuthRealmSupport extends AuthRealm {
|
||||
@Override
|
||||
public Credential credential(Object principal) {
|
||||
Credential credential = null;
|
||||
final ViewModel<User> userViewModel =
|
||||
val userViewModel =
|
||||
userService.findViewModel(new Search(User.EMPLOYEE_ID, principal));
|
||||
if (userViewModel != null) {
|
||||
User admin = userViewModel.getData();
|
||||
@ -60,12 +61,12 @@ public class AuthRealmSupport extends AuthRealm {
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> roles(Object principal) {
|
||||
final User user = userService.find(new Search(User.EMPLOYEE_ID, principal));
|
||||
final List<String> roles = new ArrayList<>(4);
|
||||
val user = userService.find(new Search(User.EMPLOYEE_ID, principal));
|
||||
val roles = new ArrayList<String>(4);
|
||||
if (user.isAdmin()) {
|
||||
roles.add(User.ROLE_ADMIN);
|
||||
}
|
||||
final String account = user.getAccount();
|
||||
val account = user.getAccount();
|
||||
if (ArrayUtils.contains(new String[] {User.ROLE_LELI, User.ROLE_CHYXION}, account)) {
|
||||
roles.add(account);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pudonghot.ambition.crm.controller;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.io.IOException;
|
||||
@ -87,7 +88,7 @@ public abstract class AbstractBaseController {
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalStateException(
|
||||
"Read Stream Bytes Error Caused", e);
|
||||
"Read stream bytes error caused", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ public abstract class AbstractBaseController {
|
||||
search.limit(limit);
|
||||
}
|
||||
if (StringUtils.isNotBlank(strSearch)) {
|
||||
final Search orSearch = new Search();
|
||||
val orSearch = new Search();
|
||||
for (final String col : searchCols()) {
|
||||
orSearch.or(new Search().like(col, decodeLike(strSearch)));
|
||||
}
|
||||
@ -203,15 +204,16 @@ public abstract class AbstractBaseController {
|
||||
"Invalid criteria [" + strCriteria + "]", e);
|
||||
}
|
||||
|
||||
for (final Object[] criterion : criteria) {
|
||||
for (val criterion : criteria) {
|
||||
if (criterion.length == 3) {
|
||||
final String field = (String) criterion[0];
|
||||
if (StringUtils.isNotBlank(field)) {
|
||||
final Pair<String, Class<?>> colProp = criterionCol(field);
|
||||
final String col = colProp.getKey();
|
||||
val colProp = criterionCol(field);
|
||||
val col = colProp.getKey();
|
||||
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
final String op = (String) criterion[1];
|
||||
final Object val = TypeUtils.castToJavaBean(criterion[2], colProp.getValue());
|
||||
val op = (String) criterion[1];
|
||||
val val = TypeUtils.castToJavaBean(criterion[2], colProp.getValue());
|
||||
if (StringUtils.isNotBlank(op) &&
|
||||
val != null && val instanceof String ?
|
||||
StringUtils.isNotBlank((String) val) : true) {
|
||||
@ -274,12 +276,12 @@ public abstract class AbstractBaseController {
|
||||
}
|
||||
|
||||
final JSONObject joFilters = filters(strFilters);
|
||||
for (Map.Entry<String, Object> filter : joFilters.entrySet()) {
|
||||
final String field = filter.getKey();
|
||||
final Pair<String, Class<?>> colProp = filterCol(filter.getKey());
|
||||
for (val filter : joFilters.entrySet()) {
|
||||
val field = filter.getKey();
|
||||
val colProp = filterCol(filter.getKey());
|
||||
if (colProp != null) {
|
||||
final String col = colProp.getKey();
|
||||
final Object filterVal = filter.getValue();
|
||||
val col = colProp.getKey();
|
||||
val filterVal = filter.getValue();
|
||||
if (filterVal != null) {
|
||||
if (onSearch(search, col, filterVal)) {
|
||||
continue;
|
||||
@ -308,12 +310,12 @@ public abstract class AbstractBaseController {
|
||||
throw new IllegalStateException(
|
||||
"Invalid orders params [" + strOrders + "]", e);
|
||||
}
|
||||
for (final Object objOrder : jaOrders) {
|
||||
final JSONObject joSorter = (JSONObject) objOrder;
|
||||
for (val objOrder : jaOrders) {
|
||||
val joSorter = (JSONObject) objOrder;
|
||||
if (!joSorter.isEmpty()) {
|
||||
final Map.Entry<String, Object> sortEntry =
|
||||
val sortEntry =
|
||||
joSorter.entrySet().iterator().next();
|
||||
final String col = orderCol(sortEntry.getKey());
|
||||
val col = orderCol(sortEntry.getKey());
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
final String dir = (String) sortEntry.getValue();
|
||||
if ("asc".equalsIgnoreCase(dir)) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pudonghot.ambition.crm.controller;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.*;
|
||||
import javax.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -41,7 +42,7 @@ public class CustomerController
|
||||
extends BaseQueryController<Customer> {
|
||||
|
||||
private static final List<String> SEARCH_COLS = Arrays.asList(
|
||||
"customer.id",
|
||||
"customer.id2",
|
||||
"customer.name",
|
||||
"customer.city",
|
||||
"customer.country_code",
|
||||
@ -124,8 +125,8 @@ public class CustomerController
|
||||
@RequestParam(value = "orders", required = false)
|
||||
final String orders) {
|
||||
|
||||
final Search search = new Search();
|
||||
User user = getUser().getData();
|
||||
val search = new Search();
|
||||
val user = getUser().getData();
|
||||
search.setAttr(User.ACCOUNT, user.getAccount());
|
||||
|
||||
// search year
|
||||
|
@ -16,6 +16,7 @@ import com.pudonghot.ambition.crm.mapper.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.pudonghot.ambition.crm.util.CSVUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import com.pudonghot.ambition.crm.common.Constants;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import com.pudonghot.ambition.crm.service.UserService;
|
||||
@ -237,7 +238,7 @@ public class CustomerServiceSupport
|
||||
val lastIssue = model.getLastIssue();
|
||||
if (StringUtils.isNotBlank(lastIssue)) {
|
||||
val issueParts = lastIssue.split(SPLITTER);
|
||||
CustomerIssue issue = new CustomerIssue();
|
||||
val issue = new CustomerIssue();
|
||||
issue.setId(issueParts[0]);
|
||||
issue.setIssue(issueParts[1]);
|
||||
issue.setDateCreated(new Date(Long.parseLong(issueParts[2])));
|
||||
@ -278,20 +279,23 @@ public class CustomerServiceSupport
|
||||
log.info("Blank customer id found, ignore.");
|
||||
return;
|
||||
}
|
||||
customer.setId(customerId);
|
||||
|
||||
customer.setId2(customerId);
|
||||
customer.setName(record.get(1).trim());
|
||||
customer.setCountryCode(record.get(2).trim());
|
||||
customer.setState(record.get(3).trim());
|
||||
customer.setCity(record.get(4).trim());
|
||||
customer.setMs(record.get(5).trim());
|
||||
customer.setRegion(record.get(6).trim());
|
||||
val employeeId = StringUtils.defaultIfBlank(record.get(7).trim(), null);
|
||||
|
||||
val employeeId = StringUtils.defaultIfBlank(
|
||||
record.get(7).trim(), null);
|
||||
customer.setSalesperson(employeeId);
|
||||
log.info("Customer [{}] read.", customer);
|
||||
|
||||
createUserIfNotExist(operator, employeeId, now);
|
||||
createOrUpdateCustomer(operator, customer, now);
|
||||
createOrUpdateCustomerPermissions(operator, customerId, record.get(8), now);
|
||||
createOrUpdateCustomerPermissions(operator, customer, record.get(8), now);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -325,7 +329,7 @@ public class CustomerServiceSupport
|
||||
user.setAccount(employeeId);
|
||||
user.setEmployeeId(employeeId);
|
||||
|
||||
val password = idSeq.get();
|
||||
val password = RandomStringUtils.randomAlphanumeric(8);
|
||||
user.setPassword(password);
|
||||
user.setGender(Constants.GENDER_MALE);
|
||||
user.setEnabled(true);
|
||||
@ -340,14 +344,17 @@ public class CustomerServiceSupport
|
||||
|
||||
private void createOrUpdateCustomer(final String operator, final Customer customer, final Date date) {
|
||||
log.info("User [{}] create or update customer [{}].", operator, customer);
|
||||
val customerId = customer.getId();
|
||||
val ms = customer.getMs();
|
||||
|
||||
val customerExisted = mapper.find(customerId);
|
||||
val customerExisted = mapper.find(
|
||||
new Search(Customer.ID2, customer.getId2())
|
||||
.eq(Customer.COUNTRY_CODE, customer.getCountryCode()));
|
||||
|
||||
if (customerExisted != null) {
|
||||
log.info("Customer existed [{}] found, update.", customerExisted);
|
||||
customer.setId(customerExisted.getId());
|
||||
// basic props
|
||||
customerExisted.setName(customer.getName());
|
||||
// customerExisted.setName(customer.getName());
|
||||
customerExisted.setCountryCode(customer.getCountryCode());
|
||||
customerExisted.setState(customer.getState());
|
||||
customerExisted.setCity(customer.getCity());
|
||||
@ -364,6 +371,7 @@ public class CustomerServiceSupport
|
||||
mapper.update(customerExisted);
|
||||
}
|
||||
else {
|
||||
customer.setId(idSeq.get());
|
||||
customer.setEnabled(true);
|
||||
customer.setCreatedBy(operator);
|
||||
customer.setDateCreated(date);
|
||||
@ -371,6 +379,7 @@ public class CustomerServiceSupport
|
||||
mapper.insert(customer);
|
||||
}
|
||||
|
||||
val customerId = customer.getId();
|
||||
// no issues
|
||||
if (customerIssueMapper.count(
|
||||
new Search(CustomerIssue.CUSTOMER_ID, customerId)
|
||||
@ -389,7 +398,8 @@ public class CustomerServiceSupport
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomerPermissions(final String operator, final String customerId, final String strAccounts, Date date) {
|
||||
private void createOrUpdateCustomerPermissions(final String operator, final Customer customer, final String strAccounts, Date date) {
|
||||
val customerId = customer.getId();
|
||||
log.info("User [{}] create or update customer [{}] permissions [{}].", operator, customerId, strAccounts);
|
||||
|
||||
if (StringUtils.isNotBlank(strAccounts)) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pudonghot.ambition.crm.service.support;
|
||||
|
||||
import lombok.val;
|
||||
import java.util.Date;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
@ -51,10 +52,9 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public void importCSV(final String operator, final InputStream csvIn) {
|
||||
val now = new Date();
|
||||
|
||||
final Date now = new Date();
|
||||
|
||||
final ImportRecord importRecord = new ImportRecord();
|
||||
val importRecord = new ImportRecord();
|
||||
importRecord.setId(idSeq.get());
|
||||
importRecord.setType(ImportRecord.TYPE_YTD_SALES);
|
||||
importRecord.setCompleted(false);
|
||||
@ -62,6 +62,7 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
importRecord.setEnabled(true);
|
||||
importRecord.setCreatedBy(operator);
|
||||
importRecord.setDateCreated(now);
|
||||
|
||||
try {
|
||||
CSVUtils.eachRecord(csvIn, CSVUtils.GBK, new CSVUtils.RecordReader() {
|
||||
private final CustomerYearToDateSale customerYtdSale =
|
||||
@ -89,17 +90,26 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
*/
|
||||
@Override
|
||||
public void read(final CSVRecord record) {
|
||||
final String customerId = StringUtils.trim(record.get(0));
|
||||
if (StringUtils.isBlank(customerId)) {
|
||||
log.info("Blank customer id found, ignore.");
|
||||
val customerName = StringUtils.trim(record.get(1));
|
||||
if (StringUtils.isBlank(customerName)) {
|
||||
log.warn("Record [{}] blank customer name found, ignore.", record);
|
||||
return;
|
||||
}
|
||||
|
||||
val customer = customerMapper.find(
|
||||
new Search(Customer.NAME, customerName));
|
||||
if (customer == null) {
|
||||
log.warn("No customer [{}] found, ignore.", customerName);
|
||||
return;
|
||||
}
|
||||
|
||||
val customerId = customer.getId();
|
||||
customerYtdSale.setCustomerId(customerId);
|
||||
customerYtdSale.setYear(StringUtils.trim(record.get(3)));
|
||||
customerYtdSale.setYtdSale(Long.parseLong(StringUtils.trim(record.get(6)).replace(",", "")));
|
||||
|
||||
// update date added
|
||||
final String strDateAdded = StringUtils.trim(record.get(5));
|
||||
val strDateAdded = StringUtils.trim(record.get(5));
|
||||
if (StringUtils.isNotBlank(strDateAdded)) {
|
||||
log.info("Update customer [{}] date added [{}].", customerId, strDateAdded);
|
||||
Date dateAdded = null;
|
||||
@ -112,8 +122,8 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
catch (ParseException e) {
|
||||
log.warn("Parse date [{}] error caused, ignore.", strDateAdded, e);
|
||||
}
|
||||
|
||||
if (dateAdded != null) {
|
||||
final Customer customer = customerMapper.find(customerId);
|
||||
customer.setDateAdded(dateAdded);
|
||||
customer.setUpdatedBy(operator);
|
||||
customer.setDateUpdated(now);
|
||||
@ -126,6 +136,7 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
createOrUpdateCustomerYTDSale(operator, customerYtdSale, now);
|
||||
}
|
||||
}, true);
|
||||
|
||||
// update customer's status
|
||||
customerPropertyService.initSystemStatus(operator);
|
||||
customerMapper.listStatusSleeping().forEach(customer -> {
|
||||
@ -162,10 +173,14 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomerYTDSale(final String operator, final CustomerYearToDateSale customerYtdSale, final Date date) {
|
||||
private void createOrUpdateCustomerYTDSale(
|
||||
final String operator,
|
||||
final CustomerYearToDateSale customerYtdSale,
|
||||
final Date date) {
|
||||
|
||||
log.info("User [{}] create or update customer YTD sale [{}].", operator, customerYtdSale);
|
||||
|
||||
final CustomerYearToDateSale customerYtdSaleExisted =
|
||||
val customerYtdSaleExisted =
|
||||
mapper.find(new Search(CustomerYearToDateSale.CUSTOMER_ID,
|
||||
customerYtdSale.getCustomerId())
|
||||
.eq(CustomerYearToDateSale.YEAR,
|
||||
|
@ -2,12 +2,11 @@ package com.pudonghot.ambition.crm.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
import java.util.Date;
|
||||
import me.chyxion.tigon.model.M3;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.mybatis.Transient;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
@ -25,6 +24,7 @@ public class Customer extends M3<String, String> {
|
||||
// Properties
|
||||
private String salesperson;
|
||||
private Date dateAdded;
|
||||
private String id2;
|
||||
private String name;
|
||||
private String countryCode;
|
||||
private String state;
|
||||
|
@ -8,7 +8,7 @@ export default BaseEditRoute.extend({
|
||||
|
||||
me.set('breadcrumbs',
|
||||
[{route: 'customer.list', params: 1, text: 'Customers'},
|
||||
{text: 'Edit Customer [' + model.id + ']'}]);
|
||||
{text: 'Edit Customer [' + model.id2 + ']'}]);
|
||||
|
||||
if (model.applications) {
|
||||
let selected = model.applications.split(String.fromCharCode(0x1d));
|
||||
|
@ -9,7 +9,7 @@ export default BaseEditRoute.extend({
|
||||
|
||||
me.set('breadcrumbs',
|
||||
[{route: 'customer.list', params: 1, text: 'Customers'},
|
||||
{text: 'Show Customer [' + model.id + ']'}]);
|
||||
{text: 'Show Customer [' + model.id2 + ']'}]);
|
||||
|
||||
if (model.applications) {
|
||||
let selected = model.applications.split(String.fromCharCode(0x1d));
|
||||
|
@ -154,7 +154,7 @@
|
||||
{{#if tableOptions.showId}}
|
||||
<td>
|
||||
{{#link-to 'customer.show' it.id title='Show Customer'}}
|
||||
{{it.id}}
|
||||
{{it.id2}}
|
||||
{{/link-to}}
|
||||
</td>
|
||||
{{/if}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user