add import record
This commit is contained in:
parent
72bca1bef8
commit
52403b094e
@ -0,0 +1,48 @@
|
||||
package com.pudonghot.ambition.crm.controller;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.pudonghot.ambition.crm.model.ImportRecord;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Mar 09, 2017 21:54:00
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RequestMapping("/import-record")
|
||||
public class ImportRecordController
|
||||
extends BaseQueryController<ImportRecord> {
|
||||
|
||||
@RequestMapping("/list")
|
||||
public ViewModel<List<ViewModel<ImportRecord>>> list(
|
||||
@Min(0)
|
||||
@RequestParam(value = "start", defaultValue = "0")
|
||||
final int start,
|
||||
@Min(1)
|
||||
@Max(512)
|
||||
@RequestParam(value = "limit", defaultValue = "64")
|
||||
final int limit,
|
||||
@RequestParam(value = "search", required = false)
|
||||
final String search) {
|
||||
|
||||
return listViewModels(search(start, limit, search, null)
|
||||
.table("r")
|
||||
.desc(ImportRecord.DATE_CREATED));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @return search cols
|
||||
*/
|
||||
protected String[] searchCols() {
|
||||
return new String[] { "r.type", "r.note", "u.name", "u.en_name", "u.account", "u.employee_id" };
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ import me.chyxion.tigon.webmvc.exception.DefaultExceptionResolver;
|
||||
*/
|
||||
@Service
|
||||
@Order(16)
|
||||
public class DbExceptionResolver extends DefaultExceptionResolver {
|
||||
public class CRMExceptionResolver extends DefaultExceptionResolver {
|
||||
|
||||
private static final Map<Class<?>, Pair<Integer, String>>
|
||||
EXCEPTIONS_MAP =
|
||||
@ -24,7 +24,9 @@ public class DbExceptionResolver extends DefaultExceptionResolver {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
put(DuplicateKeyException.class,
|
||||
pair(5039, "Duplicate Key"));
|
||||
pair(5039, "Duplicate key"));
|
||||
put(CVSFileImportingException.class,
|
||||
pair(5060, "CVS file is importing, please wait"));
|
||||
}
|
||||
|
||||
/**
|
@ -0,0 +1,24 @@
|
||||
package com.pudonghot.ambition.crm.exception;
|
||||
|
||||
/**
|
||||
* @author Donghuang <br>
|
||||
* donghuang@wacai.com <br>
|
||||
* Sep 30, 2017 19:16
|
||||
*/
|
||||
public class CVSFileImportingException extends IllegalStateException {
|
||||
public CVSFileImportingException() {
|
||||
}
|
||||
|
||||
public CVSFileImportingException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public CVSFileImportingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CVSFileImportingException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.pudonghot.ambition.crm.service;
|
||||
|
||||
import me.chyxion.tigon.service.BaseCrudService;
|
||||
import com.pudonghot.ambition.crm.model.ImportRecord;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Sep 30, 2017 18:58:21
|
||||
*/
|
||||
public interface ImportRecordService
|
||||
extends BaseCrudService<String, ImportRecord> {
|
||||
}
|
||||
|
@ -8,21 +8,19 @@ import me.chyxion.tigon.model.ViewModel;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import com.pudonghot.ambition.crm.model.*;
|
||||
import me.chyxion.tigon.model.ListResult;
|
||||
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 com.pudonghot.ambition.crm.common.Constants;
|
||||
import com.pudonghot.ambition.crm.service.UserService;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerMapper;
|
||||
import com.pudonghot.ambition.crm.service.CustomerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.pudonghot.ambition.crm.service.CustomerIssueService;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerPropertyMapper;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerPermissionMapper;
|
||||
import com.pudonghot.ambition.crm.form.create.CustomerFormForCreate;
|
||||
import com.pudonghot.ambition.crm.form.update.CustomerFormForUpdate;
|
||||
import me.chyxion.tigon.service.support.BaseCrudByFormServiceSupport;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerYearToDateSaleMapper;
|
||||
import com.pudonghot.ambition.crm.exception.CVSFileImportingException;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
@ -46,6 +44,8 @@ public class CustomerServiceSupport
|
||||
private CustomerPropertyMapper customerPropertyMapper;
|
||||
@Autowired
|
||||
private CustomerYearToDateSaleMapper customerYearToDateSaleMapper;
|
||||
@Autowired
|
||||
private ImportRecordMapper importRecordMapper;
|
||||
|
||||
/**
|
||||
* override find by id with find by search
|
||||
@ -151,137 +151,168 @@ public class CustomerServiceSupport
|
||||
public void importCSV(final String operator, final InputStream csvIn) {
|
||||
|
||||
final Date now = new Date();
|
||||
CSVUtils.eachRecord(csvIn, CSVUtils.GBK, new CSVUtils.RecordReader() {
|
||||
private final Customer customer = new Customer();
|
||||
private final User user = new User();
|
||||
private final CustomerPermission permission = new CustomerPermission();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterParsed() {
|
||||
// disable existed records
|
||||
/*
|
||||
final Map<String, Object> update = new HashMap<>();
|
||||
update.put(Customer.ENABLED, false);
|
||||
update.put(Customer.UPDATED_BY, operator);
|
||||
update.put(Customer.DATE_UPDATED, now);
|
||||
customerPermissionMapper.update(update, (Search) null);
|
||||
*/
|
||||
}
|
||||
final ImportRecord importRecord = new ImportRecord();
|
||||
importRecord.setId(idSeq.get());
|
||||
importRecord.setType(ImportRecord.TYPE_CUSTOMER);
|
||||
importRecord.setCompleted(false);
|
||||
importRecord.setSuccess(false);
|
||||
importRecord.setEnabled(true);
|
||||
importRecord.setCreatedBy(operator);
|
||||
importRecord.setDateCreated(now);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void read(final CSVRecord record) {
|
||||
final String customerId = record.get(0).trim();
|
||||
customer.setId(customerId);
|
||||
try {
|
||||
CSVUtils.eachRecord(csvIn, CSVUtils.GBK, new CSVUtils.RecordReader() {
|
||||
private final Customer customer = new Customer();
|
||||
private final User user = new User();
|
||||
private final CustomerPermission permission = new CustomerPermission();
|
||||
|
||||
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());
|
||||
final String employeeId = record.get(7).trim();
|
||||
customer.setSalesperson(employeeId);
|
||||
log.info("Customer [{}] read.", customer);
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterParsed() {
|
||||
importRecordMapper.insert(importRecord);
|
||||
importRecord.setCompleted(true);
|
||||
importRecord.setUpdatedBy(operator);
|
||||
|
||||
createUserIfNotExist(operator, employeeId, now);
|
||||
createOrUpdateCustomer(operator, customer, now);
|
||||
createOrUpdateCustomerPermissions(operator, customerId, record.get(8), now);
|
||||
}
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
private void createUserIfNotExist(final String operator, final String employeeId, final Date date) {
|
||||
if (userService.find(new Search(User.EMPLOYEE_ID, employeeId)) == null) {
|
||||
user.setId(idSeq.get());
|
||||
user.setName(employeeId);
|
||||
user.setEnName(employeeId);
|
||||
user.setAccount(employeeId);
|
||||
user.setEmployeeId(employeeId);
|
||||
|
||||
final String password = idSeq.get();
|
||||
user.setPassword(password);
|
||||
user.setGender(Constants.GENDER_MALE);
|
||||
user.setEnabled(true);
|
||||
user.setAdmin(false);
|
||||
user.setCreatedBy(operator);
|
||||
user.setDateCreated(date);
|
||||
user.setNote("Init Password: " + password);
|
||||
log.info("User [{}] does not exist, create.", user);
|
||||
userService.create(user);
|
||||
// disable existed records
|
||||
/*
|
||||
final Map<String, Object> update = new HashMap<>();
|
||||
update.put(Customer.ENABLED, false);
|
||||
update.put(Customer.UPDATED_BY, operator);
|
||||
update.put(Customer.DATE_UPDATED, now);
|
||||
customerPermissionMapper.update(update, (Search) null);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomer(final String operator, final Customer customer, final Date date) {
|
||||
log.info("User [{}] create or update customer [{}].", operator, customer);
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void read(final CSVRecord record) {
|
||||
final String customerId = record.get(0).trim();
|
||||
customer.setId(customerId);
|
||||
|
||||
final Customer customerExisted = mapper.find(customer.getId());
|
||||
if (customerExisted != null) {
|
||||
log.info("Customer existed [{}] found, update.", customerExisted);
|
||||
// basic props
|
||||
customerExisted.setName(customer.getName());
|
||||
customerExisted.setCountryCode(customer.getCountryCode());
|
||||
customerExisted.setState(customer.getState());
|
||||
customerExisted.setCity(customer.getCity());
|
||||
customerExisted.setMs(customer.getMs());
|
||||
customerExisted.setRegion(customer.getRegion());
|
||||
customerExisted.setSalesperson(customer.getSalesperson());
|
||||
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());
|
||||
final String employeeId = record.get(7).trim();
|
||||
customer.setSalesperson(employeeId);
|
||||
log.info("Customer [{}] read.", customer);
|
||||
|
||||
// common updated
|
||||
customerExisted.setEnabled(true);
|
||||
customerExisted.setUpdatedBy(operator);
|
||||
customerExisted.setDateUpdated(date);
|
||||
|
||||
log.info("Update customer [{}].", customerExisted);
|
||||
mapper.update(customerExisted);
|
||||
createUserIfNotExist(operator, employeeId, now);
|
||||
createOrUpdateCustomer(operator, customer, now);
|
||||
createOrUpdateCustomerPermissions(operator, customerId, record.get(8), now);
|
||||
}
|
||||
else {
|
||||
customer.setEnabled(true);
|
||||
customer.setCreatedBy(operator);
|
||||
customer.setDateCreated(date);
|
||||
log.info("Create customer [{}].", customer);
|
||||
mapper.insert(customer);
|
||||
|
||||
// --
|
||||
// private methods
|
||||
|
||||
private void createUserIfNotExist(final String operator, final String employeeId, final Date date) {
|
||||
if (userService.find(new Search(User.EMPLOYEE_ID, employeeId)) == null) {
|
||||
user.setId(idSeq.get());
|
||||
user.setName(employeeId);
|
||||
user.setEnName(employeeId);
|
||||
user.setAccount(employeeId);
|
||||
user.setEmployeeId(employeeId);
|
||||
|
||||
final String password = idSeq.get();
|
||||
user.setPassword(password);
|
||||
user.setGender(Constants.GENDER_MALE);
|
||||
user.setEnabled(true);
|
||||
user.setAdmin(false);
|
||||
user.setCreatedBy(operator);
|
||||
user.setDateCreated(date);
|
||||
user.setNote("Init Password: " + password);
|
||||
log.info("User [{}] does not exist, create.", user);
|
||||
userService.create(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomerPermissions(final String operator, final String customerId, final String strAccounts, Date date) {
|
||||
log.info("User [{}] create or update customer [{}] permissions [{}].", operator, customerId, strAccounts);
|
||||
private void createOrUpdateCustomer(final String operator, final Customer customer, final Date date) {
|
||||
log.info("User [{}] create or update customer [{}].", operator, customer);
|
||||
|
||||
if (StringUtils.isNotBlank(strAccounts)) {
|
||||
for (final String account : new HashSet<>(
|
||||
Arrays.asList(strAccounts.trim().split("\\s*,\\s*")))) {
|
||||
final Customer customerExisted = mapper.find(customer.getId());
|
||||
if (customerExisted != null) {
|
||||
log.info("Customer existed [{}] found, update.", customerExisted);
|
||||
// basic props
|
||||
customerExisted.setName(customer.getName());
|
||||
customerExisted.setCountryCode(customer.getCountryCode());
|
||||
customerExisted.setState(customer.getState());
|
||||
customerExisted.setCity(customer.getCity());
|
||||
customerExisted.setMs(customer.getMs());
|
||||
customerExisted.setRegion(customer.getRegion());
|
||||
customerExisted.setSalesperson(customer.getSalesperson());
|
||||
|
||||
if (StringUtils.isNotBlank(account)) {
|
||||
final CustomerPermission permOld = customerPermissionMapper.find(
|
||||
new Search(CustomerPermission.CUSTOMER_ID, customerId)
|
||||
.eq(CustomerPermission.USER_ACCOUNT, account));
|
||||
if (permOld != null) {
|
||||
permOld.setUpdatedBy(operator);
|
||||
permOld.setDateUpdated(date);
|
||||
permOld.setEnabled(true);
|
||||
log.info("Update customer permission [{}].", permOld);
|
||||
customerPermissionMapper.update(permOld);
|
||||
}
|
||||
else {
|
||||
permission.setId(idSeq.get());
|
||||
permission.setCustomerId(customerId);
|
||||
permission.setUserAccount(account);
|
||||
permission.setEnabled(true);
|
||||
permission.setCreatedBy(operator);
|
||||
permission.setDateCreated(date);
|
||||
log.info("Insert customer permission [{}].", permission);
|
||||
customerPermissionMapper.insert(permission);
|
||||
// common updated
|
||||
customerExisted.setEnabled(true);
|
||||
customerExisted.setUpdatedBy(operator);
|
||||
customerExisted.setDateUpdated(date);
|
||||
|
||||
log.info("Update customer [{}].", customerExisted);
|
||||
mapper.update(customerExisted);
|
||||
}
|
||||
else {
|
||||
customer.setEnabled(true);
|
||||
customer.setCreatedBy(operator);
|
||||
customer.setDateCreated(date);
|
||||
log.info("Create customer [{}].", customer);
|
||||
mapper.insert(customer);
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomerPermissions(final String operator, final String customerId, final String strAccounts, Date date) {
|
||||
log.info("User [{}] create or update customer [{}] permissions [{}].", operator, customerId, strAccounts);
|
||||
|
||||
if (StringUtils.isNotBlank(strAccounts)) {
|
||||
for (final String account : new HashSet<>(
|
||||
Arrays.asList(strAccounts.trim().split("\\s*,\\s*")))) {
|
||||
|
||||
if (StringUtils.isNotBlank(account)) {
|
||||
final CustomerPermission permOld = customerPermissionMapper.find(
|
||||
new Search(CustomerPermission.CUSTOMER_ID, customerId)
|
||||
.eq(CustomerPermission.USER_ACCOUNT, account));
|
||||
if (permOld != null) {
|
||||
permOld.setUpdatedBy(operator);
|
||||
permOld.setDateUpdated(date);
|
||||
permOld.setEnabled(true);
|
||||
log.info("Update customer permission [{}].", permOld);
|
||||
customerPermissionMapper.update(permOld);
|
||||
}
|
||||
else {
|
||||
permission.setId(idSeq.get());
|
||||
permission.setCustomerId(customerId);
|
||||
permission.setUserAccount(account);
|
||||
permission.setEnabled(true);
|
||||
permission.setCreatedBy(operator);
|
||||
permission.setDateCreated(date);
|
||||
log.info("Insert customer permission [{}].", permission);
|
||||
customerPermissionMapper.insert(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}, true);
|
||||
importRecord.setSuccess(true);
|
||||
importRecord.setDateUpdated(new Date());
|
||||
log.info("Import customers completed, update import record [{}].", importRecord);
|
||||
importRecordMapper.update(importRecord);
|
||||
}
|
||||
catch (CVSFileImportingException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
importRecord.setSuccess(false);
|
||||
importRecord.setNote(e.getMessage());
|
||||
importRecord.setDateUpdated(new Date());
|
||||
log.info("Import customers error caused, update import record [{}].", importRecord);
|
||||
importRecordMapper.update(importRecord);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,13 @@ import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.pudonghot.ambition.crm.util.CSVUtils;
|
||||
import com.pudonghot.ambition.crm.model.Customer;
|
||||
import com.pudonghot.ambition.crm.model.ImportRecord;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerMapper;
|
||||
import com.pudonghot.ambition.crm.mapper.ImportRecordMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.pudonghot.ambition.crm.model.CustomerYearToDateSale;
|
||||
import me.chyxion.tigon.service.support.BaseCrudByFormServiceSupport;
|
||||
import com.pudonghot.ambition.crm.exception.CVSFileImportingException;
|
||||
import com.pudonghot.ambition.crm.mapper.CustomerYearToDateSaleMapper;
|
||||
import com.pudonghot.ambition.crm.service.CustomerYearToDateSaleService;
|
||||
import com.pudonghot.ambition.crm.form.create.CustomerYearToDateSaleFormForCreate;
|
||||
@ -36,6 +39,8 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
implements CustomerYearToDateSaleService {
|
||||
@Autowired
|
||||
private CustomerMapper customerMapper;
|
||||
@Autowired
|
||||
private ImportRecordMapper importRecordMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -44,58 +49,88 @@ public class CustomerYearToDateSaleServiceSupport
|
||||
public void importCSV(final String operator, final InputStream csvIn) {
|
||||
|
||||
final Date now = new Date();
|
||||
CSVUtils.eachRecord(csvIn, CSVUtils.GBK, new CSVUtils.RecordReader() {
|
||||
private final CustomerYearToDateSale customerYtdSale =
|
||||
new CustomerYearToDateSale();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterParsed() {
|
||||
// disable existed records
|
||||
// final Map<String, Object> update = new HashMap<>();
|
||||
// update.put(CustomerYearToDateSale.ENABLED, false);
|
||||
// update.put(CustomerYearToDateSale.UPDATED_BY, operator);
|
||||
// update.put(CustomerYearToDateSale.DATE_UPDATED, now);
|
||||
// mapper.update(update, (Search) null);
|
||||
}
|
||||
final ImportRecord importRecord = new ImportRecord();
|
||||
importRecord.setId(idSeq.get());
|
||||
importRecord.setType(ImportRecord.TYPE_YTD_SALES);
|
||||
importRecord.setCompleted(false);
|
||||
importRecord.setSuccess(false);
|
||||
importRecord.setEnabled(true);
|
||||
importRecord.setCreatedBy(operator);
|
||||
importRecord.setDateCreated(now);
|
||||
try {
|
||||
CSVUtils.eachRecord(csvIn, CSVUtils.GBK, new CSVUtils.RecordReader() {
|
||||
private final CustomerYearToDateSale customerYtdSale =
|
||||
new CustomerYearToDateSale();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void read(final CSVRecord record) {
|
||||
final String customerId = StringUtils.trim(record.get(0));
|
||||
customerYtdSale.setCustomerId(customerId);
|
||||
customerYtdSale.setYear(StringUtils.trim(record.get(3)));
|
||||
customerYtdSale.setYtdSale(Long.parseLong(StringUtils.trim(record.get(6)).replace(",", "")));
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterParsed() {
|
||||
importRecordMapper.insert(importRecord);
|
||||
importRecord.setCompleted(true);
|
||||
importRecord.setUpdatedBy(operator);
|
||||
|
||||
// update date added
|
||||
final String strDateAdded = StringUtils.trim(record.get(5));
|
||||
if (StringUtils.isNotBlank(strDateAdded)) {
|
||||
log.info("Update customer [{}] date added [{}].", customerId, strDateAdded);
|
||||
Date dateAdded = null;
|
||||
try {
|
||||
dateAdded = DateUtils.parseDate(strDateAdded, "M/d/yyyy");
|
||||
}
|
||||
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);
|
||||
log.info("Update customer [{}] date added.", customer);
|
||||
customerMapper.update(customer);
|
||||
}
|
||||
// disable existed records
|
||||
// final Map<String, Object> update = new HashMap<>();
|
||||
// update.put(CustomerYearToDateSale.ENABLED, false);
|
||||
// update.put(CustomerYearToDateSale.UPDATED_BY, operator);
|
||||
// update.put(CustomerYearToDateSale.DATE_UPDATED, now);
|
||||
// mapper.update(update, (Search) null);
|
||||
}
|
||||
|
||||
log.info("Customer YTD sale [{}] read.", customerYtdSale);
|
||||
createOrUpdateCustomerYTDSale(operator, customerYtdSale, now);
|
||||
}
|
||||
}, true);
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void read(final CSVRecord record) {
|
||||
final String customerId = StringUtils.trim(record.get(0));
|
||||
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));
|
||||
if (StringUtils.isNotBlank(strDateAdded)) {
|
||||
log.info("Update customer [{}] date added [{}].", customerId, strDateAdded);
|
||||
Date dateAdded = null;
|
||||
try {
|
||||
dateAdded = DateUtils.parseDate(strDateAdded, "M/d/yyyy");
|
||||
}
|
||||
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);
|
||||
log.info("Update customer [{}] date added.", customer);
|
||||
customerMapper.update(customer);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Customer YTD sale [{}] read.", customerYtdSale);
|
||||
createOrUpdateCustomerYTDSale(operator, customerYtdSale, now);
|
||||
}
|
||||
}, true);
|
||||
importRecord.setSuccess(true);
|
||||
importRecord.setDateUpdated(new Date());
|
||||
log.info("Import YTD sales completed, update import record [{}].", importRecord);
|
||||
importRecordMapper.update(importRecord);
|
||||
}
|
||||
catch (CVSFileImportingException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
importRecord.setSuccess(false);
|
||||
importRecord.setDateUpdated(new Date());
|
||||
importRecord.setNote(e.getMessage());
|
||||
log.info("Import YTD sales error caused, update import record [{}].", importRecord);
|
||||
importRecordMapper.update(importRecord);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateCustomerYTDSale(final String operator, final CustomerYearToDateSale customerYtdSale, final Date date) {
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.pudonghot.ambition.crm.service.support;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import me.chyxion.tigon.model.ViewModel;
|
||||
import me.chyxion.tigon.model.ListResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.pudonghot.ambition.crm.model.ImportRecord;
|
||||
import com.pudonghot.ambition.crm.mapper.ImportRecordMapper;
|
||||
import com.pudonghot.ambition.crm.service.ImportRecordService;
|
||||
import me.chyxion.tigon.service.support.BaseCrudServiceSupport;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @since 0.0.1
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Sep 22, 2015 10:45:41 AM
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ImportRecordSupport
|
||||
extends BaseCrudServiceSupport<String, ImportRecord, ImportRecordMapper>
|
||||
implements ImportRecordService {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListResult<ViewModel<ImportRecord>> listViewModelsPage(Search search) {
|
||||
return new ListResult<>(toViewModel(mapper.listForShow(search)), mapper.countForShow(search));
|
||||
}
|
||||
}
|
@ -11,10 +11,11 @@ import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import com.pudonghot.ambition.crm.exception.CVSFileImportingException;
|
||||
|
||||
/**
|
||||
* @author Donghuang <br>
|
||||
* donghuang@wacai.com <br>
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Jun 24, 2017 10:36 PM
|
||||
*/
|
||||
@Slf4j
|
||||
@ -69,7 +70,7 @@ public class CSVUtils {
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
throw new CVSFileImportingException(
|
||||
"File is importing, please wait");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.pudonghot.ambition.crm.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import me.chyxion.tigon.mybatis.Search;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import com.pudonghot.ambition.crm.model.ImportRecord;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Sep 30, 2017 18:56:33
|
||||
*/
|
||||
public interface ImportRecordMapper extends BaseMapper<String, ImportRecord> {
|
||||
|
||||
/**
|
||||
* list for show
|
||||
* @param search search
|
||||
* @return import records
|
||||
*/
|
||||
List<ImportRecord> listForShow(@Param("s") Search search);
|
||||
|
||||
/**
|
||||
* count for show
|
||||
* @param search search
|
||||
* @return count of import records
|
||||
*/
|
||||
int countForShow(@Param("s") Search search);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Sep 30, 2017 18:57:10
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE mapper PUBLIC
|
||||
"-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pudonghot.ambition.crm.mapper.ImportRecordMapper">
|
||||
|
||||
<select id="listForShow" resultType="com.pudonghot.ambition.crm.model.ImportRecord">
|
||||
select r.*,
|
||||
u.employee_id,
|
||||
u.account,
|
||||
u.name,
|
||||
u.en_name
|
||||
from crm_import_record r
|
||||
join crm_user u
|
||||
on r.created_by = u.id
|
||||
<include refid="Tigon.search" />
|
||||
</select>
|
||||
|
||||
<select id="countForShow" resultType="int">
|
||||
select count(r.id)
|
||||
from crm_import_record r
|
||||
join crm_user u
|
||||
on r.created_by = u.id
|
||||
<include refid="Tigon.searchForCount" />
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,45 @@
|
||||
package com.pudonghot.ambition.crm.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chyxion.tigon.model.M3;
|
||||
import me.chyxion.tigon.mybatis.Table;
|
||||
import me.chyxion.tigon.mybatis.NotUpdate;
|
||||
import me.chyxion.tigon.mybatis.Transient;
|
||||
|
||||
/**
|
||||
* @author Shaun Chyxion <br>
|
||||
* chyxion@163.com <br>
|
||||
* Sep 30, 2017 18:54:16
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Table("crm_import_record")
|
||||
public class ImportRecord extends M3<String, String> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// roles
|
||||
public static final String TYPE_CUSTOMER = "CUSTOMER";
|
||||
public static final String TYPE_YTD_SALES = "YTD_SALES";
|
||||
|
||||
// Column Names
|
||||
public static final String TYPE = "type";
|
||||
public static final String COMPLETED = "completed";
|
||||
public static final String SUCCESS = "success";
|
||||
|
||||
// Properties
|
||||
@NotUpdate
|
||||
private String type;
|
||||
private boolean completed;
|
||||
private boolean success;
|
||||
|
||||
// Transients
|
||||
@Transient
|
||||
private String employeeId;
|
||||
@Transient
|
||||
private String account;
|
||||
@Transient
|
||||
private String name;
|
||||
@Transient
|
||||
private String enName;
|
||||
}
|
@ -54,6 +54,10 @@ Router.map(function() {
|
||||
this.route('mine');
|
||||
this.route('list', {path: '/list/:page'});
|
||||
});
|
||||
|
||||
this.route('import-record', function() {
|
||||
this.route('list', {path: '/list/:page'});
|
||||
});
|
||||
});
|
||||
|
||||
export default Router;
|
||||
|
7
web/app/routes/import-record/list.js
Normal file
7
web/app/routes/import-record/list.js
Normal file
@ -0,0 +1,7 @@
|
||||
import Ember from 'ember';
|
||||
import BaseListRoute from './../base-list';
|
||||
|
||||
export default BaseListRoute.extend({
|
||||
breadcrumbs: [{text: 'Import Records'}]
|
||||
});
|
||||
|
7
web/app/services/import-record/service.js
Normal file
7
web/app/services/import-record/service.js
Normal file
@ -0,0 +1,7 @@
|
||||
import Ember from 'ember';
|
||||
import BaseServiceMixin from '../../mixins/services/base-service';
|
||||
|
||||
export default Ember.Service.extend(BaseServiceMixin, {
|
||||
modelName: 'ImportRecord',
|
||||
pageSize: 128
|
||||
});
|
@ -64,6 +64,12 @@
|
||||
<span class="menu-text"> Customer Status </span>
|
||||
{{/link-to}}
|
||||
</li>
|
||||
<li>
|
||||
{{#link-to 'import-record.list' 1}}
|
||||
<i class="menu-icon fa fa-th-list blue"></i>
|
||||
<span class="menu-text"> Import Records </span>
|
||||
{{/link-to}}
|
||||
</li>
|
||||
{{!--fa-archive--}}
|
||||
{{/if}}
|
||||
<!-- end -->
|
||||
|
69
web/app/templates/import-record/list.hbs
Normal file
69
web/app/templates/import-record/list.hbs
Normal file
@ -0,0 +1,69 @@
|
||||
{{#main-content}}
|
||||
<div class="widget-box transparent">
|
||||
{{grid-header}}
|
||||
|
||||
<div class="widget-body">
|
||||
<!-- #section:custom/scrollbar -->
|
||||
<div class="widget-main no-padding table-responsive no-border">
|
||||
<table class="table table-striped table-bordered table-hover dataTable" style="border: 1px solid #ddd;">
|
||||
<thead class="thin-border-bottom">
|
||||
<tr>
|
||||
<th>
|
||||
Operator
|
||||
</th>
|
||||
<th>
|
||||
Type
|
||||
</th>
|
||||
<th>
|
||||
Start
|
||||
</th>
|
||||
<th>
|
||||
End
|
||||
</th>
|
||||
<th>
|
||||
Status
|
||||
</th>
|
||||
<th>
|
||||
Note
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{{#each model.data as |it|}}
|
||||
<tr>
|
||||
<td>
|
||||
{{it.name}}
|
||||
</td>
|
||||
<td>
|
||||
{{it.type}}
|
||||
</td>
|
||||
<td>
|
||||
{{moment-format it.dateCreated 'M/D/YYYY H:mm:ss'}}
|
||||
</td>
|
||||
<td>
|
||||
{{#if it.dateUpdated}}
|
||||
{{moment-format it.dateUpdated 'M/D/YYYY H:mm:ss'}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td>
|
||||
{{#if it.success}}
|
||||
SUCCESSFUL
|
||||
{{else if (not it.completed)}}
|
||||
IMPORTING
|
||||
{{else}}
|
||||
ERROR
|
||||
{{/if}}
|
||||
</td>
|
||||
<td>
|
||||
{{it.note}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{pagination-bar}}
|
||||
</div>
|
||||
</div>
|
||||
{{/main-content}}
|
11
web/tests/unit/routes/import-record/list-test.js
Normal file
11
web/tests/unit/routes/import-record/list-test.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { moduleFor, test } from 'ember-qunit';
|
||||
|
||||
moduleFor('route:import-record/list', 'Unit | Route | import record/list', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['controller:foo']
|
||||
});
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.subject();
|
||||
assert.ok(route);
|
||||
});
|
12
web/tests/unit/services/import-record/service-test.js
Normal file
12
web/tests/unit/services/import-record/service-test.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { moduleFor, test } from 'ember-qunit';
|
||||
|
||||
moduleFor('service:import-record/service', 'Unit | Service | import record/service', {
|
||||
// Specify the other units that are required for this test.
|
||||
// needs: ['service:foo']
|
||||
});
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
let service = this.subject();
|
||||
assert.ok(service);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user