DictionaryServiceImpl.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.tld.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import com.tld.mapper.DictionaryMapper;
  6. import com.tld.model.Access;
  7. import com.tld.model.Goods;
  8. import com.tld.service.DictionaryService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import com.tld.model.Dictionary;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import javax.servlet.http.HttpServletRequest;
  14. import java.util.HashMap;
  15. import java.util.List;
  16. import java.util.Map;
  17. @Service
  18. public class DictionaryServiceImpl implements DictionaryService {
  19. @Autowired
  20. private DictionaryMapper dictionaryMapper;
  21. @Override
  22. @Transactional(rollbackFor = Exception.class)
  23. public Map<String, Object> addDictionary(List<Dictionary> dictionarys) {
  24. Map<String, Object> map = new HashMap<>();
  25. try{
  26. for(Dictionary dictionary : dictionarys) {
  27. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  28. if ("null".equals(tableName)) {
  29. map.put("msg", "500");
  30. map.put("errMsg", "失败,请联系是否存在此字典");
  31. return map;
  32. }
  33. dictionary.setTableName(tableName);
  34. dictionary.setTypeVal("0");
  35. if (dictionary.getType().equals("物料字典")) {
  36. dictionaryMapper.addMaterial(dictionary);
  37. } else if (dictionary.getType().equals("库账对存")) {
  38. dictionaryMapper.addTreasuryAccount(dictionary);
  39. } else {
  40. dictionaryMapper.addDictionary(dictionary);
  41. }
  42. }
  43. //新增日志
  44. Access access = new Access().setType("字典信息").setData(JSON.toJSONString(dictionarys)).setAccessType("0");
  45. dictionaryMapper.addAccess(access);
  46. map.put("msg", "200");
  47. } catch (Exception e){
  48. e.printStackTrace();
  49. map.put("msg", "500");
  50. map.put("errMsg", "失败");
  51. }
  52. return map;
  53. }
  54. @Override
  55. public Map<String, Object> getDictionary(Dictionary dictionary) {
  56. Map<String, Object> map = new HashMap<>();
  57. try{
  58. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  59. dictionary.setTableName(tableName);
  60. List<Dictionary> list = dictionaryMapper.getDictionary(dictionary);
  61. map.put("msg", "200");
  62. map.put("data", list);
  63. } catch (Exception e){
  64. e.printStackTrace();
  65. map.put("msg", "500");
  66. map.put("errMsg", "失败");
  67. }
  68. return map;
  69. }
  70. @Override
  71. public Map<String, Object> getDictionaryPage(Dictionary dictionary) {
  72. Map<String, Object> map = new HashMap<>();
  73. try{
  74. Map<String, Object> amountMap = new HashMap<>();
  75. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  76. dictionary.setTableName(tableName);
  77. PageHelper.startPage(dictionary.getPage(), dictionary.getLimit());
  78. PageInfo<Dictionary> list = null;
  79. if(dictionary.getType().equals("物料字典")){
  80. list = new PageInfo<>(dictionaryMapper.getDictionaryMaterialPage(dictionary));
  81. for(Dictionary dictionary1 : list.getList()){
  82. int amount = dictionaryMapper.getInventorySumAmount(dictionary1);
  83. amountMap.put(dictionary1.getTldId(), amount);
  84. }
  85. map.put("amount", amountMap);
  86. } else {
  87. list = new PageInfo<>(dictionaryMapper.getDictionaryPage(dictionary));
  88. }
  89. map.put("msg", "200");
  90. map.put("data", list);
  91. } catch (Exception e){
  92. e.printStackTrace();
  93. map.put("msg", "500");
  94. map.put("errMsg", "失败");
  95. }
  96. return map;
  97. }
  98. @Override
  99. public Map<String, Object> updateDictionary(Dictionary dictionary, HttpServletRequest request) {
  100. Map<String, Object> map = new HashMap<>();
  101. try{
  102. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  103. if ("null".equals(tableName)) {
  104. map.put("msg", "500");
  105. map.put("errMsg", "失败,请联系是否存在此字典");
  106. return map;
  107. }
  108. dictionary.setTableName(tableName);
  109. dictionary.setModifyUser(request.getHeader("userId"));
  110. if (dictionary.getType().equals("物料字典")) {
  111. dictionaryMapper.updateMaterial(dictionary);
  112. } else if (dictionary.getType().equals("库账对存")) {
  113. dictionaryMapper.updateTreasuryAccount(dictionary);
  114. } else {
  115. dictionaryMapper.updateDictionary(dictionary);
  116. }
  117. map.put("msg", "200");
  118. } catch (Exception e){
  119. e.printStackTrace();
  120. map.put("msg", "500");
  121. map.put("errMsg", "失败");
  122. }
  123. return map;
  124. }
  125. @Override
  126. public Map<String, Object> deleteDictionary(Dictionary dictionary) {
  127. Map<String, Object> map = new HashMap<>();
  128. try{
  129. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  130. if ("null".equals(tableName)) {
  131. map.put("msg", "500");
  132. map.put("errMsg", "失败,请联系是否存在此字典");
  133. return map;
  134. }
  135. dictionary.setTableName(tableName);
  136. dictionaryMapper.deleteDictionary(dictionary);
  137. map.put("msg", "200");
  138. } catch (Exception e){
  139. e.printStackTrace();
  140. map.put("msg", "500");
  141. map.put("errMsg", "失败");
  142. }
  143. return map;
  144. }
  145. @Override
  146. public Map<String, Object> addDiction(Dictionary dictionary, HttpServletRequest request) {
  147. Map<String, Object> map = new HashMap<>();
  148. try{
  149. String tableName = dictionaryMapper.getTableName(dictionary.getType());
  150. if ("null".equals(tableName)) {
  151. map.put("msg", "500");
  152. map.put("errMsg", "失败,请联系是否存在此字典");
  153. return map;
  154. }
  155. dictionary.setTableName(tableName);
  156. dictionary.setTypeVal("1");
  157. if (dictionary.getType().equals("物料字典")) {
  158. dictionaryMapper.addMaterial(dictionary);
  159. } else if (dictionary.getType().equals("库账对存")) {
  160. dictionaryMapper.addTreasuryAccount(dictionary);
  161. } else {
  162. dictionaryMapper.addDictionary(dictionary);
  163. }
  164. map.put("msg", "200");
  165. } catch (Exception e){
  166. e.printStackTrace();
  167. map.put("msg", "500");
  168. map.put("errMsg", "失败");
  169. }
  170. return map;
  171. }
  172. }