Commit c77e605f authored by wangyihao's avatar wangyihao

新增 mapper 修改推荐员工

parent 75a36aea
package cn.com.fqy.controller.mapi; package cn.com.fqy.controller.mapi;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -44,15 +45,15 @@ public class IndexController { ...@@ -44,15 +45,15 @@ public class IndexController {
*/ */
@RequestMapping("getAdvertList") @RequestMapping("getAdvertList")
@ResponseBody @ResponseBody
public ResultInfo<List<Map<String,Object>>> getAdvertList() { public ResultInfo<List<Map<String, Object>>> getAdvertList() {
ResultInfo<List<Map<String,Object>>> resultInfo = new ResultInfo<>(); ResultInfo<List<Map<String, Object>>> resultInfo = new ResultInfo<>();
List<Map<String,Object>> listQuery = new ArrayList<>(); List<Map<String, Object>> listQuery = new ArrayList<>();
Advert advert = new Advert(); Advert advert = new Advert();
advert.setIsAvailable(1); // 可用 advert.setIsAvailable(1); // 可用
List<Advert> advList = advertService.getAdvertList(new Query(advert)); List<Advert> advList = advertService.getAdvertList(new Query(advert));
if (null != advList && advList.size() > 0) { if (null != advList && advList.size() > 0) {
for(Advert list:advList) { for (Advert list : advList) {
Map<String,Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("advertId", list.getAdvertId()); map.put("advertId", list.getAdvertId());
map.put("advertPicUrl", list.getAdvertPicUrl()); map.put("advertPicUrl", list.getAdvertPicUrl());
map.put("advertContent", list.getAdvertContent()); map.put("advertContent", list.getAdvertContent());
...@@ -76,19 +77,19 @@ public class IndexController { ...@@ -76,19 +77,19 @@ public class IndexController {
@ResponseBody @ResponseBody
public ResultInfo<List<Store>> getStoreList(Store store) { public ResultInfo<List<Store>> getStoreList(Store store) {
ResultInfo<List<Store>> resultInfo = new ResultInfo<List<Store>>(); ResultInfo<List<Store>> resultInfo = new ResultInfo<List<Store>>();
List<Store> listQuery = new ArrayList<>(); List<Store> listQuery = new ArrayList<>();
store.setIsDeleted(0); // 未删除 store.setIsDeleted(0); // 未删除
store.setIsAuditing(1); // 店铺启用状态 store.setIsAuditing(1); // 店铺启用状态
store.setIsShopping(1); // 店铺展示状态 store.setIsShopping(1); // 店铺展示状态
List<Store> stoList= storeService.getStoreList(new Query(store)); List<Store> stoList = storeService.getStoreList(new Query(store));
if (null != stoList && stoList.size() > 0) { if (null != stoList && stoList.size() > 0) {
int number =0; int number = 0;
if(stoList.size()>3) { if (stoList.size() > 3) {
number =3; number = 3;
}else { } else {
number=stoList.size(); number = stoList.size();
} }
for(int i=0;i<number;i++) { for (int i = 0; i < number; i++) {
listQuery.add(stoList.get(i)); listQuery.add(stoList.get(i));
} }
resultInfo.setData(listQuery); resultInfo.setData(listQuery);
...@@ -106,25 +107,42 @@ public class IndexController { ...@@ -106,25 +107,42 @@ public class IndexController {
*/ */
@RequestMapping("getWorkerList") @RequestMapping("getWorkerList")
@ResponseBody @ResponseBody
public ResultInfo<List<Worker>> getWorkerList(Worker worker) { public ResultInfo<List<Worker>> getWorkerList(String cityId) {
ResultInfo<List<Worker>> resultInfo = new ResultInfo<List<Worker>>(); ResultInfo<List<Worker>> resultInfo = new ResultInfo<List<Worker>>();
List<Worker> listQuery = new ArrayList<>(); List<Worker> listQuery = new ArrayList<>();
worker.setIsDeleted(0); // 未删除 List<String> stoListQuery = new ArrayList<>();
worker.setIsShopping(1); // 员工展示状态 if (cityId == null || "".equals(cityId)) {
worker.setIsAuditing(1); resultInfo.setCode("0");
List<Worker> workerList = workerService.getWorkerList(new Query(worker)); resultInfo.setMsg("市 ID 参数为空");
return resultInfo;
}
Store store = new Store();
store.setCityId(cityId);
// 通过城市ID查询返回店铺ID
List<Store> stoList = storeService.getStoreList(new Query(store));
if (stoList != null && stoList.size() > 0) {
for (Store list : stoList) {
stoListQuery.add(list.getStoreId());
}
} else {
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg("暂无数据");
return resultInfo;
}
// 将storeId的集合转换数组
String[] strArray = stoListQuery.toArray(new String[stoListQuery.size()]);
// 通过storeId查询返回员工列表
List<Worker> workerList = workerService.getWorkerSByIds(strArray);
if (null != workerList && workerList.size() > 0) { if (null != workerList && workerList.size() > 0) {
int number =0; int number = 0;
if(workerList.size()>9) { if (workerList.size() > 9) {
number =9; number = 9;
}else { } else {
number=workerList.size(); number = workerList.size();
}
for (int i = 0; i < number; i++) {
listQuery.add(workerList.get(i));
} }
for(int i=0;i<number;i++) {
listQuery.add(workerList.get(i));
}
resultInfo.setData(listQuery); resultInfo.setData(listQuery);
resultInfo.setCode(Constant.SUCCESS); resultInfo.setCode(Constant.SUCCESS);
resultInfo.setMsg("请求成功"); resultInfo.setMsg("请求成功");
......
package cn.com.fqy.core.dao; package cn.com.fqy.core.dao;
import java.util.List;
import cn.com.fqy.core.common.BaseDao; import cn.com.fqy.core.common.BaseDao;
import cn.com.fqy.core.model.Worker; import cn.com.fqy.core.model.Worker;
...@@ -7,5 +9,10 @@ import cn.com.fqy.core.model.Worker; ...@@ -7,5 +9,10 @@ import cn.com.fqy.core.model.Worker;
* Worker 数据库处理类 * Worker 数据库处理类
*/ */
public interface WorkerDao extends BaseDao<Worker,String> { public interface WorkerDao extends BaseDao<Worker,String> {
/**
* 根据 一组ID 查询返回一个对象集合
* @param ids
* @return
*/
public List<Worker> getWorkerByIds(String[] ids);
} }
...@@ -78,4 +78,11 @@ public interface WorkerService extends BaseService { ...@@ -78,4 +78,11 @@ public interface WorkerService extends BaseService {
*/ */
public void fillDefaultValues(Worker obj); public void fillDefaultValues(Worker obj);
/**
* 根据 一组ID 查询返回一个对象集合
* @param ids
* @return
*/
public List<Worker> getWorkerSByIds(String[] ids);
} }
...@@ -295,5 +295,29 @@ public class WorkerServiceImpl implements WorkerService { ...@@ -295,5 +295,29 @@ public class WorkerServiceImpl implements WorkerService {
} }
} }
} }
/**
* 根据主键数组,查询并返回一组Worker对象
* @param ids 主键数组,数组中的主键值应当无重复值,如有重复值时,则返回的列表长度可能小于传入的数组长度
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public List<Worker> getWorkerSByIds(String[] ids) {
List<Worker> list = null;
if (ids == null || ids.length == 0) {
log.info(Constant.ERR_MSG_INVALID_ARG + " ids is null or empty array.");
} else {
try {
//调用dao,根据主键数组查询
list = workerDao.getWorkerByIds(ids);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
return list;
}
} }
...@@ -246,6 +246,16 @@ UPDATE_TIME,OPERATOR_ID,OPERATOR_TYPE,SERIAL_NUMBER,IS_DELETED,STORE_NAME,BRIEF ...@@ -246,6 +246,16 @@ UPDATE_TIME,OPERATOR_ID,OPERATOR_TYPE,SERIAL_NUMBER,IS_DELETED,STORE_NAME,BRIEF
</where> </where>
</select> </select>
<select id="getWorkerByIds" resultMap="Worker">
select <include refid="AllColumnlist"/> from T_WORKER
<where>
STORE_ID in <foreach item="item" index="index" collection="array" open="(" separator="," close=")">#{item}</foreach>
AND IS_DELETED=0
AND IS_AUDITING=1
AND IS_SHOPPING=1
</where>
</select>
<select id="getByIds" resultMap="Worker"> <select id="getByIds" resultMap="Worker">
select <include refid="AllColumnlist"/> from T_WORKER select <include refid="AllColumnlist"/> from T_WORKER
<where> <where>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment