Commit 9c5bc464 authored by wyh's avatar wyh

新增 批量

parent 0a146a21
package cn.com.fqy.controller.mapi;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.fqy.common.ResultInfo;
import cn.com.fqy.common.constants.Constant;
import cn.com.fqy.core.common.PageFinder;
import cn.com.fqy.core.model.Advert;
import cn.com.fqy.core.model.Query;
import cn.com.fqy.core.model.Store;
import cn.com.fqy.core.model.Worker;
......@@ -67,8 +67,9 @@ public class WebWorkerController {
*/
@RequestMapping("workerDetails")
@ResponseBody
public ResultInfo<Worker> workerDetails(String workerId){
ResultInfo<Worker> resultInfo = new ResultInfo<>();
public ResultInfo<Map<String,Object>> workerDetails(String workerId){
ResultInfo<Map<String,Object>> resultInfo = new ResultInfo<>();
Map<String,Object> map = new HashMap<>();
if(workerId == null || "".equals(workerId)) {
resultInfo.setCode("0");
resultInfo.setMsg("员工参数为空");
......@@ -76,8 +77,38 @@ public class WebWorkerController {
}
Worker res = workerService.getWorker(workerId);
if (null != res ) {
Store store = storeService.getStore(res.getStoreId());
if(null != store) {
map.put("workerId",res.getWorkerId());
map.put("workerName",res.getWorkerName());
map.put("workerAge",res.getWorkerAge());
map.put("workerNumber",res.getWorkerNumber());
map.put("workerBirthday",res.getWorkerBirthday());
map.put("workerAncestral",res.getWorkerAncestral());
map.put("workerBust",res.getWorkerBust());
map.put("workerHeight",res.getWorkerHeight());
map.put("workerHipline",res.getWorkerHipline());
map.put("workerHomePic",res.getWorkerHomePic());
map.put("workerPic",res.getWorkerPic());
map.put("workerResume",res.getWorkerResume());
map.put("workerSex",res.getWorkerSex());
map.put("workerWaist",res.getWorkerWaist());
map.put("workerWeight",res.getWorkerWeight());
map.put("storeId",res.getStoreId());
map.put("brief",res.getBrief());
map.put("clicks",res.getClicks());
map.put("matureTime",res.getMatureTime());
map.put("serialNumber",res.getSerialNumber());
map.put("storeName",res.getStoreName());
map.put("storeBrief",store.getBrief());
map.put("storeCityName",store.getCityName());
map.put("storeProvince",store.getProvince());
map.put("storeCounty",store.getCounty());
map.put("storeHomePic",store.getStoreHomePic());
map.put("storePosition",store.getStorePosition());
}
resultInfo.setCode("1");
resultInfo.setData(res);
resultInfo.setData(map);
}else {
resultInfo.setCode("0");
resultInfo.setMsg("员工信息丢失");
......
......@@ -114,4 +114,25 @@ public class WorkerController extends BaseController {
}
return result;
}
/**
* 批量审核
* @param workerIds
* @return
*/
@RequestMapping("batchWorkers")
@ResponseBody
public ResultInfo<Worker> batchWorkers(String[] workerIds) {
return workerService.batchWorkerUpdate(workerIds, getOperator());
}
/**
* 批量展示
* @param workerIds
* @return
*/
@RequestMapping("batchWorkerShop")
@ResponseBody
public ResultInfo<Worker> batchWorkerShop(String[] workerIds) {
return workerService.batchWorkerShopping(workerIds, getOperator());
}
}
package cn.com.fqy.core.service;
import java.util.List;
import cn.com.fqy.common.Operator;
import cn.com.fqy.common.ResultInfo;
import cn.com.fqy.core.common.BaseService;
import cn.com.fqy.core.common.PageFinder;
import cn.com.fqy.core.model.Query;
import cn.com.fqy.core.model.Worker;
/**
* Worker 服务接口类
*/
public interface WorkerService extends BaseService {
/**
* 根据查询条件,查询并返回Worker的列表
* @param q 查询条件
* @return
*/
public List<Worker> getWorkerList(Query q);
/**
* 根据查询条件,分页查询并返回Worker的分页结果
* @param q 查询条件
* @return
*/
public PageFinder<Worker> getWorkerPagedList(Query q);
/**
* 根据主键,查询并返回一个Worker对象
* @param id 主键id
* @return
*/
public Worker getWorker(String id);
/**
* 根据主键数组,查询并返回一组Worker对象
* @param ids 主键数组,数组中的主键值应当无重复值,如有重复值时,则返回的列表长度可能小于传入的数组长度
* @return
*/
public List<Worker> getWorkerByIds(String[] ids);
/**
* 根据主键,删除特定的Worker记录
* @param id 主键id
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> delWorker(String id, Operator operator);
/**
* 新增一条Worker记录,执行成功后传入对象及返回对象的主键属性值不为null
* @param worker 新增的Worker数据(如果无特殊需求,新增对象的主键值请保留为null)
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> addWorker(Worker worker, Operator operator);
/**
* 根据主键,更新一条Worker记录
* @param worker 更新的Worker数据,且其主键不能为空
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> updateWorker(Worker worker, Operator operator);
/**
* 生成主键
* @return
*/
public String generatePK();
/**
* 为Worker对象设置默认值
* @param obj
*/
public void fillDefaultValues(Worker obj);
/**
* 根据 一组ID 查询返回一个对象集合
* @param ids
* @return
*/
public List<Worker> getWorkerSByIds(String[] ids);
}
package cn.com.fqy.core.service;
import java.util.List;
import cn.com.fqy.common.Operator;
import cn.com.fqy.common.ResultInfo;
import cn.com.fqy.core.common.BaseService;
import cn.com.fqy.core.common.PageFinder;
import cn.com.fqy.core.model.Query;
import cn.com.fqy.core.model.SysUser;
import cn.com.fqy.core.model.Worker;
/**
* Worker 服务接口类
*/
public interface WorkerService extends BaseService {
/**
* 根据查询条件,查询并返回Worker的列表
* @param q 查询条件
* @return
*/
public List<Worker> getWorkerList(Query q);
/**
* 根据查询条件,分页查询并返回Worker的分页结果
* @param q 查询条件
* @return
*/
public PageFinder<Worker> getWorkerPagedList(Query q);
/**
* 根据主键,查询并返回一个Worker对象
* @param id 主键id
* @return
*/
public Worker getWorker(String id);
/**
* 根据主键数组,查询并返回一组Worker对象
* @param ids 主键数组,数组中的主键值应当无重复值,如有重复值时,则返回的列表长度可能小于传入的数组长度
* @return
*/
public List<Worker> getWorkerByIds(String[] ids);
/**
* 根据主键,删除特定的Worker记录
* @param id 主键id
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> delWorker(String id, Operator operator);
/**
* 新增一条Worker记录,执行成功后传入对象及返回对象的主键属性值不为null
* @param worker 新增的Worker数据(如果无特殊需求,新增对象的主键值请保留为null)
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> addWorker(Worker worker, Operator operator);
/**
* 根据主键,更新一条Worker记录
* @param worker 更新的Worker数据,且其主键不能为空
* @param operator 操作人对象
* @return
*/
public ResultInfo<Worker> updateWorker(Worker worker, Operator operator);
/**
* 生成主键
* @return
*/
public String generatePK();
/**
* 为Worker对象设置默认值
* @param obj
*/
public void fillDefaultValues(Worker obj);
/**
* 根据 一组ID 查询返回一个对象集合
* @param ids
* @return
*/
public List<Worker> getWorkerSByIds(String[] ids);
/**
* 根据 一组ID 修改一组数据
* @param workerId
* @return
*/
public ResultInfo<Worker> batchWorkerUpdate(String[] workerIds,Operator operator);
public ResultInfo<Worker> batchWorkerShopping(String[] workerIds,Operator operator);
}
package cn.com.fqy.core.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import cn.com.fqy.common.Operator;
import cn.com.fqy.common.ResultInfo;
import cn.com.fqy.common.constants.Constant;
import cn.com.fqy.core.common.PageFinder;
import cn.com.fqy.core.dao.WorkerDao;
import cn.com.fqy.core.model.Query;
import cn.com.fqy.core.model.Worker;
import cn.com.fqy.core.service.WorkerService;
/**
* Worker 服务实现类
*/
@Service
public class WorkerServiceImpl implements WorkerService {
private static final Log log = LogFactory.getLog(WorkerServiceImpl.class);
@Resource
private WorkerDao workerDao;
/**
* 根据查询条件,查询并返回Worker的列表
* @param q 查询条件
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public List<Worker> getWorkerList(Query q) {
List<Worker> list = null;
try {
//直接调用Dao方法进行查询
list = workerDao.queryAll(q);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
return list;
}
/**
* 根据查询条件,分页查询并返回Worker的分页结果
* @param q 查询条件
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public PageFinder<Worker> getWorkerPagedList(Query q) {
PageFinder<Worker> page = new PageFinder<Worker>();
List<Worker> list = null;
long rowCount = 0L;
try {
//调用dao查询满足条件的分页数据
list = workerDao.pageList(q);
//调用dao统计满足条件的记录总数
rowCount = workerDao.count(q);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
//将分页数据和记录总数设置到分页结果对象中
page.setData(list);
page.setRowCount(rowCount);
page.setPageSize(q.getPageSize());
return page;
}
/**
* 根据主键,查询并返回一个Worker对象
* @param id 主键id
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public Worker getWorker(String id) {
Worker obj = null;
if (id == null || id.length() == 0) { //传入的主键无效时直接返回null
log.info(Constant.ERR_MSG_INVALID_ARG + " id = " + id);
return obj;
}
try {
//调用dao,根据主键查询
obj = workerDao.get(id);
if(null != obj) {
if(obj.getClicks()== null || "".equals(obj.getClicks())) {
obj.setClicks(0);
}
Worker worker = new Worker();
worker.setWorkerId(obj.getWorkerId());
worker.setClicks(obj.getClicks()+1);
workerDao.update(worker);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return obj;
}
/**
* 根据主键数组,查询并返回一组Worker对象
* @param ids 主键数组,数组中的主键值应当无重复值,如有重复值时,则返回的列表长度可能小于传入的数组长度
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public List<Worker> getWorkerByIds(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.getByIds(ids);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
return list;
}
/**
* 根据主键,删除特定的Worker记录
* @param id 主键id
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> delWorker(String id, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (id == null || id.length() == 0) { //传入的主键无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " id = " + id);
return resultInfo;
}
try {
//调用Dao执行删除,并判断删除语句执行结果
int count = workerDao.delete(id);
if (count > 0) {
resultInfo.setCode(Constant.SUCCESS);
} else {
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_DATA_NOT_EXISTS);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
return resultInfo;
}
/**
* 新增一条Worker记录,执行成功后传入对象及返回对象的主键属性值不为null
* @param worker 新增的Worker数据(如果无特殊需求,新增对象的主键值请保留为null)
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> addWorker(Worker worker, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (worker == null) { //传入参数无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " worker = " + worker);
} else {
try {
//如果传入参数的主键为null,则调用生成主键的方法获取新的主键
if (worker.getWorkerId() == null || "".equals(worker.getWorkerId())) {
worker.setWorkerId(this.generatePK());
}
//如果传入的操作人不为null,则设置新增记录的操作人类型和操作人id
if (operator != null) {
worker.setOperatorType(operator.getOperatorType());
worker.setOperatorId(operator.getOperatorId());
}
//设置创建时间和更新时间为当前时间
Date now = new Date();
worker.setCreateTime(now);
worker.setUpdateTime(now);
//填充默认值
this.fillDefaultValues(worker);
//调用Dao执行插入操作
workerDao.add(worker);
resultInfo.setCode(Constant.SUCCESS);
resultInfo.setData(worker);
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
}
return resultInfo;
}
/**
* 根据主键,更新一条Worker记录
* @param worker 更新的Worker数据,且其主键不能为空
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> updateWorker(Worker worker, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (worker == null || worker.getWorkerId() == null) { //传入参数无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " worker = " + worker);
} else {
try {
//如果传入的操作人不为null,则设置更新记录的操作人类型和操作人id
if (operator != null) {
worker.setOperatorType(operator.getOperatorType());
worker.setOperatorId(operator.getOperatorId());
}
//设置更新时间为当前时间
worker.setUpdateTime(new Date());
//调用Dao执行更新操作,并判断更新语句执行结果
int count = workerDao.update(worker);
if (count > 0) {
resultInfo.setCode(Constant.SUCCESS);
} else {
resultInfo.setCode(Constant.FAIL);
}
resultInfo.setData(worker);
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
}
return resultInfo;
}
/**
* 生成主键
* @return
*/
public String generatePK() {
return String.valueOf(new Date().getTime() * 1000000 + new Random().nextInt(1000000));
}
/**
* 为Worker对象设置默认值
* @param obj
*/
public void fillDefaultValues(Worker obj) {
if (obj != null) {
if(obj.getIsAuditing() == null) {
obj.setIsAuditing(0);
}
if(obj.getIsDeleted() == null) {
obj.setIsDeleted(0);
}
if(obj.getIsShopping() == null) {
obj.setIsShopping(0);
}
if(obj.getIsRecommend() == null) {
obj.setIsRecommend(0);
}
}
}
/**
* 根据主键数组,查询并返回一组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;
}
}
package cn.com.fqy.core.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import cn.com.fqy.common.Operator;
import cn.com.fqy.common.ResultInfo;
import cn.com.fqy.common.constants.Constant;
import cn.com.fqy.core.common.PageFinder;
import cn.com.fqy.core.dao.WorkerDao;
import cn.com.fqy.core.model.Query;
import cn.com.fqy.core.model.SysUser;
import cn.com.fqy.core.model.Worker;
import cn.com.fqy.core.service.WorkerService;
/**
* Worker 服务实现类
*/
@Service
public class WorkerServiceImpl implements WorkerService {
private static final Log log = LogFactory.getLog(WorkerServiceImpl.class);
@Resource
private WorkerDao workerDao;
/**
* 根据查询条件,查询并返回Worker的列表
* @param q 查询条件
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public List<Worker> getWorkerList(Query q) {
List<Worker> list = null;
try {
//直接调用Dao方法进行查询
list = workerDao.queryAll(q);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
return list;
}
/**
* 根据查询条件,分页查询并返回Worker的分页结果
* @param q 查询条件
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public PageFinder<Worker> getWorkerPagedList(Query q) {
PageFinder<Worker> page = new PageFinder<Worker>();
List<Worker> list = null;
long rowCount = 0L;
try {
//调用dao查询满足条件的分页数据
list = workerDao.pageList(q);
//调用dao统计满足条件的记录总数
rowCount = workerDao.count(q);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
//将分页数据和记录总数设置到分页结果对象中
page.setData(list);
page.setRowCount(rowCount);
page.setPageSize(q.getPageSize());
return page;
}
/**
* 根据主键,查询并返回一个Worker对象
* @param id 主键id
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public Worker getWorker(String id) {
Worker obj = null;
if (id == null || id.length() == 0) { //传入的主键无效时直接返回null
log.info(Constant.ERR_MSG_INVALID_ARG + " id = " + id);
return obj;
}
try {
//调用dao,根据主键查询
obj = workerDao.get(id);
if(null != obj) {
if(obj.getClicks()== null || "".equals(obj.getClicks())) {
obj.setClicks(0);
}
Worker worker = new Worker();
worker.setWorkerId(obj.getWorkerId());
worker.setClicks(obj.getClicks()+1);
workerDao.update(worker);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return obj;
}
/**
* 根据主键数组,查询并返回一组Worker对象
* @param ids 主键数组,数组中的主键值应当无重复值,如有重复值时,则返回的列表长度可能小于传入的数组长度
* @return
*/
@Transactional(propagation = Propagation.SUPPORTS)
public List<Worker> getWorkerByIds(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.getByIds(ids);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
//如list为null时,则改为返回一个空列表
list = list == null ? new ArrayList<Worker>(0) : list;
return list;
}
/**
* 根据主键,删除特定的Worker记录
* @param id 主键id
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> delWorker(String id, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (id == null || id.length() == 0) { //传入的主键无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " id = " + id);
return resultInfo;
}
try {
//调用Dao执行删除,并判断删除语句执行结果
int count = workerDao.delete(id);
if (count > 0) {
resultInfo.setCode(Constant.SUCCESS);
} else {
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_DATA_NOT_EXISTS);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
return resultInfo;
}
/**
* 新增一条Worker记录,执行成功后传入对象及返回对象的主键属性值不为null
* @param worker 新增的Worker数据(如果无特殊需求,新增对象的主键值请保留为null)
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> addWorker(Worker worker, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (worker == null) { //传入参数无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " worker = " + worker);
} else {
try {
//如果传入参数的主键为null,则调用生成主键的方法获取新的主键
if (worker.getWorkerId() == null || "".equals(worker.getWorkerId())) {
worker.setWorkerId(this.generatePK());
}
//如果传入的操作人不为null,则设置新增记录的操作人类型和操作人id
if (operator != null) {
worker.setOperatorType(operator.getOperatorType());
worker.setOperatorId(operator.getOperatorId());
}
//设置创建时间和更新时间为当前时间
Date now = new Date();
worker.setCreateTime(now);
worker.setUpdateTime(now);
//填充默认值
this.fillDefaultValues(worker);
//调用Dao执行插入操作
workerDao.add(worker);
resultInfo.setCode(Constant.SUCCESS);
resultInfo.setData(worker);
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
}
return resultInfo;
}
/**
* 根据主键,更新一条Worker记录
* @param worker 更新的Worker数据,且其主键不能为空
* @param operator 操作人对象
* @return
*/
@Transactional
public ResultInfo<Worker> updateWorker(Worker worker, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
if (worker == null || worker.getWorkerId() == null) { //传入参数无效时直接返回失败结果
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_INVALID_ARG );
log.info(Constant.ERR_MSG_INVALID_ARG + " worker = " + worker);
} else {
try {
//如果传入的操作人不为null,则设置更新记录的操作人类型和操作人id
if (operator != null) {
worker.setOperatorType(operator.getOperatorType());
worker.setOperatorId(operator.getOperatorId());
}
//设置更新时间为当前时间
worker.setUpdateTime(new Date());
//调用Dao执行更新操作,并判断更新语句执行结果
int count = workerDao.update(worker);
if (count > 0) {
resultInfo.setCode(Constant.SUCCESS);
} else {
resultInfo.setCode(Constant.FAIL);
}
resultInfo.setData(worker);
} catch (Exception e) {
log.error(e.getMessage(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
resultInfo.setCode(Constant.FAIL);
resultInfo.setMsg(Constant.ERR_MSG_EXCEPTION_CATCHED);
}
}
return resultInfo;
}
/**
* 生成主键
* @return
*/
public String generatePK() {
return String.valueOf(new Date().getTime() * 1000000 + new Random().nextInt(1000000));
}
/**
* 为Worker对象设置默认值
* @param obj
*/
public void fillDefaultValues(Worker obj) {
if (obj != null) {
if(obj.getIsAuditing() == null) {
obj.setIsAuditing(0);
}
if(obj.getIsDeleted() == null) {
obj.setIsDeleted(0);
}
if(obj.getIsShopping() == null) {
obj.setIsShopping(0);
}
if(obj.getIsRecommend() == null) {
obj.setIsRecommend(0);
}
}
}
/**
* 根据主键数组,查询并返回一组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;
}
@Override
public ResultInfo<Worker> batchWorkerUpdate(String[] workerIds,Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
for (String id : workerIds) {
Worker worker =new Worker();
worker.setWorkerId(id);
worker.setIsAuditing(1);
resultInfo = updateWorker(worker,operator);
}
return resultInfo;
}
@Override
public ResultInfo<Worker> batchWorkerShopping(String[] workerIds, Operator operator) {
ResultInfo<Worker> resultInfo = new ResultInfo<Worker>();
for (String id : workerIds) {
Worker worker =new Worker();
worker.setWorkerId(id);
worker.setIsShopping(1);;
resultInfo = updateWorker(worker,operator);
}
return resultInfo;
}
}
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