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