喻健
2018-11-29 2c2837073e599812dc5a5f7d0605d7a61b6d270b
客服问题编辑
1个文件已添加
5个文件已修改
491 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/customerservice/CustomerServiceCommonQuestionAdminController.java 274 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/customerservice/CustomerServiceCommonQuestionMapper.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/entity/customerservice/CustomerServiceCommonQuestion.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/customerservice/CustomerServiceCommonQuestionMapper.xml 59 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/customerservice/CustomerServiceCommonQuestionServiceImpl.java 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/customerservice/CustomerServiceCommonQuestionService.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/customerservice/CustomerServiceCommonQuestionAdminController.java
New file
@@ -0,0 +1,274 @@
package com.yeshi.fanli.controller.admin.customerservice;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.common.AdminUser;
import com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion;
import com.yeshi.fanli.exception.CustomerServiceCommonQuestionException;
import com.yeshi.fanli.service.AdminUserService;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.annotation.RequestNoLogin;
@Controller
@RequestMapping("admin/new/api/v1/commonQuestion")
public class CustomerServiceCommonQuestionAdminController {
    @Resource
    private AdminUserService adminUserService;
    @Resource
    private CustomerServiceCommonQuestionService commonQuestionService;
    /**
     * 新增
     * @param callback
     * @param special
     * @param out
     */
    @RequestNoLogin()
    @RequestMapping(value = "save")
    public void saveAdd(String callback, long uid, CustomerServiceCommonQuestion commonQuestion,
            HttpServletResponse response, PrintWriter out) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        try {
            AdminUser admin = adminUserService.selectByPrimaryKey(uid);
            if (admin == null) {
                out.print(JsonUtil.loadFalseResult("当前账户验证失败"));
                return;
            }
            commonQuestionService.save(commonQuestion);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("添加成功"));
        } catch (CustomerServiceCommonQuestionException e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    /**
     * 修改
     * @param callback
     * @param special
     * @param out
     */
    @RequestMapping(value = "getInfo")
    public void getInfo(String callback, Long id,  PrintWriter out) {
        if (id == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
            return;
        }
        try {
            CustomerServiceCommonQuestion commonQuestion = commonQuestionService.selectByPrimaryKey(id);
            if (commonQuestion == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("数据已不存在"));
                return;
            }
            JSONObject data = new JSONObject();
            data.put("result", commonQuestion);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取信息失败"));
            e.printStackTrace();
        }
    }
    /**
     * 修改
     * @param callback
     * @param special
     * @param out
     */
    @RequestMapping(value = "saveWeight")
    public void saveWeight(String callback, Long id, Integer weight, PrintWriter out) {
        if (id == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
            return;
        }
        try {
            CustomerServiceCommonQuestion commonQuestion = commonQuestionService.selectByPrimaryKey(id);
            if (commonQuestion == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("数据已不存在"));
                return;
            }
            commonQuestion.setWeight(weight);
            commonQuestion.setUpdateTime(new Date());
            commonQuestionService.updateByPrimaryKeySelective(commonQuestion);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("修改失败"));
            e.printStackTrace();
        }
    }
    /**
     * 修该状态
     * @param callback
     * @param id
     * @param out
     */
    @RequestMapping(value = "updateState")
    public void updateState(String callback, Long id, PrintWriter out) {
        try {
            if (id == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
                return;
            }
            CustomerServiceCommonQuestion resultObj = commonQuestionService.selectByPrimaryKey(id);
            if (resultObj == null) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作数据已不存在"));
                return;
            }
            boolean state = resultObj.isState();
            if (state) {
                resultObj.setState(false);
            } else {
                resultObj.setState(true);
            }
            commonQuestionService.updateByPrimaryKeySelective(resultObj);
            JSONObject data = new JSONObject();
            data.put("state",  resultObj.isState());
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    /**
     * 查询
     * @param callback
     * @param pageIndex
     * @param pageSize
     * @param key  模糊查询:说明、标识
     * @param out
     */
    @RequestMapping(value = "query")
    public void query(String callback, Integer pageIndex, Integer pageSize, String key,
            String type, Integer state, Integer sort, PrintWriter out) {
        if (pageIndex == null || pageIndex < 1) {
            pageIndex = 1;
        }
        if (pageSize == null || pageSize < 1) {
            pageSize = Constant.PAGE_SIZE;
        }
        try {
            List<CustomerServiceCommonQuestion> list = commonQuestionService.listQuery((pageIndex - 1) * pageSize, pageSize,
                    key, type, state, sort);
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
                return;
            }
            long count = commonQuestionService.countQuery(key, type, state);
            int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
            PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.serializeNulls();
            Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
            JSONObject data = new JSONObject();
            data.put("pe", pe);
            data.put("result_list", gson.toJson(list));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
            e.printStackTrace();
        }
    }
    /**
     * 删除
     * @param callback
     * @param idArray
     * @param out
     */
    @RequestMapping(value = "delete")
    public void delete(String callback, String idArray, PrintWriter out) {
        try {
            if (StringUtil.isNullOrEmpty(idArray)) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择操作的数据"));
                return;
            }
            Gson gson = new Gson();
            List<Long> list = gson.fromJson(idArray, new TypeToken<ArrayList<Long>>() {}.getType());
            if (list == null || list.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检测到删除的数据"));
                return;
            }
            int count = commonQuestionService.deleteBatchByPrimaryKey(list);
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("成功删除["+ count +"]条数据"));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("删除失败"));
            e.printStackTrace();
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/customerservice/CustomerServiceCommonQuestionMapper.java
@@ -10,6 +10,8 @@
    int deleteByPrimaryKey(Long id);
    int deleteBatchByPrimaryKey(List<Long> list);
    int insert(CustomerServiceCommonQuestion record);
    int insertSelective(CustomerServiceCommonQuestion record);
