异常封装之多单位信息后台修改
This commit is contained in:
@@ -20,16 +20,16 @@ public class UnitComponent implements ICommonQuery {
|
|||||||
private UnitService unitService;
|
private UnitService unitService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object selectOne(String condition) {
|
public Object selectOne(String condition)throws Exception {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<?> select(Map<String, String> map) {
|
public List<?> select(Map<String, String> map)throws Exception {
|
||||||
return getUnitList(map);
|
return getUnitList(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<?> getUnitList(Map<String, String> map) {
|
private List<?> getUnitList(Map<String, String> map)throws Exception {
|
||||||
String search = map.get(Constants.SEARCH);
|
String search = map.get(Constants.SEARCH);
|
||||||
String name = StringUtil.getInfo(search, "name");
|
String name = StringUtil.getInfo(search, "name");
|
||||||
String order = QueryUtils.order(map);
|
String order = QueryUtils.order(map);
|
||||||
@@ -37,34 +37,34 @@ public class UnitComponent implements ICommonQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long counts(Map<String, String> map) {
|
public Long counts(Map<String, String> map)throws Exception {
|
||||||
String search = map.get(Constants.SEARCH);
|
String search = map.get(Constants.SEARCH);
|
||||||
String name = StringUtil.getInfo(search, "name");
|
String name = StringUtil.getInfo(search, "name");
|
||||||
return unitService.countUnit(name);
|
return unitService.countUnit(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(String beanJson, HttpServletRequest request) {
|
public int insert(String beanJson, HttpServletRequest request)throws Exception {
|
||||||
return unitService.insertUnit(beanJson, request);
|
return unitService.insertUnit(beanJson, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(String beanJson, Long id) {
|
public int update(String beanJson, Long id)throws Exception {
|
||||||
return unitService.updateUnit(beanJson, id);
|
return unitService.updateUnit(beanJson, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Long id) {
|
public int delete(Long id)throws Exception {
|
||||||
return unitService.deleteUnit(id);
|
return unitService.deleteUnit(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int batchDelete(String ids) {
|
public int batchDelete(String ids)throws Exception {
|
||||||
return unitService.batchDeleteUnit(ids);
|
return unitService.batchDeleteUnit(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkIsNameExist(Long id, String name) {
|
public int checkIsNameExist(Long id, String name)throws Exception {
|
||||||
return unitService.checkIsNameExist(id, name);
|
return unitService.checkIsNameExist(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.jsh.erp.constants.BusinessConstants;
|
import com.jsh.erp.constants.BusinessConstants;
|
||||||
import com.jsh.erp.constants.ExceptionConstants;
|
import com.jsh.erp.constants.ExceptionConstants;
|
||||||
import com.jsh.erp.datasource.entities.Material;
|
import com.jsh.erp.datasource.entities.*;
|
||||||
import com.jsh.erp.datasource.entities.Unit;
|
|
||||||
import com.jsh.erp.datasource.entities.UnitExample;
|
|
||||||
import com.jsh.erp.datasource.entities.User;
|
|
||||||
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
||||||
import com.jsh.erp.datasource.mappers.UnitMapper;
|
import com.jsh.erp.datasource.mappers.UnitMapper;
|
||||||
import com.jsh.erp.datasource.mappers.UnitMapperEx;
|
import com.jsh.erp.datasource.mappers.UnitMapperEx;
|
||||||
@@ -43,55 +40,135 @@ public class UnitService {
|
|||||||
@Resource
|
@Resource
|
||||||
private MaterialMapperEx materialMapperEx;
|
private MaterialMapperEx materialMapperEx;
|
||||||
|
|
||||||
public Unit getUnit(long id) {
|
public Unit getUnit(long id)throws Exception {
|
||||||
return unitMapper.selectByPrimaryKey(id);
|
Unit result=null;
|
||||||
|
try{
|
||||||
|
result=unitMapper.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<Unit> getUnit() {
|
public List<Unit> getUnit()throws Exception {
|
||||||
UnitExample example = new UnitExample();
|
UnitExample example = new UnitExample();
|
||||||
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||||
return unitMapper.selectByExample(example);
|
List<Unit> list=null;
|
||||||
|
try{
|
||||||
|
list=unitMapper.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<Unit> select(String name, int offset, int rows) {
|
public List<Unit> select(String name, int offset, int rows)throws Exception {
|
||||||
return unitMapperEx.selectByConditionUnit(name, offset, rows);
|
List<Unit> list=null;
|
||||||
|
try{
|
||||||
|
list=unitMapperEx.selectByConditionUnit(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 countUnit(String name) {
|
public Long countUnit(String name)throws Exception {
|
||||||
return unitMapperEx.countsByUnit(name);
|
Long result=null;
|
||||||
|
try{
|
||||||
|
result=unitMapperEx.countsByUnit(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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int insertUnit(String beanJson, HttpServletRequest request) {
|
public int insertUnit(String beanJson, HttpServletRequest request)throws Exception {
|
||||||
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
||||||
return unitMapper.insertSelective(unit);
|
int result=0;
|
||||||
|
try{
|
||||||
|
result=unitMapper.insertSelective(unit);
|
||||||
|
}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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int updateUnit(String beanJson, Long id) {
|
public int updateUnit(String beanJson, Long id)throws Exception {
|
||||||
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
Unit unit = JSONObject.parseObject(beanJson, Unit.class);
|
||||||
unit.setId(id);
|
unit.setId(id);
|
||||||
return unitMapper.updateByPrimaryKeySelective(unit);
|
int result=0;
|
||||||
|
try{
|
||||||
|
result=unitMapper.updateByPrimaryKeySelective(unit);
|
||||||
|
}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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int deleteUnit(Long id) {
|
public int deleteUnit(Long id)throws Exception {
|
||||||
return unitMapper.deleteByPrimaryKey(id);
|
int result=0;
|
||||||
|
try{
|
||||||
|
result=unitMapper.deleteByPrimaryKey(id);
|
||||||
|
}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)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int batchDeleteUnit(String ids) {
|
public int batchDeleteUnit(String ids) throws Exception{
|
||||||
List<Long> idList = StringUtil.strToLongList(ids);
|
List<Long> idList = StringUtil.strToLongList(ids);
|
||||||
UnitExample example = new UnitExample();
|
UnitExample example = new UnitExample();
|
||||||
example.createCriteria().andIdIn(idList);
|
example.createCriteria().andIdIn(idList);
|
||||||
return unitMapper.deleteByExample(example);
|
int result=0;
|
||||||
|
try{
|
||||||
|
result=unitMapper.deleteByExample(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);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int checkIsNameExist(Long id, String name) {
|
public int checkIsNameExist(Long id, String name)throws Exception {
|
||||||
UnitExample example = new UnitExample();
|
UnitExample example = new UnitExample();
|
||||||
example.createCriteria().andIdNotEqualTo(id).andUnameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
example.createCriteria().andIdNotEqualTo(id).andUnameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||||
List<Unit> list = unitMapper.selectByExample(example);
|
List<Unit> list=null;
|
||||||
return list.size();
|
try{
|
||||||
|
list=unitMapper.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();
|
||||||
}
|
}
|
||||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||||
public int batchDeleteUnitByIds(String ids)throws Exception {
|
public int batchDeleteUnitByIds(String ids)throws Exception {
|
||||||
@@ -100,7 +177,16 @@ public class UnitService {
|
|||||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||||
User userInfo=userService.getCurrentUser();
|
User userInfo=userService.getCurrentUser();
|
||||||
String [] idArray=ids.split(",");
|
String [] idArray=ids.split(",");
|
||||||
return unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
|
int result=0;
|
||||||
|
try{
|
||||||
|
result=unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +213,15 @@ public class UnitService {
|
|||||||
/**
|
/**
|
||||||
* 校验产品表 jsh_material
|
* 校验产品表 jsh_material
|
||||||
* */
|
* */
|
||||||
List<Material> materialList=materialMapperEx.getMaterialListByUnitIds(idArray);
|
List<Material> materialList=null;
|
||||||
|
try{
|
||||||
|
materialList=materialMapperEx.getMaterialListByUnitIds(idArray);
|
||||||
|
}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);
|
||||||
|
}
|
||||||
if(materialList!=null&&materialList.size()>0){
|
if(materialList!=null&&materialList.size()>0){
|
||||||
logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
|
logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
|
||||||
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
|
ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
|
||||||
|
|||||||
Reference in New Issue
Block a user