123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package com.tld.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.tld.mapper.DictionaryMapper;
- import com.tld.model.Access;
- import com.tld.model.Goods;
- import com.tld.service.DictionaryService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.tld.model.Dictionary;
- import org.springframework.transaction.annotation.Transactional;
- import javax.servlet.http.HttpServletRequest;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Service
- public class DictionaryServiceImpl implements DictionaryService {
- @Autowired
- private DictionaryMapper dictionaryMapper;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Map<String, Object> addDictionary(List<Dictionary> dictionarys) {
- Map<String, Object> map = new HashMap<>();
- try{
- for(Dictionary dictionary : dictionarys) {
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- if ("null".equals(tableName)) {
- map.put("msg", "500");
- map.put("errMsg", "失败,请联系是否存在此字典");
- return map;
- }
- dictionary.setTableName(tableName);
- dictionary.setTypeVal("0");
- if (dictionary.getType().equals("物料字典")) {
- dictionaryMapper.addMaterial(dictionary);
- } else if (dictionary.getType().equals("库账对存")) {
- dictionaryMapper.addTreasuryAccount(dictionary);
- } else {
- dictionaryMapper.addDictionary(dictionary);
- }
- }
- //新增日志
- Access access = new Access().setType("字典信息").setData(JSON.toJSONString(dictionarys)).setAccessType("0");
- dictionaryMapper.addAccess(access);
- map.put("msg", "200");
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- @Override
- public Map<String, Object> getDictionary(Dictionary dictionary) {
- Map<String, Object> map = new HashMap<>();
- try{
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- dictionary.setTableName(tableName);
- List<Dictionary> list = dictionaryMapper.getDictionary(dictionary);
- map.put("msg", "200");
- map.put("data", list);
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- @Override
- public Map<String, Object> getDictionaryPage(Dictionary dictionary) {
- Map<String, Object> map = new HashMap<>();
- try{
- Map<String, Object> amountMap = new HashMap<>();
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- dictionary.setTableName(tableName);
- PageHelper.startPage(dictionary.getPage(), dictionary.getLimit());
- PageInfo<Dictionary> list = null;
- if(dictionary.getType().equals("物料字典")){
- list = new PageInfo<>(dictionaryMapper.getDictionaryMaterialPage(dictionary));
- for(Dictionary dictionary1 : list.getList()){
- int amount = dictionaryMapper.getInventorySumAmount(dictionary1);
- amountMap.put(dictionary1.getTldId(), amount);
- }
- map.put("amount", amountMap);
- } else {
- list = new PageInfo<>(dictionaryMapper.getDictionaryPage(dictionary));
- }
- map.put("msg", "200");
- map.put("data", list);
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- @Override
- public Map<String, Object> updateDictionary(Dictionary dictionary, HttpServletRequest request) {
- Map<String, Object> map = new HashMap<>();
- try{
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- if ("null".equals(tableName)) {
- map.put("msg", "500");
- map.put("errMsg", "失败,请联系是否存在此字典");
- return map;
- }
- dictionary.setTableName(tableName);
- dictionary.setModifyUser(request.getHeader("userId"));
- if (dictionary.getType().equals("物料字典")) {
- dictionaryMapper.updateMaterial(dictionary);
- } else if (dictionary.getType().equals("库账对存")) {
- dictionaryMapper.updateTreasuryAccount(dictionary);
- } else {
- dictionaryMapper.updateDictionary(dictionary);
- }
- map.put("msg", "200");
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- @Override
- public Map<String, Object> deleteDictionary(Dictionary dictionary) {
- Map<String, Object> map = new HashMap<>();
- try{
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- if ("null".equals(tableName)) {
- map.put("msg", "500");
- map.put("errMsg", "失败,请联系是否存在此字典");
- return map;
- }
- dictionary.setTableName(tableName);
- dictionaryMapper.deleteDictionary(dictionary);
- map.put("msg", "200");
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- @Override
- public Map<String, Object> addDiction(Dictionary dictionary, HttpServletRequest request) {
- Map<String, Object> map = new HashMap<>();
- try{
- String tableName = dictionaryMapper.getTableName(dictionary.getType());
- if ("null".equals(tableName)) {
- map.put("msg", "500");
- map.put("errMsg", "失败,请联系是否存在此字典");
- return map;
- }
- dictionary.setTableName(tableName);
- dictionary.setTypeVal("1");
- if (dictionary.getType().equals("物料字典")) {
- dictionaryMapper.addMaterial(dictionary);
- } else if (dictionary.getType().equals("库账对存")) {
- dictionaryMapper.addTreasuryAccount(dictionary);
- } else {
- dictionaryMapper.addDictionary(dictionary);
- }
- map.put("msg", "200");
- } catch (Exception e){
- e.printStackTrace();
- map.put("msg", "500");
- map.put("errMsg", "失败");
- }
- return map;
- }
- }
|