@ -2,9 +2,7 @@ package com.epmet.service.impl;
import com.alibaba.excel.EasyExcel ;
import com.alibaba.excel.EasyExcel ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl ;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl ;
import com.epmet.commons.tools.constant.FieldConstant ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult ;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult ;
@ -129,14 +127,6 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl<IcDangerous
return new PageData < > ( list , pageInfo . getTotal ( ) ) ;
return new PageData < > ( list , pageInfo . getTotal ( ) ) ;
}
}
private QueryWrapper < IcDangerousChemicalsEntity > getWrapper ( Map < String , Object > params ) {
String id = ( String ) params . get ( FieldConstant . ID_HUMP ) ;
QueryWrapper < IcDangerousChemicalsEntity > wrapper = new QueryWrapper < > ( ) ;
wrapper . eq ( StringUtils . isNotBlank ( id ) , FieldConstant . ID , id ) ;
return wrapper ;
}
@Override
@Override
public IcDangerousChemicalsDTO get ( String id ) {
public IcDangerousChemicalsDTO get ( String id ) {
@ -147,32 +137,38 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl<IcDangerous
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public void save ( IcDangerousChemicalsAddEditFormDTO formDTO ) {
public void save ( IcDangerousChemicalsAddEditFormDTO formDTO ) {
//1.获取网格信息
//同一网格下,企业名称唯一
CustomerGridDTO customerGridDTO = SpringContextUtils . getBean ( CustomerGridService . class ) . get ( formDTO . getGridId ( ) ) ;
checkNameUnqiue ( formDTO . getOrgId ( ) , formDTO . getName ( ) , StrConstant . EPMETY_STR ) ;
// 2.同一网格下,企业名称唯一
//新增服务组织数据
checkNameUnqiue ( formDTO . getGridId ( ) , formDTO . getName ( ) , StrConstant . EPMETY_STR , customerGridDTO . getGridName ( ) ) ;
//3.新增服务组织数据
IcDangerousChemicalsEntity entity = ConvertUtils . sourceToTarget ( formDTO , IcDangerousChemicalsEntity . class ) ;
IcDangerousChemicalsEntity entity = ConvertUtils . sourceToTarget ( formDTO , IcDangerousChemicalsEntity . class ) ;
entity . setSourceType ( "add" ) ;
entity . setSourceType ( "add" ) ;
entity . setAgencyId ( customerGridDTO . getPid ( ) ) ;
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis . getStaffInfo ( formDTO . getCustomerId ( ) , formDTO . getUserId ( ) ) ;
entity . setAgencyIdPath ( customerGridDTO . getPids ( ) ) ;
entity . setAgencyId ( staffInfoCacheResult . getAgencyId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerGridDTO . getId ( ) , customerGridDTO . getPids ( ) ) ) ;
entity . setAgencyIdPath ( StringUtils . isNotBlank ( staffInfoCacheResult . getAgencyPIds ( ) ) ? staffInfoCacheResult . getAgencyPIds ( ) . concat ( StrConstant . COLON ) . concat ( staffInfoCacheResult . getAgencyId ( ) ) : staffInfoCacheResult . getAgencyId ( ) ) ;
if ( OrgTypeEnum . GRID . equals ( formDTO . getOrgType ( ) ) ) {
// 获取网格信息
CustomerGridDTO customerGridDTO = SpringContextUtils . getBean ( CustomerGridService . class ) . get ( formDTO . getOrgId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerGridDTO . getId ( ) , customerGridDTO . getPids ( ) ) ) ;
} else if ( OrgTypeEnum . AGENCY . equals ( formDTO . getOrgType ( ) ) ) {
CustomerAgencyDTO customerAgencyDTO = SpringContextUtils . getBean ( CustomerAgencyService . class ) . get ( formDTO . getOrgId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerAgencyDTO . getId ( ) , customerAgencyDTO . getPids ( ) ) ) ;
}
insert ( entity ) ;
insert ( entity ) ;
}
}
/ * *
/ * *
* 同一网格下 , 企业名称唯一
* 同一网格下 , 企业名称唯一
* @param gridId
* @param or gId
* @param name
* @param name
* @param icDangerousChemicalsId
* @param icDangerousChemicalsId
* /
* /
private void checkNameUnqiue ( String grid Id , String name , String icDangerousChemicalsId , String gridName ) {
private void checkNameUnqiue ( String or gId, String name , String icDangerousChemicalsId ) {
LambdaQueryWrapper < IcDangerousChemicalsEntity > tWrapper = new LambdaQueryWrapper < > ( ) ;
LambdaQueryWrapper < IcDangerousChemicalsEntity > tWrapper = new LambdaQueryWrapper < > ( ) ;
tWrapper . eq ( IcDangerousChemicalsEntity : : getGrid Id , grid Id ) ;
tWrapper . eq ( IcDangerousChemicalsEntity : : getOrg Id , or gId) ;
tWrapper . eq ( IcDangerousChemicalsEntity : : getName , name )
tWrapper . eq ( IcDangerousChemicalsEntity : : getName , name )
. ne ( StringUtils . isNotBlank ( icDangerousChemicalsId ) , IcDangerousChemicalsEntity : : getId , icDangerousChemicalsId ) ;
. ne ( StringUtils . isNotBlank ( icDangerousChemicalsId ) , IcDangerousChemicalsEntity : : getId , icDangerousChemicalsId ) ;
if ( baseDao . selectCount ( tWrapper ) > NumConstant . ZERO ) {
if ( baseDao . selectCount ( tWrapper ) > NumConstant . ZERO ) {
String msg = String . format ( "%下已存在%s" , gridName , name ) ;
String msg = String . format ( "所属组织下已存在%s" , name ) ;
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , msg , msg ) ;
throw new EpmetException ( EpmetErrorCode . EPMET_COMMON_OPERATION_FAIL . getCode ( ) , msg , msg ) ;
}
}
}
}
@ -180,16 +176,22 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl<IcDangerous
@Override
@Override
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public void update ( IcDangerousChemicalsAddEditFormDTO formDTO ) {
public void update ( IcDangerousChemicalsAddEditFormDTO formDTO ) {
//1.获取网格信息
CustomerGridDTO customerGridDTO = SpringContextUtils . getBean ( CustomerGridService . class ) . get ( formDTO . getGridId ( ) ) ;
// 2.同一网格下,企业名称唯一
// 2.同一网格下,企业名称唯一
checkNameUnqiue ( formDTO . getGrid Id ( ) , formDTO . getName ( ) , formDTO . getIcDangerousChemicalsId ( ) , customerGridDTO . getGridName ( ) ) ;
checkNameUnqiue ( formDTO . getOrgId ( ) , formDTO . getName ( ) , formDTO . getIcDangerousChemicalsId ( ) ) ;
//3.更新服务组织数据
//3.更新服务组织数据
IcDangerousChemicalsEntity entity = ConvertUtils . sourceToTarget ( formDTO , IcDangerousChemicalsEntity . class ) ;
IcDangerousChemicalsEntity entity = ConvertUtils . sourceToTarget ( formDTO , IcDangerousChemicalsEntity . class ) ;
entity . setId ( formDTO . getIcDangerousChemicalsId ( ) ) ;
entity . setId ( formDTO . getIcDangerousChemicalsId ( ) ) ;
entity . setAgencyId ( customerGridDTO . getPid ( ) ) ;
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis . getStaffInfo ( formDTO . getCustomerId ( ) , formDTO . getUserId ( ) ) ;
entity . setAgencyIdPath ( customerGridDTO . getPids ( ) ) ;
entity . setAgencyId ( staffInfoCacheResult . getAgencyId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerGridDTO . getId ( ) , customerGridDTO . getPids ( ) ) ) ;
entity . setAgencyIdPath ( StringUtils . isNotBlank ( staffInfoCacheResult . getAgencyPIds ( ) ) ? staffInfoCacheResult . getAgencyPIds ( ) . concat ( StrConstant . COLON ) . concat ( staffInfoCacheResult . getAgencyId ( ) ) : staffInfoCacheResult . getAgencyId ( ) ) ;
if ( OrgTypeEnum . GRID . equals ( formDTO . getOrgType ( ) ) ) {
// 获取网格信息
CustomerGridDTO customerGridDTO = SpringContextUtils . getBean ( CustomerGridService . class ) . get ( formDTO . getOrgId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerGridDTO . getId ( ) , customerGridDTO . getPids ( ) ) ) ;
} else if ( OrgTypeEnum . AGENCY . equals ( formDTO . getOrgType ( ) ) ) {
CustomerAgencyDTO customerAgencyDTO = SpringContextUtils . getBean ( CustomerAgencyService . class ) . get ( formDTO . getOrgId ( ) ) ;
entity . setOrgIdPath ( PidUtils . convertPid2OrgIdPath ( customerAgencyDTO . getId ( ) , customerAgencyDTO . getPids ( ) ) ) ;
}
updateById ( entity ) ;
updateById ( entity ) ;
}
}