service

package com.sunsoft.facade.admin.service.impl;

import static com.sunsoft.sys.util.AppConstant.*;
import static com.sunsoft.sys.util.AppConstant.evaluate_status;
import static com.sunsoft.sys.util.AppConstant.evaluate_statuslook;
import static com.sunsoft.sys.util.AppConstant.success;
import static com.sunsoft.sys.util.AppMessageCode.*;
import static com.sunsoft.sys.util.AppMessageCode.SERVER_ERROR;
import static com.sunsoft.sys.util.AppMessageCode.SPECIALNULL_ERROR;
import static com.sunsoft.sys.util.AppMessageCode.SUCCESS;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sunsoft.cmmon.util.ResultJsonUtil;
import com.sunsoft.facade.admin.service.EvaluateFacade;
import com.sunsoft.facade.admin.vo.EvaluateInfoVo;
import com.sunsoft.facade.admin.vo.GoodsInfoVo;
import com.sunsoft.facade.admin.vo.VipUserTopVo;
import com.sunsoft.service.admin.biz.LogBiz;
import com.sunsoft.service.admin.dao.BrandInfoDao;
import com.sunsoft.service.admin.dao.EvaluateImgDao;
import com.sunsoft.service.admin.dao.EvaluateInfoDao;
import com.sunsoft.service.admin.dao.GoodsInfoDao;
import com.sunsoft.service.admin.dao.SpecialInfoDao;
import com.sunsoft.service.admin.dao.SystemParametersDao;
import com.sunsoft.service.admin.dao.VipUserTopDao;
import com.sunsoft.sys.entity.BrandInfo;
import com.sunsoft.sys.entity.EvaluateImg;
import com.sunsoft.sys.entity.EvaluateInfo;
import com.sunsoft.sys.entity.SpecialInfo;
import com.sunsoft.sys.entity.SystemParameters;
import com.sunsoft.sys.entity.VipUserTop;
import com.sunsoft.sys.util.StringUtil;
import com.sunsoft.sys.util.UUIDUtil;
/**
 * 头号买手后台发现管理
 * @author  zhaorui
 * @date: 2018年10月7日14:23:34
 * @version: 1.0 
 */
@Transactional
@Service("evaluateFacade")
public class EvaluateFacadeImpl implements EvaluateFacade {

    @Autowired
    private EvaluateImgDao evaluateImgDao;
    @Autowired
    private EvaluateInfoDao evaluateInfoDao;
    @Autowired
    private SystemParametersDao systemParametersDao;
    @Autowired
    private SpecialInfoDao specialInfoDao;
    @Autowired
    private VipUserTopDao vipUserTopDao;
    @Autowired
    private GoodsInfoDao goodsInfoDao;
    @Autowired
    private BrandInfoDao brandInfoDao;
    
    @Autowired
    private LogBiz logBiz;
    
    /**
     * 查看发现列表
     * 
     * @auth zhaorui
     * @date 2018年10月24日09:39:30
     * @return
     */
    @Override
    public JSONObject queryEvaluate(JSONObject param) {
        JSONObject result = new JSONObject();
        Map<String, Object> map = new HashMap<String, Object>();

        String info = StringUtil.validataParam(param, map);

        if (success.equals(info)) {
            Integer pageIndex = param.getInteger("pageIndex");
            pageIndex = pageIndex == null ? 1 : pageIndex;
            Integer pageSize = param.getInteger("pageSize");
            pageSize = pageSize == null ? SIZE : pageSize;

            if (pageSize < 0 || pageSize > 50) {// 每页显示记录数最大 100,默认显示10
                pageSize = SIZE;
            }
            
            List<EvaluateInfoVo> evaluateInfoVoList = new ArrayList<EvaluateInfoVo>();
            PageHelper.startPage(pageIndex, pageSize);
            evaluateInfoVoList = evaluateInfoDao.selectEvaluateList(param);
            PageInfo<EvaluateInfoVo> pages = new PageInfo<>(evaluateInfoVoList);
            map.put("hasNext", pages.isHasNextPage());
            map.put("total", pages.getTotal());
            map.put("pageNum", pages.getPageNum());
            map.put("pages", pages.getPages());
            
            map.put("evaluateList", pages.getList());

            result = ResultJsonUtil.json(map, SUCCESS);
            
        } else {
            result = ResultJsonUtil.json(info);
        }
        return result;
    }