@@ -40,4 +42,25 @@
    int updateByPrimaryKey(CustomerServiceCommonQuestion record);
    
    List<String> selectKeys();
    /**
     * 后端查询列表
     * @param start
     * @param count
     * @param key
     * @param type
     * @param state
     * @return
     */
    List<CustomerServiceCommonQuestion> listQuery(@Param("start") long start, @Param("count") int count,
            @Param("key")String key, @Param("type")String type,
            @Param("state") Integer state, @Param("sort") Integer sort);
    /**
     * 统计
     * @param key
     * @param type
     * @param state
     * @return
     */
    long countQuery(@Param("key")String key, @Param("type")String type, @Param("state") Integer state);
}
fanli/src/main/java/com/yeshi/fanli/entity/customerservice/CustomerServiceCommonQuestion.java
@@ -32,14 +32,21 @@
    @Expose
    @Column(name = "cscq_content_type")
    private String contentType;
    // 是否启用
    @Column(name = "cscq_state")
    private boolean state;
    @Column(name = "cscq_weight")
    private Integer weight;
    @Column(name = "cscq_createtime")
    private Date createTime;
    @Column(name = "cscq_updatetime")
    private Date updateTime;
    //显示选择项
    // 显示选择项
    @Expose
    private boolean showChoice;
