Skip to content

Commit

Permalink
加入友好的数据显示
Browse files Browse the repository at this point in the history
  • Loading branch information
reedmi committed Mar 18, 2015
1 parent f2a829c commit 5f1cfac
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.originspark.drp.models.projects.invoices.StockInInvoice;
import com.originspark.drp.util.enums.Status;
import com.originspark.drp.util.json.FilterRequest;
import com.originspark.drp.util.json.IdsJson;
import com.originspark.drp.util.json.JsonUtils;
Expand Down Expand Up @@ -55,7 +56,6 @@ public String update(@PathVariable Long id, @RequestBody StockInInvoice invoice)
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String list(@RequestParam int start, @RequestParam int limit, @RequestParam(required = false) Object filter) {

List<FilterRequest> filters = new ArrayList<FilterRequest>();

if (filter != null) {
Expand All @@ -74,28 +74,25 @@ public String deleteBatch() {
String data = request().getParameter("data");
ObjectMapper mapper = new ObjectMapper();
IdsJson json = null;

try {
json = mapper.readValue(data, IdsJson.class);
} catch (Exception e) {
return failure("提交数据有误");
}

if (json == null) {
return failure("没有需要删除的数据");
}

for (Long id : json.getIds()) {
if(id==null){
continue;
}
StockInInvoice invoice = stockInInvoiceService.findById(StockInInvoice.class, id);

if(invoice != null && invoice.getCosts().isEmpty()){
stockInInvoiceService.delete(invoice);
logger.info(">删除成功:"+invoice.toString());
invoice.setStatus(Status.DESTORYED);
stockInInvoiceService.update(invoice);
}

}
return ok("删除成功(注释:部分合价不为0的入库单已忽略)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.originspark.drp.models.projects.invoices.StockOutInvoice;
import com.originspark.drp.util.enums.Status;
import com.originspark.drp.util.json.FilterRequest;
import com.originspark.drp.util.json.IdsJson;
import com.originspark.drp.util.json.JsonUtils;
Expand Down Expand Up @@ -46,19 +47,17 @@ public String deleteBatch(HttpServletRequest request) {
} catch (Exception e) {
return failure("提交数据有误");
}

if (json == null) {
return failure("没有需要审核的数据");
}

for (Long id : json.getIds()) {
if(id == null){
continue;
}
StockOutInvoice invoice = stockOutInvoiceService.findById(StockOutInvoice.class, id);
if (invoice != null && invoice.getCosts().isEmpty()) {
stockOutInvoiceService.delete(invoice);
logger.info(">删除成功:" + invoice.toString());
invoice.setStatus(Status.DESTORYED);
stockOutInvoiceService.update(invoice);
}
}
return ok("删除成功(注释:部分合价不为0的入库单已忽略)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.originspark.drp.models.resources.Ware;
import com.originspark.drp.util.FileUtil;
import com.originspark.drp.util.SessionUtil;
import com.originspark.drp.util.enums.Status;
import com.originspark.drp.util.json.FilterRequest;
import com.originspark.drp.util.json.IdsJson;
import com.originspark.drp.util.json.JsonUtils;
Expand Down Expand Up @@ -73,8 +74,8 @@ public String create(@RequestBody Ware ware) {

@RequestMapping(value = "/deleteBatch", method = RequestMethod.GET)
@ResponseBody
public String deleteBatch(HttpServletRequest request) {
String data = request.getParameter("data");
public String deleteBatch() {
String data = request().getParameter("data");
ObjectMapper mapper = new ObjectMapper();
IdsJson json = null;
try {
Expand All @@ -87,10 +88,9 @@ public String deleteBatch(HttpServletRequest request) {
}
for (long id : json.getIds()) {
Ware ware = wareService.findById(Ware.class, id);

if(ware != null && ware.getInCosts().isEmpty() && ware.getOutCosts().isEmpty() && ware.getInventories().isEmpty()){
wareService.delete(ware);
logger.info(">删除成功:"+ware.toString());
ware.setStatus(Status.DESTORYED);
wareService.save(ware);
}
}
return ok("删除成功");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public List<StockInCost> pagedDataSet(int start, int limit,
if (predicates != null) {
dataQuery.where(cb.and(predicates));
}
dataQuery.orderBy(cb.desc(stockInCost.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public List<StockOutCost> pagedDataSet(int start, int limit,
dataQuery.where(cb.and(predicates));
}

dataQuery.orderBy(cb.desc(stockOutCost.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class InventoryServiceBean extends BaseDAOSupport implements InventorySer
// 实时库存量统计
final String CURRENT_SUM_SQL = "SELECT t3.name, t3.model, t3.unit, t3.brand, t1.outcome, t1.incount, t2.income, t2.outcount FROM "
+ CURRENT_IN_SQL + " LEFT JOIN " + CURRENT_OUT_SQL + " ON t1.wid = t2.wid"
+ " JOIN wares as t3 WHERE t1.wid = t3.id";
+ " JOIN wares as t3 WHERE t1.wid = t3.id ORDER BY t2.income - t1.outcome DESC";
// 实时库存量总数计算
final String CURRENT_COUNT = "SELECT COUNT(DISTINCT(ware)) FROM cost_stock_in";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<StockInInvoice> pagedDataSet(int start, int limit,
Root<StockInInvoice> stockin = dataQuery.from(StockInInvoice.class);

dataQuery.select(stockin);

StockInCost[] inCosts = findByWareName(filters);
if(inCosts == null){
return null;
Expand All @@ -56,8 +56,7 @@ public List<StockInInvoice> pagedDataSet(int start, int limit,
dataQuery.where(cb.and(andPredicates),cb.or(orPredicates));
}
}

dataQuery.orderBy(cb.desc(stockin.get("forDate")));
dataQuery.orderBy(cb.asc(stockin.get("status")), cb.desc(stockin.get("forDate")), cb.desc(stockin.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
Expand All @@ -69,14 +68,14 @@ public Long pagedDataCount(List<FilterRequest> filters) {
CriteriaQuery<Long> countQuery = cb.createQuery(Long.class);
Root<StockInInvoice> stockin = countQuery.from(StockInInvoice.class);
countQuery.select(cb.count(stockin));

StockInCost[] inCosts = findByWareName(filters);
if(inCosts == null){
return 0L;
}

List<Predicate[]> predicates = toPredicates(cb, stockin, filters, findByWareName(filters));

if (predicates != null) {
Predicate[] andPredicates = predicates.get(0);
Predicate[] orPredicates = predicates.get(1);
Expand All @@ -85,10 +84,9 @@ public Long pagedDataCount(List<FilterRequest> filters) {
}else if(andPredicates.length == 0 && orPredicates.length != 0){
countQuery.where(cb.or(orPredicates));
}else{
countQuery.where(cb.and(andPredicates),cb.or(orPredicates));
countQuery.where(cb.and(andPredicates), cb.or(orPredicates));
}
}

return em.createQuery(countQuery).getSingleResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.originspark.drp.models.projects.invoices.AbstractInvoice.COLUMNS;
import com.originspark.drp.models.projects.invoices.StockOutInvoice;
import com.originspark.drp.util.StringUtil;
import com.originspark.drp.util.enums.AuditState;
import com.originspark.drp.util.json.FilterRequest;

@Transactional
Expand All @@ -37,14 +36,14 @@ public List<StockOutInvoice> pagedDataSet(int start, int limit,
Root<StockOutInvoice> stockout = dataQuery.from(StockOutInvoice.class);

dataQuery.select(stockout);

StockOutCost[] outCosts = findByWareName(filters);
if(outCosts == null){
return null;
}

List<Predicate[]> predicates = toPredicates(cb, stockout, filters, outCosts);

if (predicates != null) {
Predicate[] andPredicates = predicates.get(0);
Predicate[] orPredicates = predicates.get(1);
Expand All @@ -57,8 +56,8 @@ public List<StockOutInvoice> pagedDataSet(int start, int limit,
}
}

dataQuery.orderBy(cb.desc(stockout.get("forDate")));
dataQuery.orderBy(cb.asc(stockout.get("status")), cb.desc(stockout.get("forDate")), cb.desc(stockout.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import com.originspark.drp.dao.BaseDAOSupport;
import com.originspark.drp.models.resources.Vendor;
import com.originspark.drp.models.resources.Ware;
import com.originspark.drp.models.resources.Vendor.COLUMNS;
import com.originspark.drp.util.json.FilterRequest;

Expand All @@ -37,6 +36,8 @@ public List<Vendor> pagedDataSet(int start, int limit, List<FilterRequest> filte
dataQuery.where(cb.and(predicates));
}

dataQuery.orderBy(cb.asc(vendor.get("status")), cb.desc(vendor.get("id")));

return em.createQuery(dataQuery).
setFirstResult(start).
setMaxResults(limit).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.originspark.drp.service.resources;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.originspark.drp.dao.BaseDAOSupport;
import com.originspark.drp.models.resources.WareCategory;

Expand All @@ -19,16 +13,8 @@ public class WareCategoryServiceBean extends BaseDAOSupport<WareCategory> implem

@Override
public List<WareCategory> treeViewData() {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<WareCategory> dataQuery = cb.createQuery(WareCategory.class);

Root<WareCategory> category = dataQuery.from(WareCategory.class);

dataQuery.select(category);

dataQuery.where(cb.isNull(category.get("parent")));

return em.createQuery(dataQuery).getResultList();
String sql = "from WareCategory where parent is null order by status asc, id desc";
return em.createQuery(sql, WareCategory.class).getResultList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public List<Ware> pagedDataSet(int start, int limit,
if (predicates != null) {
dataQuery.where(cb.and(predicates));
}
dataQuery.orderBy(cb.desc(ware.get("id")));

dataQuery.orderBy(cb.asc(ware.get("status")), cb.desc(ware.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public List<User> pagedDataSet(int start, int limit,List<FilterRequest> filters)
dataQuery.where(cb.and(predicates));
}

dataQuery.orderBy(cb.asc(user.get("status")), cb.desc(user.get("id")));

return em.createQuery(dataQuery).setFirstResult(start)
.setMaxResults(limit).getResultList();
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/drp/app/controller/AbstractController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Ext.define("drp.app.controller.AbstractController", {
grid.getStore().load();
},
failure : function(response, operation) {
if(response.status == 404) {
Ext.Msg.alert("操作失败", "服务器出现错误,请联系管理员.");
}
Ext.Msg.alert("失败!", operation.request.scope.reader.jsonData["message"]);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ Ext.define('drp.app.view.projects.inventories.CurrentInventoryView', {
flex : 1,
text : '盈余'
}],
viewConfig : {
listeners: {
refresh: function(grid) {
var nodes = grid.getNodes();
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var record = grid.getRecord(node);
var cells = Ext.get(node).query('td');
var restcount = record.get('restcount');
if(restcount < 10) {
Ext.fly(cells[5]).setStyle('background-color', '#FFCCCC');
}
var profit = record.get('profit');
if(profit < 0) {
Ext.fly(cells[8]).setStyle('background-color', '#FF0033');
}
}
}
}
},
dockedItems : [{
xtype : 'pagingtoolbar',
dock : 'bottom',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ Ext.define('drp.app.view.projects.invoices.StockInInvoiceView', {
flex : 2,
text : '经手人'
}],
viewConfig : {
listeners: {
refresh: function(grid) {
var nodes = grid.getNodes();
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var record = grid.getRecord(node);
var cells = Ext.get(node).query('td');
var status = record.get('status');
if(status == 'DESTORYED') {
for(var j = 0; j < cells.length; j++) {
Ext.fly(cells[j]).setStyle('background-color', '#FFCCCC');
}
}
}
}
}
},
dockedItems : [{
xtype : 'pagingtoolbar',
dock : 'bottom',
Expand All @@ -177,7 +195,7 @@ Ext.define('drp.app.view.projects.invoices.StockInInvoiceView', {
action : 'showAddInInvoiceUI',
itemId : 'addInInvoice_btn',
text : '增加'
}, {
}, '-', {
xtype : 'button',
icon : 'resources/images/icons/delete.png',
action : 'deleteInInvoice',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ Ext.define('drp.app.view.projects.invoices.StockOutInvoiceView', {
flex : 2,
text : '经手人'
}],
viewConfig : {
listeners: {
refresh: function(grid) {
var nodes = grid.getNodes();
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
var record = grid.getRecord(node);
var cells = Ext.get(node).query('td');
var status = record.get('status');
if(status == 'DESTORYED') {
for(var j = 0; j < cells.length; j++) {
Ext.fly(cells[j]).setStyle('background-color', '#FFCCCC');
}
}
}
}
}
},
dockedItems : [{
xtype : 'pagingtoolbar',
dock : 'bottom',
Expand All @@ -182,7 +200,7 @@ Ext.define('drp.app.view.projects.invoices.StockOutInvoiceView', {
action : 'showAddOutInvoiceUI',
itemId : 'addOutInvoice_btn',
text : '增加'
}, {
}, '-', {
xtype : 'button',
icon : 'resources/images/icons/delete.png',
action : 'deleteOutInvoice',
Expand Down
Loading

0 comments on commit 5f1cfac

Please sign in to comment.