    /** 
     * 更新评价状态
     * @auth  zhaorui
     * @date 2018年10月24日14:45:01
     * @return
     */
    @Override
    public JSONObject updateEvaluate(JSONObject param) {
        JSONObject result = new JSONObject();

        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", "id");
            map.put("evaluateStatus", "evaluateStatus");

            String info = StringUtil.validataParam(param, map);

            if (success.equals(info)) {
                String staff = param.getString("staff");
                String id = param.getString("id");
                Integer evaluateStatus = param.getInteger("evaluateStatus");

                EvaluateInfo evaluateInfo = evaluateInfoDao.selectByPrimaryKey(id);
                if (evaluateInfo == null) {
                    result = ResultJsonUtil.json(ERROR_EVALUATE);
                    return result;
                }
                if (evaluateStatus == evaluate_status) {

                    EvaluateInfo evaluate = new EvaluateInfo();
                    evaluate.setId(id);
                    evaluate.setEvaluateStatus(evaluate_status);
                    evaluateInfoDao.updateByPrimaryKeySelective(evaluate);
                    result = ResultJsonUtil.json(SUCCESS);
                } else if (evaluateStatus == evaluate_statuslook) {

                    EvaluateInfo evaluate = new EvaluateInfo();
                    evaluate.setId(id);
                    evaluate.setEvaluateStatus(evaluate_statuslook);
                    evaluateInfoDao.updateByPrimaryKeySelective(evaluate);
                    result = ResultJsonUtil.json(SUCCESS);
                    
                }
                logBiz.addLog(id, "更新评价状态",  "【更新评价状态】:" + id, LogBiz.LOG_TYPE_UPDATE, LogBiz.LOG_AREA_FIND, staff);
            } else {
                result = ResultJsonUtil.json(info);
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            result = ResultJsonUtil.json(SERVER_ERROR);
            e.printStackTrace();
        }
        return result;
    }
    /** 
     * 新增评价
     * @auth  zhaorui
     * @date 2018年11月7日14:30:42
     * @return
     */
    @Override
    public JSONObject addEvaluate(JSONObject param) {
        JSONObject result = new JSONObject();    
        try {
            Map<String, Object> map = new HashMap<String, Object>();
//            map.put("userId", "userId");
            map.put("specialCode", "specialCode");
            map.put("evaluateDes", "evaluateDes");
            map.put("brandId", "brandId");
            
            
            String info = StringUtil.validataParam(param, map);
            if (success.equals(info)) {
                String staff = param.getString("staff");
                String brandId = param.getString("brandId");
                String evaluateUserId = param.getString("userId");
                //查询后台新增评价专用id
                SystemParameters systemParameters=systemParametersDao.selectEvaluateUserId();
                if(StringUtils.isBlank(evaluateUserId)) {
                    evaluateUserId=systemParameters.getParam7();
                }
                VipUserTop userTop=vipUserTopDao.selectByUserId(evaluateUserId);
                if(userTop==null) {
                    result = ResultJsonUtil.json(USER__ROLE_ERROR);
                    return result;
                }
                String evaluateDes = URLDecoder.decode(param.getString("evaluateDes"), "UTF-8");
                
                
                String specialCode = param.getString("specialCode");
                
                SpecialInfo specialInfo = specialInfoDao.selectSpecialNameBySpecialCode(specialCode);
                if(specialInfo!=null) {
                    String specialName =specialInfo.getSpecialName();
                    String specialId =specialInfo.getId();
                    String evaluateId = UUIDUtil.generateUUID();
                    
                    EvaluateInfo evaluateInfo=new EvaluateInfo();
                    evaluateInfo.setId(evaluateId);
                    evaluateInfo.setUserId(evaluateUserId);
                    evaluateInfo.setCreateName(staff);
                    evaluateInfo.setSpecialName(specialName);
                    evaluateInfo.setEvaluateDes(evaluateDes);
                    evaluateInfo.setSpecialId(specialId);
                    evaluateInfo.setSpecialCode(specialCode);
                    evaluateInfo.setCreateDate(new Date());
                    evaluateInfo.setEvaluateStatus(status_enable);
                    evaluateInfo.setStatus(status_normal);
                    evaluateInfo.setBrandId(brandId);
                    evaluateInfoDao.insertSelective(evaluateInfo);
                    
                    //添加评价图片
                    List<EvaluateImg> imgList = new ArrayList<EvaluateImg>();
                    String evaluateImgList = param.getString("evaluateImgList");
                    JSONArray imgs = JSONArray.parseArray(evaluateImgList);
                    for (int i = 0; i < imgs.size(); i++) {
                    
                        String imgUrl = JSONObject.parseObject(JSONObject.toJSONString(imgs.get(i)))
                                .getString("imgUrl");
                        EvaluateImg evaluateImg=new EvaluateImg();
                        evaluateImg.setEvaluateId(evaluateId);
                        evaluateImg.setImgUrl(imgUrl);
                        evaluateImg.setSort(i+1);
                        imgList.add(evaluateImg);
                        
                    }
                    if (imgList != null && !imgList.isEmpty()) {
                        
                        if(imgList.size()>9) {
                            
                            result = ResultJsonUtil.json(IMG_ERRPR);
                            return result;
                        }
                        
                        // 批量插入
                        evaluateImgDao.insertList(imgList);
                    }
                    
                    result = ResultJsonUtil.json(SUCCESS);
                }else {
                    result = ResultJsonUtil.json(SPECIALNULL_ERROR);
                    return result;
                }
            
                
            }else {

                result = ResultJsonUtil.json(info);
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            result = ResultJsonUtil.json(SERVER_ERROR);
            e.printStackTrace();
        }
        
        
        return result;
    }
    /** 
     * 批量更新评价状态
     * @auth  zhaorui
     * @date 2018年11月7日15:19:40
     * @return
     */
    @Override
    public JSONObject updateAllEvaluate(JSONObject param) {
        JSONObject result = new JSONObject();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("evaluateIdList", "evaluateIdList");
            map.put("evaluateStatus", "evaluateStatus");
            
            
            String info = StringUtil.validataParam(param, map);
            if (success.equals(info)) {
                Integer evaluateStatus = param.getInteger("evaluateStatus");
                List<EvaluateInfo> evaluateList = new ArrayList<EvaluateInfo>();
                String evaluateIdList = param.getString("evaluateIdList");
                JSONArray ids = JSONArray.parseArray(evaluateIdList);
                for (int i = 0; i < ids.size(); i++) {
                    String id = JSONObject.parseObject(JSONObject.toJSONString(ids.get(i)))
                            .getString("id");
                    EvaluateInfo evaluateInfo=new EvaluateInfo();
                    evaluateInfo.setId(id);
                    evaluateInfo.setEvaluateStatus(evaluateStatus);
                    evaluateList.add(evaluateInfo);
                    
                }
                if (evaluateList != null && !evaluateList.isEmpty()) {
                    // 批量更新
                    evaluateInfoDao.updateAllById(evaluateList,evaluateStatus);
                }
                result = ResultJsonUtil.json(SUCCESS);
            }else {

                result = ResultJsonUtil.json(info);
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            result = ResultJsonUtil.json(SERVER_ERROR);
            e.printStackTrace();
        }
        return result;
    }
    
    /** 
      * 查询评价用户
      * @auth  zhaorui
      * @date 2018年12月3日16:45:54
      * @return
      */
    @Override
    public JSONObject queryEvaluateUser(JSONObject param) {
        JSONObject result = new JSONObject();
        Map<String, Object> map = new HashMap<String, Object>();

        String info = StringUtil.validataParam(param, map);

        if (success.equals(info)) {
            Integer pageIndex = param.getInteger("pageIndex");
            pageIndex = pageIndex == null ? 1 : pageIndex;
            Integer pageSize = param.getInteger("pageSize");
            pageSize = pageSize == null ? SIZE : pageSize;

            if (pageSize < 0 || pageSize > 50) {// 每页显示记录数最大 100,默认显示10
                pageSize = SIZE;
            }
            
            List<VipUserTopVo> userList = new ArrayList<VipUserTopVo>();
            PageHelper.startPage(pageIndex, pageSize);
            userList = vipUserTopDao.selectUserList(param);
            PageInfo<VipUserTopVo> pages = new PageInfo<>(userList);
            map.put("hasNext", pages.isHasNextPage());
            map.put("total", pages.getTotal());
            map.put("pageNum", pages.getPageNum());
            map.put("pages", pages.getPages());
            
            map.put("userList", pages.getList());

            result = ResultJsonUtil.json(map, SUCCESS);
            
        } else {
            result = ResultJsonUtil.json(info);
        }
        
        
        return result;
    }
    
    
    /** 
      * 查询品牌
      * @auth  zhaorui
      * @date 2018年12月10日15:34:03
      * @return
      */
    @Override
    public JSONObject queryBrand(JSONObject param) {
        JSONObject result = new JSONObject();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("specialCode", "specialCode");
        String info = StringUtil.validataParam(param, map);

        if (success.equals(info)) {
            Map<String, Object> map1 = new HashMap<>();
            Integer pageIndex = param.getInteger("pageIndex");
            pageIndex = pageIndex == null ? 1 : pageIndex;
            Integer pageSize = param.getInteger("pageSize");
            pageSize = pageSize == null ? SIZE : pageSize;

            if (pageSize < 0 || pageSize > 50) {// 每页显示记录数最大 100,默认显示10
                pageSize = SIZE;
            }
            String specialCode = param.getString("specialCode");
            SpecialInfo specialInfo = specialInfoDao.selectSpecialNameBySpecialCode(specialCode);
            if(specialInfo!=null) {
                List<BrandInfo> brand=brandInfoDao.selectBySpecialCode(specialCode);
                
                map1.put("brand", brand);
                result = ResultJsonUtil.json(map1, SUCCESS);
            }else {
                result = ResultJsonUtil.json(SPECIALNULL_ERROR);
                return result;
            }
            
        }else {
            result = ResultJsonUtil.json(info);
        }
        return result;
    }
    
    /** 
     * 新增评价绑定品牌
     * @auth  zhaorui
     * @date 2018年12月10日15:32:22
     * @return
     */
    @Override
    public JSONObject addEvaluate2(JSONObject param) {
        JSONObject result = new JSONObject();    
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("specialCode", "specialCode");
            map.put("evaluateDes", "evaluateDes");
            map.put("brandId", "brandId");
            
            String info = StringUtil.validataParam(param, map);
            if (success.equals(info)) {
                String staff = param.getString("staff");
                String evaluateUserId = param.getString("userId");
                String brandId = param.getString("brandId");
                //查询后台新增评价专用id
                SystemParameters systemParameters=systemParametersDao.selectEvaluateUserId();
                if(StringUtils.isBlank(evaluateUserId)) {
                    evaluateUserId=systemParameters.getParam7();
                }
                VipUserTop userTop=vipUserTopDao.selectByUserId(evaluateUserId);
                if(userTop==null) {
                    result = ResultJsonUtil.json(USER__ROLE_ERROR);
                    return result;
                }
                String evaluateDes = URLDecoder.decode(param.getString("evaluateDes"), "UTF-8");
                
                
                String specialCode = param.getString("specialCode");
                
                SpecialInfo specialInfo = specialInfoDao.selectSpecialNameBySpecialCode(specialCode);
                if(specialInfo!=null) {
                    String evaluateId = UUIDUtil.generateUUID();
                    EvaluateInfo evaluateInfo=new EvaluateInfo();
                    evaluateInfo.setId(evaluateId);
                    evaluateInfo.setUserId(evaluateUserId);
                    evaluateInfo.setCreateName(staff);
                    evaluateInfo.setSpecialName(specialInfo.getSpecialName());
                    evaluateInfo.setEvaluateDes(evaluateDes);
                    evaluateInfo.setSpecialId(specialInfo.getId());
                    evaluateInfo.setSpecialCode(specialCode);
                    evaluateInfo.setCreateDate(new Date());
                    evaluateInfo.setEvaluateStatus(status_enable);
                    evaluateInfo.setStatus(status_normal);
                    evaluateInfo.setBrandId(brandId);
                    evaluateInfo.setScId(specialInfo.getScId());
                    evaluateInfo.setSlId(specialInfo.getSlId());
                    evaluateInfoDao.insertSelective(evaluateInfo);
                    
                    //添加评价图片
                    List<EvaluateImg> imgList = new ArrayList<EvaluateImg>();
                    String evaluateImgList = param.getString("evaluateImgList");
                    JSONArray imgs = JSONArray.parseArray(evaluateImgList);
                    for (int i = 0; i < imgs.size(); i++) {
                    
                        String imgUrl = JSONObject.parseObject(JSONObject.toJSONString(imgs.get(i)))
                                .getString("imgUrl");
                        EvaluateImg evaluateImg=new EvaluateImg();
                        evaluateImg.setEvaluateId(evaluateId);
                        evaluateImg.setImgUrl(imgUrl);
                        evaluateImg.setSort(i+1);
                        imgList.add(evaluateImg);
                        
                    }
                    if (imgList != null && !imgList.isEmpty()) {
                        
                        if(imgList.size()>9) {
                            
                            result = ResultJsonUtil.json(IMG_ERRPR);
                            return result;
                        }
                        
                        // 批量插入
                        evaluateImgDao.insertList(imgList);
                    }
                    
                    result = ResultJsonUtil.json(SUCCESS);
                }else {
                    result = ResultJsonUtil.json(SPECIALNULL_ERROR);
                    return result;
                }
            
                
            }else {

                result = ResultJsonUtil.json(info);
            }
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            result = ResultJsonUtil.json(SERVER_ERROR);
            e.printStackTrace();
        }
        
        
        return result;
    }
    
    
    
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值