UserBusinessService.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package com.jsh.erp.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.jsh.erp.constants.BusinessConstants;
  4. import com.jsh.erp.datasource.entities.User;
  5. import com.jsh.erp.datasource.entities.UserBusiness;
  6. import com.jsh.erp.datasource.entities.UserBusinessExample;
  7. import com.jsh.erp.datasource.mappers.UserBusinessMapper;
  8. import com.jsh.erp.datasource.mappers.UserBusinessMapperEx;
  9. import com.jsh.erp.exception.JshException;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import org.springframework.web.context.request.RequestContextHolder;
  15. import org.springframework.web.context.request.ServletRequestAttributes;
  16. import javax.annotation.Resource;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.util.Date;
  19. import java.util.List;
  20. @Service
  21. public class UserBusinessService {
  22. private Logger logger = LoggerFactory.getLogger(UserBusinessService.class);
  23. @Resource
  24. private UserBusinessMapper userBusinessMapper;
  25. @Resource
  26. private UserBusinessMapperEx userBusinessMapperEx;
  27. @Resource
  28. private LogService logService;
  29. @Resource
  30. private UserService userService;
  31. public UserBusiness getUserBusiness(long id)throws Exception {
  32. UserBusiness result=null;
  33. try{
  34. result=userBusinessMapper.selectByPrimaryKey(id);
  35. }catch(Exception e){
  36. JshException.readFail(logger, e);
  37. }
  38. return result;
  39. }
  40. public List<UserBusiness> getUserBusiness()throws Exception {
  41. UserBusinessExample example = new UserBusinessExample();
  42. example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  43. List<UserBusiness> list=null;
  44. try{
  45. list=userBusinessMapper.selectByExample(example);
  46. }catch(Exception e){
  47. JshException.readFail(logger, e);
  48. }
  49. return list;
  50. }
  51. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  52. public int insertUserBusiness(JSONObject obj, HttpServletRequest request) throws Exception {
  53. UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
  54. int result=0;
  55. try{
  56. String value = userBusiness.getValue();
  57. String newValue = value.replaceAll(",","\\]\\[");
  58. newValue = newValue.replaceAll("\\[0\\]","").replaceAll("\\[\\]","");
  59. userBusiness.setValue(newValue);
  60. result=userBusinessMapper.insertSelective(userBusiness);
  61. logService.insertLog("关联关系", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
  62. }catch(Exception e){
  63. JshException.writeFail(logger, e);
  64. }
  65. return result;
  66. }
  67. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  68. public int updateUserBusiness(JSONObject obj, HttpServletRequest request) throws Exception {
  69. UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
  70. int result=0;
  71. try{
  72. String value = userBusiness.getValue();
  73. String newValue = value.replaceAll(",","\\]\\[");
  74. newValue = newValue.replaceAll("\\[0\\]","").replaceAll("\\[\\]","");
  75. userBusiness.setValue(newValue);
  76. result=userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
  77. logService.insertLog("关联关系", BusinessConstants.LOG_OPERATION_TYPE_EDIT, request);
  78. }catch(Exception e){
  79. JshException.writeFail(logger, e);
  80. }
  81. return result;
  82. }
  83. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  84. public int deleteUserBusiness(Long id, HttpServletRequest request)throws Exception {
  85. return batchDeleteUserBusinessByIds(id.toString());
  86. }
  87. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  88. public int batchDeleteUserBusiness(String ids, HttpServletRequest request)throws Exception {
  89. return batchDeleteUserBusinessByIds(ids);
  90. }
  91. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  92. public int batchDeleteUserBusinessByIds(String ids) throws Exception{
  93. logService.insertLog("关联关系",
  94. new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
  95. ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
  96. User userInfo=userService.getCurrentUser();
  97. String [] idArray=ids.split(",");
  98. int result=0;
  99. try{
  100. result= userBusinessMapperEx.batchDeleteUserBusinessByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
  101. }catch(Exception e){
  102. JshException.writeFail(logger, e);
  103. }
  104. return result;
  105. }
  106. public int checkIsNameExist(Long id, String name)throws Exception {
  107. return 1;
  108. }
  109. public List<UserBusiness> getBasicData(String keyId, String type)throws Exception{
  110. List<UserBusiness> list=null;
  111. try{
  112. list= userBusinessMapperEx.getBasicDataByKeyIdAndType(keyId, type);
  113. }catch(Exception e){
  114. JshException.readFail(logger, e);
  115. }
  116. return list;
  117. }
  118. public String getUBValueByTypeAndKeyId(String type, String keyId) throws Exception {
  119. String ubValue = "";
  120. List<UserBusiness> ubList = getBasicData(keyId, type);
  121. if(ubList!=null && ubList.size()>0) {
  122. ubValue = ubList.get(0).getValue();
  123. }
  124. return ubValue;
  125. }
  126. public Long checkIsValueExist(String type, String keyId)throws Exception {
  127. UserBusinessExample example = new UserBusinessExample();
  128. example.createCriteria().andTypeEqualTo(type).andKeyIdEqualTo(keyId)
  129. .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  130. List<UserBusiness> list=null;
  131. try{
  132. list= userBusinessMapper.selectByExample(example);
  133. }catch(Exception e){
  134. JshException.readFail(logger, e);
  135. }
  136. Long id = null;
  137. if(list!=null&&list.size() > 0) {
  138. id = list.get(0).getId();
  139. }
  140. return id;
  141. }
  142. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  143. public int updateBtnStr(String keyId, String type, String btnStr) throws Exception{
  144. logService.insertLog("关联关系",
  145. new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append("角色的按钮权限").toString(),
  146. ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
  147. UserBusiness userBusiness = new UserBusiness();
  148. userBusiness.setBtnStr(btnStr);
  149. UserBusinessExample example = new UserBusinessExample();
  150. example.createCriteria().andKeyIdEqualTo(keyId).andTypeEqualTo(type);
  151. int result=0;
  152. try{
  153. result= userBusinessMapper.updateByExampleSelective(userBusiness, example);
  154. }catch(Exception e){
  155. JshException.writeFail(logger, e);
  156. }
  157. return result;
  158. }
  159. }