@@ -106,4 +113,13 @@
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public boolean isState() {
        return state;
    }
    public void setState(boolean state) {
        this.state = state;
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/customerservice/CustomerServiceCommonQuestionMapper.xml
@@ -10,12 +10,13 @@
        <result column="cscq_content_type" property="contentType"
            jdbcType="VARCHAR" />
        <result column="cscq_weight" property="weight" jdbcType="INTEGER" />
        <result column="cscq_state" property="state" jdbcType="VARCHAR"/>
        <result column="cscq_createtime" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="cscq_updatetime" property="updateTime"
            jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">cscq_id,cscq_key,cscq_content,cscq_content_type,cscq_weight,cscq_createtime,cscq_updatetime
    <sql id="Base_Column_List">cscq_id,cscq_key,cscq_content,cscq_content_type,cscq_weight,cscq_state,cscq_createtime,cscq_updatetime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
@@ -51,10 +52,9 @@
    </select>
    <select id="selectKeys" resultType="java.lang.String">
        select
        cscq_key
        from
        yeshi_ec_customer_service_common_question order by cscq_weight desc
        select cscq_key from yeshi_ec_customer_service_common_question
        where cscq_state = 1
        order by cscq_weight desc
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
@@ -65,9 +65,9 @@
        parameterType="com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_customer_service_common_question
        (cscq_id,cscq_key,cscq_content,cscq_content_type,cscq_weight,cscq_createtime,cscq_updatetime)
        (cscq_id,cscq_key,cscq_content,cscq_content_type,cscq_weight,cscq_state,cscq_createtime,cscq_updatetime)
        values
        (#{id,jdbcType=BIGINT},#{key,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{contentType,jdbcType=VARCHAR},#{weight,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
        (#{id,jdbcType=BIGINT},#{key,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{contentType,jdbcType=VARCHAR},#{weight,jdbcType=INTEGER},#{state,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion"
@@ -79,6 +79,7 @@
            <if test="content != null">cscq_content,</if>
            <if test="contentType != null">cscq_content_type,</if>
            <if test="weight != null">cscq_weight,</if>
            <if test="state != null">cscq_state,</if>
            <if test="createTime != null">cscq_createtime,</if>
            <if test="updateTime != null">cscq_updatetime,</if>
        </trim>
@@ -89,6 +90,7 @@
            <if test="content != null">#{content,jdbcType=VARCHAR},</if>
            <if test="contentType != null">#{contentType,jdbcType=VARCHAR},</if>
            <if test="weight != null">#{weight,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
@@ -98,7 +100,8 @@
        cscq_key = #{key,jdbcType=VARCHAR},cscq_content =
        #{content,jdbcType=VARCHAR},cscq_content_type =
        #{contentType,jdbcType=VARCHAR},cscq_weight =
        #{weight,jdbcType=INTEGER},cscq_createtime =
        #{weight,jdbcType=INTEGER},
        cscq_state =#{state,jdbcType=VARCHAR},cscq_createtime =
        #{createTime,jdbcType=TIMESTAMP},cscq_updatetime =
        #{updateTime,jdbcType=TIMESTAMP} where cscq_id =
        #{id,jdbcType=BIGINT}
@@ -111,9 +114,49 @@
            <if test="content != null">cscq_content=#{content,jdbcType=VARCHAR},</if>
            <if test="contentType != null">cscq_content_type=#{contentType,jdbcType=VARCHAR},</if>
            <if test="weight != null">cscq_weight=#{weight,jdbcType=INTEGER},</if>
            <if test="state != null">cscq_state=#{state,jdbcType=VARCHAR},</if>
            <if test="createTime != null">cscq_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">cscq_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where cscq_id = #{id,jdbcType=BIGINT}
    </update>
     <select id="listQuery" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />  FROM yeshi_ec_customer_service_common_question
        WHERE 1=1
           <if test='key != null and key != ""'>
               AND (cscq_key like '%${key}%' or cscq_content like '%${key}%')
           </if>
           <if test='type != null and type != ""'>
               AND cscq_content_type
           </if>
           ORDER BY
              <if test="sort == 1">
                      cscq_weight,
              </if>
              <if test="sort == 2">
                      cscq_weight desc,
              </if>
              cscq_createtime desc
        LIMIT ${start},${count}
   </select>
   <select id="countQuery" resultType="java.lang.Long">
        SELECT IFNULL(count(cscq_id),0)  FROM yeshi_ec_customer_service_common_question
        WHERE 1=1
            <if test='key != null and key != ""'>
               AND (cscq_key like '%${key}%' or cscq_content like '%${key}%')
           </if>
           <if test='type != null and type != ""'>
               AND cscq_content_type
           </if>
    </select>
      <delete id="deleteBatchByPrimaryKey" parameterType="java.util.List">
        delete from yeshi_ec_customer_service_common_question WHERE cscq_id in
        <foreach collection="list" item="item" open="(" close=")"
            separator=",">#{item}</foreach>
    </delete>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/customerservice/CustomerServiceCommonQuestionServiceImpl.java
@@ -2,17 +2,18 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.dao.mybatis.customerservice.CustomerServiceCommonQuestionMapper;
import com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion;
import com.yeshi.fanli.exception.CustomerServiceCommonQuestionException;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService;
import org.yeshi.utils.StringUtil;
@Service
public class CustomerServiceCommonQuestionServiceImpl implements CustomerServiceCommonQuestionService {
@@ -82,5 +83,83 @@
    public Long countCustomerServiceCommonQuestion() {
        return customerServiceCommonQuestionMapper.selectCount();
    }
    @Override
    public List<CustomerServiceCommonQuestion> listQuery(long start, int count, String key,
            String type, Integer state, Integer sort){
        return customerServiceCommonQuestionMapper.listQuery(start, count, key, type, state, sort);
    }
    @Override
    public long countQuery(String key, String type, Integer state) {
        return customerServiceCommonQuestionMapper.countQuery(key, type, state);
    }
    @Override
    public int deleteBatchByPrimaryKey(List<Long> list) {
        return customerServiceCommonQuestionMapper.deleteBatchByPrimaryKey(list);
    }
    @Override
    public int insert(CustomerServiceCommonQuestion record) {
        return customerServiceCommonQuestionMapper.insert(record);
    }
    @Override
    public int insertSelective(CustomerServiceCommonQuestion record) {
        return customerServiceCommonQuestionMapper.insertSelective(record);
    }
    @Override
    public int updateByPrimaryKeySelective(CustomerServiceCommonQuestion record) {
        return customerServiceCommonQuestionMapper.updateByPrimaryKeySelective(record);
    }
    @Override
    public int updateByPrimaryKey(CustomerServiceCommonQuestion record) {
        return customerServiceCommonQuestionMapper.updateByPrimaryKey(record);
    }
    @Override
    public CustomerServiceCommonQuestion selectByPrimaryKey(Long id) {
        return customerServiceCommonQuestionMapper.selectByPrimaryKey(id);
    }
    @Override
    public void save(CustomerServiceCommonQuestion record) throws Exception, CustomerServiceCommonQuestionException {
        if (record == null) {
            throw new  CustomerServiceCommonQuestionException(1, "参数不能为空");
        }
        String key = record.getKey();
        String content = record.getContent();
        String contentType = record.getContentType();
        if (key == null || key.trim().length() == 0 || content == null || content.trim().length() == 0
                || contentType == null || contentType.trim().length() == 0) {
            throw new  CustomerServiceCommonQuestionException(1, "编辑内容不能为空");
        }
        Long id = record.getId();
        if (id == null) {
            // 新增
            record.setWeight(0);
            record.setCreateTime(new Date());
            record.setUpdateTime(new Date());
            customerServiceCommonQuestionMapper.insert(record);
        } else {
            CustomerServiceCommonQuestion commonQuestion = customerServiceCommonQuestionMapper.selectByPrimaryKey(id);
            if (commonQuestion == null) {
                throw new  CustomerServiceCommonQuestionException(1, "数据已不存在");
            }
            // 修改
            record.setUpdateTime(new Date());
            // 保存之前的状态
            record.setState(commonQuestion.isState());
            customerServiceCommonQuestionMapper.updateByPrimaryKeySelective(record);
        }
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/customerservice/CustomerServiceCommonQuestionService.java
@@ -69,4 +69,38 @@
     */
    public Long countCustomerServiceCommonQuestion();
    CustomerServiceCommonQuestion selectByPrimaryKey(Long id);
    int deleteBatchByPrimaryKey(List<Long> list);
    int insert(CustomerServiceCommonQuestion record);
    int insertSelective(CustomerServiceCommonQuestion record);
    int updateByPrimaryKeySelective(CustomerServiceCommonQuestion record);
    int updateByPrimaryKey(CustomerServiceCommonQuestion record);
    /**
     * 后台查询列表
     * @param start
     * @param count
     * @param key 关键词 、内容搜索
     * @param type 类型
     * @param state 状态
     * @param sort 排序: 1权重低到高  2权重高到低
     * @return
     */
    public List<CustomerServiceCommonQuestion> listQuery(long start, int count, String key, String type,
            Integer state, Integer sort);
    public long countQuery(String key, String type, Integer state);
    /**
     * 保存
     * @param record
     * @throws CustomerServiceCommonQuestionException
     */
    public void save(CustomerServiceCommonQuestion record) throws Exception, CustomerServiceCommonQuestionException;
}