vue版本上线

This commit is contained in:
季圣华
2021-04-07 23:53:57 +08:00
parent 76a0033a4e
commit f4ef5aa067
803 changed files with 171959 additions and 27 deletions

View File

@@ -0,0 +1,137 @@
package com.jsh.erp.service;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author jishenghua 752718920 2018-10-7 15:25:58
*/
@Service
public class CommonQueryManager {
@Resource
private InterfaceContainer container;
@Resource
private LogService logService;
/**
* 查询单条
*
* @param apiName 接口名称
* @param id ID
*/
public Object selectOne(String apiName, Long id) throws Exception {
if (StringUtil.isNotEmpty(apiName) && id!=null) {
return container.getCommonQuery(apiName).selectOne(id);
}
return null;
}
/**
* 查询
* @param apiName
* @param parameterMap
* @return
*/
public List<?> select(String apiName, Map<String, String> parameterMap)throws Exception {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).select(parameterMap);
}
return new ArrayList<Object>();
}
/**
* 计数
* @param apiName
* @param parameterMap
* @return
*/
public Long counts(String apiName, Map<String, String> parameterMap)throws Exception {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).counts(parameterMap);
}
return BusinessConstants.DEFAULT_LIST_NULL_NUMBER;
}
/**
* 插入
* @param apiName
* @param obj
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insert(String apiName, JSONObject obj, HttpServletRequest request) throws Exception{
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).insert(obj, request);
}
return 0;
}
/**
* 更新
* @param apiName
* @param obj
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int update(String apiName, JSONObject obj, HttpServletRequest request)throws Exception {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).update(obj, request);
}
return 0;
}
/**
* 删除
* @param apiName
* @param id
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int delete(String apiName, Long id, HttpServletRequest request)throws Exception {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).delete(id, request);
}
return 0;
}
/**
* 批量删除
* @param apiName
* @param ids
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteBatch(String apiName, String ids, HttpServletRequest request)throws Exception {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).deleteBatch(ids, request);
}
return 0;
}
/**
* 判断是否存在
* @param apiName
* @param id
* @param name
* @return
*/
public int checkIsNameExist(String apiName, Long id, String name) throws Exception{
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).checkIsNameExist(id, name);
}
return 0;
}
}

View File

@@ -0,0 +1,80 @@
package com.jsh.erp.service;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* 通用查询接口
* 功能1、单条查询 2、分页+搜索 3、查询数量
*
* @author jishenghua
* @version 1.0
*/
public interface ICommonQuery {
/**
* 根据id查询明细。
*
* @param id 资源id
* @return 资源
*/
Object selectOne(Long id) throws Exception;
/**
* 自定义查询
*
* @param parameterMap 查询参数
* @return 查询结果
*/
List<?> select(Map<String, String> parameterMap) throws Exception;
/**
* 查询数量
*
* @param parameterMap 查询参数
* @return 查询结果
*/
Long counts(Map<String, String> parameterMap) throws Exception;
/**
* 新增数据
*
* @param obj
* @return
*/
int insert(JSONObject obj, HttpServletRequest request) throws Exception;
/**
* 更新数据
*
* @param obj
* @return
*/
int update(JSONObject obj, HttpServletRequest request) throws Exception;
/**
* 删除数据
*
* @param id
* @return
*/
int delete(Long id, HttpServletRequest request) throws Exception;
/**
* 批量删除数据
*
* @param ids
* @return
*/
int deleteBatch(String ids, HttpServletRequest request) throws Exception;
/**
* 查询名称是否存在
*
* @param id
* @return
*/
int checkIsNameExist(Long id, String name) throws Exception;
}

View File

@@ -0,0 +1,31 @@
package com.jsh.erp.service;
import com.jsh.erp.utils.AnnotationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
/**
* @author jishenghua 2018-10-7 15:25:09
*/
@Service
public class InterfaceContainer {
private final Map<String, ICommonQuery> configComponentMap = new HashMap<>();
@Autowired(required = false)
private synchronized void init(ICommonQuery[] configComponents) {
for (ICommonQuery configComponent : configComponents) {
ResourceInfo info = AnnotationUtils.getAnnotation(configComponent, ResourceInfo.class);
if (info != null) {
configComponentMap.put(info.value(), configComponent);
}
}
}
public ICommonQuery getCommonQuery(String apiName) {
return configComponentMap.get(apiName);
}
}

View File

