| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package cn.com.lzt.extattribute.service.impl;
- import cn.com.lzt.extattribute.entity.ExtAttributeEntity;
- import cn.com.lzt.extattribute.service.ExtAttributeServiceI;
- import cn.com.lzt.extattributedefset.entity.ExtAttributeDefsetEntity;
- import org.apache.commons.lang3.StringUtils;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
- import org.jeecgframework.core.util.MyBeanUtils;
- import org.jeecgframework.core.util.StringUtil;
- import org.jeecgframework.core.util.oConvertUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- @Service("extAttributeService")
- @Transactional
- public class ExtAttributeServiceImpl extends CommonServiceImpl implements ExtAttributeServiceI {
-
- public <T> void delete(T entity) {
- super.delete(entity);
- //执行删除操作配置的sql增强
- this.doDelSql((ExtAttributeEntity)entity);
- }
-
- public void addMain(ExtAttributeEntity extAttribute,
- List<ExtAttributeDefsetEntity> extAttributeDefsetList){
- //保存主信息
- this.save(extAttribute);
-
- /**保存-扩展属性设置明细*/
- for(ExtAttributeDefsetEntity extAttributeDefset:extAttributeDefsetList){
- if(StringUtils.isEmpty(extAttributeDefset.getExtname())) {
- extAttributeDefset.setBpmStatus("0");
- }
- //外键设置
- extAttributeDefset.setExtattributeid(extAttribute.getId());
- this.save(extAttributeDefset);
- }
- //执行新增操作配置的sql增强
- this.doAddSql(extAttribute);
- }
-
- public void updateMain(ExtAttributeEntity extAttribute,
- List<ExtAttributeDefsetEntity> extAttributeDefsetList) {
- //保存主表信息
- if(StringUtil.isNotEmpty(extAttribute.getId())){
- try {
- ExtAttributeEntity temp = findUniqueByProperty(ExtAttributeEntity.class, "id", extAttribute.getId());
- MyBeanUtils.copyBeanNotNull2Bean(extAttribute, temp);
- this.saveOrUpdate(temp);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }else{
- this.saveOrUpdate(extAttribute);
- }
- //===================================================================================
- //获取参数
- Object id0 = extAttribute.getId();
- //===================================================================================
- //1.查询出数据库的明细数据-扩展属性设置明细
- String hql0 = "from ExtAttributeDefsetEntity where 1 = 1 AND eXTATTRIBUTEID =? ";
- List<ExtAttributeDefsetEntity> extAttributeDefsetOldList = this.findHql(hql0,id0);
- //2.筛选更新明细数据-扩展属性设置明细
- if(extAttributeDefsetList!=null&&extAttributeDefsetList.size()>0){
- for(ExtAttributeDefsetEntity oldE:extAttributeDefsetOldList){
- boolean isUpdate = false;
- for(ExtAttributeDefsetEntity sendE:extAttributeDefsetList){
- //需要更新的明细数据-扩展属性设置明细
- if(oldE.getId().equals(sendE.getId())){
- try {
- MyBeanUtils.copyBeanNotNull2Bean(sendE,oldE);
- if(StringUtils.isEmpty(oldE.getExtname())) {
- oldE.setBpmStatus("0");
- }else {
- oldE.setBpmStatus("1");
- }
- this.saveOrUpdate(oldE);
- } catch (Exception e) {
- e.printStackTrace();
- throw new BusinessException(e.getMessage());
- }
- isUpdate= true;
- break;
- }
- }
- if(!isUpdate){
- //如果数据库存在的明细,前台没有传递过来则是删除-扩展属性设置明细
- super.delete(oldE);
- }
-
- }
- //3.持久化新增的数据-扩展属性设置明细
- for(ExtAttributeDefsetEntity extAttributeDefset:extAttributeDefsetList){
- if(oConvertUtils.isEmpty(extAttributeDefset.getId())){
- //外键设置
- extAttributeDefset.setExtattributeid(extAttribute.getId());
- if(StringUtils.isEmpty(extAttributeDefset.getExtname())) {
- extAttributeDefset.setBpmStatus("0");
- }
- this.save(extAttributeDefset);
- }
- }
- }
- //执行更新操作配置的sql增强
- this.doUpdateSql(extAttribute);
- }
-
- public void delMain(ExtAttributeEntity extAttribute) {
- //删除主表信息
- this.delete(extAttribute);
- //===================================================================================
- //获取参数
- Object id0 = extAttribute.getId();
- //===================================================================================
- //删除-扩展属性设置明细
- String hql0 = "from ExtAttributeDefsetEntity where 1 = 1 AND eXTATTRIBUTEID =? ";
- List<ExtAttributeDefsetEntity> extAttributeDefsetOldList = this.findHql(hql0,id0);
- this.deleteAllEntitie(extAttributeDefsetOldList);
- }
-
-
- /**
- * 默认按钮-sql增强-新增操作
- * @param id
- * @return
- */
- public boolean doAddSql(ExtAttributeEntity t){
- return true;
- }
- /**
- * 默认按钮-sql增强-更新操作
- * @param id
- * @return
- */
- public boolean doUpdateSql(ExtAttributeEntity t){
- return true;
- }
- /**
- * 默认按钮-sql增强-删除操作
- * @param id
- * @return
- */
- public boolean doDelSql(ExtAttributeEntity t){
- return true;
- }
-
- /**
- * 替换sql中的变量
- * @param sql
- * @return
- */
- public String replaceVal(String sql,ExtAttributeEntity t){
- sql = sql.replace("#{id}",String.valueOf(t.getId()));
- sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
- sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
- sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
- sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
- sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
- sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
- sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
- sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
- sql = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
- sql = sql.replace("#{billtypecode}",String.valueOf(t.getBilltypecode()));
- sql = sql.replace("#{billtypename}",String.valueOf(t.getBilltypename()));
- sql = sql.replace("#{tablename}",String.valueOf(t.getTablename()));
- sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
- return sql;
- }
- @Override
- public List<ExtAttributeDefsetEntity> getExtSetting(String tablename) {
- List<ExtAttributeDefsetEntity> extList = new ArrayList<ExtAttributeDefsetEntity>();
- ExtAttributeEntity t = findUniqueByProperty(ExtAttributeEntity.class, "tablename", tablename);
- if(t != null) {
- extList = findHql(" FROM ExtAttributeDefsetEntity where extattributeid =? and bpmStatus = ? ", t.getId(),"1");
- }
- return extList;
- }
- }
|