MealsDeductServiceImpl.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package cn.com.lzt.mealsdeduct.service.impl;
  2. import cn.com.lzt.mealsdeduct.dao.MealsDeductMinidaoDao;
  3. import cn.com.lzt.mealsdeduct.dto.MealsDeduct4SelectDto;
  4. import cn.com.lzt.mealsdeduct.entity.MealsDeductEntity;
  5. import cn.com.lzt.mealsdeduct.service.MealsDeductServiceI;
  6. import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
  7. import org.jeecgframework.core.util.ApplicationContextUtil;
  8. import org.jeecgframework.core.util.MyClassLoader;
  9. import org.jeecgframework.core.util.StringUtil;
  10. import org.jeecgframework.minidao.pojo.MiniDaoPage;
  11. import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import java.io.Serializable;
  16. import java.util.*;
  17. @Service("mealsDeductService")
  18. @Transactional
  19. public class MealsDeductServiceImpl extends CommonServiceImpl implements MealsDeductServiceI {
  20. @Autowired
  21. MealsDeductMinidaoDao minidao;
  22. public void delete(MealsDeductEntity entity) throws Exception{
  23. super.delete(entity);
  24. //执行删除操作增强业务
  25. this.doDelBus(entity);
  26. }
  27. public Serializable save(MealsDeductEntity entity) throws Exception{
  28. Serializable t = super.save(entity);
  29. //执行新增操作增强业务
  30. this.doAddBus(entity);
  31. return t;
  32. }
  33. public void saveOrUpdate(MealsDeductEntity entity) throws Exception{
  34. super.saveOrUpdate(entity);
  35. //执行更新操作增强业务
  36. this.doUpdateBus(entity);
  37. }
  38. /**
  39. * 批量更新操作
  40. *
  41. */
  42. public void batchUpdate(List<MealsDeductEntity> entityList) throws Exception{
  43. for(MealsDeductEntity entity : entityList){
  44. super.updateEntitie(entity);
  45. }
  46. }
  47. /**
  48. * 查询分页列表(MiniDao方式)
  49. *
  50. */
  51. public MiniDaoPage<MealsDeduct4SelectDto> getAllEntities(MealsDeduct4SelectDto dto, int page, int rows, String sql){
  52. return minidao.getAllEntities(dto, page, rows, sql);
  53. }
  54. /**
  55. * 新增操作增强业务
  56. * @param t
  57. * @return
  58. */
  59. private void doAddBus(MealsDeductEntity t) throws Exception{
  60. //-----------------sql增强 start----------------------------
  61. //-----------------sql增强 end------------------------------
  62. //-----------------java增强 start---------------------------
  63. //-----------------java增强 end-----------------------------
  64. }
  65. /**
  66. * 更新操作增强业务
  67. * @param t
  68. * @return
  69. */
  70. private void doUpdateBus(MealsDeductEntity t) throws Exception{
  71. //-----------------sql增强 start----------------------------
  72. //-----------------sql增强 end------------------------------
  73. //-----------------java增强 start---------------------------
  74. //-----------------java增强 end-----------------------------
  75. }
  76. /**
  77. * 删除操作增强业务
  78. * @param id
  79. * @return
  80. */
  81. private void doDelBus(MealsDeductEntity t) throws Exception{
  82. //-----------------sql增强 start----------------------------
  83. //-----------------sql增强 end------------------------------
  84. //-----------------java增强 start---------------------------
  85. //-----------------java增强 end-----------------------------
  86. }
  87. private Map<String,Object> populationMap(MealsDeductEntity t){
  88. Map<String,Object> map = new HashMap<String,Object>();
  89. map.put("id", t.getId());
  90. map.put("create_name", t.getCreateName());
  91. map.put("create_by", t.getCreateBy());
  92. map.put("create_date", t.getCreateDate());
  93. map.put("update_name", t.getUpdateName());
  94. map.put("update_by", t.getUpdateBy());
  95. map.put("update_date", t.getUpdateDate());
  96. map.put("sys_org_code", t.getSysOrgCode());
  97. map.put("sys_company_code", t.getSysCompanyCode());
  98. map.put("subsidy_type", t.getSubsidyType());
  99. map.put("left_hours", t.getLeftHours());
  100. map.put("right_hours", t.getRightHours());
  101. map.put("deduct_num", t.getDeductNum());
  102. map.put("calcu_unit", t.getCalcuUnit());
  103. map.put("status", t.getStatus());
  104. map.put("delete_flag", t.getDeleteFlag());
  105. return map;
  106. }
  107. /**
  108. * 替换sql中的变量
  109. * @param sql
  110. * @param t
  111. * @return
  112. */
  113. public String replaceVal(String sql,MealsDeductEntity t){
  114. sql = sql.replace("#{id}",String.valueOf(t.getId()));
  115. sql = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
  116. sql = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
  117. sql = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
  118. sql = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
  119. sql = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
  120. sql = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
  121. sql = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
  122. sql = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
  123. sql = sql.replace("#{subsidy_type}",String.valueOf(t.getSubsidyType()));
  124. sql = sql.replace("#{left_hours}",String.valueOf(t.getLeftHours()));
  125. sql = sql.replace("#{right_hours}",String.valueOf(t.getRightHours()));
  126. sql = sql.replace("#{deduct_num}",String.valueOf(t.getDeductNum()));
  127. sql = sql.replace("#{calcu_unit}",String.valueOf(t.getCalcuUnit()));
  128. sql = sql.replace("#{status}",String.valueOf(t.getStatus()));
  129. sql = sql.replace("#{delete_flag}",String.valueOf(t.getDeleteFlag()));
  130. sql = sql.replace("#{UUID}",UUID.randomUUID().toString());
  131. return sql;
  132. }
  133. /**
  134. * 执行JAVA增强
  135. */
  136. private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
  137. if(StringUtil.isNotEmpty(cgJavaValue)){
  138. Object obj = null;
  139. try {
  140. if("class".equals(cgJavaType)){
  141. //因新增时已经校验了实例化是否可以成功,所以这块就不需要再做一次判断
  142. obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
  143. }else if("spring".equals(cgJavaType)){
  144. obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
  145. }
  146. if(obj instanceof CgformEnhanceJavaInter){
  147. CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
  148. javaInter.execute("t_bus_meals_deduct",data);
  149. }
  150. } catch (Exception e) {
  151. e.printStackTrace();
  152. throw new Exception("执行JAVA增强出现异常!");
  153. }
  154. }
  155. }
  156. @Override
  157. public Boolean findMealsDeductByHours(MealsDeductEntity mealsDeduct) {
  158. List<MealsDeductEntity> postobj = new ArrayList<MealsDeductEntity>();
  159. StringBuffer hql = new StringBuffer(" from MealsDeductEntity where leftHours=? and rightHours=? and deleteFlag=0");
  160. if(StringUtil.isNotEmpty(mealsDeduct.getId())){
  161. hql = new StringBuffer(" from MealsDeductEntity where id!=? and leftHours=? and rightHours=? and deleteFlag=0");
  162. postobj = findHql(hql.toString(),mealsDeduct.getId(),mealsDeduct.getLeftHours(),mealsDeduct.getRightHours());
  163. }else{
  164. postobj = findHql(hql.toString(),mealsDeduct.getLeftHours(),mealsDeduct.getRightHours());
  165. }
  166. Boolean flag = true;
  167. if(postobj.size() > 0){
  168. flag = false;
  169. }
  170. return flag;
  171. }
  172. }