@@ -0,0 +1,14 @@
package com.jsh.erp.service;
import java.lang.annotation.*;
/**
* @author jishenghua 2018-10-7 15:25:39
*/
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface ResourceInfo {
String value();
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.account;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "account_component")
@AccountResource
public class AccountComponent implements ICommonQuery {
@Resource
private AccountService accountService;
@Override
public Object selectOne(Long id) throws Exception {
return accountService.getAccount(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getAccountList(map);
}
private List<?> getAccountList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String serialNo = StringUtil.getInfo(search, "serialNo");
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return accountService.select(name, serialNo, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String serialNo = StringUtil.getInfo(search, "serialNo");
String remark = StringUtil.getInfo(search, "remark");
return accountService.countAccount(name, serialNo, remark);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return accountService.insertAccount(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return accountService.updateAccount(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return accountService.deleteAccount(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return accountService.batchDeleteAccount(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return accountService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.account;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "account")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountResource {
}

View File

@@ -0,0 +1,555 @@
package com.jsh.erp.service.account;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.datasource.vo.AccountVo4List;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
@Service
public class AccountService {
private Logger logger = LoggerFactory.getLogger(AccountService.class);
@Resource
private AccountMapper accountMapper;
@Resource
private AccountMapperEx accountMapperEx;
@Resource
private DepotHeadMapper depotHeadMapper;
@Resource
private DepotHeadMapperEx depotHeadMapperEx;
@Resource
private AccountHeadMapper accountHeadMapper;
@Resource
private AccountHeadMapperEx accountHeadMapperEx;
@Resource
private AccountItemMapper accountItemMapper;
@Resource
private AccountItemMapperEx accountItemMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
public Account getAccount(long id) throws Exception{
return accountMapper.selectByPrimaryKey(id);
}
public List<Account> getAccountListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Account> list = new ArrayList<>();
try{
AccountExample example = new AccountExample();
example.createCriteria().andIdIn(idList);
list = accountMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Account> getAccount() throws Exception{
AccountExample example = new AccountExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Account> list=null;
try{
list=accountMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Account> getAccountByParam(String name, String serialNo) throws Exception{
List<Account> list=null;
try{
list=accountMapperEx.getAccountByParam(name, serialNo);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<AccountVo4List> select(String name, String serialNo, String remark, int offset, int rows) throws Exception{
List<AccountVo4List> resList = new ArrayList<AccountVo4List>();
List<AccountVo4List> list=null;
try{
list = accountMapperEx.selectByConditionAccount(name, serialNo, remark, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
String timeStr = Tools.getCurrentMonth();
if (null != list && null !=timeStr) {
for (AccountVo4List al : list) {
DecimalFormat df = new DecimalFormat(".##");
BigDecimal thisMonthAmount = getAccountSum(al.getId(), timeStr, "month").add(getAccountSumByHead(al.getId(), timeStr, "month")).add(getAccountSumByDetail(al.getId(), timeStr, "month")).add(getManyAccountSum(al.getId(), timeStr, "month"));
String thisMonthAmountFmt = "0";
if ((thisMonthAmount.compareTo(BigDecimal.ZERO))!=0) {
thisMonthAmountFmt = df.format(thisMonthAmount);
}
al.setThisMonthAmount(thisMonthAmountFmt); //本月发生额
BigDecimal currentAmount = getAccountSum(al.getId(), "", "month").add(getAccountSumByHead(al.getId(), "", "month")).add(getAccountSumByDetail(al.getId(), "", "month")).add(getManyAccountSum(al.getId(), "", "month")) .add(al.getInitialAmount()) ;
al.setCurrentAmount(currentAmount);
resList.add(al);
}
}
return resList;
}
public Long countAccount(String name, String serialNo, String remark)throws Exception {
Long result=null;
try{
result=accountMapperEx.countsByAccount(name, serialNo, remark);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertAccount(JSONObject obj, HttpServletRequest request)throws Exception {
Account account = JSONObject.parseObject(obj.toJSONString(), Account.class);
if(account.getInitialAmount() == null) {
account.setInitialAmount(BigDecimal.ZERO);
}
account.setIsDefault(false);
int result=0;
try{
result = accountMapper.insertSelective(account);
logService.insertLog("账户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(account.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAccount(JSONObject obj, HttpServletRequest request)throws Exception {
Account account = JSONObject.parseObject(obj.toJSONString(), Account.class);
int result=0;
try{
result = accountMapper.updateByPrimaryKeySelective(account);
logService.insertLog("账户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(account.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteAccount(Long id, HttpServletRequest request) throws Exception{
return batchDeleteAccountByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccount(String ids, HttpServletRequest request)throws Exception {
return batchDeleteAccountByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccountByIds(String ids) throws Exception{
int result=0;
String [] idArray=ids.split(",");
//校验财务主表 jsh_accounthead
List<AccountHead> accountHeadList=null;
try{
accountHeadList = accountHeadMapperEx.getAccountHeadListByAccountIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(accountHeadList!=null&&accountHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验财务子表 jsh_accountitem
List<AccountItem> accountItemList=null;
try{
accountItemList = accountItemMapperEx.getAccountItemListByAccountIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(accountItemList!=null&&accountItemList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验单据主表 jsh_depot_head
List<DepotHead> depotHeadList =null;
try{
depotHeadList = depotHeadMapperEx.getDepotHeadListByAccountIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(depotHeadList!=null&&depotHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Account> list = getAccountListByIds(ids);
for(Account account: list){
sb.append("[").append(account.getName()).append("]");
}
logService.insertLog("账户", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
//校验通过执行删除操作
try{
result = accountMapperEx.batchDeleteAccountByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
AccountExample example = new AccountExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Account> list=null;
try{
list = accountMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<Account> findBySelect()throws Exception {
AccountExample example = new AccountExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Account> list=null;
try{
list = accountMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* 单个账户的金额求和-入库和出库
*
* @param id
* @return
*/
public BigDecimal getAccountSum(Long id, String timeStr, String type) throws Exception{
BigDecimal accountSum = BigDecimal.ZERO;
try {
DepotHeadExample example = new DepotHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountIdEqualTo(id).andPayTypeNotEqualTo("预付款")
.andOperTimeGreaterThanOrEqualTo(bTime).andOperTimeLessThanOrEqualTo(eTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else if (type.equals("date")) {
example.createCriteria().andAccountIdEqualTo(id).andPayTypeNotEqualTo("预付款")
.andOperTimeLessThanOrEqualTo(mTime).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
} else {
example.createCriteria().andAccountIdEqualTo(id).andPayTypeNotEqualTo("预付款")
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<DepotHead> dataList=null;
try{
dataList = depotHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (dataList != null) {
for (DepotHead depotHead : dataList) {
if(depotHead.getChangeAmount()!=null) {
accountSum = accountSum .add(depotHead.getChangeAmount()) ;
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-收入、支出、转账的单据表头的合计
*
* @param id
* @return
*/
public BigDecimal getAccountSumByHead(Long id, String timeStr, String type) throws Exception{
BigDecimal accountSum = BigDecimal.ZERO;
try {
AccountHeadExample example = new AccountHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountIdEqualTo(id)
.andBillTimeGreaterThanOrEqualTo(bTime).andBillTimeLessThanOrEqualTo(eTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else if (type.equals("date")) {
example.createCriteria().andAccountIdEqualTo(id)
.andBillTimeLessThanOrEqualTo(mTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
} else {
example.createCriteria().andAccountIdEqualTo(id)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<AccountHead> dataList=null;
try{
dataList = accountHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (dataList != null) {
for (AccountHead accountHead : dataList) {
if(accountHead.getChangeAmount()!=null) {
accountSum = accountSum.add(accountHead.getChangeAmount());
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-收款、付款、转账、收预付款的单据明细的合计
*
* @param id
* @return
*/
public BigDecimal getAccountSumByDetail(Long id, String timeStr, String type)throws Exception {
BigDecimal accountSum =BigDecimal.ZERO ;
try {
AccountHeadExample example = new AccountHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andBillTimeGreaterThanOrEqualTo(bTime).andBillTimeLessThanOrEqualTo(eTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else if (type.equals("date")) {
example.createCriteria().andBillTimeLessThanOrEqualTo(mTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
}
List<AccountHead> dataList=null;
try{
dataList = accountHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (dataList != null) {
String ids = "";
for (AccountHead accountHead : dataList) {
ids = ids + accountHead.getId() + ",";
}
if (!ids.equals("")) {
ids = ids.substring(0, ids.length() - 1);
}
AccountItemExample exampleAi = new AccountItemExample();
if (!ids.equals("")) {
List<Long> idList = StringUtil.strToLongList(ids);
exampleAi.createCriteria().andAccountIdEqualTo(id).andHeaderIdIn(idList)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountItem> dataListOne = accountItemMapper.selectByExample(exampleAi);
if (dataListOne != null) {
for (AccountItem accountItem : dataListOne) {
if(accountItem.getEachAmount()!=null) {
accountSum = accountSum.add(accountItem.getEachAmount());
}
}
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
} catch (Exception e) {
logger.error(">>>>>>>>>异常信息:", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-多账户的明细合计
*
* @param id
* @return
*/
public BigDecimal getManyAccountSum(Long id, String timeStr, String type)throws Exception {
BigDecimal accountSum = BigDecimal.ZERO;
try {
DepotHeadExample example = new DepotHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountIdListLike("%" +id.toString() + "%")
.andOperTimeGreaterThanOrEqualTo(bTime).andOperTimeLessThanOrEqualTo(eTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else if (type.equals("date")) {
example.createCriteria().andAccountIdListLike("%" +id.toString() + "%")
.andOperTimeLessThanOrEqualTo(mTime)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
} else {
example.createCriteria().andAccountIdListLike("%" +id.toString() + "%")
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<DepotHead> dataList=null;
try{
dataList = depotHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (dataList != null) {
for (DepotHead depotHead : dataList) {
String accountIdList = depotHead.getAccountIdList();
String accountMoneyList = depotHead.getAccountMoneyList();
if(StringUtil.isNotEmpty(accountIdList) && StringUtil.isNotEmpty(accountMoneyList)) {
accountIdList = accountIdList.replace("[", "").replace("]", "").replace("\"", "");
accountMoneyList = accountMoneyList.replace("[", "").replace("]", "").replace("\"", "");
String[] aList = accountIdList.split(",");
String[] amList = accountMoneyList.split(",");
for (int i = 0; i < aList.length; i++) {
if (aList[i].toString().equals(id.toString())) {
if(amList!=null && amList.length>0) {
accountSum = accountSum.add(new BigDecimal(amList[i]));
}
}
}
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找信息异常", e);
}
return accountSum;
}
public List<AccountVo4InOutList> findAccountInOutList(Long accountId, Integer offset, Integer rows) throws Exception{
List<AccountVo4InOutList> list=null;
try{
list = accountMapperEx.findAccountInOutList(accountId, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findAccountInOutListCount(Long accountId) throws Exception{
int result=0;
try{
result = accountMapperEx.findAccountInOutListCount(accountId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateIsDefault(Long accountId) throws Exception{
int result=0;
try{
//全部取消默认
Account allAccount = new Account();
allAccount.setIsDefault(false);
AccountExample allExample = new AccountExample();
allExample.createCriteria();
accountMapper.updateByExampleSelective(allAccount, allExample);
//给指定账户设为默认
Account account = new Account();
account.setIsDefault(true);
AccountExample example = new AccountExample();
example.createCriteria().andIdEqualTo(accountId);
accountMapper.updateByExampleSelective(account, example);
logService.insertLog("账户",BusinessConstants.LOG_OPERATION_TYPE_EDIT+accountId,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
result = 1;
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public Map<String, Object> getStatistics(String name, String serialNo) {
Map<String, Object> map = new HashMap<>();
try {
List<Account> list = getAccountByParam(name, serialNo);
String timeStr = Tools.getCurrentMonth();
BigDecimal allMonthAmount = BigDecimal.ZERO;
BigDecimal allCurrentAmount = BigDecimal.ZERO;
if (null != list && null !=timeStr) {
for (Account a : list) {
BigDecimal monthAmount = getAccountSum(a.getId(), timeStr, "month").add(getAccountSumByHead(a.getId(), timeStr, "month"))
.add(getAccountSumByDetail(a.getId(), timeStr, "month")).add(getManyAccountSum(a.getId(), timeStr, "month"));
BigDecimal currentAmount = getAccountSum(a.getId(), "", "month").add(getAccountSumByHead(a.getId(), "", "month"))
.add(getAccountSumByDetail(a.getId(), "", "month")).add(getManyAccountSum(a.getId(), "", "month")).add(a.getInitialAmount());
allMonthAmount = allMonthAmount.add(monthAmount);
allCurrentAmount = allCurrentAmount.add(currentAmount);
}
}
map.put("allCurrentAmount", priceFormat(allCurrentAmount)); //当前总金额
map.put("allMonthAmount", priceFormat(allMonthAmount)); //本月发生额
} catch (Exception e) {
JshException.readFail(logger, e);
}
return map;
}
/**
* 价格格式化
* @param price
* @return
*/
private String priceFormat(BigDecimal price) {
String priceFmt = "0";
DecimalFormat df = new DecimalFormat(".##");
if ((price.compareTo(BigDecimal.ZERO))!=0) {
priceFmt = df.format(price);
}
return priceFmt;
}
}

View File

@@ -0,0 +1,79 @@
package com.jsh.erp.service.accountHead;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "accountHead_component")
@AccountHeadResource
public class AccountHeadComponent implements ICommonQuery {
@Resource
private AccountHeadService accountHeadService;
@Override
public Object selectOne(Long id) throws Exception {
return accountHeadService.getAccountHead(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getAccountHeadList(map);
}
private List<?> getAccountHeadList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String roleType = StringUtil.getInfo(search, "roleType");
String billNo = StringUtil.getInfo(search, "billNo");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String order = QueryUtils.order(map);
return accountHeadService.select(type, roleType, billNo, beginTime, endTime, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String roleType = StringUtil.getInfo(search, "roleType");
String billNo = StringUtil.getInfo(search, "billNo");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
return accountHeadService.countAccountHead(type, roleType, billNo, beginTime, endTime);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return accountHeadService.insertAccountHead(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return accountHeadService.updateAccountHead(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return accountHeadService.deleteAccountHead(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return accountHeadService.batchDeleteAccountHead(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return accountHeadService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.accountHead;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "accountHead")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountHeadResource {
}

View File

@@ -0,0 +1,342 @@
package com.jsh.erp.service.accountHead;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.AccountHeadExample;
import com.jsh.erp.datasource.entities.AccountHeadVo4ListEx;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.AccountHeadMapper;
import com.jsh.erp.datasource.mappers.AccountHeadMapperEx;
import com.jsh.erp.datasource.mappers.AccountItemMapperEx;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.accountItem.AccountItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.orgaUserRel.OrgaUserRelService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.jsh.erp.utils.Tools.getCenternTime;
@Service
public class AccountHeadService {
private Logger logger = LoggerFactory.getLogger(AccountHeadService.class);
@Resource
private AccountHeadMapper accountHeadMapper;
@Resource
private AccountHeadMapperEx accountHeadMapperEx;
@Resource
private OrgaUserRelService orgaUserRelService;
@Resource
private AccountItemService accountItemService;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private AccountItemMapperEx accountItemMapperEx;
public AccountHead getAccountHead(long id) throws Exception {
AccountHead result=null;
try{
result=accountHeadMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<AccountHead> getAccountHeadListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<AccountHead> list = new ArrayList<>();
try{
AccountHeadExample example = new AccountHeadExample();
example.createCriteria().andIdIn(idList);
list = accountHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<AccountHead> getAccountHead() throws Exception{
AccountHeadExample example = new AccountHeadExample();
List<AccountHead> list=null;
try{
list=accountHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<AccountHeadVo4ListEx> select(String type, String roleType, String billNo, String beginTime, String endTime, int offset, int rows) throws Exception{
List<AccountHeadVo4ListEx> resList = new ArrayList<AccountHeadVo4ListEx>();
List<AccountHeadVo4ListEx> list=null;
try{
String [] creatorArray = getCreatorArray(roleType);
list = accountHeadMapperEx.selectByConditionAccountHead(type, creatorArray, billNo, beginTime, endTime, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (AccountHeadVo4ListEx ah : list) {
if(ah.getChangeAmount() != null) {
ah.setChangeAmount(ah.getChangeAmount().abs());
}
if(ah.getTotalPrice() != null) {
ah.setTotalPrice(ah.getTotalPrice().abs());
}
ah.setBillTimeStr(getCenternTime(ah.getBillTime()));
resList.add(ah);
}
}
return resList;
}
public Long countAccountHead(String type, String roleType, String billNo, String beginTime, String endTime) throws Exception{
Long result=null;
try{
String [] creatorArray = getCreatorArray(roleType);
result = accountHeadMapperEx.countsByAccountHead(type, creatorArray, billNo, beginTime, endTime);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* 根据角色类型获取操作员数组
* @param roleType
* @return
* @throws Exception
*/
private String[] getCreatorArray(String roleType) throws Exception {
String creator = "";
User user = userService.getCurrentUser();
if(BusinessConstants.ROLE_TYPE_PRIVATE.equals(roleType)) {
creator = user.getId().toString();
} else if(BusinessConstants.ROLE_TYPE_THIS_ORG.equals(roleType)) {
creator = orgaUserRelService.getUserIdListByUserId(user.getId());
}
String [] creatorArray=null;
if(StringUtil.isNotEmpty(creator)){
creatorArray = creator.split(",");
}
return creatorArray;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertAccountHead(JSONObject obj, HttpServletRequest request) throws Exception{
AccountHead accountHead = JSONObject.parseObject(obj.toJSONString(), AccountHead.class);
int result=0;
try{
User userInfo=userService.getCurrentUser();
accountHead.setCreator(userInfo==null?null:userInfo.getId());
result = accountHeadMapper.insertSelective(accountHead);
logService.insertLog("财务",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(accountHead.getBillNo()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAccountHead(JSONObject obj, HttpServletRequest request)throws Exception {
AccountHead accountHead = JSONObject.parseObject(obj.toJSONString(), AccountHead.class);
int result=0;
try{
result = accountHeadMapper.updateByPrimaryKeySelective(accountHead);
logService.insertLog("财务",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(accountHead.getBillNo()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteAccountHead(Long id, HttpServletRequest request)throws Exception {
return batchDeleteAccountHeadByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccountHead(String ids, HttpServletRequest request)throws Exception {
return batchDeleteAccountHeadByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccountHeadByIds(String ids)throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<AccountHead> list = getAccountHeadListByIds(ids);
for(AccountHead accountHead: list){
sb.append("[").append(accountHead.getBillNo()).append("]");
}
logService.insertLog("财务", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result = 0;
try{
//删除主表
result = accountItemMapperEx.batchDeleteAccountItemByHeadIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
//删除子表
result = accountHeadMapperEx.batchDeleteAccountHeadByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
AccountHeadExample example = new AccountHeadExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountHead> list = null;
try{
list = accountHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public void addAccountHeadAndDetail(String beanJson, String rows, HttpServletRequest request) throws Exception {
AccountHead accountHead = JSONObject.parseObject(beanJson, AccountHead.class);
User userInfo=userService.getCurrentUser();
accountHead.setCreator(userInfo==null?null:userInfo.getId());
accountHeadMapper.insertSelective(accountHead);
//根据单据编号查询单据id
AccountHeadExample dhExample = new AccountHeadExample();
dhExample.createCriteria().andBillNoEqualTo(accountHead.getBillNo()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountHead> list = accountHeadMapper.selectByExample(dhExample);
if(list!=null) {
Long headId = list.get(0).getId();
String type = list.get(0).getType();
/**处理单据子表信息*/
accountItemService.saveDetials(rows, headId, type, request);
}
logService.insertLog("财务单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(accountHead.getBillNo()).toString(), request);
}
public void updateAccountHeadAndDetail(String beanJson, String rows, HttpServletRequest request) throws Exception {
AccountHead accountHead = JSONObject.parseObject(beanJson, AccountHead.class);
accountHeadMapper.updateByPrimaryKeySelective(accountHead);
//根据单据编号查询单据id
AccountHeadExample dhExample = new AccountHeadExample();
dhExample.createCriteria().andBillNoEqualTo(accountHead.getBillNo()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountHead> list = accountHeadMapper.selectByExample(dhExample);
if(list!=null) {
Long headId = list.get(0).getId();
String type = list.get(0).getType();
/**处理单据子表信息*/
accountItemService.saveDetials(rows, headId, type, request);
}
logService.insertLog("财务单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(accountHead.getBillNo()).toString(), request);
}
public BigDecimal findAllMoney(Integer supplierId, String type, String mode, String endTime) {
String modeName = "";
if (mode.equals("实际")) {
modeName = "change_amount";
} else if (mode.equals("合计")) {
modeName = "total_price";
}
BigDecimal result = null;
try{
result = accountHeadMapperEx.findAllMoney(supplierId, type, modeName, endTime);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* 统计总金额
* @param getS
* @param type
* @param mode 合计或者金额
* @param endTime
* @return
*/
public BigDecimal allMoney(String getS, String type, String mode, String endTime) {
BigDecimal allMoney = BigDecimal.ZERO;
try {
Integer supplierId = Integer.valueOf(getS);
BigDecimal sum = findAllMoney(supplierId, type, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if ((allMoney.compareTo(BigDecimal.ZERO))==-1) {
allMoney = allMoney.abs();
}
return allMoney;
}
/**
* 查询单位的累计应收和累计应付,收预付款不计入此处
* @param supplierId
* @param endTime
* @param supType
* @return
*/
public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) {
BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString();
int i = 1;
if (("customer").equals(supType)) { //客户
i = 1;
} else if (("vendor").equals(supType)) { //供应商
i = -1;
}
//收付款部分
sum = sum.add((allMoney(getS, "付款", "合计",endTime).add(allMoney(getS, "付款", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.subtract((allMoney(getS, "收款", "合计",endTime).add(allMoney(getS, "收款", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "收入", "合计",endTime).subtract(allMoney(getS, "收入", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.subtract((allMoney(getS, "支出", "合计",endTime).subtract(allMoney(getS, "支出", "实际",endTime))).multiply(new BigDecimal(i)));
return sum;
}
public List<AccountHeadVo4ListEx> getDetailByNumber(String billNo)throws Exception {
List<AccountHeadVo4ListEx> resList = new ArrayList<AccountHeadVo4ListEx>();
List<AccountHeadVo4ListEx> list = null;
try{
list = accountHeadMapperEx.getDetailByNumber(billNo);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (AccountHeadVo4ListEx ah : list) {
if(ah.getChangeAmount() != null) {
ah.setChangeAmount(ah.getChangeAmount().abs());
}
if(ah.getTotalPrice() != null) {
ah.setTotalPrice(ah.getTotalPrice().abs());
}
ah.setBillTimeStr(getCenternTime(ah.getBillTime()));
resList.add(ah);
}
}
return resList;
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.accountItem;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "accountItem_component")
@AccountItemResource
public class AccountItemComponent implements ICommonQuery {
@Resource
private AccountItemService accountItemService;
@Override
public Object selectOne(Long id) throws Exception {
return accountItemService.getAccountItem(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getAccountItemList(map);
}
private List<?> getAccountItemList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return accountItemService.select(name, type, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
return accountItemService.countAccountItem(name, type, remark);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return accountItemService.insertAccountItem(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return accountItemService.updateAccountItem(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return accountItemService.deleteAccountItem(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return accountItemService.batchDeleteAccountItem(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return accountItemService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.accountItem;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "accountItem")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountItemResource {
}

View File

@@ -0,0 +1,241 @@
package com.jsh.erp.service.accountItem;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.AccountItem;
import com.jsh.erp.datasource.entities.AccountItemExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.AccountItemMapper;
import com.jsh.erp.datasource.mappers.AccountItemMapperEx;
import com.jsh.erp.datasource.vo.AccountItemVo4List;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Service
public class AccountItemService {
private Logger logger = LoggerFactory.getLogger(AccountItemService.class);
@Resource
private AccountItemMapper accountItemMapper;
@Resource
private AccountItemMapperEx accountItemMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
public AccountItem getAccountItem(long id)throws Exception {
AccountItem result=null;
try{
result=accountItemMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<AccountItem> getAccountItem()throws Exception {
AccountItemExample example = new AccountItemExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountItem> list=null;
try{
list=accountItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<AccountItem> select(String name, Integer type, String remark, int offset, int rows)throws Exception {
List<AccountItem> list=null;
try{
list = accountItemMapperEx.selectByConditionAccountItem(name, type, remark, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countAccountItem(String name, Integer type, String remark)throws Exception {
Long result=null;
try{
result = accountItemMapperEx.countsByAccountItem(name, type, remark);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertAccountItem(JSONObject obj, HttpServletRequest request) throws Exception{
AccountItem accountItem = JSONObject.parseObject(obj.toJSONString(), AccountItem.class);
int result=0;
try{
result = accountItemMapper.insertSelective(accountItem);
logService.insertLog("财务明细", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAccountItem(JSONObject obj, HttpServletRequest request)throws Exception {
AccountItem accountItem = JSONObject.parseObject(obj.toJSONString(), AccountItem.class);
int result=0;
try{
result = accountItemMapper.updateByPrimaryKeySelective(accountItem);
logService.insertLog("财务明细",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(accountItem.getId()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteAccountItem(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result = accountItemMapper.deleteByPrimaryKey(id);
logService.insertLog("财务明细",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(id).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccountItem(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
AccountItemExample example = new AccountItemExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result = accountItemMapper.deleteByExample(example);
logService.insertLog("财务明细", "批量删除,id集:" + ids, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
AccountItemExample example = new AccountItemExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<AccountItem> list = null;
try{
list = accountItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertAccountItemWithObj(AccountItem accountItem)throws Exception {
int result=0;
try{
result = accountItemMapper.insertSelective(accountItem);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAccountItemWithObj(AccountItem accountItem)throws Exception {
int result=0;
try{
result = accountItemMapper.updateByPrimaryKeySelective(accountItem);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<AccountItemVo4List> getDetailList(Long headerId) {
List<AccountItemVo4List> list=null;
try{
list = accountItemMapperEx.getDetailList(headerId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void saveDetials(String rows, Long headerId, String type, HttpServletRequest request) throws Exception {
//删除单据的明细
deleteAccountItemHeadId(headerId);
JSONArray rowArr = JSONArray.parseArray(rows);
if (null != rowArr) {
for (int i = 0; i < rowArr.size(); i++) {
AccountItem accountItem = new AccountItem();
JSONObject tempInsertedJson = JSONObject.parseObject(rowArr.getString(i));
accountItem.setHeaderId(headerId);
if (tempInsertedJson.get("accountId") != null && !tempInsertedJson.get("accountId").equals("")) {
accountItem.setAccountId(tempInsertedJson.getLong("accountId"));
}
if (tempInsertedJson.get("inOutItemId") != null && !tempInsertedJson.get("inOutItemId").equals("")) {
accountItem.setInOutItemId(tempInsertedJson.getLong("inOutItemId"));
}
if (tempInsertedJson.get("eachAmount") != null && !tempInsertedJson.get("eachAmount").equals("")) {
BigDecimal eachAmount = tempInsertedJson.getBigDecimal("eachAmount");
if (type.equals("付款")) {
eachAmount = BigDecimal.ZERO.subtract(eachAmount);
}
accountItem.setEachAmount(eachAmount);
} else {
accountItem.setEachAmount(BigDecimal.ZERO);
}
accountItem.setRemark(tempInsertedJson.getString("remark"));
this.insertAccountItemWithObj(accountItem);
}
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void deleteAccountItemHeadId(Long headerId)throws Exception {
AccountItemExample example = new AccountItemExample();
example.createCriteria().andHeaderIdEqualTo(headerId);
try{
accountItemMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteAccountItemByIds(String ids) throws Exception{
logService.insertLog("财务明细",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result = accountItemMapperEx.batchDeleteAccountItemByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.depot;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "depot_component")
@DepotResource
public class DepotComponent implements ICommonQuery {
@Resource
private DepotService depotService;
@Override
public Object selectOne(Long id) throws Exception {
return depotService.getDepot(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getDepotList(map);
}
private List<?> getDepotList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return depotService.select(name, type, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
return depotService.countDepot(name, type, remark);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return depotService.insertDepot(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return depotService.updateDepot(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return depotService.deleteDepot(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return depotService.batchDeleteDepot(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return depotService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.depot;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "depot")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DepotResource {
}

View File

@@ -0,0 +1,265 @@
package com.jsh.erp.service.depot;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class DepotService {
private Logger logger = LoggerFactory.getLogger(DepotService.class);
@Resource
private DepotMapper depotMapper;
@Resource
private DepotMapperEx depotMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private DepotHeadMapperEx depotHeadMapperEx;
@Resource
private DepotItemMapperEx depotItemMapperEx;
public Depot getDepot(long id)throws Exception {
Depot result=null;
try{
result=depotMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Depot> getDepotListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Depot> list = new ArrayList<>();
try{
DepotExample example = new DepotExample();
example.createCriteria().andIdIn(idList);
list = depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Depot> getDepot()throws Exception {
DepotExample example = new DepotExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Depot> list=null;
try{
list=depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Depot> getAllList()throws Exception {
DepotExample example = new DepotExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("sort");
List<Depot> list=null;
try{
list=depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotEx> select(String name, Integer type, String remark, int offset, int rows)throws Exception {
List<DepotEx> list=null;
try{
list=depotMapperEx.selectByConditionDepot(name, type, remark, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countDepot(String name, Integer type, String remark)throws Exception {
Long result=null;
try{
result=depotMapperEx.countsByDepot(name, type, remark);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertDepot(JSONObject obj, HttpServletRequest request)throws Exception {
Depot depot = JSONObject.parseObject(obj.toJSONString(), Depot.class);
int result=0;
try{
result=depotMapper.insertSelective(depot);
logService.insertLog("仓库",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(depot.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateDepot(JSONObject obj, HttpServletRequest request) throws Exception{
Depot depot = JSONObject.parseObject(obj.toJSONString(), Depot.class);
int result=0;
try{
result= depotMapper.updateByPrimaryKeySelective(depot);
logService.insertLog("仓库",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depot.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteDepot(Long id, HttpServletRequest request)throws Exception {
return batchDeleteDepotByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteDepot(String ids, HttpServletRequest request) throws Exception{
return batchDeleteDepotByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteDepotByIds(String ids)throws Exception {
int result=0;
String [] idArray=ids.split(",");
//校验单据子表 jsh_depot_item
List<DepotItem> depotItemList=null;
try{
depotItemList = depotItemMapperEx.getDepotItemListListByDepotIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(depotItemList!=null&&depotItemList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,DepotIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Depot> list = getDepotListByIds(ids);
for(Depot depot: list){
sb.append("[").append(depot.getName()).append("]");
}
logService.insertLog("仓库", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
//校验通过执行删除操作
try{
result = depotMapperEx.batchDeleteDepotByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
DepotExample example = new DepotExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Depot> list=null;
try{
list= depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<Depot> findUserDepot()throws Exception{
DepotExample example = new DepotExample();
example.createCriteria().andTypeEqualTo(0).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort");
List<Depot> list=null;
try{
list= depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Depot> findGiftByType(Integer type)throws Exception{
DepotExample example = new DepotExample();
example.createCriteria().andTypeEqualTo(type);
example.setOrderByClause("Sort");
List<Depot> list=null;
try{
list= depotMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateIsDefault(Long depotId) throws Exception{
int result=0;
try{
//全部取消默认
Depot allDepot = new Depot();
allDepot.setIsDefault(false);
DepotExample allExample = new DepotExample();
allExample.createCriteria();
depotMapper.updateByExampleSelective(allDepot, allExample);
//给指定仓库设为默认
Depot depot = new Depot();
depot.setIsDefault(true);
DepotExample example = new DepotExample();
example.createCriteria().andIdEqualTo(depotId);
depotMapper.updateByExampleSelective(depot, example);
logService.insertLog("仓库",BusinessConstants.LOG_OPERATION_TYPE_EDIT+depotId,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
result = 1;
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* 根据名称获取id
* @param name
*/
public Long getIdByName(String name){
Long id = 0L;
DepotExample example = new DepotExample();
example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Depot> list = depotMapper.selectByExample(example);
if(list!=null && list.size()>0) {
id = list.get(0).getId();
}
return id;
}
}

View File

@@ -0,0 +1,86 @@
package com.jsh.erp.service.depotHead;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "depotHead_component")
@DepotHeadResource
public class DepotHeadComponent implements ICommonQuery {
@Resource
private DepotHeadService depotHeadService;
@Override
public Object selectOne(Long id) throws Exception {
return depotHeadService.getDepotHead(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getDepotHeadList(map);
}
private List<?> getDepotHeadList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String subType = StringUtil.getInfo(search, "subType");
String roleType = StringUtil.getInfo(search, "roleType");
String status = StringUtil.getInfo(search, "status");
String number = StringUtil.getInfo(search, "number");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String materialParam = StringUtil.getInfo(search, "materialParam");
String depotIds = StringUtil.getInfo(search, "depotIds");
return depotHeadService.select(type, subType, roleType, status, number, beginTime, endTime, materialParam, depotIds, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String subType = StringUtil.getInfo(search, "subType");
String roleType = StringUtil.getInfo(search, "roleType");
String status = StringUtil.getInfo(search, "status");
String number = StringUtil.getInfo(search, "number");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String materialParam = StringUtil.getInfo(search, "materialParam");
String depotIds = StringUtil.getInfo(search, "depotIds");
return depotHeadService.countDepotHead(type, subType, roleType, status, number, beginTime, endTime, materialParam, depotIds);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return depotHeadService.insertDepotHead(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return depotHeadService.updateDepotHead(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return depotHeadService.deleteDepotHead(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return depotHeadService.batchDeleteDepotHead(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return depotHeadService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.depotHead;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "depotHead")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DepotHeadResource {
}

View File

@@ -0,0 +1,592 @@
package com.jsh.erp.service.depotHead;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
import com.jsh.erp.datasource.vo.DepotHeadVo4InDetail;
import com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount;
import com.jsh.erp.datasource.vo.DepotHeadVo4List;
import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.orgaUserRel.OrgaUserRelService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.serialNumber.SerialNumberService;
import com.jsh.erp.service.supplier.SupplierService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.jsh.erp.utils.Tools.getCenternTime;
@Service
public class DepotHeadService {
private Logger logger = LoggerFactory.getLogger(DepotHeadService.class);
@Resource
private DepotHeadMapper depotHeadMapper;
@Resource
private DepotHeadMapperEx depotHeadMapperEx;
@Resource
private UserService userService;
@Resource
DepotItemService depotItemService;
@Resource
private SupplierService supplierService;
@Resource
private SerialNumberService serialNumberService;
@Resource
private OrgaUserRelService orgaUserRelService;
@Resource
DepotItemMapperEx depotItemMapperEx;
@Resource
private LogService logService;
@Resource
private RedisService redisService;
public DepotHead getDepotHead(long id)throws Exception {
DepotHead result=null;
try{
result=depotHeadMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotHead> getDepotHead()throws Exception {
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotHead> list=null;
try{
list=depotHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotHeadVo4List> select(String type, String subType, String roleType, String status, String number, String beginTime, String endTime,
String materialParam, String depotIds, int offset, int rows)throws Exception {
List<DepotHeadVo4List> resList = new ArrayList<DepotHeadVo4List>();
List<DepotHeadVo4List> list=null;
try{
String [] creatorArray = getCreatorArray(roleType);
list=depotHeadMapperEx.selectByConditionDepotHead(type, subType, creatorArray, status, number, beginTime, endTime, materialParam, depotIds, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (DepotHeadVo4List dh : list) {
if(dh.getAccountIdList() != null) {
String accountidlistStr = dh.getAccountIdList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setAccountIdList(accountidlistStr);
}
if(dh.getAccountMoneyList() != null) {
String accountmoneylistStr = dh.getAccountMoneyList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setAccountMoneyList(accountmoneylistStr);
}
if(dh.getOtherMoneyList() != null) {
String otherMoneyListStr = dh.getOtherMoneyList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setOtherMoneyList(otherMoneyListStr);
}
if(dh.getChangeAmount() != null) {
dh.setChangeAmount(dh.getChangeAmount().abs());
}
if(dh.getTotalPrice() != null) {
dh.setTotalPrice(dh.getTotalPrice().abs());
}
if(dh.getOperTime() != null) {
dh.setOperTimeStr(getCenternTime(dh.getOperTime()));
}
dh.setMaterialsList(findMaterialsListByHeaderId(dh.getId()));
resList.add(dh);
}
}
return resList;
}
public Long countDepotHead(String type, String subType, String roleType, String status, String number, String beginTime, String endTime,
String materialParam, String depotIds) throws Exception{
Long result=null;
try{
String [] creatorArray = getCreatorArray(roleType);
result=depotHeadMapperEx.countsByDepotHead(type, subType, creatorArray, status, number, beginTime, endTime, materialParam, depotIds);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* 根据角色类型获取操作员数组
* @param roleType
* @return
* @throws Exception
*/
public String[] getCreatorArray(String roleType) throws Exception {
String creator = getCreatorByRoleType(roleType);
String [] creatorArray=null;
if(StringUtil.isNotEmpty(creator)){
creatorArray = creator.split(",");
}
return creatorArray;
}
/**
* 根据角色类型获取操作员
* @param roleType
* @return
* @throws Exception
*/
public String getCreatorByRoleType(String roleType) throws Exception {
String creator = "";
User user = userService.getCurrentUser();
if(BusinessConstants.ROLE_TYPE_PRIVATE.equals(roleType)) {
creator = user.getId().toString();
} else if(BusinessConstants.ROLE_TYPE_THIS_ORG.equals(roleType)) {
creator = orgaUserRelService.getUserIdListByUserId(user.getId());
}
return creator;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertDepotHead(JSONObject obj, HttpServletRequest request)throws Exception {
DepotHead depotHead = JSONObject.parseObject(obj.toJSONString(), DepotHead.class);
depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
depotHead.setStatus(BusinessConstants.BILLS_STATUS_UN_AUDIT);
int result=0;
try{
result=depotHeadMapper.insert(depotHead);
logService.insertLog("单据", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateDepotHead(JSONObject obj, HttpServletRequest request) throws Exception{
DepotHead depotHead = JSONObject.parseObject(obj.toJSONString(), DepotHead.class);
DepotHead dh=null;
try{
dh = depotHeadMapper.selectByPrimaryKey(depotHead.getId());
}catch(Exception e){
JshException.readFail(logger, e);
}
depotHead.setStatus(dh.getStatus());
depotHead.setCreateTime(dh.getCreateTime());
int result=0;
try{
result = depotHeadMapper.updateByPrimaryKey(depotHead);
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depotHead.getId()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteDepotHead(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
//查询单据主表信息
DepotHead depotHead =getDepotHead(id);
User userInfo=userService.getCurrentUser();
//删除出库数据回收序列号
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())){
//查询单据子表列表
List<DepotItem> depotItemList=null;
try{
depotItemList = depotItemMapperEx.findDepotItemListBydepotheadId(id,BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED);
}catch(Exception e){
JshException.readFail(logger, e);
}
/**回收序列号*/
if(depotItemList!=null&&depotItemList.size()>0){
for(DepotItem depotItem:depotItemList){
//BasicNumber=OperNumber*ratio
serialNumberService.cancelSerialNumber(depotItem.getMaterialId(), depotItem.getHeaderId(),(depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue(),userInfo);
}
}
}
/**删除单据子表数据*/
try{
depotItemMapperEx.batchDeleteDepotItemByDepotHeadIds(new Long []{id});
//更新当前库存
List<DepotItem> list = depotItemService.getListByHeaderId(id);
for(DepotItem depotItem: list){
Long tenantId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"tenantId").toString());
depotItemService.updateCurrentStock(depotItem,tenantId);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
/**删除单据主表信息*/
batchDeleteDepotHeadByIds(id.toString());
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(depotHead.getNumber()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
result = 1;
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteDepotHead(String ids, HttpServletRequest request)throws Exception {
int result=0;
try{
if(StringUtil.isNotEmpty(ids)){
String [] headIds=ids.split(",");
for(int i=0;i<headIds.length;i++){
deleteDepotHead(Long.valueOf(headIds[i]), request);
}
}
result = 1;
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteDepotHeadByIds(String ids)throws Exception {
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result = depotHeadMapperEx.batchDeleteDepotHeadByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotHead> list = null;
try{
list = depotHeadMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetStatus(String status, String depotHeadIDs)throws Exception {
List<Long> ids = StringUtil.strToLongList(depotHeadIDs);
DepotHead depotHead = new DepotHead();
depotHead.setStatus(status);
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andIdIn(ids);
int result = 0;
try{
result = depotHeadMapper.updateByExampleSelective(depotHead, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public String findMaterialsListByHeaderId(Long id)throws Exception {
String result = null;
try{
result = depotHeadMapperEx.findMaterialsListByHeaderId(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotHeadVo4InDetail> findByAll(String beginTime, String endTime, String type, String materialParam, Integer depotId, Integer oId, Integer offset, Integer rows) throws Exception{
List<DepotHeadVo4InDetail> list = null;
try{
list =depotHeadMapperEx.findByAll(beginTime, endTime, type, materialParam, depotId, oId, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findByAllCount(String beginTime, String endTime, String type, String materialParam, Integer depotId, Integer oId) throws Exception{
int result = 0;
try{
result =depotHeadMapperEx.findByAllCount(beginTime, endTime, type, materialParam, depotId, oId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotHeadVo4InOutMCount> findInOutMaterialCount(String beginTime, String endTime, String type, String materialParam, Integer depotId, Integer oId, Integer offset, Integer rows)throws Exception {
List<DepotHeadVo4InOutMCount> list = null;
try{
list =depotHeadMapperEx.findInOutMaterialCount(beginTime, endTime, type, materialParam, depotId, oId, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findInOutMaterialCountTotal(String beginTime, String endTime, String type, String materialParam, Integer depotId, Integer oId)throws Exception {
int result = 0;
try{
result =depotHeadMapperEx.findInOutMaterialCountTotal(beginTime, endTime, type, materialParam, depotId, oId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotHeadVo4StatementAccount> findStatementAccount(String beginTime, String endTime, Integer organId, String supType, Integer offset, Integer rows)throws Exception {
List<DepotHeadVo4StatementAccount> list = null;
try{
list =depotHeadMapperEx.findStatementAccount(beginTime, endTime, organId, supType, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findStatementAccountCount(String beginTime, String endTime, Integer organId, String supType) throws Exception{
int result = 0;
try{
result =depotHeadMapperEx.findStatementAccountCount(beginTime, endTime, organId, supType);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public BigDecimal findAllMoney(Integer supplierId, String type, String subType, String mode, String endTime)throws Exception {
String modeName = "";
BigDecimal allOtherMoney = BigDecimal.ZERO;
if (mode.equals("实际")) {
modeName = "change_amount";
} else if (mode.equals("合计")) {
modeName = "discount_last_money";
allOtherMoney = depotHeadMapperEx.findAllOtherMoney(supplierId, type, subType, endTime);
}
BigDecimal result = BigDecimal.ZERO;
try{
result =depotHeadMapperEx.findAllMoney(supplierId, type, subType, modeName, endTime);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(allOtherMoney!=null) {
result = result.add(allOtherMoney);
}
return result;
}
/**
* 统计总金额
* @param getS
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
public BigDecimal allMoney(String getS, String type, String subType, String mode, String endTime) {
BigDecimal allMoney = BigDecimal.ZERO;
try {
Integer supplierId = Integer.valueOf(getS);
BigDecimal sum = findAllMoney(supplierId, type, subType, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if ((allMoney.compareTo(BigDecimal.ZERO))==-1) {
allMoney = allMoney.abs();
}
return allMoney;
}
/**
* 查询单位的累计应收和累计应付,零售不能计入
* @param supplierId
* @param endTime
* @param supType
* @return
*/
public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) {
BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString();
int i = 1;
if (("customer").equals(supType)) { //客户
i = 1;
} else if (("vendor").equals(supType)) { //供应商
i = -1;
}
//进销部分
sum = sum.subtract((allMoney(getS, "入库", "采购", "合计",endTime).subtract(allMoney(getS, "入库", "采购", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.subtract((allMoney(getS, "入库", "销售退货", "合计",endTime).subtract(allMoney(getS, "入库", "销售退货", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "出库", "销售", "合计",endTime).subtract(allMoney(getS, "出库", "销售", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "出库", "采购退货", "合计",endTime).subtract(allMoney(getS, "出库", "采购退货", "实际",endTime))).multiply(new BigDecimal(i)));
return sum;
}
public List<DepotHeadVo4List> getDetailByNumber(String number)throws Exception {
List<DepotHeadVo4List> resList = new ArrayList<DepotHeadVo4List>();
List<DepotHeadVo4List> list = null;
try{
list = depotHeadMapperEx.getDetailByNumber(number);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (DepotHeadVo4List dh : list) {
if(dh.getAccountIdList() != null) {
String accountidlistStr = dh.getAccountIdList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setAccountIdList(accountidlistStr);
}
if(dh.getAccountMoneyList() != null) {
String accountmoneylistStr = dh.getAccountMoneyList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setAccountMoneyList(accountmoneylistStr);
}
if(dh.getOtherMoneyList() != null) {
String otherMoneyListStr = dh.getOtherMoneyList().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setOtherMoneyList(otherMoneyListStr);
}
if(dh.getOtherMoneyItem() != null) {
String otherMoneyItemStr = dh.getOtherMoneyItem().replace("[", "").replace("]", "").replaceAll("\"", "");
dh.setOtherMoneyItem(otherMoneyItemStr);
}
if(dh.getChangeAmount() != null) {
dh.setChangeAmount(dh.getChangeAmount().abs());
}
if(dh.getTotalPrice() != null) {
dh.setTotalPrice(dh.getTotalPrice().abs());
}
dh.setOperTimeStr(getCenternTime(dh.getOperTime()));
dh.setMaterialsList(findMaterialsListByHeaderId(dh.getId()));
resList.add(dh);
}
}
return resList;
}
/**
* 新增单据主表及单据子表信息
* @param beanJson
* @param rows
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addDepotHeadAndDetail(String beanJson, String rows, Long tenantId,
HttpServletRequest request) throws Exception {
/**处理单据主表数据*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
//判断用户是否已经登录过,登录过不再处理
User userInfo=userService.getCurrentUser();
depotHead.setCreator(userInfo==null?null:userInfo.getId());
depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
depotHead.setStatus(BusinessConstants.BILLS_STATUS_UN_AUDIT);
try{
depotHeadMapper.insertSelective(depotHead);
}catch(Exception e){
JshException.writeFail(logger, e);
}
/**入库和出库处理预付款信息*/
if(BusinessConstants.PAY_TYPE_PREPAID.equals(depotHead.getPayType())){
if(depotHead.getOrganId()!=null) {
supplierService.updateAdvanceIn(depotHead.getOrganId(), BigDecimal.ZERO.subtract(depotHead.getTotalPrice()));
}
}
//根据单据编号查询单据id
DepotHeadExample dhExample = new DepotHeadExample();
dhExample.createCriteria().andNumberEqualTo(depotHead.getNumber()).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotHead> list = depotHeadMapper.selectByExample(dhExample);
if(list!=null) {
Long headId = list.get(0).getId();
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(rows,headId,tenantId, request);
}
/**如果关联单据号非空则更新订单的状态为2 */
if(depotHead.getLinkNumber()!=null) {
DepotHead depotHeadOrders = new DepotHead();
depotHeadOrders.setStatus(BusinessConstants.BILLS_STATUS_SKIP);
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andNumberEqualTo(depotHead.getLinkNumber());
try{
depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(depotHead.getNumber()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
/**
* 更新单据主表及单据子表信息
* @param beanJson
* @param rows
* @param preTotalPrice
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateDepotHeadAndDetail(String beanJson, String rows,
BigDecimal preTotalPrice, Long tenantId,HttpServletRequest request)throws Exception {
/**更新单据主表信息*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
try{
depotHeadMapper.updateByPrimaryKeySelective(depotHead);
}catch(Exception e){
JshException.writeFail(logger, e);
}
/**入库和出库处理预付款信息*/
if(BusinessConstants.PAY_TYPE_PREPAID.equals(depotHead.getPayType())){
if(depotHead.getOrganId()!=null){
supplierService.updateAdvanceIn(depotHead.getOrganId(), BigDecimal.ZERO.subtract(depotHead.getTotalPrice().subtract(preTotalPrice)));
}
}
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(rows,depotHead.getId(),tenantId,request);
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depotHead.getNumber()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
public BigDecimal getBuyAndSaleStatistics(String type, String subType, Integer hasSupplier, String beginTime, String endTime) {
return depotHeadMapperEx.getBuyAndSaleStatistics(type, subType, hasSupplier, beginTime, endTime);
}
public BigDecimal getBuyAndSaleRetailStatistics(String type, String subType, Integer hasSupplier, String beginTime, String endTime) {
return depotHeadMapperEx.getBuyAndSaleRetailStatistics(type, subType, hasSupplier, beginTime, endTime);
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.depotItem;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "depotItem_component")
@DepotItemResource
public class DepotItemComponent implements ICommonQuery {
@Resource
private DepotItemService depotItemService;
@Override
public Object selectOne(Long id) throws Exception {
return depotItemService.getDepotItem(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getDepotItemList(map);
}
private List<?> getDepotItemList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return depotItemService.select(name, type, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
String remark = StringUtil.getInfo(search, "remark");
return depotItemService.countDepotItem(name, type, remark);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return depotItemService.insertDepotItem(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return depotItemService.updateDepotItem(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return depotItemService.deleteDepotItem(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return depotItemService.batchDeleteDepotItem(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return depotItemService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.depotItem;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "depotItem")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface DepotItemResource {
}

View File

@@ -0,0 +1,530 @@
package com.jsh.erp.service.depotItem;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.materialExtend.MaterialExtendService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.service.serialNumber.SerialNumberService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class DepotItemService {
private Logger logger = LoggerFactory.getLogger(DepotItemService.class);
private final static String TYPE = "入库";
private final static String SUM_TYPE = "number";
private final static String IN = "in";
private final static String OUT = "out";
@Resource
private DepotItemMapper depotItemMapper;
@Resource
private DepotItemMapperEx depotItemMapperEx;
@Resource
private MaterialService materialService;
@Resource
private MaterialExtendService materialExtendService;
@Resource
SerialNumberMapperEx serialNumberMapperEx;
@Resource
private DepotHeadMapper depotHeadMapper;
@Resource
SerialNumberService serialNumberService;
@Resource
private UserService userService;
@Resource
private SystemConfigService systemConfigService;
@Resource
private MaterialCurrentStockMapper materialCurrentStockMapper;
@Resource
private LogService logService;
public DepotItem getDepotItem(long id)throws Exception {
DepotItem result=null;
try{
result=depotItemMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<DepotItem> getDepotItem()throws Exception {
DepotItemExample example = new DepotItemExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotItem> list=null;
try{
list=depotItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotItem> select(String name, Integer type, String remark, int offset, int rows)throws Exception {
List<DepotItem> list=null;
try{
list=depotItemMapperEx.selectByConditionDepotItem(name, type, remark, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countDepotItem(String name, Integer type, String remark) throws Exception{
Long result =null;
try{
result=depotItemMapperEx.countsByDepotItem(name, type, remark);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertDepotItem(JSONObject obj, HttpServletRequest request)throws Exception {
DepotItem depotItem = JSONObject.parseObject(obj.toJSONString(), DepotItem.class);
int result =0;
try{
result=depotItemMapper.insertSelective(depotItem);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateDepotItem(JSONObject obj, HttpServletRequest request)throws Exception {
DepotItem depotItem = JSONObject.parseObject(obj.toJSONString(), DepotItem.class);
int result =0;
try{
result=depotItemMapper.updateByPrimaryKeySelective(depotItem);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteDepotItem(Long id, HttpServletRequest request)throws Exception {
int result =0;
try{
result=depotItemMapper.deleteByPrimaryKey(id);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteDepotItem(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
DepotItemExample example = new DepotItemExample();
example.createCriteria().andIdIn(idList);
int result =0;
try{
result=depotItemMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
DepotItemExample example = new DepotItemExample();
example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<DepotItem> list =null;
try{
list=depotItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<DepotItemVo4DetailByTypeAndMId> findDetailByTypeAndMaterialIdList(Map<String, String> map)throws Exception {
String mIdStr = map.get("mId");
Long mId = null;
if(!StringUtil.isEmpty(mIdStr)) {
mId = Long.parseLong(mIdStr);
}
List<DepotItemVo4DetailByTypeAndMId> list =null;
try{
list = depotItemMapperEx.findDetailByTypeAndMaterialIdList(mId, QueryUtils.offset(map), QueryUtils.rows(map));
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long findDetailByTypeAndMaterialIdCounts(Map<String, String> map)throws Exception {
String mIdStr = map.get("mId");
Long mId = null;
if(!StringUtil.isEmpty(mIdStr)) {
mId = Long.parseLong(mIdStr);
}
Long result =null;
try{
result = depotItemMapperEx.findDetailByTypeAndMaterialIdCounts(mId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertDepotItemWithObj(DepotItem depotItem)throws Exception {
int result =0;
try{
result = depotItemMapper.insertSelective(depotItem);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateDepotItemWithObj(DepotItem depotItem)throws Exception {
int result =0;
try{
result = depotItemMapper.updateByPrimaryKeySelective(depotItem);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<DepotItem> getListByHeaderId(Long headerId)throws Exception {
List<DepotItem> list =null;
try{
DepotItemExample example = new DepotItemExample();
example.createCriteria().andHeaderIdEqualTo(headerId);
list = depotItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotItemVo4WithInfoEx> getDetailList(Long headerId)throws Exception {
List<DepotItemVo4WithInfoEx> list =null;
try{
list = depotItemMapperEx.getDetailList(headerId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotItemVo4WithInfoEx> findByAll(String materialParam, String endTime, Integer offset, Integer rows)throws Exception {
List<DepotItemVo4WithInfoEx> list =null;
try{
list = depotItemMapperEx.findByAll(materialParam, endTime, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findByAllCount(String materialParam, String endTime)throws Exception {
int result=0;
try{
result = depotItemMapperEx.findByAllCount(materialParam, endTime);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public BigDecimal buyOrSale(String type, String subType, Long MId, String MonthTime, String sumType) throws Exception{
BigDecimal result= BigDecimal.ZERO;
try{
if (SUM_TYPE.equals(sumType)) {
result= depotItemMapperEx.buyOrSaleNumber(type, subType, MId, MonthTime, sumType);
} else {
result= depotItemMapperEx.buyOrSalePrice(type, subType, MId, MonthTime, sumType);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* 统计采购或销售的总金额
* @param type
* @param subType
* @param MonthTime
* @return
* @throws Exception
*/
public BigDecimal inOrOutPrice(String type, String subType, String MonthTime) throws Exception{
BigDecimal result= BigDecimal.ZERO;
try{
result = depotItemMapperEx.inOrOutPrice(type, subType, MonthTime);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void saveDetials(String rows, Long headerId, Long tenantId, HttpServletRequest request) throws Exception{
//查询单据主表信息
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
//获得当前操作人
User userInfo=userService.getCurrentUser();
//首先回收序列号,如果是调拨,不用处理序列号
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())){
List<DepotItem> depotItemList = getListByHeaderId(headerId);
for(DepotItem depotItem : depotItemList){
Material material= materialService.getMaterial(depotItem.getMaterialId());
if(material==null){
continue;
}
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())){
serialNumberService.cancelSerialNumber(depotItem.getMaterialId(),depotItem.getHeaderId(),
(depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue(), userInfo);
}
}
}
//删除单据的明细
deleteDepotItemHeadId(headerId);
JSONArray rowArr = JSONArray.parseArray(rows);
if (null != rowArr) {
for (int i = 0; i < rowArr.size(); i++) {
DepotItem depotItem = new DepotItem();
JSONObject rowObj = JSONObject.parseObject(rowArr.getString(i));
depotItem.setHeaderId(headerId);
String barCode = rowObj.getString("barCode");
MaterialExtend materialExtend = materialExtendService.getInfoByBarCode(barCode);
depotItem.setMaterialId(materialExtend.getMaterialId());
depotItem.setMaterialExtendId(materialExtend.getId());
depotItem.setMaterialUnit(rowObj.getString("unit"));
if (StringUtil.isExist(rowObj.get("operNumber"))) {
depotItem.setOperNumber(rowObj.getBigDecimal("operNumber"));
String unit = rowObj.get("unit").toString();
BigDecimal oNumber = rowObj.getBigDecimal("operNumber");
//以下进行单位换算
Unit unitInfo = materialService.findUnit(materialExtend.getMaterialId()); //查询计量单位信息
if (StringUtil.isNotEmpty(unitInfo.getName())) {
String basicUnit = unitInfo.getBasicUnit(); //基本单位
String otherUnit = unitInfo.getOtherUnit(); //副单位
Integer ratio = unitInfo.getRatio(); //比例
if (unit.equals(basicUnit)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber.multiply(new BigDecimal(ratio)) ); //数量乘以比例
}
} else {
depotItem.setBasicNumber(oNumber); //其他情况
}
}
if (StringUtil.isExist(rowObj.get("unitPrice"))) {
depotItem.setUnitPrice(rowObj.getBigDecimal("unitPrice"));
}
if (StringUtil.isExist(rowObj.get("taxUnitPrice"))) {
depotItem.setTaxUnitPrice(rowObj.getBigDecimal("taxUnitPrice"));
}
if (StringUtil.isExist(rowObj.get("allPrice"))) {
depotItem.setAllPrice(rowObj.getBigDecimal("allPrice"));
}
if (StringUtil.isExist(rowObj.get("depotId"))) {
depotItem.setDepotId(rowObj.getLong("depotId"));
} else {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_DEPOT_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_DEPOT_FAILED_MSG));
}
if(BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())) {
if (StringUtil.isExist(rowObj.get("anotherDepotId"))) {
depotItem.setAnotherDepotId(rowObj.getLong("anotherDepotId"));
} else {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_FAILED_MSG));
}
}
if (StringUtil.isExist(rowObj.get("taxRate"))) {
depotItem.setTaxRate(rowObj.getBigDecimal("taxRate"));
}
if (StringUtil.isExist(rowObj.get("taxMoney"))) {
depotItem.setTaxMoney(rowObj.getBigDecimal("taxMoney"));
}
if (StringUtil.isExist(rowObj.get("taxLastMoney"))) {
depotItem.setTaxLastMoney(rowObj.getBigDecimal("taxLastMoney"));
}
if (StringUtil.isExist(rowObj.get("mType"))) {
depotItem.setMaterialType(rowObj.getString("mType"));
}
if (StringUtil.isExist(rowObj.get("remark"))) {
depotItem.setRemark(rowObj.getString("remark"));
}
//出库时判断库存是否充足
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
if(depotItem==null){
continue;
}
Material material= materialService.getMaterial(depotItem.getMaterialId());
if(material==null){
continue;
}
BigDecimal stock = getStockByParam(depotItem.getDepotId(),depotItem.getMaterialId(),null,null,tenantId);
BigDecimal thisBasicNumber = depotItem.getBasicNumber()==null?BigDecimal.ZERO:depotItem.getBasicNumber();
if(systemConfigService.getMinusStockFlag() == false && stock.compareTo(thisBasicNumber)<0){
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE,
String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG,material==null?"":material.getName()));
}
//出库时处理序列号
if(!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())) {
//判断商品是否开启序列号,开启的收回序列号,未开启的跳过
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
//查询单据子表中开启序列号的数据列表
serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo);
}
}
}
this.insertDepotItemWithObj(depotItem);
//更新当前库存
updateCurrentStock(depotItem,tenantId);
}
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void deleteDepotItemHeadId(Long headerId)throws Exception {
DepotItemExample example = new DepotItemExample();
example.createCriteria().andHeaderIdEqualTo(headerId);
try{
depotItemMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public List<DepotItemStockWarningCount> findStockWarningCount(Integer offset, Integer rows, String materialParam, Long depotId) {
List<DepotItemStockWarningCount> list = null;
try{
list =depotItemMapperEx.findStockWarningCount(offset, rows, materialParam, depotId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int findStockWarningCountTotal(String materialParam, Long depotId) {
int result = 0;
try{
result =depotItemMapperEx.findStockWarningCountTotal(materialParam, depotId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* 库存统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
//初始库存
BigDecimal initStock = materialService.getInitStockByMid(depotId, mId);
//盘点复盘后数量的变动
BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSum(depotId, mId, beginTime, endTime);
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
BigDecimal intNum = stockObj.getInNum();
BigDecimal outNum = stockObj.getOutNum();
return initStock.add(intNum).subtract(outNum).add(stockCheckSum);
}
/**
* 入库统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
return stockObj.getInNum();
}
/**
* 出库统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
return stockObj.getOutNum();
}
/**
* 根据单据明细来批量更新当前库存
* @param depotItem
* @param tenantId
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateCurrentStock(DepotItem depotItem, Long tenantId){
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId(),tenantId);
if(depotItem.getAnotherDepotId()!=null){
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId(),tenantId);
}
}
/**
* 根据商品和仓库来更新当前库存
* @param mId
* @param dId
* @param tenantId
*/
public void updateCurrentStockFun(Long mId, Long dId, Long tenantId) {
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
materialCurrentStock.setMaterialId(mId);
materialCurrentStock.setDepotId(dId);
materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null,tenantId));
if(list!=null && list.size()>0) {
Long mcsId = list.get(0).getId();
materialCurrentStock.setId(mcsId);
materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
} else {
materialCurrentStockMapper.insertSelective(materialCurrentStock);
}
}
}

View File

@@ -0,0 +1,73 @@
package com.jsh.erp.service.functions;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "function_component")
@FunctionResource
public class FunctionComponent implements ICommonQuery {
@Resource
private FunctionService functionService;
@Override
public Object selectOne(Long id) throws Exception {
return functionService.getFunction(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getFunctionsList(map);
}
private List<?> getFunctionsList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
String order = QueryUtils.order(map);
return functionService.select(name, type, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
return functionService.countFunction(name, type);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return functionService.insertFunction(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return functionService.updateFunction(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return functionService.deleteFunction(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return functionService.batchDeleteFunction(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return functionService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.functions;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "function")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface FunctionResource {
}

View File

@@ -0,0 +1,209 @@
package com.jsh.erp.service.functions;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.Function;
import com.jsh.erp.datasource.entities.FunctionExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.FunctionMapper;
import com.jsh.erp.datasource.mappers.FunctionMapperEx;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class FunctionService {
private Logger logger = LoggerFactory.getLogger(FunctionService.class);
@Resource
private FunctionMapper functionsMapper;
@Resource
private FunctionMapperEx functionMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
public Function getFunction(long id)throws Exception {
Function result=null;
try{
result=functionsMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Function> getFunctionListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Function> list = new ArrayList<>();
try{
FunctionExample example = new FunctionExample();
example.createCriteria().andIdIn(idList);
list = functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Function> getFunction()throws Exception {
FunctionExample example = new FunctionExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Function> list=null;
try{
list=functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Function> select(String name, String type, int offset, int rows)throws Exception {
List<Function> list=null;
try{
list= functionMapperEx.selectByConditionFunction(name, type, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countFunction(String name, String type)throws Exception {
Long result=null;
try{
result= functionMapperEx.countsByFunction(name, type);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertFunction(JSONObject obj, HttpServletRequest request)throws Exception {
Function functions = JSONObject.parseObject(obj.toJSONString(), Function.class);
int result=0;
try{
result=functionsMapper.insertSelective(functions);
logService.insertLog("功能",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(functions.getName()).toString(),request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateFunction(JSONObject obj, HttpServletRequest request) throws Exception{
Function functions = JSONObject.parseObject(obj.toJSONString(), Function.class);
int result=0;
try{
result=functionsMapper.updateByPrimaryKeySelective(functions);
logService.insertLog("功能",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(functions.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteFunction(Long id, HttpServletRequest request)throws Exception {
return batchDeleteFunctionByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteFunction(String ids, HttpServletRequest request)throws Exception {
return batchDeleteFunctionByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteFunctionByIds(String ids)throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Function> list = getFunctionListByIds(ids);
for(Function functions: list){
sb.append("[").append(functions.getName()).append("]");
}
logService.insertLog("功能", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result = functionMapperEx.batchDeleteFunctionByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
FunctionExample example = new FunctionExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Function> list=null;
try{
list = functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<Function> getRoleFunction(String pNumber)throws Exception {
FunctionExample example = new FunctionExample();
example.createCriteria().andEnabledEqualTo(true).andParentNumberEqualTo(pNumber)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort");
List<Function> list=null;
try{
list = functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Function> findRoleFunction(String pnumber)throws Exception{
FunctionExample example = new FunctionExample();
example.createCriteria().andEnabledEqualTo(true).andParentNumberEqualTo(pnumber)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort");
List<Function> list=null;
try{
list =functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Function> findByIds(String functionsIds)throws Exception{
List<Long> idList = StringUtil.strToLongList(functionsIds);
FunctionExample example = new FunctionExample();
example.createCriteria().andEnabledEqualTo(true).andIdIn(idList)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("Sort asc");
List<Function> list=null;
try{
list =functionsMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.inOutItem;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "inOutItem_component")
@InOutItemResource
public class InOutItemComponent implements ICommonQuery {
@Resource
private InOutItemService inOutItemService;
@Override
public Object selectOne(Long id) throws Exception {
return inOutItemService.getInOutItem(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getFunctionsList(map);
}
private List<?> getFunctionsList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return inOutItemService.select(name, type, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
String remark = StringUtil.getInfo(search, "remark");
return inOutItemService.countInOutItem(name, type, remark);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return inOutItemService.insertInOutItem(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return inOutItemService.updateInOutItem(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return inOutItemService.deleteInOutItem(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return inOutItemService.batchDeleteInOutItem(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return inOutItemService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.inOutItem;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "inOutItem")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface InOutItemResource {
}

View File

@@ -0,0 +1,202 @@
package com.jsh.erp.service.inOutItem;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.AccountItemMapperEx;
import com.jsh.erp.datasource.mappers.InOutItemMapper;
import com.jsh.erp.datasource.mappers.InOutItemMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class InOutItemService {
private Logger logger = LoggerFactory.getLogger(InOutItemService.class);
@Resource
private InOutItemMapper inOutItemMapper;
@Resource
private InOutItemMapperEx inOutItemMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private AccountItemMapperEx accountItemMapperEx;
public InOutItem getInOutItem(long id)throws Exception {
InOutItem result=null;
try{
result=inOutItemMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<InOutItem> getInOutItemListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<InOutItem> list = new ArrayList<>();
try{
InOutItemExample example = new InOutItemExample();
example.createCriteria().andIdIn(idList);
list = inOutItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<InOutItem> getInOutItem()throws Exception {
InOutItemExample example = new InOutItemExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<InOutItem> list=null;
try{
list=inOutItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<InOutItem> select(String name, String type, String remark, int offset, int rows)throws Exception {
List<InOutItem> list=null;
try{
list=inOutItemMapperEx.selectByConditionInOutItem(name, type, remark, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countInOutItem(String name, String type, String remark)throws Exception {
Long result=null;
try{
result=inOutItemMapperEx.countsByInOutItem(name, type, remark);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertInOutItem(JSONObject obj, HttpServletRequest request)throws Exception {
InOutItem inOutItem = JSONObject.parseObject(obj.toJSONString(), InOutItem.class);
int result=0;
try{
result=inOutItemMapper.insertSelective(inOutItem);
logService.insertLog("收支项目",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(inOutItem.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateInOutItem(JSONObject obj, HttpServletRequest request)throws Exception {
InOutItem inOutItem = JSONObject.parseObject(obj.toJSONString(), InOutItem.class);
int result=0;
try{
result=inOutItemMapper.updateByPrimaryKeySelective(inOutItem);
logService.insertLog("收支项目",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(inOutItem.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteInOutItem(Long id, HttpServletRequest request)throws Exception {
return batchDeleteInOutItemByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteInOutItem(String ids, HttpServletRequest request)throws Exception {
return batchDeleteInOutItemByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteInOutItemByIds(String ids)throws Exception {
int result = 0;
String [] idArray=ids.split(",");
//校验财务子表 jsh_accountitem
List<AccountItem> accountItemList=null;
try{
accountItemList=accountItemMapperEx.getAccountItemListByInOutItemIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(accountItemList!=null&&accountItemList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,InOutItemIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验通过执行删除操作
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<InOutItem> list = getInOutItemListByIds(ids);
for(InOutItem inOutItem: list){
sb.append("[").append(inOutItem.getName()).append("]");
}
logService.insertLog("收支项目", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
try{
result=inOutItemMapperEx.batchDeleteInOutItemByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
InOutItemExample example = new InOutItemExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<InOutItem> list = null;
try{
list=inOutItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<InOutItem> findBySelect(String type)throws Exception {
InOutItemExample example = new InOutItemExample();
if (type.equals("in")) {
example.createCriteria().andTypeEqualTo("收入").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else if (type.equals("out")) {
example.createCriteria().andTypeEqualTo("支出").andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
example.setOrderByClause("id desc");
List<InOutItem> list = null;
try{
list=inOutItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
}

View File

@@ -0,0 +1,83 @@
package com.jsh.erp.service.log;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "log_component")
@LogResource
public class LogComponent implements ICommonQuery {
@Resource
private LogService logService;
@Override
public Object selectOne(Long id) throws Exception {
return logService.getLog(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getLogList(map);
}
private List<?> getLogList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String operation = StringUtil.getInfo(search, "operation");
Integer userId = StringUtil.parseInteger(StringUtil.getInfo(search, "userId"));
String clientIp = StringUtil.getInfo(search, "clientIp");
Integer status = StringUtil.parseInteger(StringUtil.getInfo(search, "status"));
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String content = StringUtil.getInfo(search, "content");
return logService.select(operation, userId, clientIp, status, beginTime, endTime, content,
QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String operation = StringUtil.getInfo(search, "operation");
Integer userId = StringUtil.parseInteger(StringUtil.getInfo(search, "userId"));
String clientIp = StringUtil.getInfo(search, "clientIp");
Integer status = StringUtil.parseInteger(StringUtil.getInfo(search, "status"));
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String content = StringUtil.getInfo(search, "content");
return logService.countLog(operation, userId, clientIp, status, beginTime, endTime, content);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return logService.insertLog(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return logService.updateLog(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return logService.deleteLog(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return logService.batchDeleteLog(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.log;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "log")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogResource {
}

View File

@@ -0,0 +1,180 @@
package com.jsh.erp.service.log;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Log;
import com.jsh.erp.datasource.entities.LogExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.LogMapper;
import com.jsh.erp.datasource.mappers.LogMapperEx;
import com.jsh.erp.datasource.vo.LogVo4List;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import static com.jsh.erp.utils.Tools.getLocalIp;
@Service
public class LogService {
private Logger logger = LoggerFactory.getLogger(LogService.class);
@Resource
private LogMapper logMapper;
@Resource
private LogMapperEx logMapperEx;
@Resource
private UserService userService;
@Resource
private RedisService redisService;
public Log getLog(long id)throws Exception {
Log result=null;
try{
result=logMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Log> getLog()throws Exception {
LogExample example = new LogExample();
List<Log> list=null;
try{
list=logMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<LogVo4List> select(String operation, Integer userId, String clientIp, Integer status, String beginTime, String endTime,
String content, int offset, int rows)throws Exception {
List<LogVo4List> list=null;
try{
list=logMapperEx.selectByConditionLog(operation, userId, clientIp, status, beginTime, endTime,
content, offset, rows);
if (null != list) {
for (LogVo4List log : list) {
log.setCreateTimeStr(Tools.getCenternTime(log.getCreateTime()));
}
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countLog(String operation, Integer userId, String clientIp, Integer status, String beginTime, String endTime,
String content)throws Exception {
Long result=null;
try{
result=logMapperEx.countsByLog(operation, userId, clientIp, status, beginTime, endTime, content);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertLog(JSONObject obj, HttpServletRequest request) throws Exception{
Log log = JSONObject.parseObject(obj.toJSONString(), Log.class);
int result=0;
try{
result=logMapper.insertSelective(log);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateLog(JSONObject obj, HttpServletRequest request)throws Exception {
Log log = JSONObject.parseObject(obj.toJSONString(), Log.class);
int result=0;
try{
result=logMapper.updateByPrimaryKeySelective(log);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteLog(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result=logMapper.deleteByPrimaryKey(id);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteLog(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
LogExample example = new LogExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result=logMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public void insertLog(String moduleName, String content, HttpServletRequest request)throws Exception{
try{
Long userId = userService.getUserId(request);
if(userId!=null) {
Log log = new Log();
log.setUserId(userId);
log.setOperation(moduleName);
log.setClientIp(getLocalIp(request));
log.setCreateTime(new Date());
Byte status = 0;
log.setStatus(status);
log.setContent(content);
logMapper.insertSelective(log);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
public void insertLogWithUserId(Long userId, Long tenantId, String moduleName, String content, HttpServletRequest request)throws Exception{
try{
if(userId!=null) {
Log log = new Log();
log.setUserId(userId);
log.setOperation(moduleName);
log.setClientIp(getLocalIp(request));
log.setCreateTime(new Date());
Byte status = 0;
log.setStatus(status);
log.setContent(content);
log.setTenantId(tenantId);
logMapper.insertSelective(log);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
}

View File

@@ -0,0 +1,82 @@
package com.jsh.erp.service.material;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.depot.DepotResource;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "material_component")
@MaterialResource
public class MaterialComponent implements ICommonQuery {
@Resource
private MaterialService materialService;
@Override
public Object selectOne(Long id) throws Exception {
return materialService.getMaterial(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getMaterialList(map);
}
private List<?> getMaterialList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String categoryId = StringUtil.getInfo(search, "categoryId");
String barCode = StringUtil.getInfo(search, "barCode");
String name = StringUtil.getInfo(search, "name");
String standard = StringUtil.getInfo(search, "standard");
String model = StringUtil.getInfo(search, "model");
String mpList = StringUtil.getInfo(search, "mpList");
return materialService.select(barCode, name, standard, model,categoryId,mpList, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String categoryId = StringUtil.getInfo(search, "categoryId");
String barCode = StringUtil.getInfo(search, "barCode");
String name = StringUtil.getInfo(search, "name");
String standard = StringUtil.getInfo(search, "standard");
String model = StringUtil.getInfo(search, "model");
String mpList = StringUtil.getInfo(search, "mpList");
return materialService.countMaterial(barCode, name, standard, model,categoryId,mpList);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return materialService.insertMaterial(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return materialService.updateMaterial(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return materialService.deleteMaterial(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return materialService.batchDeleteMaterial(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return materialService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.material;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "material")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaterialResource {
}

View File

@@ -0,0 +1,796 @@
package com.jsh.erp.service.material;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.materialExtend.MaterialExtendService;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.materialCategory.MaterialCategoryService;
import com.jsh.erp.service.unit.UnitService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ExcelUtils;
import com.jsh.erp.utils.StringUtil;
import jxl.Sheet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
@Service
public class MaterialService {
private Logger logger = LoggerFactory.getLogger(MaterialService.class);
@Resource
private MaterialMapper materialMapper;
@Resource
private MaterialExtendMapper materialExtendMapper;
@Resource
private MaterialMapperEx materialMapperEx;
@Resource
private MaterialCategoryMapperEx materialCategoryMapperEx;
@Resource
private MaterialExtendMapperEx materialExtendMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
@Resource
private DepotItemMapperEx depotItemMapperEx;
@Resource
private DepotItemService depotItemService;
@Resource
private MaterialCategoryService materialCategoryService;
@Resource
private UnitService unitService;
@Resource
private MaterialInitialStockMapper materialInitialStockMapper;
@Resource
private MaterialCurrentStockMapper materialCurrentStockMapper;
@Resource
private DepotService depotService;
@Resource
private MaterialExtendService materialExtendService;
public Material getMaterial(long id)throws Exception {
Material result=null;
try{
result=materialMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Material> getMaterialListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Material> list = new ArrayList<>();
try{
MaterialExample example = new MaterialExample();
example.createCriteria().andIdIn(idList);
list = materialMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Material> getMaterial() throws Exception{
MaterialExample example = new MaterialExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Material> list=null;
try{
list=materialMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialVo4Unit> select(String barCode, String name, String standard, String model, String categoryId,String mpList, int offset, int rows)
throws Exception{
String[] mpArr = new String[]{};
if(StringUtil.isNotEmpty(mpList)){
mpArr= mpList.split(",");
}
List<MaterialVo4Unit> resList = new ArrayList<>();
List<MaterialVo4Unit> list =null;
try{
List<Long> idList = new ArrayList<>();
if(StringUtil.isNotEmpty(categoryId)){
idList = getListByParentId(Long.parseLong(categoryId));
}
list= materialMapperEx.selectByConditionMaterial(barCode, name, standard, model, idList, mpList, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (MaterialVo4Unit m : list) {
//扩展信息
String materialOther = "";
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("制造商")) {
materialOther = materialOther + ((m.getMfrs() == null || m.getMfrs().equals("")) ? "" : "(" + m.getMfrs() + ")");
}
if (mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((m.getOtherField1() == null || m.getOtherField1().equals("")) ? "" : "(" + m.getOtherField1() + ")");
}
if (mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((m.getOtherField2() == null || m.getOtherField2().equals("")) ? "" : "(" + m.getOtherField2() + ")");
}
if (mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((m.getOtherField3() == null || m.getOtherField3().equals("")) ? "" : "(" + m.getOtherField3() + ")");
}
}
m.setMaterialOther(materialOther);
Long tenantId = m.getTenantId();
m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null,tenantId));
resList.add(m);
}
}
return resList;
}
public Long countMaterial(String barCode, String name, String standard, String model, String categoryId,String mpList)throws Exception {
Long result =null;
try{
List<Long> idList = new ArrayList<>();
if(StringUtil.isNotEmpty(categoryId)){
idList = getListByParentId(Long.parseLong(categoryId));
}
result= materialMapperEx.countsByMaterial(barCode, name, standard, model, idList, mpList);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertMaterial(JSONObject obj, HttpServletRequest request)throws Exception {
Material m = JSONObject.parseObject(obj.toJSONString(), Material.class);
m.setEnabled(true);
try{
Long mId = null;
materialMapper.insertSelective(m);
List<Material> materials = getMaterialListByParam(m.getName(),m.getModel(),m.getColor(),
m.getStandard(), m.getMfrs(),m.getUnit(),m.getUnitId());
if(materials!=null && materials.size()>0) {
mId = materials.get(0).getId();
}
materialExtendService.saveDetials(obj, obj.getString("sortList"), mId);
if(obj.get("stock")!=null) {
JSONArray stockArr = obj.getJSONArray("stock");
for (int i = 0; i < stockArr.size(); i++) {
JSONObject jsonObj = stockArr.getJSONObject(i);
if(jsonObj.get("id")!=null && jsonObj.get("initStock")!=null) {
String number = jsonObj.getString("initStock");
Long depotId = jsonObj.getLong("id");
if(StringUtil.isNotEmpty(number) && Double.valueOf(number)>0) {
insertStockByMaterialAndDepot(depotId, mId, parseBigDecimalEx(number));
}
}
}
}
logService.insertLog("商品",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(m.getName()).toString(), request);
return 1;
}catch(Exception e){
JshException.writeFail(logger, e);
return 0;
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateMaterial(JSONObject obj, HttpServletRequest request) throws Exception{
Material material = JSONObject.parseObject(obj.toJSONString(), Material.class);
try{
materialMapper.updateByPrimaryKeySelective(material);
if(material.getUnitId() == null) {
materialMapperEx.setUnitIdToNull(material.getId());
}
materialExtendService.saveDetials(obj, obj.getString("sortList"),material.getId());
if(obj.get("stock")!=null) {
JSONArray stockArr = obj.getJSONArray("stock");
for (int i = 0; i < stockArr.size(); i++) {
JSONObject jsonObj = stockArr.getJSONObject(i);
if (jsonObj.get("id") != null && jsonObj.get("initStock") != null) {
String number = jsonObj.getString("initStock");
Long depotId = jsonObj.getLong("id");
//先清除再插入
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(material.getId()).andDepotIdEqualTo(depotId);
materialInitialStockMapper.deleteByExample(example);
if (StringUtil.isNotEmpty(number) && Double.valueOf(number) > 0) {
insertStockByMaterialAndDepot(depotId, material.getId(), parseBigDecimalEx(number));
}
}
}
}
logService.insertLog("商品",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(material.getName()).toString(), request);
return 1;
}catch(Exception e){
JshException.writeFail(logger, e);
return 0;
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteMaterial(Long id, HttpServletRequest request)throws Exception {
return batchDeleteMaterialByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterial(String ids, HttpServletRequest request)throws Exception {
return batchDeleteMaterialByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialByIds(String ids) throws Exception{
String [] idArray=ids.split(",");
//校验单据子表 jsh_depot_item
List<DepotItem> depotItemList =null;
try{
depotItemList= depotItemMapperEx.getDepotItemListListByMaterialIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(depotItemList!=null&&depotItemList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,MaterialIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Material> list = getMaterialListByIds(ids);
for(Material material: list){
sb.append("[").append(material.getName()).append("]");
}
logService.insertLog("商品", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
//校验通过执行删除操作
try{
//逻辑删除商品
materialMapperEx.batchDeleteMaterialByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
//逻辑删除商品价格扩展
materialExtendMapperEx.batchDeleteMaterialExtendByMIds(idArray);
return 1;
}catch(Exception e){
JshException.writeFail(logger, e);
return 0;
}
}
public int checkIsNameExist(Long id, String name)throws Exception {
MaterialExample example = new MaterialExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Material> list =null;
try{
list= materialMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public int checkIsExist(Long id, String name, String model, String color, String standard, String mfrs,
String otherField1, String otherField2, String otherField3, String unit, Long unitId)throws Exception {
MaterialExample example = new MaterialExample();
MaterialExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(name).andModelEqualTo(model).andColorEqualTo(color)
.andStandardEqualTo(standard).andMfrsEqualTo(mfrs)
.andOtherField1EqualTo(otherField1).andOtherField2EqualTo(otherField2).andOtherField2EqualTo(otherField3)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
if (id > 0) {
criteria.andIdNotEqualTo(id);
}
if (!StringUtil.isEmpty(unit)) {
criteria.andUnitEqualTo(unit);
}
if (unitId !=null) {
criteria.andUnitIdEqualTo(unitId);
}
List<Material> list =null;
try{
list= materialMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetStatus(Boolean status, String ids)throws Exception {
logService.insertLog("商品",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
List<Long> materialIds = StringUtil.strToLongList(ids);
Material material = new Material();
material.setEnabled(status);
MaterialExample example = new MaterialExample();
example.createCriteria().andIdIn(materialIds);
int result =0;
try{
result= materialMapper.updateByExampleSelective(material, example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public Unit findUnit(Long mId)throws Exception{
Unit unit = new Unit();
try{
List<Unit> list = materialMapperEx.findUnitList(mId);
if(list!=null && list.size()>0) {
unit = list.get(0);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return unit;
}
public List<MaterialVo4Unit> findById(Long id)throws Exception{
List<MaterialVo4Unit> list =null;
try{
list= materialMapperEx.findById(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialVo4Unit> findByIdWithBarCode(Long meId)throws Exception{
List<MaterialVo4Unit> list =null;
try{
list= materialMapperEx.findByIdWithBarCode(meId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Long> getListByParentId(Long parentId) {
List<Long> idList = new ArrayList<Long>();
List<MaterialCategory> list = materialCategoryMapperEx.getListByParentId(parentId);
idList.add(parentId);
if(list!=null && list.size()>0) {
getIdListByParentId(idList, parentId);
}
return idList;
}
public List<Long> getIdListByParentId(List<Long> idList, Long parentId){
List<MaterialCategory> list = materialCategoryMapperEx.getListByParentId(parentId);
if(list!=null && list.size()>0) {
for(MaterialCategory mc : list){
idList.add(mc.getId());
getIdListByParentId(idList, mc.getId());
}
}
return idList;
}
public List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, Integer offset, Integer rows)throws Exception{
List<MaterialVo4Unit> list =null;
try{
List<Long> idList = new ArrayList<>();
if(categoryId!=null){
Long parentId = categoryId;
idList = getListByParentId(parentId);
}
if(StringUtil.isNotEmpty(q)) {
q = q.replace("'", "");
}
list= materialMapperEx.findBySelectWithBarCode(idList, q, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public int findBySelectWithBarCodeCount(Long categoryId, String q)throws Exception{
int result=0;
try{
List<Long> idList = new ArrayList<>();
if(categoryId!=null){
Long parentId = categoryId;
idList = getListByParentId(parentId);
}
if(StringUtil.isNotEmpty(q)) {
q = q.replace("'", "");
}
result = materialMapperEx.findBySelectWithBarCodeCount(idList, q);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
public List<MaterialVo4Unit> findByAll(String barCode, String name, String standard, String model, String categoryId)throws Exception {
List<MaterialVo4Unit> resList = new ArrayList<>();
List<MaterialVo4Unit> list =null;
try{
List<Long> idList = new ArrayList<>();
if(StringUtil.isNotEmpty(categoryId)){
idList = getListByParentId(Long.parseLong(categoryId));
}
list= materialMapperEx.findByAll(barCode, name, standard, model, idList);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (null != list) {
for (MaterialVo4Unit m : list) {
resList.add(m);
}
}
return resList;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public BaseResponseInfo importExcel(Sheet src) throws Exception {
List<Depot> depotList= depotService.getDepot();
int depotCount = depotList.size();
List<MaterialWithInitStock> mList = new ArrayList<>();
for (int i = 2; i < src.getRows(); i++) {
String name = ExcelUtils.getContent(src, i, 0); //名称
String standard = ExcelUtils.getContent(src, i, 1); //规格
String model = ExcelUtils.getContent(src, i, 2); //型号
String color = ExcelUtils.getContent(src, i, 3); //颜色
String categoryName = ExcelUtils.getContent(src, i, 4); //类别
String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量
String unit = ExcelUtils.getContent(src, i, 6); //基础单位
//校验名称、型号、单位是否为空
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) {
MaterialWithInitStock m = new MaterialWithInitStock();
m.setName(name);
m.setStandard(standard);
m.setModel(model);
m.setColor(color);
Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
m.setCategoryId(categoryId);
m.setSafetyStock(parseBigDecimalEx(safetyStock));
String manyUnit = ExcelUtils.getContent(src, i, 7); //副单位
String barCode = ExcelUtils.getContent(src, i, 8); //基础条码
String manyBarCode = ExcelUtils.getContent(src, i, 9); //副条码
String ratio = ExcelUtils.getContent(src, i, 10); //比例
String purchaseDecimal = ExcelUtils.getContent(src, i, 11); //采购价
String commodityDecimal = ExcelUtils.getContent(src, i, 12); //零售价
String wholesaleDecimal = ExcelUtils.getContent(src, i, 13); //销售价
String lowDecimal = ExcelUtils.getContent(src, i, 14); //最低售价
JSONObject materialExObj = new JSONObject();
JSONObject basicObj = new JSONObject();
basicObj.put("barCode", barCode);
basicObj.put("commodityUnit", unit);
basicObj.put("purchaseDecimal", purchaseDecimal);
basicObj.put("commodityDecimal", commodityDecimal);
basicObj.put("wholesaleDecimal", wholesaleDecimal);
basicObj.put("lowDecimal", lowDecimal);
materialExObj.put("basic", basicObj);
if(StringUtil.isNotEmpty(manyUnit.trim())){ //多单位
String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")";
Long unitId = unitService.getUnitIdByName(manyUnitAll);
m.setUnitId(unitId);
JSONObject otherObj = new JSONObject();
otherObj.put("barCode", manyBarCode);
otherObj.put("commodityUnit", manyUnit);
otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio));
otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio));
otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio));
otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio));
materialExObj.put("other", otherObj);
} else {
m.setUnit(unit);
}
m.setMaterialExObj(materialExObj);
String enabled = ExcelUtils.getContent(src, i, 15); //状态
m.setEnabled(enabled.equals("1")? true: false);
//缓存各个仓库的库存信息
Map<Long, BigDecimal> stockMap = new HashMap<Long, BigDecimal>();
for(int j=1; j<=depotCount;j++) {
int col = 15+j;
if(col < src.getColumns()){
String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称
Long depotId = depotService.getIdByName(depotName);
if(depotId!=0L){
String stockStr = ExcelUtils.getContent(src, i, col);
if(StringUtil.isNotEmpty(stockStr)) {
stockMap.put(depotId, parseBigDecimalEx(stockStr));
}
}
}
}
m.setStockMap(stockMap);
mList.add(m);
}
}
logService.insertLog("商品",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
BaseResponseInfo info = new BaseResponseInfo();
try {
Long mId = 0L;
for(MaterialWithInitStock m: mList) {
//判断该商品是否存在,如果不存在就新增,如果存在就更新
List<Material> materials = getMaterialListByParam(m.getName(),m.getModel(),m.getColor(),m.getStandard(),
m.getMfrs(),m.getUnit(),m.getUnitId());
if(materials.size()<=0) {
materialMapper.insertSelective(m);
List<Material> newList = getMaterialListByParam(m.getName(),m.getModel(),m.getColor(),m.getStandard(),
m.getMfrs(),m.getUnit(),m.getUnitId());
if(newList!=null && newList.size()>0) {
mId = newList.get(0).getId();
}
} else {
mId = materials.get(0).getId();
String materialJson = JSON.toJSONString(m);
Material material = JSONObject.parseObject(materialJson, Material.class);
material.setId(mId);
materialMapper.updateByPrimaryKeySelective(material);
}
//给商品新增条码与价格相关信息
User user = userService.getCurrentUser();
JSONObject materialExObj = m.getMaterialExObj();
if(StringUtil.isExist(materialExObj.get("basic"))){
String basicStr = materialExObj.getString("basic");
MaterialExtend basicMaterialExtend = JSONObject.parseObject(basicStr, MaterialExtend.class);
basicMaterialExtend.setMaterialId(mId);
basicMaterialExtend.setDefaultFlag("1");
basicMaterialExtend.setCreateTime(new Date());
basicMaterialExtend.setUpdateTime(System.currentTimeMillis());
basicMaterialExtend.setCreateSerial(user.getLoginName());
basicMaterialExtend.setUpdateSerial(user.getLoginName());
Long meId = materialExtendService.selectIdByMaterialIdAndDefaultFlag(mId, "1");
if(meId==0L){
materialExtendMapper.insertSelective(basicMaterialExtend);
} else {
basicMaterialExtend.setId(meId);
materialExtendMapper.updateByPrimaryKeySelective(basicMaterialExtend);
}
}
if(StringUtil.isExist(materialExObj.get("other"))) {
String otherStr = materialExObj.getString("other");
MaterialExtend otherMaterialExtend = JSONObject.parseObject(otherStr, MaterialExtend.class);
otherMaterialExtend.setMaterialId(mId);
otherMaterialExtend.setDefaultFlag("0");
otherMaterialExtend.setCreateTime(new Date());
otherMaterialExtend.setUpdateTime(System.currentTimeMillis());
otherMaterialExtend.setCreateSerial(user.getLoginName());
otherMaterialExtend.setUpdateSerial(user.getLoginName());
Long meId = materialExtendService.selectIdByMaterialIdAndDefaultFlag(mId, "0");
if(meId==0L){
materialExtendMapper.insertSelective(otherMaterialExtend);
} else {
otherMaterialExtend.setId(meId);
materialExtendMapper.updateByPrimaryKeySelective(otherMaterialExtend);
}
}
//给商品初始化库存getAllListWithStock
Map<Long, BigDecimal> stockMap = m.getStockMap();
Long depotId = null;
for(Depot depot: depotList){
BigDecimal stock = stockMap.get(depot.getId());
//先清除再插入
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(depot.getId());
materialInitialStockMapper.deleteByExample(example);
if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
depotId = depot.getId();
insertStockByMaterialAndDepot(depotId, mId, stock);
}
}
}
info.code = 200;
info.data = "导入成功";
} catch (Exception e) {
e.printStackTrace();
info.code = 500;
info.data = "导入失败";
}
return info;
}
/**
* 根据条件返回产品列表
* @param name
* @param model
* @param color
* @param standard
* @param mfrs
* @param unit
* @param unitId
* @return
*/
private List<Material> getMaterialListByParam(String name, String model, String color,
String standard, String mfrs, String unit, Long unitId) {
MaterialExample example = new MaterialExample();
MaterialExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(name);
if (StringUtil.isNotEmpty(model)) {
criteria.andModelEqualTo(model);
}
if (StringUtil.isNotEmpty(color)) {
criteria.andColorEqualTo(color);
}
if (StringUtil.isNotEmpty(standard)) {
criteria.andStandardEqualTo(standard);
}
if (StringUtil.isNotEmpty(mfrs)) {
criteria.andMfrsEqualTo(mfrs);
}
if (StringUtil.isNotEmpty(unit)) {
criteria.andUnitEqualTo(unit);
}
if (unitId !=null) {
criteria.andUnitIdEqualTo(unitId);
}
criteria.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Material> list = materialMapper.selectByExample(example);
return list;
}
/**
* 写入初始库存
* @param depotId
* @param mId
* @param stock
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void insertStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock){
MaterialInitialStock materialInitialStock = new MaterialInitialStock();
materialInitialStock.setDepotId(depotId);
materialInitialStock.setMaterialId(mId);
materialInitialStock.setNumber(stock);
materialInitialStockMapper.insertSelective(materialInitialStock); //存入初始库存
}
public List<MaterialVo4Unit> getMaterialEnableSerialNumberList(String q, Integer offset, Integer rows)throws Exception {
List<MaterialVo4Unit> list =null;
try{
list= materialMapperEx.getMaterialEnableSerialNumberList(q, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long getMaterialEnableSerialNumberCount(String q)throws Exception {
Long count =null;
try{
count= materialMapperEx.getMaterialEnableSerialNumberCount(q);
}catch(Exception e){
JshException.readFail(logger, e);
}
return count;
}
public BigDecimal parseBigDecimalEx(String str) throws Exception{
if(!StringUtil.isEmpty(str)) {
return new BigDecimal(str);
} else {
return null;
}
}
public BigDecimal parsePrice(String price, String ratio) throws Exception{
if(StringUtil.isEmpty(price) || StringUtil.isEmpty(ratio)) {
return BigDecimal.ZERO;
} else {
BigDecimal pr=new BigDecimal(price);
BigDecimal r=new BigDecimal(ratio);
return pr.multiply(r);
}
}
/**
* 根据商品获取初始库存,仓库为空的时候查全部库存
* @param materialId
* @return
*/
public BigDecimal getInitStockByMid(Long depotId, Long materialId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialInitialStockExample example = new MaterialInitialStockExample();
if(depotId!=null) {
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else {
example.createCriteria().andMaterialIdEqualTo(materialId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
for(MaterialInitialStock ms: list) {
if(ms!=null) {
stock = stock.add(ms.getNumber());
}
}
}
return stock;
}
/**
* 根据商品和仓库获取初始库存
* @param materialId
* @param depotId
* @return
*/
public BigDecimal getInitStock(Long materialId, Long depotId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
stock = list.get(0).getNumber();
}
return stock;
}
/**
* 根据商品和仓库获取当前库存
* @param materialId
* @param depotId
* @return
*/
public BigDecimal getCurrentStock(Long materialId, Long depotId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
stock = list.get(0).getCurrentNumber();
} else {
stock = getInitStock(materialId,depotId);
}
return stock;
}
public List<MaterialVo4Unit> getMaterialByMeId(Long meId) {
List<MaterialVo4Unit> result = new ArrayList<MaterialVo4Unit>();
try{
if(meId!=null) {
result= materialMapperEx.getMaterialByMeId(meId);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public String getMaxBarCode() {
String maxBarCodeOld = materialMapperEx.getMaxBarCode();
return Long.parseLong(maxBarCodeOld)+"";
}
public List<String> getMaterialNameList() {
return materialMapperEx.getMaterialNameList();
}
public List<MaterialVo4Unit> getMaterialByBarCode(String barCode) {
return materialMapperEx.getMaterialByBarCode(barCode);
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.materialCategory;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.materialProperty.MaterialPropertyResource;
import com.jsh.erp.service.materialProperty.MaterialPropertyService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "materialCategory_component")
@MaterialCategoryResource
public class MaterialCategoryComponent implements ICommonQuery {
@Resource
private MaterialCategoryService materialCategoryService;
@Override
public Object selectOne(Long id) throws Exception {
return materialCategoryService.getMaterialCategory(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getMaterialCategoryList(map);
}
private List<?> getMaterialCategoryList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer parentId = StringUtil.parseInteger(StringUtil.getInfo(search, "parentId"));
String order = QueryUtils.order(map);
return materialCategoryService.select(name, parentId, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
Integer parentId = StringUtil.parseInteger(StringUtil.getInfo(search, "parentId"));
return materialCategoryService.countMaterialCategory(name, parentId);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return materialCategoryService.insertMaterialCategory(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return materialCategoryService.updateMaterialCategory(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return materialCategoryService.deleteMaterialCategory(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return materialCategoryService.batchDeleteMaterialCategory(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return materialCategoryService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.materialCategory;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "materialCategory")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaterialCategoryResource {
}

View File

@@ -0,0 +1,374 @@
package com.jsh.erp.service.materialCategory;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class MaterialCategoryService {
private Logger logger = LoggerFactory.getLogger(MaterialCategoryService.class);
@Resource
private MaterialCategoryMapper materialCategoryMapper;
@Resource
private MaterialCategoryMapperEx materialCategoryMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private MaterialMapperEx materialMapperEx;
public MaterialCategory getMaterialCategory(long id)throws Exception {
MaterialCategory result=null;
try{
result=materialCategoryMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<MaterialCategory> getMaterialCategoryListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<MaterialCategory> list = new ArrayList<>();
try{
MaterialCategoryExample example = new MaterialCategoryExample();
example.createCriteria().andIdIn(idList);
list = materialCategoryMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialCategory> getMaterialCategory()throws Exception {
MaterialCategoryExample example = new MaterialCategoryExample();
List<MaterialCategory> list=null;
try{
list=materialCategoryMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialCategory> getAllList(Long parentId)throws Exception {
List<MaterialCategory> list=null;
try{
list = getMCList(parentId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialCategory> getMCList(Long parentId)throws Exception {
List<MaterialCategory> res= new ArrayList<MaterialCategory>();
List<MaterialCategory> list=null;
MaterialCategoryExample example = new MaterialCategoryExample();
example.createCriteria().andParentIdEqualTo(parentId).andIdNotEqualTo(1L);
example.setOrderByClause("id");
list=materialCategoryMapper.selectByExample(example);
if(list!=null && list.size()>0) {
res.addAll(list);
for(MaterialCategory mc : list) {
List<MaterialCategory> mcList = getMCList(mc.getId());
if(mcList!=null && mcList.size()>0) {
res.addAll(mcList);
}
}
}
return res;
}
public List<MaterialCategory> select(String name, Integer parentId, int offset, int rows) throws Exception{
List<MaterialCategory> list=null;
try{
list=materialCategoryMapperEx.selectByConditionMaterialCategory(name, parentId, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countMaterialCategory(String name, Integer parentId) throws Exception{
Long result=null;
try{
result=materialCategoryMapperEx.countsByMaterialCategory(name, parentId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertMaterialCategory(JSONObject obj, HttpServletRequest request)throws Exception {
MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
materialCategory.setCreateTime(new Date());
materialCategory.setUpdateTime(new Date());
int result=0;
try{
result=materialCategoryMapper.insertSelective(materialCategory);
logService.insertLog("商品类型",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialCategory.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateMaterialCategory(JSONObject obj, HttpServletRequest request) throws Exception{
MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
materialCategory.setUpdateTime(new Date());
int result=0;
try{
result=materialCategoryMapper.updateByPrimaryKeySelective(materialCategory);
logService.insertLog("商品类型",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialCategory.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteMaterialCategory(Long id, HttpServletRequest request)throws Exception {
return batchDeleteMaterialCategoryByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialCategory(String ids, HttpServletRequest request)throws Exception {
return batchDeleteMaterialCategoryByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialCategoryByIds(String ids) throws Exception {
int result=0;
String [] idArray=ids.split(",");
//校验产品表 jsh_material
List<Material> materialList=null;
try{
materialList= materialMapperEx.getMaterialListByCategoryIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(materialList!=null&&materialList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验产品类型表 jsh_material_category
List<MaterialCategory> materialCategoryList=null;
try{
materialCategoryList= materialCategoryMapperEx.getMaterialCategoryListByCategoryIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(materialCategoryList!=null&&materialCategoryList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<MaterialCategory> list = getMaterialCategoryListByIds(ids);
for(MaterialCategory materialCategory: list){
sb.append("[").append(materialCategory.getName()).append("]");
}
logService.insertLog("商品类型", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//更新时间
Date updateDate =new Date();
//更新人
User userInfo=userService.getCurrentUser();
Long updater=userInfo==null?null:userInfo.getId();
String strArray[]=ids.split(",");
if(strArray.length<1){
return 0;
}
try{
result=materialCategoryMapperEx.batchDeleteMaterialCategoryByIds(updateDate,updater,strArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
public List<MaterialCategory> findById(Long id)throws Exception {
List<MaterialCategory> list=null;
if(id!=null) {
MaterialCategoryExample example = new MaterialCategoryExample();
example.createCriteria().andIdEqualTo(id);
try{
list=materialCategoryMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
}
return list;
}
/**
* create by: cjl
* description:
*获取商品类别树数据
* create time: 2019/2/19 14:30
* @Param:
* @return java.util.List<com.jsh.erp.datasource.vo.TreeNode>
*/
public List<TreeNode> getMaterialCategoryTree(Long id) throws Exception{
List<TreeNode> list=null;
try{
list=materialCategoryMapperEx.getNodeTree(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* create by: cjl
* description:
* 新增商品类别信息
* create time: 2019/2/19 16:30
* @Param: mc
* @return void
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int addMaterialCategory(MaterialCategory mc) throws Exception {
logService.insertLog("商品类型",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(mc.getName()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(mc==null){
return 0;
}
if(mc.getParentId()==null){
//没有给定父级目录的id默认设置父级目录为根目录的父目录
mc.setParentId(BusinessConstants.MATERIAL_CATEGORY_ROOT_PARENT_ID);
}
//检查商品类型编号是否已存在
checkMaterialCategorySerialNo(mc);
//数据状态新增时默认设置为启用
Date date=new Date();
User userInfo=userService.getCurrentUser();
//创建时间
mc.setCreateTime(date);
//更新时间
mc.setUpdateTime(date);
int result=0;
try{
result=materialCategoryMapperEx.addMaterialCategory(mc);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int editMaterialCategory(MaterialCategory mc) throws Exception{
logService.insertLog("商品类型",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(mc.getName()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(mc.getParentId()==null){
//没有给定父级目录的id默认设置父级目录为根目录的父目录
mc.setParentId(BusinessConstants.MATERIAL_CATEGORY_ROOT_PARENT_ID);
}
//检查商品类型编号是否已存在
checkMaterialCategorySerialNo(mc);
//更新时间
mc.setUpdateTime(new Date());
//更新人
User userInfo=userService.getCurrentUser();
int result=0;
try{
result= materialCategoryMapperEx.editMaterialCategory(mc);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* 根据商品类别编号判断商品类别是否已存在
* */
public void checkMaterialCategorySerialNo(MaterialCategory mc)throws Exception {
if(mc==null){
return;
}
if(StringUtil.isEmpty(mc.getSerialNo())){
return;
}
//根据商品类别编号查询商品类别
List<MaterialCategory> mList=null;
try{
mList= materialCategoryMapperEx.getMaterialCategoryBySerialNo(mc.getSerialNo(), mc.getId());
}catch(Exception e){
JshException.readFail(logger, e);
}
if(mList==null||mList.size()<1){
//未查询到对应数据,编号可用
return;
}
if(mList.size()>1){
//查询到的数据条数大于1编号已存在
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
}
if(mc.getId()==null){
//新增时,编号已存在
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
}
/**
* 包装类型用equals来比较
* */
if(mc.getId().equals(mList.get(0).getId())){
//修改时相同编号id不同
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
}
}
/**
* 根据名称获取类型
* @param name
*/
public Long getCategoryIdByName(String name){
Long categoryId = 0L;
MaterialCategoryExample example = new MaterialCategoryExample();
example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialCategory> list = materialCategoryMapper.selectByExample(example);
if(list!=null && list.size()>0) {
categoryId = list.get(0).getId();
}
return categoryId;
}
}

View File

@@ -0,0 +1,65 @@
package com.jsh.erp.service.materialExtend;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "material_extend")
@MaterialExtendResource
public class MaterialExtendComponent implements ICommonQuery {
@Resource
private MaterialExtendService materialExtendService;
@Override
public Object selectOne(Long id) throws Exception {
return materialExtendService.getMaterialExtend(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getMaterialList(map);
}
private List<?> getMaterialList(Map<String, String> map) throws Exception{
return null;
}
@Override
public Long counts(Map<String, String> map)throws Exception {
return 0L;
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
return materialExtendService.insertMaterialExtend(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return materialExtendService.updateMaterialExtend(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return materialExtendService.deleteMaterialExtend(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return materialExtendService.batchDeleteMaterialExtendByIds(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return materialExtendService.checkIsExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.materialExtend;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "materialExtend")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaterialExtendResource {
}

View File

@@ -0,0 +1,362 @@
package com.jsh.erp.service.materialExtend;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.MaterialExtend;
import com.jsh.erp.datasource.entities.MaterialExtendExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MaterialExtendMapper;
import com.jsh.erp.datasource.mappers.MaterialExtendMapperEx;
import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class MaterialExtendService {
private Logger logger = LoggerFactory.getLogger(MaterialExtendService.class);
@Resource
private MaterialExtendMapper materialExtendMapper;
@Resource
private MaterialExtendMapperEx materialExtendMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
@Resource
private RedisService redisService;
public MaterialExtend getMaterialExtend(long id)throws Exception {
MaterialExtend result=null;
try{
result=materialExtendMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<MaterialExtendVo4List> getDetailList(Long materialId) {
List<MaterialExtendVo4List> list=null;
try{
list = materialExtendMapperEx.getDetailList(materialId);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialExtend> getListByMIds(List<Long> idList) {
List<MaterialExtend> meList = null;
try{
Long [] idArray= StringUtil.listToLongArray(idList);
if(idArray!=null && idArray.length>0) {
meList = materialExtendMapperEx.getListByMId(idArray);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return meList;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String saveDetials(JSONObject obj, String sortList, Long materialId) throws Exception {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
JSONArray meArr = obj.getJSONArray("meList");
JSONArray insertedJson = new JSONArray();
JSONArray updatedJson = new JSONArray();
JSONArray deletedJson = new JSONArray();
List<String> barCodeList=new ArrayList<>();
if (null != meArr) {
for (int i = 0; i < meArr.size(); i++) {
JSONObject tempJson = meArr.getJSONObject(i);
String barCode = tempJson.getString("barCode");
barCodeList.add(barCode);
MaterialExtend materialExtend = getInfoByBarCode(barCode);
if(materialExtend.getBarCode() == null){
insertedJson.add(tempJson);
} else {
updatedJson.add(tempJson);
}
}
List<MaterialExtend> materialExtendList = getMeListByBarCodeAndMid(barCodeList, materialId);
for (MaterialExtend meObj: materialExtendList) {
JSONObject deleteObj = new JSONObject();
deleteObj.put("id", meObj.getId());
deletedJson.add(deleteObj);
}
}
JSONArray sortJson = JSONArray.parseArray(sortList);
if (null != insertedJson) {
for (int i = 0; i < insertedJson.size(); i++) {
MaterialExtend materialExtend = new MaterialExtend();
JSONObject tempInsertedJson = JSONObject.parseObject(insertedJson.getString(i));
materialExtend.setMaterialId(materialId);
if (StringUtils.isNotEmpty(tempInsertedJson.getString("barCode"))) {
materialExtend.setBarCode(tempInsertedJson.getString("barCode"));
}
if (StringUtils.isNotEmpty(tempInsertedJson.getString("commodityUnit"))) {
materialExtend.setCommodityUnit(tempInsertedJson.getString("commodityUnit"));
}
if (StringUtils.isNotEmpty(tempInsertedJson.getString("purchaseDecimal"))) {
materialExtend.setPurchaseDecimal(tempInsertedJson.getBigDecimal("purchaseDecimal"));
}
if (StringUtils.isNotEmpty(tempInsertedJson.getString("commodityDecimal"))) {
materialExtend.setCommodityDecimal(tempInsertedJson.getBigDecimal("commodityDecimal"));
}
if (StringUtils.isNotEmpty(tempInsertedJson.getString("wholesaleDecimal"))) {
materialExtend.setWholesaleDecimal(tempInsertedJson.getBigDecimal("wholesaleDecimal"));
}
if (StringUtils.isNotEmpty(tempInsertedJson.getString("lowDecimal"))) {
materialExtend.setLowDecimal(tempInsertedJson.getBigDecimal("lowDecimal"));
}
this.insertMaterialExtend(materialExtend);
}
}
if (null != deletedJson) {
StringBuffer bf=new StringBuffer();
for (int i = 0; i < deletedJson.size(); i++) {
JSONObject tempDeletedJson = JSONObject.parseObject(deletedJson.getString(i));
bf.append(tempDeletedJson.getLong("id"));
if(i<(deletedJson.size()-1)){
bf.append(",");
}
}
this.batchDeleteMaterialExtendByIds(bf.toString(), request);
}
if (null != updatedJson) {
for (int i = 0; i < updatedJson.size(); i++) {
JSONObject tempUpdatedJson = JSONObject.parseObject(updatedJson.getString(i));
MaterialExtend materialExtend = new MaterialExtend();
materialExtend.setId(tempUpdatedJson.getLong("id"));
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("barCode"))) {
materialExtend.setBarCode(tempUpdatedJson.getString("barCode"));
}
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("commodityUnit"))) {
materialExtend.setCommodityUnit(tempUpdatedJson.getString("commodityUnit"));
}
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("purchaseDecimal"))) {
materialExtend.setPurchaseDecimal(tempUpdatedJson.getBigDecimal("purchaseDecimal"));
}
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("commodityDecimal"))) {
materialExtend.setCommodityDecimal(tempUpdatedJson.getBigDecimal("commodityDecimal"));
}
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("wholesaleDecimal"))) {
materialExtend.setWholesaleDecimal(tempUpdatedJson.getBigDecimal("wholesaleDecimal"));
}
if (StringUtils.isNotEmpty(tempUpdatedJson.getString("lowDecimal"))) {
materialExtend.setLowDecimal(tempUpdatedJson.getBigDecimal("lowDecimal"));
}
this.updateMaterialExtend(materialExtend);
}
}
//处理条码的排序,基础单位排第一个
if (null != sortJson && sortJson.size()>0) {
//此处为更新的逻辑
for (int i = 0; i < sortJson.size(); i++) {
JSONObject tempSortJson = JSONObject.parseObject(sortJson.getString(i));
MaterialExtend materialExtend = new MaterialExtend();
if(StringUtil.isExist(tempSortJson.get("id"))) {
materialExtend.setId(tempSortJson.getLong("id"));
}
if(StringUtil.isExist(tempSortJson.get("defaultFlag"))) {
materialExtend.setDefaultFlag(tempSortJson.getString("defaultFlag"));
}
this.updateMaterialExtend(materialExtend);
}
} else {
//新增的时候将第一条记录设置为默认基础单位
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialExtend> meList = materialExtendMapper.selectByExample(example);
if(meList!=null) {
for(int i=0; i<meList.size(); i++) {
MaterialExtend materialExtend = new MaterialExtend();
materialExtend.setId(meList.get(i).getId());
if(i==0) {
materialExtend.setDefaultFlag("1"); //默认
} else {
materialExtend.setDefaultFlag("0"); //非默认
}
this.updateMaterialExtend(materialExtend);
}
}
}
return null;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertMaterialExtend(MaterialExtend materialExtend)throws Exception {
User user = userService.getCurrentUser();
materialExtend.setDeleteFlag(BusinessConstants.DELETE_FLAG_EXISTS);
materialExtend.setCreateTime(new Date());
materialExtend.setUpdateTime(new Date().getTime());
materialExtend.setCreateSerial(user.getLoginName());
materialExtend.setUpdateSerial(user.getLoginName());
int result =0;
try{
result= materialExtendMapper.insertSelective(materialExtend);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateMaterialExtend(MaterialExtend MaterialExtend) throws Exception{
User user = userService.getCurrentUser();
MaterialExtend.setUpdateTime(System.currentTimeMillis());
MaterialExtend.setUpdateSerial(user.getLoginName());
int res =0;
try{
res= materialExtendMapper.updateByPrimaryKeySelective(MaterialExtend);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return res;
}
public int checkIsExist(Long id, String MaterialExtendName)throws Exception {
MaterialExtendExample example = new MaterialExtendExample();
MaterialExtendExample.Criteria criteria = example.createCriteria();
criteria.andBarCodeEqualTo(MaterialExtendName);
if (id > 0) {
criteria.andIdNotEqualTo(id);
}
List<MaterialExtend> list =null;
try{
list= materialExtendMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteMaterialExtend(Long id, HttpServletRequest request)throws Exception {
int result =0;
MaterialExtend materialExtend = new MaterialExtend();
materialExtend.setId(id);
materialExtend.setDeleteFlag(BusinessConstants.DELETE_FLAG_DELETED);
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
User user = userService.getUser(userId);
materialExtend.setUpdateTime(new Date().getTime());
materialExtend.setUpdateSerial(user.getLoginName());
try{
result= materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialExtendByIds(String ids, HttpServletRequest request) throws Exception{
String [] idArray=ids.split(",");
int result = 0;
try{
result = materialExtendMapperEx.batchDeleteMaterialExtendByIds(idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int insertMaterialExtend(JSONObject obj, HttpServletRequest request) throws Exception{
MaterialExtend materialExtend = JSONObject.parseObject(obj.toJSONString(), MaterialExtend.class);
int result=0;
try{
result = materialExtendMapper.insertSelective(materialExtend);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int updateMaterialExtend(JSONObject obj, HttpServletRequest request)throws Exception {
MaterialExtend materialExtend = JSONObject.parseObject(obj.toJSONString(), MaterialExtend.class);
int result=0;
try{
result = materialExtendMapper.insertSelective(materialExtend);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<MaterialExtend> getMaterialExtendByTenantAndTime(Long tenantId, Long lastTime, Long syncNum)throws Exception {
List<MaterialExtend> list=new ArrayList<MaterialExtend>();
try{
//先获取最大的时间戳,再查两个时间戳之间的数据,这样同步能够防止丢失数据(应为时间戳有重复)
Long maxTime = materialExtendMapperEx.getMaxTimeByTenantAndTime(tenantId, lastTime, syncNum);
if(tenantId!=null && lastTime!=null && maxTime!=null) {
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andTenantIdEqualTo(tenantId)
.andUpdateTimeGreaterThan(lastTime)
.andUpdateTimeLessThanOrEqualTo(maxTime);
list=materialExtendMapper.selectByExample(example);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public Long selectIdByMaterialIdAndDefaultFlag(Long materialId, String defaultFlag)throws Exception {
Long id = 0L;
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDefaultFlagEqualTo(defaultFlag)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialExtend> list = materialExtendMapper.selectByExample(example);
if(list!=null && list.size()>0) {
id = list.get(0).getId();
}
return id;
}
public MaterialExtend getInfoByBarCode(String barCode)throws Exception {
MaterialExtend materialExtend = new MaterialExtend();
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andBarCodeEqualTo(barCode)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialExtend> list = materialExtendMapper.selectByExample(example);
if(list!=null && list.size()>0) {
materialExtend = list.get(0);
}
return materialExtend;
}
/**
* 查询某个商品里面被清除的条码信息
* @param barCodeList
* @param mId
* @return
* @throws Exception
*/
public List<MaterialExtend> getMeListByBarCodeAndMid(List<String> barCodeList, Long mId)throws Exception {
MaterialExtend materialExtend = new MaterialExtend();
MaterialExtendExample example = new MaterialExtendExample();
example.createCriteria().andBarCodeNotIn(barCodeList).andMaterialIdEqualTo(mId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialExtend> list = materialExtendMapper.selectByExample(example);
return list;
}
}

View File

@@ -0,0 +1,71 @@
package com.jsh.erp.service.materialProperty;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "materialProperty_component")
@MaterialPropertyResource
public class MaterialPropertyComponent implements ICommonQuery {
@Resource
private MaterialPropertyService materialPropertyService;
@Override
public Object selectOne(Long id) throws Exception {
return materialPropertyService.getMaterialProperty(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getMaterialPropertyList(map);
}
private List<?> getMaterialPropertyList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String order = QueryUtils.order(map);
return materialPropertyService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return materialPropertyService.countMaterialProperty(name);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return materialPropertyService.insertMaterialProperty(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return materialPropertyService.updateMaterialProperty(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return materialPropertyService.deleteMaterialProperty(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return materialPropertyService.batchDeleteMaterialProperty(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return materialPropertyService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.materialProperty;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "materialProperty")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MaterialPropertyResource {
}

View File

@@ -0,0 +1,141 @@
package com.jsh.erp.service.materialProperty;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.MaterialProperty;
import com.jsh.erp.datasource.entities.MaterialPropertyExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MaterialPropertyMapper;
import com.jsh.erp.datasource.mappers.MaterialPropertyMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Service
public class MaterialPropertyService {
private Logger logger = LoggerFactory.getLogger(MaterialPropertyService.class);
@Resource
private MaterialPropertyMapper materialPropertyMapper;
@Resource
private MaterialPropertyMapperEx materialPropertyMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
public MaterialProperty getMaterialProperty(long id)throws Exception {
MaterialProperty result=null;
try{
result=materialPropertyMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<MaterialProperty> getMaterialProperty()throws Exception {
MaterialPropertyExample example = new MaterialPropertyExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialProperty> list=null;
try{
list=materialPropertyMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<MaterialProperty> select(String name, int offset, int rows)throws Exception {
List<MaterialProperty> list=null;
try{
list=materialPropertyMapperEx.selectByConditionMaterialProperty(name, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countMaterialProperty(String name)throws Exception {
Long result=null;
try{
result=materialPropertyMapperEx.countsByMaterialProperty(name);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertMaterialProperty(JSONObject obj, HttpServletRequest request)throws Exception {
MaterialProperty materialProperty = JSONObject.parseObject(obj.toJSONString(), MaterialProperty.class);
int result=0;
try{
result=materialPropertyMapper.insertSelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialProperty.getNativeName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateMaterialProperty(JSONObject obj, HttpServletRequest request)throws Exception {
MaterialProperty materialProperty = JSONObject.parseObject(obj.toJSONString(), MaterialProperty.class);
int result=0;
try{
result=materialPropertyMapper.updateByPrimaryKeySelective(materialProperty);
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialProperty.getNativeName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteMaterialProperty(Long id, HttpServletRequest request)throws Exception {
return batchDeleteMaterialPropertyByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialProperty(String ids, HttpServletRequest request)throws Exception {
return batchDeleteMaterialPropertyByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialPropertyByIds(String ids) throws Exception{
logService.insertLog("商品属性",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result=materialPropertyMapperEx.batchDeleteMaterialPropertyByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
}

View File

@@ -0,0 +1,72 @@
package com.jsh.erp.service.msg;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "msg_component")
@MsgResource
public class MsgComponent implements ICommonQuery {
@Resource
private MsgService msgService;
@Override
public Object selectOne(Long id) throws Exception {
return msgService.getMsg(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getMsgList(map);
}
private List<?> getMsgList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String order = QueryUtils.order(map);
String filter = QueryUtils.filter(map);
return msgService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return msgService.countMsg(name);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return msgService.insertMsg(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return msgService.updateMsg(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return msgService.deleteMsg(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return msgService.batchDeleteMsg(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return msgService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.msg;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2019-9-7 22:52:35
*/
@ResourceInfo(value = "msg")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface MsgResource {
}

View File

@@ -0,0 +1,252 @@
package com.jsh.erp.service.msg;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Msg;
import com.jsh.erp.datasource.entities.MsgExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MsgMapper;
import com.jsh.erp.datasource.mappers.MsgMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Service
public class MsgService {
private Logger logger = LoggerFactory.getLogger(MsgService.class);
@Resource
private MsgMapper msgMapper;
@Resource
private MsgMapperEx msgMapperEx;
@Resource
private DepotHeadService depotHeadService;
@Resource
private UserService userService;
@Resource
private LogService logService;
public Msg getMsg(long id)throws Exception {
Msg result=null;
try{
result=msgMapper.selectByPrimaryKey(id);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
public List<Msg> getMsg()throws Exception {
MsgExample example = new MsgExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list=null;
try{
list=msgMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public List<Msg> select(String name, int offset, int rows)throws Exception {
List<Msg> list=null;
try{
list=msgMapperEx.selectByConditionMsg(name, offset, rows);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public Long countMsg(String name)throws Exception {
Long result=null;
try{
result=msgMapperEx.countsByMsg(name);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertMsg(JSONObject obj, HttpServletRequest request)throws Exception {
Msg msg = JSONObject.parseObject(obj.toJSONString(), Msg.class);
int result=0;
try{
result=msgMapper.insertSelective(msg);
logService.insertLog("消息",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(msg.getMsgTitle()).toString(), request);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateMsg(JSONObject obj, HttpServletRequest request) throws Exception{
Msg msg = JSONObject.parseObject(obj.toJSONString(), Msg.class);
int result=0;
try{
result=msgMapper.updateByPrimaryKeySelective(msg);
logService.insertLog("消息",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(msg.getMsgTitle()).toString(), request);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteMsg(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result=msgMapper.deleteByPrimaryKey(id);
logService.insertLog("消息",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(id).toString(), request);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMsg(String ids, HttpServletRequest request) throws Exception{
List<Long> idList = StringUtil.strToLongList(ids);
MsgExample example = new MsgExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result=msgMapper.deleteByExample(example);
logService.insertLog("消息", "批量删除,id集:" + ids, request);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
MsgExample example = new MsgExample();
example.createCriteria().andIdNotEqualTo(id).andMsgTitleEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list=null;
try{
list= msgMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list==null?0:list.size();
}
/**
* create by: qiankunpingtai
* 逻辑删除角色信息
* create time: 2019/3/28 15:44
* @Param: ids
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMsgByIds(String ids) throws Exception{
logService.insertLog("序列号",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
String [] idArray=ids.split(",");
int result=0;
try{
result=msgMapperEx.batchDeleteMsgByIds(idArray);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
public List<Msg> getMsgByStatus(String status)throws Exception {
MsgExample example = new MsgExample();
example.createCriteria().andStatusEqualTo(status).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Msg> list=null;
try{
list=msgMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void batchUpdateStatus(String ids, String status) throws Exception{
List<Long> idList = StringUtil.strToLongList(ids);
Msg msg = new Msg();
msg.setStatus(status);
MsgExample example = new MsgExample();
example.createCriteria().andIdIn(idList);
try{
msgMapper.updateByExampleSelective(msg, example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE, ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
}
public Long getMsgCountByStatus(String status)throws Exception {
Long result=null;
try{
User userInfo=userService.getCurrentUser();
result=msgMapperEx.getMsgCountByStatus(status, userInfo.getId());
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE, ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
}

View File

@@ -0,0 +1,67 @@
package com.jsh.erp.service.orgaUserRel;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.organization.OrganizationResource;
import com.jsh.erp.service.organization.OrganizationService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* Description
*
* @Author: cjl
* @Date: 2019/3/11 18:10
*/
@Service(value = "orgaUserRel_component")
@OrgaUserRelResource
public class OrgaUserRelComponent implements ICommonQuery {
@Resource
private OrgaUserRelService orgaUserRelService;
@Override
public Object selectOne(Long id) throws Exception {
return orgaUserRelService.getOrgaUserRel(id);
}
@Override
public List<?> select(Map<String, String> parameterMap)throws Exception {
return getOrgaUserRelList(parameterMap);
}
private List<?> getOrgaUserRelList(Map<String, String> map)throws Exception {
return null;
}
@Override
public Long counts(Map<String, String> parameterMap)throws Exception {
return null;
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return orgaUserRelService.insertOrgaUserRel(obj,request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return orgaUserRelService.updateOrgaUserRel(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return orgaUserRelService.deleteOrgaUserRel(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return orgaUserRelService.batchDeleteOrgaUserRel(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
}

View File

@@ -0,0 +1,19 @@
package com.jsh.erp.service.orgaUserRel;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* Description
* 机构用户关系
* @Author: cjl
* @Date: 2019/3/11 18:11
*/
@ResourceInfo(value = "orgaUserRel")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface OrgaUserRelResource {
}

View File

@@ -0,0 +1,222 @@
package com.jsh.erp.service.orgaUserRel;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.OrgaUserRel;
import com.jsh.erp.datasource.entities.OrgaUserRelExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.OrgaUserRelMapper;
import com.jsh.erp.datasource.mappers.OrgaUserRelMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.organization.OrganizationService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Description
*
* @Author: cjl
* @Date: 2019/3/11 18:11
*/
@Service
public class OrgaUserRelService {
private Logger logger = LoggerFactory.getLogger(OrganizationService.class);
@Resource
private OrgaUserRelMapper orgaUserRelMapper;
@Resource
private OrgaUserRelMapperEx orgaUserRelMapperEx;
@Resource
private UserService userService;
@Resource
private OrganizationService organizationService;
@Resource
private LogService logService;
public OrgaUserRel getOrgaUserRel(long id) throws Exception{
return orgaUserRelMapper.selectByPrimaryKey(id);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertOrgaUserRel(JSONObject obj, HttpServletRequest request) throws Exception{
OrgaUserRel orgaUserRel = JSONObject.parseObject(obj.toJSONString(), OrgaUserRel.class);
int result=0;
try{
result=orgaUserRelMapper.insertSelective(orgaUserRel);
logService.insertLog("用户与机构关系", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateOrgaUserRel(JSONObject obj, HttpServletRequest request) throws Exception{
OrgaUserRel orgaUserRel = JSONObject.parseObject(obj.toJSONString(), OrgaUserRel.class);
int result=0;
try{
result=orgaUserRelMapper.updateByPrimaryKeySelective(orgaUserRel);
logService.insertLog("用户与机构关系",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(orgaUserRel.getId()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteOrgaUserRel(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result=orgaUserRelMapper.deleteByPrimaryKey(id);
logService.insertLog("用户与机构关系",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(id).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteOrgaUserRel(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
OrgaUserRelExample example = new OrgaUserRelExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result=orgaUserRelMapper.deleteByExample(example);
logService.insertLog("用户与机构关系", "批量删除,id集:" + ids, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 新增机构用户关联关系,反显id
* create time: 2019/3/12 9:40
* @Param: orgaUserRel
* @return void
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public OrgaUserRel addOrgaUserRel(OrgaUserRel orgaUserRel) throws Exception{
Date date = new Date();
User userInfo=userService.getCurrentUser();
//创建时间
if(orgaUserRel.getCreateTime()==null){
orgaUserRel.setCreateTime(date);
}
//创建人
if(orgaUserRel.getCreator()==null){
orgaUserRel.setCreator(userInfo==null?null:userInfo.getId());
}
//更新时间
if(orgaUserRel.getUpdateTime()==null){
orgaUserRel.setUpdateTime(date);
}
//更新人
if(orgaUserRel.getUpdater()==null){
orgaUserRel.setUpdater(userInfo==null?null:userInfo.getId());
}
orgaUserRel.setDeleteFlag(BusinessConstants.DELETE_FLAG_EXISTS);
int result=0;
try{
result=orgaUserRelMapperEx.addOrgaUserRel(orgaUserRel);
}catch(Exception e){
JshException.writeFail(logger, e);
}
if(result>0){
return orgaUserRel;
}
return null;
}
/**
* create by: cjl
* description:
* 更新机构用户关联关系
* create time: 2019/3/12 9:40
* @Param: orgaUserRel
* @return void
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public OrgaUserRel updateOrgaUserRel(OrgaUserRel orgaUserRel) throws Exception{
User userInfo=userService.getCurrentUser();
//更新时间
if(orgaUserRel.getUpdateTime()==null){
orgaUserRel.setUpdateTime(new Date());
}
//更新人
if(orgaUserRel.getUpdater()==null){
orgaUserRel.setUpdater(userInfo==null?null:userInfo.getId());
}
int result=0;
try{
result=orgaUserRelMapperEx.updateOrgaUserRel(orgaUserRel);
}catch(Exception e){
JshException.writeFail(logger, e);
}
if(result>0){
return orgaUserRel;
}
return null;
}
/**
* 根据用户id获取用户id列表
* @param userId
* @return
* @throws Exception
*/
public String getUserIdListByUserId(Long userId) throws Exception{
OrgaUserRel our = new OrgaUserRel();
OrgaUserRelExample example = new OrgaUserRelExample();
example.createCriteria().andUserIdEqualTo(userId);
List<OrgaUserRel> list = orgaUserRelMapper.selectByExample(example);
if(list!=null && list.size()>0) {
our = list.get(0);
}
List<Long> userIdList = getUserIdListByOrgId(our.getOrgaId());
String users = "";
for(Long u: userIdList){
users = users + u + ",";
}
if(users.length()>0){
users = users.substring(0,users.length()-1);
}
return users;
}
/**
* 根据组织id获取所属的用户id列表包含组织的递归
* @param orgId
* @return
*/
public List<Long> getUserIdListByOrgId(Long orgId) {
List<Long> orgIdList = organizationService.getOrgIdByParentId(orgId);
List<Long> userIdList = new ArrayList<Long>();
OrgaUserRelExample example = new OrgaUserRelExample();
if(orgIdList!=null && orgIdList.size()>0) {
example.createCriteria().andOrgaIdIn(orgIdList).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else {
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<OrgaUserRel> list = orgaUserRelMapper.selectByExample(example);
if(list!=null && list.size()>0) {
for(OrgaUserRel our: list) {
userIdList.add(our.getUserId());
}
}
return userIdList;
}
}

View File

@@ -0,0 +1,68 @@
package com.jsh.erp.service.organization;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* Description
*
* @Author: cjl
* @Date: 2019/3/6 15:09
*/
@Service(value = "organization_component")
@OrganizationResource
public class OrganizationComponent implements ICommonQuery {
@Resource
private OrganizationService organizationService;
@Override
public Object selectOne(Long id) throws Exception {
return organizationService.getOrganization(id);
}
@Override
public List<?> select(Map<String, String> parameterMap)throws Exception {
return getOrganizationList(parameterMap);
}
private List<?> getOrganizationList(Map<String, String> map)throws Exception {
return null;
}
@Override
public Long counts(Map<String, String> parameterMap)throws Exception {
return null;
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return organizationService.insertOrganization(obj,request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return organizationService.updateOrganization(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return organizationService.deleteOrganization(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return organizationService.batchDeleteOrganization(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
}

View File

@@ -0,0 +1,18 @@
package com.jsh.erp.service.organization;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* Description
* 机构
* @Author: cjl
* @Date: 2019/3/6 15:10
*/
@ResourceInfo(value = "organization")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface OrganizationResource {
}

View File

@@ -0,0 +1,306 @@
package com.jsh.erp.service.organization;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.MaterialProperty;
import com.jsh.erp.datasource.entities.Organization;
import com.jsh.erp.datasource.entities.OrganizationExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.OrganizationMapper;
import com.jsh.erp.datasource.mappers.OrganizationMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Description
*
* @Author: cjl
* @Date: 2019/3/6 15:10
*/
@Service
public class OrganizationService {
private Logger logger = LoggerFactory.getLogger(OrganizationService.class);
@Resource
private OrganizationMapper organizationMapper;
@Resource
private OrganizationMapperEx organizationMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
public Organization getOrganization(long id) throws Exception {
return organizationMapper.selectByPrimaryKey(id);
}
public List<Organization> getOrganizationListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Organization> list = new ArrayList<>();
try{
OrganizationExample example = new OrganizationExample();
example.createCriteria().andIdIn(idList);
list = organizationMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertOrganization(JSONObject obj, HttpServletRequest request)throws Exception {
Organization organization = JSONObject.parseObject(obj.toJSONString(), Organization.class);
organization.setCreateTime(new Date());
organization.setUpdateTime(new Date());
int result=0;
try{
result=organizationMapper.insertSelective(organization);
logService.insertLog("机构",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(organization.getOrgFullName()).toString(),request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateOrganization(JSONObject obj, HttpServletRequest request)throws Exception {
Organization organization = JSONObject.parseObject(obj.toJSONString(), Organization.class);
organization.setUpdateTime(new Date());
int result=0;
try{
result=organizationMapper.updateByPrimaryKeySelective(organization);
logService.insertLog("机构",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(organization.getOrgFullName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteOrganization(Long id, HttpServletRequest request)throws Exception {
return batchDeleteOrganizationByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteOrganization(String ids, HttpServletRequest request)throws Exception {
return batchDeleteOrganizationByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteOrganizationByIds(String ids) throws Exception{
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Organization> list = getOrganizationListByIds(ids);
for(Organization organization: list){
sb.append("[").append(organization.getOrgFullName()).append("]");
}
logService.insertLog("机构", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result=organizationMapperEx.batchDeleteOrganizationByIds(
new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int addOrganization(Organization org) throws Exception{
logService.insertLog("机构",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(org.getOrgFullName()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//新增时间
Date date=new Date();
User userInfo=userService.getCurrentUser();
org.setCreateTime(date);
//修改时间
org.setUpdateTime(date);
/**
*添加的时候检测机构编号是否已存在
* */
if(StringUtil.isNotEmpty(org.getOrgNo())){
checkOrgNoIsExists(org.getOrgNo(),null);
}
/**
* 未指定父级机构的时候默认为根机构
* */
if(org.getParentId()!=null){
org.setParentId(null);
}
int result=0;
try{
result=organizationMapperEx.addOrganization(org);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int editOrganization(Organization org)throws Exception {
logService.insertLog("机构",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(org.getOrgFullName()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//修改时间
org.setUpdateTime(new Date());
User userInfo=userService.getCurrentUser();
/**
* 修改的时候检测机构编号是否已存在
* */
if(StringUtil.isNotEmpty(org.getOrgNo())){
checkOrgNoIsExists(org.getOrgNo(),org.getId());
}
/**
* 未指定父级机构的时候默认为根机构
* */
if(org.getParentId()!=null){
org.setParentId(null);
}
int result=0;
try{
result=organizationMapperEx.editOrganization(org);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<TreeNode> getOrganizationTree(Long id)throws Exception {
List<TreeNode> list=null;
try{
list=organizationMapperEx.getNodeTree(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Organization> findById(Long id) throws Exception{
OrganizationExample example = new OrganizationExample();
example.createCriteria().andIdEqualTo(id);
List<Organization> list=null;
try{
list=organizationMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Organization> findByParentId(Long parentId)throws Exception {
List<Organization> list=null;
if(parentId!=null){
OrganizationExample example = new OrganizationExample();
example.createCriteria().andIdEqualTo(parentId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
try{
list=organizationMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
}
return list;
}
public List<Organization> findByOrgNo(String orgNo)throws Exception {
OrganizationExample example = new OrganizationExample();
example.createCriteria().andOrgNoEqualTo(orgNo).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Organization> list=null;
try{
list=organizationMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* create by: cjl
* description:
* 检查机构编号是否已经存在
* create time: 2019/3/7 10:01
* @Param: orgNo
* @return void
*/
public void checkOrgNoIsExists(String orgNo,Long id)throws Exception {
List<Organization> orgList=findByOrgNo(orgNo);
if(orgList!=null&&orgList.size()>0){
if(orgList.size()>1){
logger.error("异常码[{}],异常提示[{}],参数,orgNo[{}]",
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG,orgNo);
//获取的数据条数大于1机构编号已存在
throw new BusinessRunTimeException(ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG);
}
if(id!=null){
if(!orgList.get(0).getId().equals(id)){
//数据条数等于1但是和编辑的数据的id不相同
logger.error("异常码[{}],异常提示[{}],参数,orgNo[{}],id[{}]",
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG,orgNo,id);
throw new BusinessRunTimeException(ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG);
}
}else{
logger.error("异常码[{}],异常提示[{}],参数,orgNo[{}]",
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG,orgNo);
//数据条数等于1但此时是新增
throw new BusinessRunTimeException(ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_CODE,
ExceptionConstants.ORGANIZATION_NO_ALREADY_EXISTS_MSG);
}
}
}
/**
* 根据父级id递归获取子集组织id
* @return
*/
public List<Long> getOrgIdByParentId(Long orgId) {
List<Long> idList = new ArrayList<Long>();
OrganizationExample example = new OrganizationExample();
example.createCriteria().andIdEqualTo(orgId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Organization> orgList = organizationMapper.selectByExample(example);
if(orgList!=null && orgList.size()>0) {
idList.add(orgId);
getOrgIdByParentNo(idList, orgList.get(0).getId());
}
return idList;
}
/**
* 根据组织编号递归获取下级编号
* @param id
* @return
*/
public void getOrgIdByParentNo(List<Long> idList,Long id) {
List<Long> list = new ArrayList<Long>();
OrganizationExample example = new OrganizationExample();
example.createCriteria().andParentIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Organization> orgList = organizationMapper.selectByExample(example);
if(orgList!=null && orgList.size()>0) {
for(Organization o: orgList) {
idList.add(o.getId());
getOrgIdByParentNo(idList, o.getId());
}
}
}
}

View File

@@ -0,0 +1,75 @@
package com.jsh.erp.service.person;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.depot.DepotResource;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "person_component")
@PersonResource
public class PersonComponent implements ICommonQuery {
@Resource
private PersonService personService;
@Override
public Object selectOne(Long id) throws Exception {
return personService.getPerson(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getPersonList(map);
}
private List<?> getPersonList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
String order = QueryUtils.order(map);
return personService.select(name, type, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String type = StringUtil.getInfo(search, "type");
return personService.countPerson(name, type);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return personService.insertPerson(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return personService.updatePerson(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return personService.deletePerson(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return personService.batchDeletePerson(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return personService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.person;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "person")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface PersonResource {
}

View File

@@ -0,0 +1,233 @@
package com.jsh.erp.service.person;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.AccountHeadMapperEx;
import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
import com.jsh.erp.datasource.mappers.PersonMapper;
import com.jsh.erp.datasource.mappers.PersonMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class PersonService {
private Logger logger = LoggerFactory.getLogger(PersonService.class);
@Resource
private PersonMapper personMapper;
@Resource
private PersonMapperEx personMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private AccountHeadMapperEx accountHeadMapperEx;
@Resource
private DepotHeadMapperEx depotHeadMapperEx;
public Person getPerson(long id)throws Exception {
Person result=null;
try{
result=personMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Person> getPersonListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Person> list = new ArrayList<>();
try{
PersonExample example = new PersonExample();
example.createCriteria().andIdIn(idList);
list = personMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Person> getPerson()throws Exception {
PersonExample example = new PersonExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Person> list=null;
try{
list=personMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Person> select(String name, String type, int offset, int rows)throws Exception {
List<Person> list=null;
try{
list=personMapperEx.selectByConditionPerson(name, type, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countPerson(String name, String type)throws Exception {
Long result=null;
try{
result=personMapperEx.countsByPerson(name, type);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertPerson(JSONObject obj, HttpServletRequest request)throws Exception {
Person person = JSONObject.parseObject(obj.toJSONString(), Person.class);
int result=0;
try{
result=personMapper.insertSelective(person);
logService.insertLog("经手人",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(person.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updatePerson(JSONObject obj, HttpServletRequest request)throws Exception {
Person person = JSONObject.parseObject(obj.toJSONString(), Person.class);
int result=0;
try{
result=personMapper.updateByPrimaryKeySelective(person);
logService.insertLog("经手人",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(person.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deletePerson(Long id, HttpServletRequest request)throws Exception {
return batchDeletePersonByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeletePerson(String ids, HttpServletRequest request) throws Exception{
return batchDeletePersonByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeletePersonByIds(String ids)throws Exception {
int result =0;
String [] idArray=ids.split(",");
//校验财务主表 jsh_accounthead
List<AccountHead> accountHeadList =null;
try{
accountHeadList=accountHeadMapperEx.getAccountHeadListByHandsPersonIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(accountHeadList!=null&&accountHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,HandsPersonIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验单据主表 jsh_depot_head
List<DepotHead> depotHeadList =null;
try{
depotHeadList=depotHeadMapperEx.getDepotHeadListByCreator(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(depotHeadList!=null&&depotHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,HandsPersonIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Person> list = getPersonListByIds(ids);
for(Person person: list){
sb.append("[").append(person.getName()).append("]");
}
logService.insertLog("经手人", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//删除经手人
try{
result=personMapperEx.batchDeletePersonByIds(idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name) throws Exception{
PersonExample example = new PersonExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Person> list =null;
try{
list=personMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public String getPersonByIds(String personIDs)throws Exception {
List<Long> ids = StringUtil.strToLongList(personIDs);
PersonExample example = new PersonExample();
example.createCriteria().andIdIn(ids).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id asc");
List<Person> list =null;
try{
list=personMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
StringBuffer sb = new StringBuffer();
if (null != list) {
for (Person person : list) {
sb.append(person.getName() + " ");
}
}
return sb.toString();
}
public List<Person> getPersonByType(String type)throws Exception {
PersonExample example = new PersonExample();
example.createCriteria().andTypeEqualTo(type).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id asc");
List<Person> list =null;
try{
list=personMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
}

View File

@@ -0,0 +1,70 @@
package com.jsh.erp.service.platformConfig;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "platformConfig_component")
@PlatformConfigResource
public class PlatformConfigComponent implements ICommonQuery {
@Resource
private PlatformConfigService platformConfigService;
@Override
public Object selectOne(Long id) throws Exception {
return platformConfigService.getPlatformConfig(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getPlatformConfigList(map);
}
private List<?> getPlatformConfigList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String key = StringUtil.getInfo(search, "key");
return platformConfigService.select(key, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String key = StringUtil.getInfo(search, "key");
return platformConfigService.countPlatformConfig(key);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return platformConfigService.insertSystemConfig(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return platformConfigService.updateSystemConfig(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return platformConfigService.deleteSystemConfig(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return platformConfigService.batchDeleteSystemConfig(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.platformConfig;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2020-10-16 22:26:27
*/
@ResourceInfo(value = "platformConfig")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface PlatformConfigResource {
}

View File

@@ -0,0 +1,148 @@
package com.jsh.erp.service.platformConfig;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.PlatformConfig;
import com.jsh.erp.datasource.entities.PlatformConfigExample;
import com.jsh.erp.datasource.mappers.PlatformConfigMapper;
import com.jsh.erp.datasource.mappers.PlatformConfigMapperEx;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Service
public class PlatformConfigService {
private Logger logger = LoggerFactory.getLogger(PlatformConfigService.class);
@Resource
private PlatformConfigMapper platformConfigMapper;
@Resource
private PlatformConfigMapperEx platformConfigMapperEx;
public PlatformConfig getPlatformConfig(long id)throws Exception {
PlatformConfig result=null;
try{
result=platformConfigMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<PlatformConfig> getPlatformConfig()throws Exception {
PlatformConfigExample example = new PlatformConfigExample();
example.createCriteria();
List<PlatformConfig> list=null;
try{
list=platformConfigMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<PlatformConfig> select(String key, int offset, int rows)throws Exception {
List<PlatformConfig> list=null;
try{
list=platformConfigMapperEx.selectByConditionPlatformConfig(key, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countPlatformConfig(String key)throws Exception {
Long result=null;
try{
result=platformConfigMapperEx.countsByPlatformConfig(key);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
int result=0;
try{
result=platformConfigMapper.insertSelective(platformConfig);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
PlatformConfig platformConfig = JSONObject.parseObject(obj.toJSONString(), PlatformConfig.class);
int result=0;
try{
result = platformConfigMapper.updateByPrimaryKeySelective(platformConfig);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSystemConfig(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result=platformConfigMapper.deleteByPrimaryKey(id);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSystemConfig(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
PlatformConfigExample example = new PlatformConfigExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result=platformConfigMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int updatePlatformConfigByKey(String platformKey, String platformValue)throws Exception {
int result=0;
try{
PlatformConfig platformConfig = new PlatformConfig();
platformConfig.setPlatformValue(platformValue);
PlatformConfigExample example = new PlatformConfigExample();
example.createCriteria().andPlatformKeyEqualTo(platformKey);
result = platformConfigMapper.updateByExampleSelective(platformConfig, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public PlatformConfig getPlatformConfigByKey(String platformKey)throws Exception {
PlatformConfig platformConfig = new PlatformConfig();
try{
PlatformConfigExample example = new PlatformConfigExample();
example.createCriteria().andPlatformKeyEqualTo(platformKey);
List<PlatformConfig> list=platformConfigMapper.selectByExample(example);
if(list!=null && list.size()>0){
platformConfig = list.get(0);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return platformConfig;
}
}

View File

@@ -0,0 +1,98 @@
package com.jsh.erp.service.redis;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;
/**
* Description
*
* @author jisheng hua
* @Date: 2021/1/28 18:10
*/
@Component
public class RedisService {
@Resource
public RedisTemplate redisTemplate;
public static final String ACCESS_TOKEN = "X-Access-Token";
@Autowired(required = false)
public void setRedisTemplate(RedisTemplate redisTemplate) {
RedisSerializer stringSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringSerializer);
redisTemplate.setValueSerializer(stringSerializer);
redisTemplate.setHashKeySerializer(stringSerializer);
redisTemplate.setHashValueSerializer(stringSerializer);
this.redisTemplate = redisTemplate;
}
/**
* @author jisheng hua
* description:
* 从session中获取信息
*@date: 2021/1/28 18:10
* @Param: request
* @Param: key
* @return Object
*/
public Object getObjectFromSessionByKey(HttpServletRequest request, String key){
Object obj=null;
if(request==null){
return null;
}
String token = request.getHeader(ACCESS_TOKEN);
if(token!=null) {
//开启redis用户数据放在redis中从redis中获取
if(redisTemplate.opsForHash().hasKey(token,key)){
//redis中存在拿出来使用
obj=redisTemplate.opsForHash().get(token,key);
redisTemplate.expire(token, BusinessConstants.MAX_SESSION_IN_SECONDS, TimeUnit.SECONDS);
}
}
return obj;
}
/**
* @author jisheng hua
* description:
* 将信息放入session或者redis中
*@date: 2021/1/28 18:10
* @Param: request
* @Param: key
* @Param: obj
* @return
*/
public void storageObjectBySession(String token, String key, Object obj) {
//开启redis用户数据放到redis中
redisTemplate.opsForHash().put(token, key, obj.toString());
redisTemplate.expire(token, BusinessConstants.MAX_SESSION_IN_SECONDS, TimeUnit.SECONDS);
}
/**
* @author jisheng hua
* description:
* 将信息从session或者redis中移除
*@date: 2021/1/28 18:10
* @Param: request
* @Param: key
* @Param: obj
* @return
*/
public void deleteObjectBySession(HttpServletRequest request, String key){
if(request!=null){
String token = request.getHeader(ACCESS_TOKEN);
if(StringUtil.isNotEmpty(token)){
//开启redis用户数据放在redis中从redis中删除
redisTemplate.opsForHash().delete(token, key);
}
}
}
}

View File

@@ -0,0 +1,70 @@
package com.jsh.erp.service.role;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "role_component")
@RoleResource
public class RoleComponent implements ICommonQuery {
@Resource
private RoleService roleService;
@Override
public Object selectOne(Long id) throws Exception {
return roleService.getRole(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getRoleList(map);
}
private List<?> getRoleList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return roleService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return roleService.countRole(name);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return roleService.insertRole(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return roleService.updateRole(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return roleService.deleteRole(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return roleService.batchDeleteRole(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return roleService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.role;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "role")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface RoleResource {
}

View File

@@ -0,0 +1,186 @@
package com.jsh.erp.service.role;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Role;
import com.jsh.erp.datasource.entities.RoleExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.RoleMapper;
import com.jsh.erp.datasource.mappers.RoleMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class RoleService {
private Logger logger = LoggerFactory.getLogger(RoleService.class);
@Resource
private RoleMapper roleMapper;
@Resource
private RoleMapperEx roleMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
public Role getRole(long id)throws Exception {
Role result=null;
try{
result=roleMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Role> getRoleListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Role> list = new ArrayList<>();
try{
RoleExample example = new RoleExample();
example.createCriteria().andIdIn(idList);
list = roleMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Role> getRole()throws Exception {
RoleExample example = new RoleExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Role> list=null;
try{
list=roleMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Role> select(String name, int offset, int rows)throws Exception {
List<Role> list=null;
try{
list=roleMapperEx.selectByConditionRole(name, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countRole(String name)throws Exception {
Long result=null;
try{
result=roleMapperEx.countsByRole(name);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertRole(JSONObject obj, HttpServletRequest request)throws Exception {
Role role = JSONObject.parseObject(obj.toJSONString(), Role.class);
int result=0;
try{
result=roleMapper.insertSelective(role);
logService.insertLog("角色",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(role.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateRole(JSONObject obj, HttpServletRequest request) throws Exception{
Role role = JSONObject.parseObject(obj.toJSONString(), Role.class);
int result=0;
try{
result=roleMapper.updateByPrimaryKeySelective(role);
logService.insertLog("角色",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(role.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteRole(Long id, HttpServletRequest request)throws Exception {
return batchDeleteRoleByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteRole(String ids, HttpServletRequest request) throws Exception{
return batchDeleteRoleByIds(ids);
}
public int checkIsNameExist(Long id, String name) throws Exception{
RoleExample example = new RoleExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Role> list =null;
try{
list=roleMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<Role> findUserRole()throws Exception{
RoleExample example = new RoleExample();
example.setOrderByClause("Id");
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Role> list=null;
try{
list=roleMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* create by: qiankunpingtai
* 逻辑删除角色信息
* create time: 2019/3/28 15:44
* @Param: ids
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteRoleByIds(String ids) throws Exception{
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Role> list = getRoleListByIds(ids);
for(Role role: list){
sb.append("[").append(role.getName()).append("]");
}
logService.insertLog("角色", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result=roleMapperEx.batchDeleteRoleByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
}

View File

@@ -0,0 +1,74 @@
package com.jsh.erp.service.sequence;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* Description
*
* @Author: jishenghua
* @Date: 2021/3/16 16:33
*/
@Service(value = "sequence_component")
@SequenceResource
public class SequenceComponent implements ICommonQuery {
@Resource
private SequenceService sequenceService;
@Override
public Object selectOne(Long id) throws Exception {
return sequenceService.getSequence(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getSequenceList(map);
}
private List<?> getSequenceList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return sequenceService.select(name,QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return sequenceService.countSequence(name);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return sequenceService.insertSequence(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return sequenceService.updateSequence(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return sequenceService.deleteSequence(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return sequenceService.batchDeleteSequence(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name) throws Exception{
return sequenceService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,18 @@
package com.jsh.erp.service.sequence;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* Description
*
* @Author: jishenghua
* @Date: 2021/3/16 16:33
*/
@ResourceInfo(value = "sequence")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SequenceResource {
}

View File

@@ -0,0 +1,100 @@
package com.jsh.erp.service.sequence;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Description
*
* @Author: jishenghua
* @Date: 2021/3/16 16:33
*/
@Service
public class SequenceService {
private Logger logger = LoggerFactory.getLogger(SequenceService.class);
@Resource
private SequenceMapperEx sequenceMapperEx;
public SerialNumber getSequence(long id)throws Exception {
return null;
}
public List<SerialNumberEx> select(String name, Integer offset, Integer rows)throws Exception {
return null;
}
public Long countSequence(String name)throws Exception {
return null;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSequence(JSONObject obj, HttpServletRequest request)throws Exception {
return 0;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSequence(JSONObject obj, HttpServletRequest request) throws Exception{
return 0;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSequence(Long id, HttpServletRequest request)throws Exception {
return 0;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSequence(String ids, HttpServletRequest request)throws Exception {
return 0;
}
public int checkIsNameExist(Long id, String serialNumber)throws Exception {
return 0;
}
/**
* 创建一个唯一的序列号
* */
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String buildOnlyNumber()throws Exception{
Long buildOnlyNumber=null;
synchronized (this){
try{
sequenceMapperEx.updateBuildOnlyNumber(); //编号+1
buildOnlyNumber= sequenceMapperEx.getBuildOnlyNumber(BusinessConstants.DEPOT_NUMBER_SEQ);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
if(buildOnlyNumber<BusinessConstants.SEQ_TO_STRING_MIN_LENGTH){
StringBuffer sb=new StringBuffer(buildOnlyNumber.toString());
int len=BusinessConstants.SEQ_TO_STRING_MIN_LENGTH.toString().length()-sb.length();
for(int i=0;i<len;i++){
sb.insert(0,BusinessConstants.SEQ_TO_STRING_LESS_INSERT);
}
return sb.toString();
}else{
return buildOnlyNumber.toString();
}
}
}

View File

@@ -0,0 +1,78 @@
package com.jsh.erp.service.serialNumber;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.material.MaterialResource;
import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* Description
*
* @Author: cjl
* @Date: 2019/1/21 16:33
*/
@Service(value = "serialNumber_component")
@SerialNumberResource
public class SerialNumberComponent implements ICommonQuery {
@Resource
private SerialNumberService serialNumberService;
@Override
public Object selectOne(Long id) throws Exception {
return serialNumberService.getSerialNumber(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getSerialNumberList(map);
}
private List<?> getSerialNumberList(Map<String, String> map) throws Exception{
String search = map.get(Constants.SEARCH);
String serialNumber = StringUtil.getInfo(search, "serialNumber");
String materialName = StringUtil.getInfo(search, "materialName");
return serialNumberService.select(serialNumber,materialName,QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String serialNumber = StringUtil.getInfo(search, "serialNumber");
String materialName = StringUtil.getInfo(search, "materialName");
return serialNumberService.countSerialNumber(serialNumber, materialName);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return serialNumberService.insertSerialNumber(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return serialNumberService.updateSerialNumber(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return serialNumberService.deleteSerialNumber(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return serialNumberService.batchDeleteSerialNumber(ids, request);
}
@Override
public int checkIsNameExist(Long id, String serialNumber) throws Exception{
return serialNumberService.checkIsNameExist(id, serialNumber);
}
}

View File

@@ -0,0 +1,18 @@
package com.jsh.erp.service.serialNumber;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* Description
*
* @Author: jishenghua
* @Date: 2019/1/21 16:33
*/
@ResourceInfo(value = "serialNumber")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SerialNumberResource {
}

View File

@@ -0,0 +1,461 @@
package com.jsh.erp.service.serialNumber;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.depotItem.DepotItemService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.material.MaterialService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Description
*
* @Author: cjl
* @Date: 2019/1/21 16:33
*/
@Service
public class SerialNumberService {
private Logger logger = LoggerFactory.getLogger(SerialNumberService.class);
@Resource
private SerialNumberMapper serialNumberMapper;
@Resource
private SerialNumberMapperEx serialNumberMapperEx;
@Resource
private MaterialMapperEx materialMapperEx;
@Resource
private MaterialMapper materialMapper;
@Resource
private MaterialService materialService;
@Resource
private UserService userService;
@Resource
private LogService logService;
public SerialNumber getSerialNumber(long id)throws Exception {
SerialNumber result=null;
try{
result=serialNumberMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<SerialNumber> getSerialNumberListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<SerialNumber> list = new ArrayList<>();
try{
SerialNumberExample example = new SerialNumberExample();
example.createCriteria().andIdIn(idList);
list = serialNumberMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<SerialNumber> getSerialNumber()throws Exception {
SerialNumberExample example = new SerialNumberExample();
List<SerialNumber> list=null;
try{
list=serialNumberMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<SerialNumberEx> select(String serialNumber, String materialName, Integer offset, Integer rows)throws Exception {
List<SerialNumberEx> list=null;
try{
list=serialNumberMapperEx.selectByConditionSerialNumber(serialNumber, materialName,offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countSerialNumber(String serialNumber,String materialName)throws Exception {
Long result=null;
try{
result=serialNumberMapperEx.countSerialNumber(serialNumber, materialName);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSerialNumber(JSONObject obj, HttpServletRequest request)throws Exception {
int result=0;
try{
SerialNumberEx serialNumberEx = JSONObject.parseObject(obj.toJSONString(), SerialNumberEx.class);
/**处理商品id*/
serialNumberEx.setMaterialId(getSerialNumberMaterialIdByBarCode(serialNumberEx.getMaterialCode()));
//删除标记,默认未删除
serialNumberEx.setDeleteFlag(BusinessConstants.DELETE_FLAG_EXISTS);
//已卖出,默认未否
serialNumberEx.setIsSell(BusinessConstants.IS_SELL_HOLD);
Date date=new Date();
serialNumberEx.setCreateTime(date);
serialNumberEx.setUpdateTime(date);
User userInfo=userService.getCurrentUser();
serialNumberEx.setCreator(userInfo==null?null:userInfo.getId());
serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId());
result = serialNumberMapperEx.addSerialNumber(serialNumberEx);
logService.insertLog("序列号",BusinessConstants.LOG_OPERATION_TYPE_ADD,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSerialNumber(JSONObject obj, HttpServletRequest request) throws Exception{
SerialNumberEx serialNumberEx = JSONObject.parseObject(obj.toJSONString(), SerialNumberEx.class);
int result=0;
try{
serialNumberEx.setMaterialId(getSerialNumberMaterialIdByBarCode(serialNumberEx.getMaterialCode()));
Date date=new Date();
serialNumberEx.setUpdateTime(date);
User userInfo=userService.getCurrentUser();
serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId());
result = serialNumberMapperEx.updateSerialNumber(serialNumberEx);
logService.insertLog("序列号",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(serialNumberEx.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSerialNumber(Long id, HttpServletRequest request)throws Exception {
return batchDeleteSerialNumberByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSerialNumber(String ids, HttpServletRequest request)throws Exception {
return batchDeleteSerialNumberByIds(ids);
}
/**
* create by: qiankunpingtai
* 逻辑删除序列号信息
* create time: 2019/3/27 17:43
* @Param: ids
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSerialNumberByIds(String ids) throws Exception{
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<SerialNumber> list = getSerialNumberListByIds(ids);
for(SerialNumber serialNumber: list){
sb.append("[").append(serialNumber.getSerialNumber()).append("]");
}
logService.insertLog("序列号", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result = serialNumberMapperEx.batchDeleteSerialNumberByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String serialNumber)throws Exception {
SerialNumberExample example = new SerialNumberExample();
example.createCriteria().andIdNotEqualTo(id).andSerialNumberEqualTo(serialNumber).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<SerialNumber> list=null;
try{
list=serialNumberMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public List<SerialNumberEx> findById(Long id)throws Exception{
List<SerialNumberEx> list=null;
try{
list=serialNumberMapperEx.findById(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public void checkIsExist(Long id, String materialName, String serialNumber) throws Exception{
/**
* 商品名称不为空时,检查商品名称是否存在
* */
if(StringUtil.isNotEmpty(materialName)){
List<Material> mlist=null;
try{
mlist = materialMapperEx.findByMaterialName(materialName);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(mlist==null||mlist.size()<1){
//商品名称不存在
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE,
ExceptionConstants.MATERIAL_NOT_EXISTS_MSG);
}else if(mlist.size()>1){
//商品信息不唯一
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ONLY_CODE,
ExceptionConstants.MATERIAL_NOT_ONLY_MSG);
}
}
/***
* 判断序列号是否已存在
* */
List <SerialNumberEx> list=null;
try{
list = serialNumberMapperEx.findBySerialNumber(serialNumber);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(list!=null&&list.size()>0){
if(list.size()>1){
//存在多个同名序列号
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
}else{
//存在一个序列号
if(id==null){
//新增,存在要添加的序列号
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
}
if(id.equals(list.get(0).getId())){
//修改的是同一条数据
}else{
//存在一条不同的序列号信息
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
}
}
}
}
/**
* create by: cjl
* description:
* 根据商品名称判断商品名称是否有效
* create time: 2019/1/23 17:04
* @Param: materialName
* @return Long 满足使用条件的商品的id
*/
public Long checkMaterialName(String materialName)throws Exception{
if(StringUtil.isNotEmpty(materialName)) {
List<Material> mlist=null;
try{
mlist = materialMapperEx.findByMaterialName(materialName);
}catch(Exception e){
JshException.readFail(logger, e);
}
if (mlist == null || mlist.size() < 1) {
//商品名称不存在
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE,
ExceptionConstants.MATERIAL_NOT_EXISTS_MSG);
}
if (mlist.size() > 1) {
//商品信息不唯一
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ONLY_CODE,
ExceptionConstants.MATERIAL_NOT_ONLY_MSG);
}
//获得唯一商品
if (BusinessConstants.ENABLE_SERIAL_NUMBER_NOT_ENABLED.equals(mlist.get(0).getEnableSerialNumber())) {
//商品未开启序列号
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ENABLE_SERIAL_NUMBER_CODE,
ExceptionConstants.MATERIAL_NOT_ENABLE_SERIAL_NUMBER_MSG);
}
return mlist.get(0).getId();
}
return null;
}
/**
* create by: cjl
* description:
* 根据商品名称判断给商品添加序列号是否可行
* 1、根据商品名称必须查询到唯一的商品
* 2、该商品必须已经启用序列号
* 3、该商品已绑定序列号数量小于商品现有库存
* 2019-02-01
* 用商品的库存去限制序列号的添加有点不合乎道理,去掉此限制
* create time: 2019/1/23 17:04
* @Param: materialName
* @return Long 满足使用条件的商品的id
*/
public Long getSerialNumberMaterialIdByBarCode(String materialCode)throws Exception{
if(StringUtil.isNotEmpty(materialCode)){
//计算商品库存和目前占用的可用序列号数量关系
//库存=入库-出库
//入库数量
Long materialId = 0L;
List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(materialCode);
if(list!=null && list.size()>0) {
materialId = list.get(0).getId();
}
return materialId;
}
return null;
}
/**
* create by: cjl
* description:
* 出库时判断序列号库存是否足够,
* 同时将对应的序列号绑定单据
* create time: 2019/1/24 16:24
* @Param: List<DepotItem>
* @return void
*/
public void checkAndUpdateSerialNumber(DepotItem depotItem,User userInfo) throws Exception{
if(depotItem!=null){
//查询商品下已分配的可用序列号数量
int SerialNumberSum= serialNumberMapperEx.countSerialNumberByMaterialIdAndDepotheadId(depotItem.getMaterialId(),null,BusinessConstants.IS_SELL_HOLD);
//BasicNumber=OperNumber*ratio
if((depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue()>SerialNumberSum){
//获取商品名称
Material material= materialMapper.selectByPrimaryKey(depotItem.getMaterialId());
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_CODE,
String.format(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_MSG,material==null?"":material.getName()));
}
//商品下序列号充足,分配序列号
sellSerialNumber(depotItem.getMaterialId(),depotItem.getHeaderId(),(depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue(),userInfo);
}
}
/**
*
*
* */
/**
* create by: cjl
* description:
* 卖出序列号
* create time: 2019/1/25 9:17
* @Param: materialId
 * @Param: depotheadId
 * @Param: isSell 卖出'1'
 * @Param: Count 卖出或者赎回的数量
* @return com.jsh.erp.datasource.entities.SerialNumberEx
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int sellSerialNumber(Long materialId, Long depotHeadId,int count,User user) throws Exception{
int result=0;
try{
result = serialNumberMapperEx.sellSerialNumber(materialId,depotHeadId,count,new Date(),user==null?null:user.getId());
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 赎回序列号
* create time: 2019/1/25 9:17
* @Param: materialId
 * @Param: depotheadId
 * @Param: isSell 赎回'0'
 * @Param: Count 卖出或者赎回的数量
* @return com.jsh.erp.datasource.entities.SerialNumberEx
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int cancelSerialNumber(Long materialId, Long depotHeadId,int count,User user) throws Exception{
int result=0;
try{
result = serialNumberMapperEx.cancelSerialNumber(materialId,depotHeadId,count,new Date(),user==null?null:user.getId());
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
*批量添加序列号最多500个
* create time: 2019/1/29 15:11
* @Param: materialName
* @Param: serialNumberPrefix
* @Param: batAddTotal
* @Param: remark
* @return java.lang.Object
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batAddSerialNumber(String materialCode, String serialNumberPrefix, Integer batAddTotal, String remark)throws Exception {
int result=0;
try {
if (StringUtil.isNotEmpty(materialCode)) {
//查询商品id
Long materialId = getSerialNumberMaterialIdByBarCode(materialCode);
List<SerialNumberEx> list = null;
//当前用户
User userInfo = userService.getCurrentUser();
Long userId = userInfo == null ? null : userInfo.getId();
Date date = null;
Long million = null;
synchronized (this) {
date = new Date();
million = date.getTime();
}
int insertNum = 0;
StringBuffer prefixBuf = new StringBuffer(serialNumberPrefix).append(million);
list = new ArrayList<SerialNumberEx>();
int forNum = BusinessConstants.BATCH_INSERT_MAX_NUMBER >= batAddTotal ? batAddTotal : BusinessConstants.BATCH_INSERT_MAX_NUMBER;
for (int i = 0; i < forNum; i++) {
insertNum++;
SerialNumberEx each = new SerialNumberEx();
each.setMaterialId(materialId);
each.setCreator(userId);
each.setCreateTime(date);
each.setUpdater(userId);
each.setUpdateTime(date);
each.setRemark(remark);
each.setSerialNumber(new StringBuffer(prefixBuf.toString()).append(insertNum).toString());
list.add(each);
}
result = serialNumberMapperEx.batAddSerialNumber(list);
logService.insertLog("序列号",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_BATCH_ADD).append(batAddTotal).append(BusinessConstants.LOG_DATA_UNIT).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
}
} catch (Exception e) {
JshException.writeFail(logger, e);
}
return result;
}
}

View File

@@ -0,0 +1,79 @@
package com.jsh.erp.service.supplier;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.depot.DepotResource;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "supplier_component")
@SupplierResource
public class SupplierComponent implements ICommonQuery {
@Resource
private SupplierService supplierService;
@Override
public Object selectOne(Long id) throws Exception {
return supplierService.getSupplier(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getSupplierList(map);
}
private List<?> getSupplierList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String supplier = StringUtil.getInfo(search, "supplier");
String type = StringUtil.getInfo(search, "type");
String phonenum = StringUtil.getInfo(search, "phonenum");
String telephone = StringUtil.getInfo(search, "telephone");
String order = QueryUtils.order(map);
return supplierService.select(supplier, type, phonenum, telephone, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String supplier = StringUtil.getInfo(search, "supplier");
String type = StringUtil.getInfo(search, "type");
String phonenum = StringUtil.getInfo(search, "phonenum");
String telephone = StringUtil.getInfo(search, "telephone");
return supplierService.countSupplier(supplier, type, phonenum, telephone);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return supplierService.insertSupplier(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return supplierService.updateSupplier(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return supplierService.deleteSupplier(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return supplierService.batchDeleteSupplier(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return supplierService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.supplier;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "supplier")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SupplierResource {
}

View File

@@ -0,0 +1,390 @@
package com.jsh.erp.service.supplier;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.AccountHeadMapperEx;
import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
import com.jsh.erp.datasource.mappers.SupplierMapper;
import com.jsh.erp.datasource.mappers.SupplierMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.accountHead.AccountHeadService;
import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import static com.jsh.erp.utils.Tools.getNow3;
@Service
public class SupplierService {
private Logger logger = LoggerFactory.getLogger(SupplierService.class);
@Resource
private SupplierMapper supplierMapper;
@Resource
private SupplierMapperEx supplierMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
@Resource
private AccountHeadMapperEx accountHeadMapperEx;
@Resource
private DepotHeadMapperEx depotHeadMapperEx;
@Resource
private DepotHeadService depotHeadService;
@Resource
private AccountHeadService accountHeadService;
public Supplier getSupplier(long id)throws Exception {
Supplier result=null;
try{
result=supplierMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Supplier> getSupplierListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Supplier> list = new ArrayList<>();
try{
SupplierExample example = new SupplierExample();
example.createCriteria().andIdIn(idList);
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> getSupplier()throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Supplier> list=null;
try{
list=supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> select(String supplier, String type, String phonenum, String telephone, int offset, int rows) throws Exception{
List<Supplier> resList = new ArrayList<Supplier>();
try{
List<Supplier> list = supplierMapperEx.selectByConditionSupplier(supplier, type, phonenum, telephone, offset, rows);
for(Supplier s : list) {
Integer supplierId = s.getId().intValue();
String endTime = getNow3();
String supType = null;
if(("客户").equals(s.getType())) {
supType = "customer";
} else if(("供应商").equals(s.getType())) {
supType = "vendor";
}
BigDecimal sum = BigDecimal.ZERO;
BigDecimal beginNeedGet = s.getBeginNeedGet();
if(beginNeedGet==null) {
beginNeedGet = BigDecimal.ZERO;
}
BigDecimal beginNeedPay = s.getBeginNeedPay();
if(beginNeedPay==null) {
beginNeedPay = BigDecimal.ZERO;
}
sum = sum.add(depotHeadService.findTotalPay(supplierId, endTime, supType));
sum = sum.add(accountHeadService.findTotalPay(supplierId, endTime, supType));
if(("客户").equals(s.getType())) {
sum = sum.add(beginNeedGet).subtract(beginNeedPay);
s.setAllNeedGet(sum);
s.setAllNeedPay(BigDecimal.ZERO);
} else if(("供应商").equals(s.getType())) {
sum = sum.add(beginNeedPay).subtract(beginNeedGet);
s.setAllNeedGet(BigDecimal.ZERO);
s.setAllNeedPay(sum);
}
resList.add(s);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return resList;
}
public Long countSupplier(String supplier, String type, String phonenum, String telephone) throws Exception{
Long result=null;
try{
result=supplierMapperEx.countsBySupplier(supplier, type, phonenum, telephone);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
int result=0;
try{
supplier.setEnabled(true);
result=supplierMapper.insertSelective(supplier);
logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(supplier.getSupplier()).toString(),request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSupplier(JSONObject obj, HttpServletRequest request)throws Exception {
Supplier supplier = JSONObject.parseObject(obj.toJSONString(), Supplier.class);
if(supplier.getBeginNeedPay() == null) {
supplier.setBeginNeedPay(BigDecimal.ZERO);
}
if(supplier.getBeginNeedGet() == null) {
supplier.setBeginNeedGet(BigDecimal.ZERO);
}
int result=0;
try{
result=supplierMapper.updateByPrimaryKeySelective(supplier);
logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplier.getSupplier()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSupplier(Long id, HttpServletRequest request)throws Exception {
return batchDeleteSupplierByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSupplier(String ids, HttpServletRequest request) throws Exception{
return batchDeleteSupplierByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSupplierByIds(String ids)throws Exception {
int result=0;
String [] idArray=ids.split(",");
//校验财务主表 jsh_accounthead
List<AccountHead> accountHeadList=null;
try{
accountHeadList = accountHeadMapperEx.getAccountHeadListByOrganIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(accountHeadList!=null&&accountHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//校验单据主表 jsh_depot_head
List<DepotHead> depotHeadList=null;
try{
depotHeadList = depotHeadMapperEx.getDepotHeadListByOrganIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(depotHeadList!=null&&depotHeadList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,OrganIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Supplier> list = getSupplierListByIds(ids);
for(Supplier supplier: list){
sb.append("[").append(supplier.getSupplier()).append("]");
}
logService.insertLog("商家", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
//校验通过执行删除操作
try{
result = supplierMapperEx.batchDeleteSupplierByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andIdNotEqualTo(id).andSupplierEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Supplier> list=null;
try{
list= supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAdvanceIn(Long supplierId, BigDecimal advanceIn)throws Exception{
logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplierId).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
Supplier supplier=null;
try{
supplier = supplierMapper.selectByPrimaryKey(supplierId);
}catch(Exception e){
JshException.readFail(logger, e);
}
int result=0;
try{
if(supplier!=null){
supplier.setAdvanceIn(supplier.getAdvanceIn().add(advanceIn)); //增加预收款的金额,可能增加的是负值
result=supplierMapper.updateByPrimaryKeySelective(supplier);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<Supplier> findBySelectCus()throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andTypeLike("客户").andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Supplier> list=null;
try{
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> findBySelectSup()throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andTypeLike("供应商").andEnabledEqualTo(true)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Supplier> list=null;
try{
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> findBySelectRetail()throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andTypeLike("会员").andEnabledEqualTo(true)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Supplier> list=null;
try{
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> findById(Long supplierId)throws Exception {
SupplierExample example = new SupplierExample();
example.createCriteria().andIdEqualTo(supplierId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Supplier> list=null;
try{
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetStatus(Boolean status, String ids)throws Exception {
logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
List<Long> supplierIds = StringUtil.strToLongList(ids);
Supplier supplier = new Supplier();
supplier.setEnabled(status);
SupplierExample example = new SupplierExample();
example.createCriteria().andIdIn(supplierIds);
int result=0;
try{
result = supplierMapper.updateByExampleSelective(supplier, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public List<Supplier> findUserCustomer()throws Exception{
SupplierExample example = new SupplierExample();
example.createCriteria().andTypeEqualTo("客户")
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
example.setOrderByClause("id desc");
List<Supplier> list=null;
try{
list = supplierMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Supplier> findByAll(String supplier, String type, String phonenum, String telephone) throws Exception{
List<Supplier> list=null;
try{
list = supplierMapperEx.findByAll(supplier, type, phonenum, telephone);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public BaseResponseInfo importExcel(List<Supplier> mList) throws Exception {
logService.insertLog("商家",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
BaseResponseInfo info = new BaseResponseInfo();
Map<String, Object> data = new HashMap<String, Object>();
try {
for(Supplier s: mList) {
supplierMapper.insertSelective(s);
}
info.code = 200;
data.put("message", "成功");
} catch (Exception e) {
e.printStackTrace();
info.code = 500;
data.put("message", e.getMessage());
}
info.data = data;
return info;
}
}

View File

@@ -0,0 +1,73 @@
package com.jsh.erp.service.systemConfig;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.systemConfig.SystemConfigResource;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "systemConfig_component")
@SystemConfigResource
public class SystemConfigComponent implements ICommonQuery {
@Resource
private SystemConfigService systemConfigService;
@Override
public Object selectOne(Long id) throws Exception {
return systemConfigService.getSystemConfig(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getSystemConfigList(map);
}
private List<?> getSystemConfigList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String companyName = StringUtil.getInfo(search, "companyName");
String order = QueryUtils.order(map);
return systemConfigService.select(companyName, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String companyName = StringUtil.getInfo(search, "companyName");
return systemConfigService.countSystemConfig(companyName);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return systemConfigService.insertSystemConfig(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return systemConfigService.updateSystemConfig(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return systemConfigService.deleteSystemConfig(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return systemConfigService.batchDeleteSystemConfig(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return systemConfigService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.systemConfig;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "systemConfig")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SystemConfigResource {
}

View File

@@ -0,0 +1,208 @@
package com.jsh.erp.service.systemConfig;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Supplier;
import com.jsh.erp.datasource.entities.SystemConfig;
import com.jsh.erp.datasource.entities.SystemConfigExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.SystemConfigMapper;
import com.jsh.erp.datasource.mappers.SystemConfigMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Service
public class SystemConfigService {
private Logger logger = LoggerFactory.getLogger(SystemConfigService.class);
@Resource
private SystemConfigMapper systemConfigMapper;
@Resource
private SystemConfigMapperEx systemConfigMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
public SystemConfig getSystemConfig(long id)throws Exception {
SystemConfig result=null;
try{
result=systemConfigMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<SystemConfig> getSystemConfig()throws Exception {
SystemConfigExample example = new SystemConfigExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<SystemConfig> list=null;
try{
list=systemConfigMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<SystemConfig> select(String companyName, int offset, int rows)throws Exception {
List<SystemConfig> list=null;
try{
list=systemConfigMapperEx.selectByConditionSystemConfig(companyName, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countSystemConfig(String companyName)throws Exception {
Long result=null;
try{
result=systemConfigMapperEx.countsBySystemConfig(companyName);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
int result=0;
try{
if(userService.checkIsTestUser()) {
result=-1;
} else {
result=systemConfigMapper.insertSelective(systemConfig);
logService.insertLog("系统配置",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(systemConfig.getCompanyName()).toString(), request);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSystemConfig(JSONObject obj, HttpServletRequest request) throws Exception{
SystemConfig systemConfig = JSONObject.parseObject(obj.toJSONString(), SystemConfig.class);
int result=0;
try{
if(userService.checkIsTestUser()) {
result=-1;
} else {
result = systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
logService.insertLog("系统配置",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(systemConfig.getCompanyName()).toString(), request);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSystemConfig(Long id, HttpServletRequest request)throws Exception {
return batchDeleteSystemConfigByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSystemConfig(String ids, HttpServletRequest request)throws Exception {
return batchDeleteSystemConfigByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSystemConfigByIds(String ids)throws Exception {
logService.insertLog("系统配置",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result=systemConfigMapperEx.batchDeleteSystemConfigByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name) throws Exception{
SystemConfigExample example = new SystemConfigExample();
example.createCriteria().andIdNotEqualTo(id).andCompanyNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<SystemConfig> list =null;
try{
list=systemConfigMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
/**
* 获取仓库开关
* @return
* @throws Exception
*/
public boolean getDepotFlag() throws Exception {
boolean depotFlag = false;
List<SystemConfig> list = getSystemConfig();
if(list.size()>0) {
String flag = list.get(0).getDepotFlag();
if(("1").equals(flag)) {
depotFlag = true;
}
}
return depotFlag;
}
/**
* 获取客户开关
* @return
* @throws Exception
*/
public boolean getCustomerFlag() throws Exception {
boolean customerFlag = false;
List<SystemConfig> list = getSystemConfig();
if(list.size()>0) {
String flag = list.get(0).getCustomerFlag();
if(("1").equals(flag)) {
customerFlag = true;
}
}
return customerFlag;
}
/**
* 获取负库存开关
* @return
* @throws Exception
*/
public boolean getMinusStockFlag() throws Exception {
boolean minusStockFlag = false;
List<SystemConfig> list = getSystemConfig();
if(list.size()>0) {
String flag = list.get(0).getMinusStockFlag();
if(("1").equals(flag)) {
minusStockFlag = true;
}
}
return minusStockFlag;
}
}

View File

@@ -0,0 +1,72 @@
package com.jsh.erp.service.tenant;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.user.UserResource;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "tenant_component")
@TenantResource
public class TenantComponent implements ICommonQuery {
@Resource
private TenantService tenantService;
@Override
public Object selectOne(Long id) throws Exception {
return tenantService.getTenant(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getTenantList(map);
}
private List<?> getTenantList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String loginName = StringUtil.getInfo(search, "loginName");
return tenantService.select(loginName, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String loginName = StringUtil.getInfo(search, "loginName");
return tenantService.countTenant(loginName);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return tenantService.insertTenant(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return tenantService.updateTenant(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return tenantService.deleteTenant(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return tenantService.batchDeleteTenant(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return tenantService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.tenant;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2019-6-27 22:56:56
*/
@ResourceInfo(value = "tenant")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface TenantResource {
}

View File

@@ -0,0 +1,153 @@
package com.jsh.erp.service.tenant;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.TenantMapper;
import com.jsh.erp.datasource.mappers.TenantMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Service
public class TenantService {
private Logger logger = LoggerFactory.getLogger(TenantService.class);
@Resource
private TenantMapper tenantMapper;
@Resource
private TenantMapperEx tenantMapperEx;
@Value("${tenant.userNumLimit}")
private Integer userNumLimit;
@Value("${tenant.billsNumLimit}")
private Integer billsNumLimit;
public Tenant getTenant(long id)throws Exception {
Tenant result=null;
try{
result=tenantMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Tenant> getTenant()throws Exception {
TenantExample example = new TenantExample();
List<Tenant> list=null;
try{
list=tenantMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Tenant> select(String loginName, int offset, int rows)throws Exception {
List<Tenant> list=null;
try{
list=tenantMapperEx.selectByConditionTenant(loginName, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countTenant(String loginName)throws Exception {
Long result=null;
try{
result=tenantMapperEx.countsByTenant(loginName);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertTenant(JSONObject obj, HttpServletRequest request)throws Exception {
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
int result=0;
try{
tenant.setUserNumLimit(userNumLimit); //默认用户限制数量
tenant.setBillsNumLimit(billsNumLimit); //默认单据限制数量
tenant.setCreateTime(new Date());
result=tenantMapper.insertSelective(tenant);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateTenant(JSONObject obj, HttpServletRequest request)throws Exception {
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
int result=0;
try{
result=tenantMapper.updateByPrimaryKeySelective(tenant);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteTenant(Long id, HttpServletRequest request)throws Exception {
int result=0;
try{
result= tenantMapper.deleteByPrimaryKey(id);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteTenant(String ids, HttpServletRequest request)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
TenantExample example = new TenantExample();
example.createCriteria().andIdIn(idList);
int result=0;
try{
result= tenantMapper.deleteByExample(example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
TenantExample example = new TenantExample();
example.createCriteria().andIdEqualTo(id);
List<Tenant> list=null;
try{
list= tenantMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
public Tenant getTenantByTenantId(long tenantId) {
Tenant tenant = new Tenant();
TenantExample example = new TenantExample();
example.createCriteria().andTenantIdEqualTo(tenantId);
List<Tenant> list = tenantMapper.selectByExample(example);
if(list.size()>0) {
tenant = list.get(0);
}
return tenant;
}
}

View File

@@ -0,0 +1,71 @@
package com.jsh.erp.service.unit;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "unit_component")
@UnitResource
public class UnitComponent implements ICommonQuery {
@Resource
private UnitService unitService;
@Override
public Object selectOne(Long id) throws Exception {
return unitService.getUnit(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getUnitList(map);
}
private List<?> getUnitList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String order = QueryUtils.order(map);
return unitService.select(name, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
return unitService.countUnit(name);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return unitService.insertUnit(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return unitService.updateUnit(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return unitService.deleteUnit(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return unitService.batchDeleteUnit(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return unitService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.unit;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "unit")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface UnitResource {
}

View File

@@ -0,0 +1,202 @@
package com.jsh.erp.service.unit;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
import com.jsh.erp.datasource.mappers.UnitMapper;
import com.jsh.erp.datasource.mappers.UnitMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class UnitService {
private Logger logger = LoggerFactory.getLogger(UnitService.class);
@Resource
private UnitMapper unitMapper;
@Resource
private UnitMapperEx unitMapperEx;
@Resource
private UserService userService;
@Resource
private LogService logService;
@Resource
private MaterialMapperEx materialMapperEx;
public Unit getUnit(long id)throws Exception {
Unit result=null;
try{
result=unitMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<Unit> getUnitListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<Unit> list = new ArrayList<>();
try{
UnitExample example = new UnitExample();
example.createCriteria().andIdIn(idList);
list = unitMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Unit> getUnit()throws Exception {
UnitExample example = new UnitExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Unit> list=null;
try{
list=unitMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<Unit> select(String name, int offset, int rows)throws Exception {
List<Unit> list=null;
try{
list=unitMapperEx.selectByConditionUnit(name, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countUnit(String name)throws Exception {
Long result=null;
try{
result=unitMapperEx.countsByUnit(name);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertUnit(JSONObject obj, HttpServletRequest request)throws Exception {
Unit unit = JSONObject.parseObject(obj.toJSONString(), Unit.class);
int result=0;
try{
unit.setName(unit.getBasicUnit() + "," + unit.getOtherUnit() + "(1:" + unit.getRatio() + ")");
result=unitMapper.insertSelective(unit);
logService.insertLog("计量单位",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(unit.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUnit(JSONObject obj, HttpServletRequest request)throws Exception {
Unit unit = JSONObject.parseObject(obj.toJSONString(), Unit.class);
int result=0;
try{
unit.setName(unit.getBasicUnit() + "," + unit.getOtherUnit() + "(1:" + unit.getRatio() + ")");
result=unitMapper.updateByPrimaryKeySelective(unit);
logService.insertLog("计量单位",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(unit.getName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteUnit(Long id, HttpServletRequest request)throws Exception {
return batchDeleteUnitByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUnit(String ids, HttpServletRequest request) throws Exception{
return batchDeleteUnitByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUnitByIds(String ids)throws Exception {
int result=0;
String [] idArray=ids.split(",");
//校验产品表 jsh_material
List<Material> materialList=null;
try{
materialList=materialMapperEx.getMaterialListByUnitIds(idArray);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(materialList!=null&&materialList.size()>0){
logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
}
//记录日志
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<Unit> list = getUnitListByIds(ids);
for(Unit unit: list){
sb.append("[").append(unit.getName()).append("]");
}
logService.insertLog("计量单位", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
//校验通过执行删除操作
try{
result=unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
UnitExample example = new UnitExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Unit> list=null;
try{
list=unitMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
/**
* 根据名称获取类型
* @param name
*/
public Long getUnitIdByName(String name){
Long unitId = 0L;
UnitExample example = new UnitExample();
example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<Unit> list = unitMapper.selectByExample(example);
if(list!=null && list.size()>0) {
unitId = list.get(0).getId();
}
return unitId;
}
}

View File

@@ -0,0 +1,73 @@
package com.jsh.erp.service.user;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Service(value = "user_component")
@UserResource
public class UserComponent implements ICommonQuery {
@Resource
private UserService userService;
@Override
public Object selectOne(Long id) throws Exception {
return userService.getUser(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getUserList(map);
}
private List<?> getUserList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String userName = StringUtil.getInfo(search, "userName");
String loginName = StringUtil.getInfo(search, "loginName");
String order = QueryUtils.order(map);
String filter = QueryUtils.filter(map);
return userService.select(userName, loginName, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String userName = StringUtil.getInfo(search, "userName");
String loginName = StringUtil.getInfo(search, "loginName");
return userService.countUser(userName, loginName);
}
@Override
public int insert(JSONObject obj, HttpServletRequest request)throws Exception {
return userService.insertUser(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return userService.updateUser(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return userService.deleteUser(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return userService.batchDeleteUser(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return userService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.user;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "user")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface UserResource {
}

View File

@@ -0,0 +1,745 @@
package com.jsh.erp.service.user;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.role.RoleService;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.mappers.UserMapper;
import com.jsh.erp.datasource.mappers.UserMapperEx;
import com.jsh.erp.datasource.vo.TreeNodeEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.orgaUserRel.OrgaUserRelService;
import com.jsh.erp.service.tenant.TenantService;
import com.jsh.erp.service.userBusiness.UserBusinessService;
import com.jsh.erp.utils.ExceptionCodeConstants;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
public class UserService {
private Logger logger = LoggerFactory.getLogger(UserService.class);
private static final String TEST_USER = "jsh";
@Value("${demonstrate.open}")
private boolean demonstrateOpen;
@Resource
private UserMapper userMapper;
@Resource
private UserMapperEx userMapperEx;
@Resource
private OrgaUserRelService orgaUserRelService;
@Resource
private LogService logService;
@Resource
private UserService userService;
@Resource
private TenantService tenantService;
@Resource
private UserBusinessService userBusinessService;
@Resource
private RoleService roleService;
@Resource
private RedisService redisService;
public User getUser(long id)throws Exception {
User result=null;
try{
result=userMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<User> getUserListByIds(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
List<User> list = new ArrayList<>();
try{
UserExample example = new UserExample();
example.createCriteria().andIdIn(idList);
list = userMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<User> getUser()throws Exception {
UserExample example = new UserExample();
example.createCriteria().andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
List<User> list=null;
try{
list=userMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<UserEx> select(String userName, String loginName, int offset, int rows)throws Exception {
List<UserEx> list=null;
try{
list=userMapperEx.selectByConditionUser(userName, loginName, offset, rows);
for(UserEx ue: list){
String userType = "";
if(demonstrateOpen && TEST_USER.equals(ue.getLoginName())){
userType = "演示用户";
} else {
if (ue.getId().equals(ue.getTenantId())) {
userType = "租户";
} else if(ue.getTenantId() == null){
userType = "超管";
} else {
userType = "普通";
}
}
ue.setUserType(userType);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long countUser(String userName, String loginName)throws Exception {
Long result=null;
try{
result=userMapperEx.countsByUser(userName, loginName);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:30
* @Param: beanJson
 * @Param: request
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertUser(JSONObject obj, HttpServletRequest request)throws Exception {
User user = JSONObject.parseObject(obj.toJSONString(), User.class);
String password = "123456";
//因密码用MD5加密需要对密码进行转化
try {
password = Tools.md5Encryp(password);
user.setPassword(password);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
logger.error(">>>>>>>>>>>>>>转化MD5字符串错误 " + e.getMessage());
}
int result=0;
try{
result=userMapper.insertSelective(user);
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(user.getLoginName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:31
* @Param: beanJson
 * @Param: id
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUser(JSONObject obj, HttpServletRequest request) throws Exception{
User user = JSONObject.parseObject(obj.toJSONString(), User.class);
int result=0;
try{
result=userMapper.updateByPrimaryKeySelective(user);
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(user.getLoginName()).toString(), request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:32
* @Param: user
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUserByObj(User user) throws Exception{
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(user.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
int result=0;
try{
result=userMapper.updateByPrimaryKeySelective(user);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:33
* @Param: md5Pwd
 * @Param: id
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int resetPwd(String md5Pwd, Long id) throws Exception{
int result=0;
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(id).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User u = getUser(id);
String loginName = u.getLoginName();
if("admin".equals(loginName)){
logger.info("禁止重置超管密码");
} else {
User user = new User();
user.setId(id);
user.setPassword(md5Pwd);
try{
result=userMapper.updateByPrimaryKeySelective(user);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteUser(Long id, HttpServletRequest request)throws Exception {
return batDeleteUser(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUser(String ids, HttpServletRequest request)throws Exception {
return batDeleteUser(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batDeleteUser(String ids) throws Exception{
int result=0;
StringBuffer sb = new StringBuffer();
sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
List<User> list = getUserListByIds(ids);
for(User user: list){
sb.append("[").append(user.getLoginName()).append("]");
}
logService.insertLog("用户", sb.toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
String idsArray[]=ids.split(",");
try{
result=userMapperEx.batDeleteOrUpdateUser(idsArray,BusinessConstants.USER_STATUS_DELETE);
}catch(Exception e){
JshException.writeFail(logger, e);
}
if(result<1){
logger.error("异常码[{}],异常提示[{}],参数,ids:[{}]",
ExceptionConstants.USER_DELETE_FAILED_CODE,ExceptionConstants.USER_DELETE_FAILED_MSG,ids);
throw new BusinessRunTimeException(ExceptionConstants.USER_DELETE_FAILED_CODE,
ExceptionConstants.USER_DELETE_FAILED_MSG);
}
return result;
}
public int validateUser(String loginName, String password) throws Exception {
/**默认是可以登录的*/
List<User> list = null;
try {
UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName);
list = userMapper.selectByExample(example);
if (null != list && list.size() == 0) {
return ExceptionCodeConstants.UserExceptionCode.USER_NOT_EXIST;
} else if(list.size() ==1) {
if(list.get(0).getStatus()!=0) {
return ExceptionCodeConstants.UserExceptionCode.BLACK_USER;
}
}
} catch (Exception e) {
logger.error(">>>>>>>>访问验证用户姓名是否存在后台信息异常", e);
return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION;
}
try {
UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andPasswordEqualTo(password)
.andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
list = userMapper.selectByExample(example);
if (null != list && list.size() == 0) {
return ExceptionCodeConstants.UserExceptionCode.USER_PASSWORD_ERROR;
}
} catch (Exception e) {
logger.error(">>>>>>>>>>访问验证用户密码后台信息异常", e);
return ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION;
}
return ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT;
}
public User getUserByLoginName(String loginName)throws Exception {
UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
List<User> list=null;
try{
list= userMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
User user =null;
if(list!=null&&list.size()>0){
user = list.get(0);
}
return user;
}
public int checkIsNameExist(Long id, String name)throws Exception {
UserExample example = new UserExample();
List <Byte> userStatus=new ArrayList<Byte>();
userStatus.add(BusinessConstants.USER_STATUS_DELETE);
userStatus.add(BusinessConstants.USER_STATUS_BANNED);
example.createCriteria().andIdNotEqualTo(id).andLoginNameEqualTo(name).andStatusNotIn(userStatus);
List<User> list=null;
try{
list= userMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list==null?0:list.size();
}
/**
* create by: cjl
* description:
* 获取当前用户信息
* create time: 2019/1/24 10:01
* @Param:
* @return com.jsh.erp.datasource.entities.User
*/
public User getCurrentUser()throws Exception{
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
return getUser(userId);
}
/**
* 检查当前用户是否是演示用户
* @return
*/
public Boolean checkIsTestUser() throws Exception{
Boolean result = false;
try {
if (demonstrateOpen) {
User user = getCurrentUser();
if (TEST_USER.equals(user.getLoginName())) {
result = true;
}
}
} catch (Exception e) {
JshException.readFail(logger, e);
}
return result;
}
/**
* 根据用户名查询id
* @param loginName
* @return
*/
public Long getIdByLoginName(String loginName) {
Long userId = 0L;
UserExample example = new UserExample();
example.createCriteria().andLoginNameEqualTo(loginName).andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
List<User> list = userMapper.selectByExample(example);
if(list!=null) {
userId = list.get(0).getId();
}
return userId;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
logService.insertLog("用户",
BusinessConstants.LOG_OPERATION_TYPE_ADD,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//检查用户名和登录名
checkUserNameAndLoginName(ue);
//新增用户信息
ue= this.addUser(ue);
if(ue==null){
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.USER_ADD_FAILED_CODE,ExceptionConstants.USER_ADD_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_ADD_FAILED_CODE,
ExceptionConstants.USER_ADD_FAILED_MSG);
}
//用户id根据用户名查询id
Long userId = getIdByLoginName(ue.getLoginName());
if(ue.getRoleId()!=null){
JSONObject ubObj = new JSONObject();
ubObj.put("type", "UserRole");
ubObj.put("keyid", userId);
ubObj.put("value", "[" + ue.getRoleId() + "]");
userBusinessService.insertUserBusiness(ubObj, null);
}
if(ue.getOrgaId()==null){
//如果没有选择机构,就不建机构和用户的关联关系
return;
}
//新增用户和机构关联关系
OrgaUserRel oul=new OrgaUserRel();
//机构id
oul.setOrgaId(ue.getOrgaId());
oul.setUserId(userId);
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
oul=orgaUserRelService.addOrgaUserRel(oul);
if(oul==null){
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_ADD_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_ADD_FAILED_MSG);
}
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx addUser(UserEx ue) throws Exception{
/**
* 新增用户默认设置
* 1、密码默认123456
* 2是否系统自带默认为非系统自带
* 3是否管理者默认为员工
* 4默认用户状态为正常
* */
ue.setPassword(Tools.md5Encryp(BusinessConstants.USER_DEFAULT_PASSWORD));
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
if(ue.getIsmanager()==null){
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
}
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int result=0;
try{
result= userMapper.insertSelective(ue);
}catch(Exception e){
JshException.writeFail(logger, e);
}
if(result>0){
return ue;
}
return null;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx registerUser(UserEx ue, Integer manageRoleId, HttpServletRequest request) throws Exception{
/**
* create by: qiankunpingtai
* create time: 2019/4/9 18:00
* 多次创建事务,事物之间无法协同,应该在入口处创建一个事务以做协调
*/
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
ue.setPassword(Tools.md5Encryp(ue.getPassword()));
ue.setIsystem(BusinessConstants.USER_NOT_SYSTEM);
if (ue.getIsmanager() == null) {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
}
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int result=0;
try{
result= userMapper.insertSelective(ue);
Long userId = getIdByLoginName(ue.getLoginName());
ue.setId(userId);
}catch(Exception e){
JshException.writeFail(logger, e);
}
//更新租户id
User user = new User();
user.setId(ue.getId());
user.setTenantId(ue.getId());
userService.updateUserTenant(user);
//新增用户与角色的关系
JSONObject ubObj = new JSONObject();
ubObj.put("type", "UserRole");
ubObj.put("keyid", ue.getId());
JSONArray ubArr = new JSONArray();
ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//创建租户信息
JSONObject tenantObj = new JSONObject();
tenantObj.put("tenantId", ue.getId());
tenantObj.put("loginName",ue.getLoginName());
tenantService.insertTenant(tenantObj, request);
logger.info("===============创建租户信息完成===============");
if (result > 0) {
return ue;
}
return null;
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserTenant(User user) throws Exception{
UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(user.getId());
try{
userMapper.updateByPrimaryKeySelective(user);
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
} else {
logService.insertLog("用户",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(ue.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
//检查用户名和登录名
checkUserNameAndLoginName(ue);
//更新用户信息
ue = this.updateUser(ue);
if (ue == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.USER_EDIT_FAILED_CODE, ExceptionConstants.USER_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.USER_EDIT_FAILED_CODE,
ExceptionConstants.USER_EDIT_FAILED_MSG);
}
if(ue.getRoleId()!=null){
JSONObject ubObj = new JSONObject();
ubObj.put("type", "UserRole");
ubObj.put("keyid", ue.getId());
ubObj.put("value", "[" + ue.getRoleId() + "]");
Long ubId = userBusinessService.checkIsValueExist("UserRole", ue.getId().toString());
if(ubId!=null) {
ubObj.put("id", ubId);
userBusinessService.updateUserBusiness(ubObj, null);
} else {
userBusinessService.insertUserBusiness(ubObj, null);
}
}
if (ue.getOrgaId() == null) {
//如果没有选择机构,就不建机构和用户的关联关系
return;
}
//更新用户和机构关联关系
OrgaUserRel oul = new OrgaUserRel();
//机构和用户关联关系id
oul.setId(ue.getOrgaUserRelId());
//机构id
oul.setOrgaId(ue.getOrgaId());
//用户id
oul.setUserId(ue.getId());
//用户在机构中的排序
oul.setUserBlngOrgaDsplSeq(ue.getUserBlngOrgaDsplSeq());
if (oul.getId() != null) {
//已存在机构和用户的关联关系,更新
oul = orgaUserRelService.updateOrgaUserRel(oul);
} else {
//不存在机构和用户的关联关系,新建
oul = orgaUserRelService.addOrgaUserRel(oul);
}
if (oul == null) {
logger.error("异常码[{}],异常提示[{}],参数,[{}]",
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE, ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
throw new BusinessRunTimeException(ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_CODE,
ExceptionConstants.ORGA_USER_REL_EDIT_FAILED_MSG);
}
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public UserEx updateUser(UserEx ue)throws Exception{
int result =0;
try{
result=userMapper.updateByPrimaryKeySelective(ue);
}catch(Exception e){
JshException.writeFail(logger, e);
}
if(result>0){
return ue;
}
return null;
}
/**
* create by: cjl
* description:
* 检查用户名称和登录名不能重复
* create time: 2019/3/12 11:36
* @Param: userEx
* @return void
*/
public void checkUserNameAndLoginName(UserEx userEx)throws Exception{
List<User> list=null;
if(userEx==null){
return;
}
Long userId=userEx.getId();
//检查登录名
if(!StringUtils.isEmpty(userEx.getLoginName())){
String loginName=userEx.getLoginName();
list=this.getUserListByloginName(loginName);
if(list!=null&&list.size()>0){
if(list.size()>1){
//超过一条数据存在,该登录名已存在
logger.error("异常码[{}],异常提示[{}],参数,loginName:[{}]",
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG,loginName);
throw new BusinessRunTimeException(ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
}
//一条数据新增时抛出异常修改时和当前的id不同时抛出异常
if(list.size()==1){
if(userId==null||(userId!=null&&!userId.equals(list.get(0).getId()))){
logger.error("异常码[{}],异常提示[{}],参数,loginName:[{}]",
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG,loginName);
throw new BusinessRunTimeException(ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_CODE,
ExceptionConstants.USER_LOGIN_NAME_ALREADY_EXISTS_MSG);
}
}
}
}
//检查用户名
if(!StringUtils.isEmpty(userEx.getUsername())){
String userName=userEx.getUsername();
list=this.getUserListByUserName(userName);
if(list!=null&&list.size()>0){
if(list.size()>1){
//超过一条数据存在,该用户名已存在
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
}
//一条数据新增时抛出异常修改时和当前的id不同时抛出异常
if(list.size()==1){
if(userId==null||(userId!=null&&!userId.equals(list.get(0).getId()))){
logger.error("异常码[{}],异常提示[{}],参数,userName:[{}]",
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG,userName);
throw new BusinessRunTimeException(ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_CODE,
ExceptionConstants.USER_USER_NAME_ALREADY_EXISTS_MSG);
}
}
}
}
}
/**
* 通过用户名获取用户列表
* */
public List<User> getUserListByUserName(String userName)throws Exception{
List<User> list =null;
try{
list=userMapperEx.getUserListByUserNameOrLoginName(userName,null);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* 通过登录名获取用户列表
* */
public List<User> getUserListByloginName(String loginName){
List<User> list =null;
try{
list=userMapperEx.getUserListByUserNameOrLoginName(null,loginName);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<TreeNodeEx> getOrganizationUserTree()throws Exception {
List<TreeNodeEx> list =null;
try{
list=userMapperEx.getNodeTree();
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
/**
* 根据用户id查询角色类型
* @param userId
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String getRoleTypeByUserId(long userId) throws Exception {
List<UserBusiness> list = userBusinessService.getBasicData(String.valueOf(userId), "UserRole");
UserBusiness ub = null;
if(list.size() > 0) {
ub = list.get(0);
String values = ub.getValue();
String roleId = null;
if(values!=null) {
values = values.replaceAll("\\[\\]",",").replace("[","").replace("]","");
}
String [] valueArray=values.split(",");
if(valueArray.length>0) {
roleId = valueArray[0];
}
Role role = roleService.getRole(Long.parseLong(roleId));
if(role!=null) {
return role.getType();
} else {
return null;
}
} else {
return null;
}
}
/**
* 获取用户id
* @param request
* @return
*/
public Long getUserId(HttpServletRequest request) throws Exception{
Object userIdObj = redisService.getObjectFromSessionByKey(request,"userId");
Long userId = null;
if(userIdObj != null) {
userId = Long.parseLong(userIdObj.toString());
}
return userId;
}
}

View File

@@ -0,0 +1,69 @@
package com.jsh.erp.service.userBusiness;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.depot.DepotResource;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "userBusiness_component")
@UserBusinessResource
public class UserBusinessComponent implements ICommonQuery {
@Resource
private UserBusinessService userBusinessService;
@Override
public Object selectOne(Long id) throws Exception {
return userBusinessService.getUserBusiness(id);
}
@Override
public List<?> select(Map<String, String> map)throws Exception {
return getUserBusinessList(map);
}
private List<?> getUserBusinessList(Map<String, String> map)throws Exception {
return null;
}
@Override
public Long counts(Map<String, String> map)throws Exception {
return BusinessConstants.DEFAULT_LIST_NULL_NUMBER;
}
@Override
public int insert(JSONObject obj, HttpServletRequest request) throws Exception {
return userBusinessService.insertUserBusiness(obj, request);
}
@Override
public int update(JSONObject obj, HttpServletRequest request)throws Exception {
return userBusinessService.updateUserBusiness(obj, request);
}
@Override
public int delete(Long id, HttpServletRequest request)throws Exception {
return userBusinessService.deleteUserBusiness(id, request);
}
@Override
public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
return userBusinessService.batchDeleteUserBusiness(ids, request);
}
@Override
public int checkIsNameExist(Long id, String name)throws Exception {
return userBusinessService.checkIsNameExist(id, name);
}
}

View File

@@ -0,0 +1,15 @@
package com.jsh.erp.service.userBusiness;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "userBusiness")
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface UserBusinessResource {
}

View File

@@ -0,0 +1,198 @@
package com.jsh.erp.service.userBusiness;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.UserBusinessMapper;
import com.jsh.erp.datasource.mappers.UserBusinessMapperEx;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.CommonQueryManager;
import com.jsh.erp.service.functions.FunctionService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Service
public class UserBusinessService {
private Logger logger = LoggerFactory.getLogger(UserBusinessService.class);
@Resource
private UserBusinessMapper userBusinessMapper;
@Resource
private UserBusinessMapperEx userBusinessMapperEx;
@Resource
private LogService logService;
@Resource
private UserService userService;
@Resource
private FunctionService functionService;
@Resource
private CommonQueryManager configResourceManager;
public UserBusiness getUserBusiness(long id)throws Exception {
UserBusiness result=null;
try{
result=userBusinessMapper.selectByPrimaryKey(id);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}
public List<UserBusiness> getUserBusiness()throws Exception {
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<UserBusiness> list=null;
try{
list=userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertUserBusiness(JSONObject obj, HttpServletRequest request) throws Exception {
UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
int result=0;
try{
String value = userBusiness.getValue();
String newValue = value.replaceAll(",","\\]\\[");
userBusiness.setValue(newValue);
result=userBusinessMapper.insertSelective(userBusiness);
logService.insertLog("关联关系", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUserBusiness(JSONObject obj, HttpServletRequest request) throws Exception {
UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
int result=0;
try{
String value = userBusiness.getValue();
String newValue = value.replaceAll(",","\\]\\[");
userBusiness.setValue(newValue);
result=userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
logService.insertLog("关联关系", BusinessConstants.LOG_OPERATION_TYPE_EDIT, request);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteUserBusiness(Long id, HttpServletRequest request)throws Exception {
return batchDeleteUserBusinessByIds(id.toString());
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUserBusiness(String ids, HttpServletRequest request)throws Exception {
return batchDeleteUserBusinessByIds(ids);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUserBusinessByIds(String ids) throws Exception{
logService.insertLog("关联关系",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(",");
int result=0;
try{
result= userBusinessMapperEx.batchDeleteUserBusinessByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
public int checkIsNameExist(Long id, String name)throws Exception {
return 1;
}
public List<UserBusiness> getBasicData(String keyId, String type)throws Exception{
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andKeyIdEqualTo(keyId).andTypeEqualTo(type)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<UserBusiness> list=null;
try{
list= userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public Long checkIsValueExist(String type, String keyId)throws Exception {
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andTypeEqualTo(type).andKeyIdEqualTo(keyId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<UserBusiness> list=null;
try{
list= userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
Long id = null;
if(list!=null&&list.size() > 0) {
id = list.get(0).getId();
}
return id;
}
public Boolean checkIsUserBusinessExist(String TypeVale, String KeyIdValue, String UBValue)throws Exception {
UserBusinessExample example = new UserBusinessExample();
String newVaule = "%" + UBValue + "%";
if(TypeVale !=null && KeyIdValue !=null) {
example.createCriteria().andTypeEqualTo(TypeVale).andKeyIdEqualTo(KeyIdValue).andValueLike(newVaule)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else {
example.createCriteria().andValueLike(newVaule)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<UserBusiness> list=null;
try{
list= userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
if(list!=null&&list.size() > 0) {
return true;
} else {
return false;
}
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateBtnStr(Long userBusinessId, String btnStr) throws Exception{
logService.insertLog("关联关系",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userBusinessId).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
UserBusiness userBusiness = new UserBusiness();
userBusiness.setBtnStr(btnStr);
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andIdEqualTo(userBusinessId);
int result=0;
try{
result= userBusinessMapper.updateByExampleSelective(userBusiness, example);
}catch(Exception e){
JshException.writeFail(logger, e);
}
return result;
}
}